Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import (
ed25519SingleSig "github.com/multiversx/mx-chain-crypto-go/signing/ed25519/singlesig"
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig"
"github.com/multiversx/mx-chain-go/testscommon/epochNotifier"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-common-go/parsers"
wasmConfig "github.com/multiversx/mx-chain-vm-go/config"

"github.com/multiversx/mx-chain-go/testscommon/epochNotifier"

"github.com/multiversx/mx-chain-go/process/aotSelection"
"github.com/multiversx/mx-chain-go/process/asyncExecution"
"github.com/multiversx/mx-chain-go/process/asyncExecution/executionManager"
Expand Down Expand Up @@ -698,6 +699,9 @@ func (tpn *TestProcessorNode) Close() {
_ = tpn.FullArchiveMessenger.Close()
_ = tpn.VMContainer.Close()
_ = tpn.ExecutionManager.Close()
if !check.IfNil(tpn.BlockTracker) {
_ = tpn.BlockTracker.Close()
}
}

func (tpn *TestProcessorNode) initAccountDBsWithPruningStorer() {
Expand Down
63 changes: 45 additions & 18 deletions process/block/metablockProposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
dataPoolMock.SetProofsPool(proofsPool)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -1859,7 +1859,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
},
"dataPool": dataPoolMock,
"proofsPool": proofsPool,
"store": storage,
"store": st,
})
require.Nil(t, err)

Expand Down Expand Up @@ -1893,7 +1893,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
dataPoolMock.SetProofsPool(proofsPool)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand Down Expand Up @@ -1929,7 +1929,7 @@ func Test_checkShardHeadersValidityAndFinalityProposal(t *testing.T) {
},
},
"proofsPool": proofsPool,
"store": storage,
"store": st,
})
require.Nil(t, err)

Expand Down Expand Up @@ -3041,7 +3041,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3062,7 +3062,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
},
},
"marshalizer": &marshal.GogoProtoMarshalizer{},
"store": storage,
"store": st,
"epochStartTrigger": &testscommon.EpochStartTriggerStub{
EpochCalled: func() uint32 {
return 1
Expand Down Expand Up @@ -3101,7 +3101,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3123,7 +3123,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
return 1
}},
"marshalizer": marshaller,
"store": storage,
"store": st,
})
require.Nil(t, err)

Expand Down Expand Up @@ -3164,7 +3164,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3188,7 +3188,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
return 1
}},
"marshalizer": marshaller,
"store": storage,
"store": st,
})
require.Nil(t, err)

