Skip to content

Commit 47e31ca

Browse files
committed
cleanup wrong type records, add tests
1 parent 817c54f commit 47e31ca

6 files changed

Lines changed: 193 additions & 35 deletions

File tree

integrationTests/testProcessorNode.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import (
3131
ed25519SingleSig "github.com/multiversx/mx-chain-crypto-go/signing/ed25519/singlesig"
3232
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
3333
mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig"
34-
"github.com/multiversx/mx-chain-go/testscommon/epochNotifier"
3534
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
3635
"github.com/multiversx/mx-chain-vm-common-go/parsers"
3736
wasmConfig "github.com/multiversx/mx-chain-vm-go/config"
3837

38+
"github.com/multiversx/mx-chain-go/testscommon/epochNotifier"
39+
3940
"github.com/multiversx/mx-chain-go/process/aotSelection"
4041
"github.com/multiversx/mx-chain-go/process/asyncExecution"
4142
"github.com/multiversx/mx-chain-go/process/asyncExecution/executionManager"
@@ -698,6 +699,9 @@ func (tpn *TestProcessorNode) Close() {
698699
_ = tpn.FullArchiveMessenger.Close()
699700
_ = tpn.VMContainer.Close()
700701
_ = tpn.ExecutionManager.Close()
702+
if !check.IfNil(tpn.BlockTracker) {
703+
_ = tpn.BlockTracker.Close()
704+
}
701705
}
702706

703707
func (tpn *TestProcessorNode) initAccountDBsWithPruningStorer() {

process/block/metablockProposal_test.go

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
18331833
dataPoolMock.SetProofsPool(proofsPool)
18341834

18351835
marshaller := &marshal.GogoProtoMarshalizer{}
1836-
storage := &storageStubs.ChainStorerStub{
1836+
st := &storageStubs.ChainStorerStub{
18371837
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
18381838
return &storageStubs.StorerStub{
18391839
GetCalled: func(key []byte) ([]byte, error) {
@@ -1859,7 +1859,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
18591859
},
18601860
"dataPool": dataPoolMock,
18611861
"proofsPool": proofsPool,
1862-
"store": storage,
1862+
"store": st,
18631863
})
18641864
require.Nil(t, err)
18651865

@@ -1893,7 +1893,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
18931893
dataPoolMock.SetProofsPool(proofsPool)
18941894

18951895
marshaller := &marshal.GogoProtoMarshalizer{}
1896-
storage := &storageStubs.ChainStorerStub{
1896+
st := &storageStubs.ChainStorerStub{
18971897
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
18981898
return &storageStubs.StorerStub{
18991899
GetCalled: func(key []byte) ([]byte, error) {
@@ -1929,7 +1929,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
19291929
},
19301930
},
19311931
"proofsPool": proofsPool,
1932-
"store": storage,
1932+
"store": st,
19331933
})
19341934
require.Nil(t, err)
19351935

@@ -3041,7 +3041,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
30413041
dataPoolMock.SetHeadersPool(headersPoolMock)
30423042

30433043
marshaller := &marshal.GogoProtoMarshalizer{}
3044-
storage := &storageStubs.ChainStorerStub{
3044+
st := &storageStubs.ChainStorerStub{
30453045
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
30463046
return &storageStubs.StorerStub{
30473047
GetCalled: func(key []byte) ([]byte, error) {
@@ -3062,7 +3062,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
30623062
},
30633063
},
30643064
"marshalizer": &marshal.GogoProtoMarshalizer{},
3065-
"store": storage,
3065+
"store": st,
30663066
"epochStartTrigger": &testscommon.EpochStartTriggerStub{
30673067
EpochCalled: func() uint32 {
30683068
return 1
@@ -3101,7 +3101,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
31013101
dataPoolMock.SetHeadersPool(headersPoolMock)
31023102

31033103
marshaller := &marshal.GogoProtoMarshalizer{}
3104-
storage := &storageStubs.ChainStorerStub{
3104+
st := &storageStubs.ChainStorerStub{
31053105
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
31063106
return &storageStubs.StorerStub{
31073107
GetCalled: func(key []byte) ([]byte, error) {
@@ -3123,7 +3123,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
31233123
return 1
31243124
}},
31253125
"marshalizer": marshaller,
3126-
"store": storage,
3126+
"store": st,
31273127
})
31283128
require.Nil(t, err)
31293129

@@ -3164,7 +3164,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
31643164
dataPoolMock.SetHeadersPool(headersPoolMock)
31653165

31663166
marshaller := &marshal.GogoProtoMarshalizer{}
3167-
storage := &storageStubs.ChainStorerStub{
3167+
st := &storageStubs.ChainStorerStub{
31683168
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
31693169
return &storageStubs.StorerStub{
31703170
GetCalled: func(key []byte) ([]byte, error) {
@@ -3188,7 +3188,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
31883188
return 1
31893189
}},
31903190
"marshalizer": marshaller,
3191-
"store": storage,
3191+
"store": st,
31923192
})
31933193
require.Nil(t, err)
31943194

@@ -3227,7 +3227,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
32273227
dataPoolMock.SetHeadersPool(headersPoolMock)
32283228

32293229
marshaller := &marshal.GogoProtoMarshalizer{}
3230-
storage := &storageStubs.ChainStorerStub{
3230+
st := &storageStubs.ChainStorerStub{
32313231
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
32323232
return &storageStubs.StorerStub{
32333233
GetCalled: func(key []byte) ([]byte, error) {
@@ -3250,7 +3250,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
32503250
"epochStartTrigger": &testscommon.EpochStartTriggerStub{EpochCalled: func() uint32 {
32513251
return 1
32523252
}},
3253-
"store": storage,
3253+
"store": st,
32543254
"marshalizer": marshaller,
32553255
})
32563256
require.Nil(t, err)
@@ -3293,7 +3293,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
32933293
dataPoolMock.SetHeadersPool(headersPoolMock)
32943294

32953295
marshaller := &marshal.GogoProtoMarshalizer{}
3296-
storage := &storageStubs.ChainStorerStub{
3296+
st := &storageStubs.ChainStorerStub{
32973297
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
32983298
return &storageStubs.StorerStub{
32993299
GetCalled: func(key []byte) ([]byte, error) {
@@ -3317,7 +3317,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
33173317
return 1
33183318
}},
33193319
"marshalizer": &marshal.GogoProtoMarshalizer{},
3320-
"store": storage,
3320+
"store": st,
33213321
})
33223322
require.Nil(t, err)
33233323
mp.SetEpochStartData(&blproc.EpochStartDataWrapper{
@@ -3363,7 +3363,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
33633363
dataPoolMock.SetHeadersPool(headersPoolMock)
33643364

33653365
marshaller := &marshal.GogoProtoMarshalizer{}
3366-
storage := &storageStubs.ChainStorerStub{
3366+
st := &storageStubs.ChainStorerStub{
33673367
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
33683368
return &storageStubs.StorerStub{
33693369
GetCalled: func(key []byte) ([]byte, error) {
@@ -3386,7 +3386,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
33863386
"epochStartTrigger": &testscommon.EpochStartTriggerStub{EpochCalled: func() uint32 {
33873387
return 1
33883388
}},
3389-
"store": storage,
3389+
"store": st,
33903390
"marshalizer": &marshal.GogoProtoMarshalizer{},
33913391
})
33923392
mp.SetEpochStartData(&blproc.EpochStartDataWrapper{
@@ -3428,7 +3428,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
34283428
dataPoolMock.SetHeadersPool(headersPoolMock)
34293429

34303430
marshaller := &marshal.GogoProtoMarshalizer{}
3431-
storage := &storageStubs.ChainStorerStub{
3431+
st := &storageStubs.ChainStorerStub{
34323432
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
34333433
return &storageStubs.StorerStub{
34343434
GetCalled: func(key []byte) ([]byte, error) {
@@ -3452,7 +3452,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
34523452
"epochStartTrigger": &testscommon.EpochStartTriggerStub{EpochCalled: func() uint32 {
34533453
return 1
34543454
}},
3455-
"store": storage,
3455+
"store": st,
34563456
})
34573457
mp.SetEpochStartData(&blproc.EpochStartDataWrapper{
34583458
Epoch: 2,
@@ -3595,6 +3595,33 @@ func TestMetaProcessor_checkHeadersSequenceCorrectness(t *testing.T) {
35953595
require.Equal(t, expectedErr, err)
35963596
})
35973597

3598+
t.Run("should return error for quarantined header", func(t *testing.T) {
3599+
t.Parallel()
3600+
3601+
quarantinedHash := []byte("quarantined hash")
3602+
mp, err := blproc.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{
3603+
"headerValidator": &processMocks.HeaderValidatorMock{
3604+
IsHeaderConstructionValidCalled: func(currHdr, prevHdr data.HeaderHandler) error {
3605+
return nil
3606+
},
3607+
},
3608+
"blockTracker": &integrationTestsMock.BlockTrackerStub{
3609+
IsHeaderQuarantinedCalled: func(hash []byte) bool {
3610+
return bytes.Equal(hash, quarantinedHash)
3611+
},
3612+
},
3613+
})
3614+
require.Nil(t, err)
3615+
3616+
err = mp.CheckHeadersSequenceCorrectness([]blproc.ShardHeaderInfo{
3617+
{
3618+
Header: &block.Header{Nonce: 2},
3619+
Hash: quarantinedHash,
3620+
},
3621+
}, blproc.ShardHeaderInfo{})
3622+
require.ErrorContains(t, err, "included quarantined header")
3623+
})
3624+
35983625
t.Run("should work", func(t *testing.T) {
35993626
t.Parallel()
36003627

process/block/shardblockProposal_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,48 @@ func TestShardProcessor_CheckMetaHeadersValidityAndFinalityProposal(t *testing.T
27402740
require.Equal(t, expectedError, err)
27412741
})
27422742

2743+
t.Run("quarantined meta header should error", func(t *testing.T) {
2744+
t.Parallel()
2745+
2746+
coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()
2747+
arguments := CreateMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents)
2748+
2749+
metaHeader := &block.MetaBlockV3{}
2750+
arguments.BlockTracker = &mock.BlockTrackerMock{
2751+
GetLastCrossNotarizedHeaderCalled: func(shardID uint32) (data.HeaderHandler, []byte, error) {
2752+
return metaHeader, []byte("h"), nil
2753+
},
2754+
IsHeaderQuarantinedCalled: func(hash []byte) bool {
2755+
return true
2756+
},
2757+
}
2758+
arguments.HeaderValidator = &processMocks.HeaderValidatorMock{
2759+
IsHeaderConstructionValidCalled: func(currHdr, prevHdr data.HeaderHandler) error {
2760+
require.Fail(t, "should not have been called for a quarantined header")
2761+
return nil
2762+
},
2763+
}
2764+
2765+
dataPool, ok := dataComponents.Datapool().(*dataRetriever.PoolsHolderStub)
2766+
require.True(t, ok)
2767+
2768+
dataPool.HeadersCalled = func() retriever.HeadersPool {
2769+
return &pool.HeadersPoolStub{
2770+
GetHeaderByHashCalled: func(hash []byte) (data.HeaderHandler, error) {
2771+
return &block.Header{}, nil
2772+
},
2773+
}
2774+
}
2775+
2776+
sp, _ := blproc.NewShardProcessor(arguments)
2777+
2778+
header := &block.HeaderV3{
2779+
MetaBlockHashes: [][]byte{[]byte("hh")},
2780+
}
2781+
err := sp.CheckMetaHeadersValidityAndFinalityProposal(header)
2782+
require.ErrorContains(t, err, "included quarantined header")
2783+
})
2784+
27432785
t.Run("invalid header should error", func(t *testing.T) {
27442786
t.Parallel()
27452787

process/track/baseBlockTrack.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,27 @@ func (bbt *baseBlockTrack) sweepQuarantinedHeaders(ctx context.Context) {
205205
case <-ctx.Done():
206206
return
207207
case <-ticker.C:
208-
currentRound := bbt.roundHandler.Index()
209-
for _, key := range bbt.quarantinedHeaders.Keys() {
210-
val, _ := bbt.quarantinedHeaders.Get(key)
211-
headerRound, ok := val.(uint64)
212-
if !ok {
213-
continue
214-
}
215-
216-
if currentRound-int64(headerRound) < maxQuarantineRoundDelta {
217-
continue
218-
}
219-
220-
bbt.quarantinedHeaders.Remove(key)
221-
}
208+
bbt.sweepExpiredQuarantinedHeaders()
209+
}
210+
}
211+
}
212+
213+
func (bbt *baseBlockTrack) sweepExpiredQuarantinedHeaders() {
214+
currentRound := bbt.roundHandler.Index()
215+
for _, key := range bbt.quarantinedHeaders.Keys() {
216+
val, _ := bbt.quarantinedHeaders.Get(key)
217+
headerRound, ok := val.(uint64)
218+
if !ok {
219+
log.Warn("sweepExpiredQuarantinedHeaders: unexpected value type, removing entry", "hash", key)
220+
bbt.quarantinedHeaders.Remove(key)
221+
continue
222222
}
223+
224+
if currentRound-int64(headerRound) < maxQuarantineRoundDelta {
225+
continue
226+
}
227+
228+
bbt.quarantinedHeaders.Remove(key)
223229
}
224230
}
225231

0 commit comments

Comments
 (0)