Skip to content

Commit bf35753

Browse files
authored
Merge pull request #7897 from multiversx/quarantined-headers-detection
added new cache for quarantined headers on late proofs
2 parents daf5c49 + 817c54f commit bf35753

30 files changed

Lines changed: 607 additions & 13 deletions

cmd/node/config/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@
619619
Type = "SizeLRU"
620620
SizeInBytes = 52428800 # 50MB
621621

622+
[QuarantinedHeadersCache]
623+
Name = "QuarantinedHeadersCache"
624+
Capacity = 100
625+
Type = "SizeLRU"
626+
SizeInBytes = 10485760 # 10MB
627+
622628
[PostProcessTransactionsCache]
623629
Name = "PostProcessTransactionsCache"
624630
Capacity = 250000

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ type Config struct {
227227
SmartContractDataPool CacheConfig
228228
ValidatorInfoPool CacheConfig
229229
ExecutedMiniBlocksCache CacheConfig
230+
QuarantinedHeadersCache CacheConfig
230231
PostProcessTransactionsCache CacheConfig
231232
HeaderBodyCacheConfig HeaderBodyCacheConfig
232233
TrieSyncStorage TrieSyncStorageConfig

dataRetriever/dataPool/dataPool.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type dataPool struct {
3030
executedMiniBlocks storage.Cacher
3131
postProcessTransactions storage.Cacher
3232
directSentTransactions storage.Cacher
33+
quarantinedHeaders storage.Cacher
3334
}
3435

3536
// DataPoolArgs represents the data pool's constructor structure
@@ -52,6 +53,7 @@ type DataPoolArgs struct {
5253
ExecutedMiniBlocks storage.Cacher
5354
PostProcessTransactions storage.Cacher
5455
DirectSentTransactions storage.Cacher
56+
QuarantinedHeaders storage.Cacher
5557
}
5658

5759
// NewDataPool creates a data pools holder object
@@ -110,6 +112,9 @@ func NewDataPool(args DataPoolArgs) (*dataPool, error) {
110112
if check.IfNil(args.DirectSentTransactions) {
111113
return nil, dataRetriever.ErrNilDirectSentTransactionsCache
112114
}
115+
if check.IfNil(args.QuarantinedHeaders) {
116+
return nil, dataRetriever.ErrNilQuarantinedHeadersCache
117+
}
113118

114119
return &dataPool{
115120
transactions: args.Transactions,
@@ -130,6 +135,7 @@ func NewDataPool(args DataPoolArgs) (*dataPool, error) {
130135
executedMiniBlocks: args.ExecutedMiniBlocks,
131136
postProcessTransactions: args.PostProcessTransactions,
132137
directSentTransactions: args.DirectSentTransactions,
138+
quarantinedHeaders: args.QuarantinedHeaders,
133139
}, nil
134140
}
135141

@@ -223,6 +229,11 @@ func (dp *dataPool) PostProcessTransactions() storage.Cacher {
223229
return dp.postProcessTransactions
224230
}
225231

232+
// QuarantinedHeaders returns the holder for quarantined header hashes (late-arriving equivalent proofs)
233+
func (dp *dataPool) QuarantinedHeaders() storage.Cacher {
234+
return dp.quarantinedHeaders
235+
}
236+
226237
// Close closes all the components
227238
func (dp *dataPool) Close() error {
228239
var lastError error

dataRetriever/dataPool/dataPool_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func createMockDataPoolArgs() dataPool.DataPoolArgs {
3737
ExecutedMiniBlocks: cache.NewCacherStub(),
3838
PostProcessTransactions: cache.NewCacherStub(),
3939
DirectSentTransactions: cache.NewCacherStub(),
40+
QuarantinedHeaders: cache.NewCacherStub(),
4041
}
4142
}
4243

@@ -216,6 +217,17 @@ func TestNewDataPool_NilPostProcessTransactionsShouldErr(t *testing.T) {
216217
require.Equal(t, dataRetriever.ErrNilPostProcessTransactionsCache, err)
217218
}
218219

220+
func TestNewDataPool_NilQuarantinedHeadersShouldErr(t *testing.T) {
221+
t.Parallel()
222+
223+
args := createMockDataPoolArgs()
224+
args.QuarantinedHeaders = nil
225+
tdp, err := dataPool.NewDataPool(args)
226+
227+
require.Nil(t, tdp)
228+
require.Equal(t, dataRetriever.ErrNilQuarantinedHeadersCache, err)
229+
}
230+
219231
func TestNewDataPool_NilCurrEpochValidatorInfoShouldErr(t *testing.T) {
220232
t.Parallel()
221233

@@ -253,6 +265,7 @@ func TestNewDataPool_OkValsShouldWork(t *testing.T) {
253265
assert.True(t, args.ExecutedMiniBlocks == tdp.ExecutedMiniBlocks())
254266
assert.True(t, args.PostProcessTransactions == tdp.PostProcessTransactions())
255267
assert.True(t, args.DirectSentTransactions == tdp.DirectSentTransactions())
268+
assert.True(t, args.QuarantinedHeaders == tdp.QuarantinedHeaders())
256269
}
257270

258271
func TestNewDataPool_Close(t *testing.T) {

dataRetriever/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ var ErrNilPostProcessTransactionsCache = errors.New("nil post process transactio
275275
// ErrNilDirectSentTransactionsCache signals that a nil direct-sent transactions cache has been provided
276276
var ErrNilDirectSentTransactionsCache = errors.New("nil direct sent transactions cache")
277277

278+
// ErrNilQuarantinedHeadersCache signals that a nil quarantined headers cache has been provided
279+
var ErrNilQuarantinedHeadersCache = errors.New("nil quarantined headers cache")
280+
278281
// ErrEquivalentProofsNotFound signals that no equivalent proof found
279282
var ErrEquivalentProofsNotFound = errors.New("equivalent proof not found")
280283

dataRetriever/factory/dataPoolFactory.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func NewDataPoolFromConfig(args ArgsDataPool) (dataRetriever.PoolsHolder, error)
162162
return nil, fmt.Errorf("%w while creating the cache for the executed mini blocks", err)
163163
}
164164

165+
cacherCfg = factory.GetCacherFromConfig(mainConfig.QuarantinedHeadersCache)
166+
quarantinedHeaders, err := storageunit.NewCache(cacherCfg)
167+
if err != nil {
168+
return nil, fmt.Errorf("%w while creating the cache for the quarantined headers", err)
169+
}
170+
165171
cacherCfg = factory.GetCacherFromConfig(mainConfig.PostProcessTransactionsCache)
166172
postProcessTransactionsCache, err := storageunit.NewCache(cacherCfg)
167173
if err != nil {
@@ -195,6 +201,7 @@ func NewDataPoolFromConfig(args ArgsDataPool) (dataRetriever.PoolsHolder, error)
195201
ExecutedMiniBlocks: executedMiniBlocksCache,
196202
PostProcessTransactions: postProcessTransactionsCache,
197203
DirectSentTransactions: directSentTransactionsCache,
204+
QuarantinedHeaders: quarantinedHeaders,
198205
}
199206
return dataPool.NewDataPool(dataPoolArgs)
200207
}

dataRetriever/factory/dataPoolFactory_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ func TestNewDataPoolFromConfig_BadConfigShouldErr(t *testing.T) {
144144
require.True(t, errors.Is(err, storage.ErrNotSupportedCacheType))
145145
require.True(t, strings.Contains(err.Error(), "the cache for the executed mini blocks"))
146146

147+
args = getGoodArgs()
148+
args.Config.QuarantinedHeadersCache.Type = "invalid cache type"
149+
holder, err = NewDataPoolFromConfig(args)
150+
require.Nil(t, holder)
151+
require.True(t, errors.Is(err, storage.ErrNotSupportedCacheType))
152+
require.True(t, strings.Contains(err.Error(), "the cache for the quarantined headers"))
153+
147154
args = getGoodArgs()
148155
args.Config.PostProcessTransactionsCache.Type = "invalid cache type"
149156
holder, err = NewDataPoolFromConfig(args)

dataRetriever/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ type PoolsHolder interface {
268268
ExecutedMiniBlocks() storage.Cacher
269269
PostProcessTransactions() storage.Cacher
270270
DirectSentTransactions() storage.Cacher
271+
QuarantinedHeaders() storage.Cacher
271272
Close() error
272273
IsInterfaceNil() bool
273274
}

factory/mock/blockTrackerStub.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type BlockTrackerStub struct {
4040
RestoreToGenesisCalled func()
4141
ShouldAddHeaderCalled func(headerHandler data.HeaderHandler) bool
4242
ComputeOwnShardStuckCalled func(lastExecutionResultsInfo data.BaseExecutionResultHandler, currentNonce uint64)
43+
IsHeaderQuarantinedCalled func(hash []byte) bool
4344
}
4445

4546
// AddTrackedHeader -
@@ -309,6 +310,19 @@ func (bts *BlockTrackerStub) ComputeOwnShardStuck(lastExecutionResultsInfo data.
309310
}
310311
}
311312

313+
// IsHeaderQuarantined -
314+
func (bts *BlockTrackerStub) IsHeaderQuarantined(hash []byte) bool {
315+
if bts.IsHeaderQuarantinedCalled != nil {
316+
return bts.IsHeaderQuarantinedCalled(hash)
317+
}
318+
return false
319+
}
320+
321+
// Close -
322+
func (bts *BlockTrackerStub) Close() error {
323+
return nil
324+
}
325+
312326
// IsInterfaceNil -
313327
func (bts *BlockTrackerStub) IsInterfaceNil() bool {
314328
return bts == nil

factory/processing/processComponents.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,9 @@ func (pc *processComponents) Close() error {
21922192
if !check.IfNil(pc.aotSelector) {
21932193
log.LogIfError(pc.aotSelector.Close())
21942194
}
2195+
if !check.IfNil(pc.blockTracker) {
2196+
log.LogIfError(pc.blockTracker.Close())
2197+
}
21952198

21962199
return nil
21972200
}

0 commit comments

Comments
 (0)