Expand Down Expand Up @@ -3227,7 +3227,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3250,7 +3250,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
"epochStartTrigger": &testscommon.EpochStartTriggerStub{EpochCalled: func() uint32 {
return 1
}},
"store": storage,
"store": st,
"marshalizer": marshaller,
})
require.Nil(t, err)
Expand Down Expand Up @@ -3293,7 +3293,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3317,7 +3317,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
return 1
}},
"marshalizer": &marshal.GogoProtoMarshalizer{},
"store": storage,
"store": st,
})
require.Nil(t, err)
mp.SetEpochStartData(&blproc.EpochStartDataWrapper{
Expand Down Expand Up @@ -3363,7 +3363,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3386,7 +3386,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
"epochStartTrigger": &testscommon.EpochStartTriggerStub{EpochCalled: func() uint32 {
return 1
}},
"store": storage,
"store": st,
"marshalizer": &marshal.GogoProtoMarshalizer{},
})
mp.SetEpochStartData(&blproc.EpochStartDataWrapper{
Expand Down Expand Up @@ -3428,7 +3428,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
dataPoolMock.SetHeadersPool(headersPoolMock)

marshaller := &marshal.GogoProtoMarshalizer{}
storage := &storageStubs.ChainStorerStub{
st := &storageStubs.ChainStorerStub{
GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) {
return &storageStubs.StorerStub{
GetCalled: func(key []byte) ([]byte, error) {
Expand All @@ -3452,7 +3452,7 @@ func TestMetaProcessor_checkEpochCorrectnessV3(t *testing.T) {
"epochStartTrigger": &testscommon.EpochStartTriggerStub{EpochCalled: func() uint32 {
return 1
}},
"store": storage,
"store": st,
})
mp.SetEpochStartData(&blproc.EpochStartDataWrapper{
Epoch: 2,
Expand Down Expand Up @@ -3595,6 +3595,33 @@ func TestMetaProcessor_checkHeadersSequenceCorrectness(t *testing.T) {
require.Equal(t, expectedErr, err)
})

t.Run("should return error for quarantined header", func(t *testing.T) {
t.Parallel()

quarantinedHash := []byte("quarantined hash")
mp, err := blproc.ConstructPartialMetaBlockProcessorForTest(map[string]interface{}{
"headerValidator": &processMocks.HeaderValidatorMock{
IsHeaderConstructionValidCalled: func(currHdr, prevHdr data.HeaderHandler) error {
return nil
},
},
"blockTracker": &integrationTestsMock.BlockTrackerStub{
IsHeaderQuarantinedCalled: func(hash []byte) bool {
return bytes.Equal(hash, quarantinedHash)
},
},
})
require.Nil(t, err)

err = mp.CheckHeadersSequenceCorrectness([]blproc.ShardHeaderInfo{
{
Header: &block.Header{Nonce: 2},
Hash: quarantinedHash,
},
}, blproc.ShardHeaderInfo{})
require.ErrorContains(t, err, "included quarantined header")
})

t.Run("should work", func(t *testing.T) {
t.Parallel()

Expand Down
42 changes: 42 additions & 0 deletions process/block/shardblockProposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,48 @@ func TestShardProcessor_CheckMetaHeadersValidityAndFinalityProposal(t *testing.T
require.Equal(t, expectedError, err)
})

t.Run("quarantined meta header should error", func(t *testing.T) {
t.Parallel()

coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()
arguments := CreateMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents)

metaHeader := &block.MetaBlockV3{}
arguments.BlockTracker = &mock.BlockTrackerMock{
GetLastCrossNotarizedHeaderCalled: func(shardID uint32) (data.HeaderHandler, []byte, error) {
return metaHeader, []byte("h"), nil
},
IsHeaderQuarantinedCalled: func(hash []byte) bool {
return true
},
}
arguments.HeaderValidator = &processMocks.HeaderValidatorMock{
IsHeaderConstructionValidCalled: func(currHdr, prevHdr data.HeaderHandler) error {
require.Fail(t, "should not have been called for a quarantined header")
return nil
},
}

dataPool, ok := dataComponents.Datapool().(*dataRetriever.PoolsHolderStub)
require.True(t, ok)

dataPool.HeadersCalled = func() retriever.HeadersPool {
return &pool.HeadersPoolStub{
GetHeaderByHashCalled: func(hash []byte) (data.HeaderHandler, error) {
return &block.Header{}, nil
},
}
}

sp, _ := blproc.NewShardProcessor(arguments)

header := &block.HeaderV3{
MetaBlockHashes: [][]byte{[]byte("hh")},
}
err := sp.CheckMetaHeadersValidityAndFinalityProposal(header)
require.ErrorContains(t, err, "included quarantined header")
})

t.Run("invalid header should error", func(t *testing.T) {
t.Parallel()

Expand Down
38 changes: 24 additions & 14 deletions process/track/baseBlockTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,34 @@ func (bbt *baseBlockTrack) sweepQuarantinedHeaders(ctx context.Context) {
case <-ctx.Done():
return
case <-ticker.C:
currentRound := bbt.roundHandler.Index()
for _, key := range bbt.quarantinedHeaders.Keys() {
val, _ := bbt.quarantinedHeaders.Get(key)
headerRound, ok := val.(uint64)
if !ok {
continue
}

if currentRound-int64(headerRound) < maxQuarantineRoundDelta {
continue
}

bbt.quarantinedHeaders.Remove(key)
}
bbt.sweepExpiredQuarantinedHeaders()
}
}
}

func (bbt *baseBlockTrack) sweepExpiredQuarantinedHeaders() {
currentRound := bbt.roundHandler.Index()
for _, key := range bbt.quarantinedHeaders.Keys() {
val, found := bbt.quarantinedHeaders.Get(key)
if !found {
continue
}

headerRound, ok := val.(uint64)
if !ok {
log.Warn("sweepExpiredQuarantinedHeaders: unexpected value type, removing entry", "hash", key)
bbt.quarantinedHeaders.Remove(key)
continue
}
Comment thread
AdoAdoAdo marked this conversation as resolved.

if currentRound-int64(headerRound) < maxQuarantineRoundDelta {
continue
}

bbt.quarantinedHeaders.Remove(key)
}
}

func (bbt *baseBlockTrack) requestHeaderForProof(proof data.HeaderProofHandler) {
if proof.GetHeaderShardId() == common.MetachainShardId {
bbt.requestHandler.RequestMetaHeader(proof.GetHeaderHash())
Expand Down
Loading
Loading