From da32bf2faf12d92bbc4a4ef330dfe029f51b8457 Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 24 Oct 2024 13:13:05 +0300 Subject: [PATCH 1/5] FIX: After review --- process/block/sovereignChainBlock.go | 14 ++++++++++---- process/track/sovereignChainShardBlockTrack.go | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/process/block/sovereignChainBlock.go b/process/block/sovereignChainBlock.go index f2c88032a3b..a5173886339 100644 --- a/process/block/sovereignChainBlock.go +++ b/process/block/sovereignChainBlock.go @@ -834,15 +834,16 @@ func (scbp *sovereignChainBlockProcessor) checkExtendedShardHeadersValidity() er return err } + log.Trace("checkExtendedShardHeadersValidity", + "lastCrossNotarizedHeader nonce", lastCrossNotarizedHeader.GetNonce(), + "lastCrossNotarizedHeader round", lastCrossNotarizedHeader.GetRound(), + ) + extendedShardHdrs := scbp.sortExtendedShardHeadersForCurrentBlockByNonce() if len(extendedShardHdrs) == 0 { return nil } - log.Trace("checkExtendedShardHeadersValidity", - "lastCrossNotarizedHeader nonce", lastCrossNotarizedHeader.GetNonce(), - "lastCrossNotarizedHeader round", lastCrossNotarizedHeader.GetRound(), - ) if scbp.receivedGenesisMainChainHeaderWithoutPreGenesis(extendedShardHdrs[0]) { // we are missing pre-genesis header, so we can't link it to previous header if len(extendedShardHdrs) == 1 { @@ -851,6 +852,11 @@ func (scbp *sovereignChainBlockProcessor) checkExtendedShardHeadersValidity() er lastCrossNotarizedHeader = extendedShardHdrs[0] extendedShardHdrs = extendedShardHdrs[1:] + + log.Debug("checkExtendedShardHeadersValidity missing pre genesis, updating lastCrossNotarizedHeader", + "lastCrossNotarizedHeader nonce", lastCrossNotarizedHeader.GetNonce(), + "lastCrossNotarizedHeader round", lastCrossNotarizedHeader.GetRound(), + ) } for _, extendedShardHdr := range extendedShardHdrs { diff --git a/process/track/sovereignChainShardBlockTrack.go b/process/track/sovereignChainShardBlockTrack.go index 422c1fb1994..8d1bf9b631b 100644 --- a/process/track/sovereignChainShardBlockTrack.go +++ b/process/track/sovereignChainShardBlockTrack.go @@ -126,6 +126,7 @@ func (scsbt *sovereignChainShardBlockTrack) receivedExtendedShardHeader( scsbt.blockProcessor.ProcessReceivedHeader(extendedShardHeaderHandler) } +// IsGenesisLastCrossNotarizedHeader returns true if the last cross chain notarized header is the dummy genesis header func (scsbt *sovereignChainShardBlockTrack) IsGenesisLastCrossNotarizedHeader() bool { lastNotarizedHeader, _, err := scsbt.crossNotarizer.GetLastNotarizedHeader(core.MainChainShardId) From 4b813d4d7a1681704bc219e427a8b9590d828f8e Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 24 Oct 2024 13:42:33 +0300 Subject: [PATCH 2/5] FIX: isGenesisHeaderWithNoPreviousTracking --- process/block/sovereignChainBlock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/process/block/sovereignChainBlock.go b/process/block/sovereignChainBlock.go index a5173886339..7fbd711a7a9 100644 --- a/process/block/sovereignChainBlock.go +++ b/process/block/sovereignChainBlock.go @@ -844,7 +844,7 @@ func (scbp *sovereignChainBlockProcessor) checkExtendedShardHeadersValidity() er return nil } - if scbp.receivedGenesisMainChainHeaderWithoutPreGenesis(extendedShardHdrs[0]) { + if scbp.isGenesisHeaderWithNoPreviousTracking(extendedShardHdrs[0]) { // we are missing pre-genesis header, so we can't link it to previous header if len(extendedShardHdrs) == 1 { return nil @@ -879,7 +879,7 @@ func (scbp *sovereignChainBlockProcessor) checkExtendedShardHeadersValidity() er // - no notifier is attached => we did not track main chain and don't have pre-genesis header // - node is in re-sync/start in the exact epoch when we start to notarize main chain => no previous // main chain tracking(notifier is also disabled) -func (scbp *sovereignChainBlockProcessor) receivedGenesisMainChainHeaderWithoutPreGenesis(incomingHeader data.HeaderHandler) bool { +func (scbp *sovereignChainBlockProcessor) isGenesisHeaderWithNoPreviousTracking(incomingHeader data.HeaderHandler) bool { return scbp.extendedShardHeaderTracker.IsGenesisLastCrossNotarizedHeader() && incomingHeader.GetRound() == scbp.mainChainNotarizationStartRound } From de11bd562771165fbea13b50c37ab051d5f360a0 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 24 Oct 2024 16:32:32 +0300 Subject: [PATCH 3/5] fix request incoming SCRs --- .../incomingHeader/extendedHeaderProcessor.go | 16 ++++++++++++-- .../incomingHeader/incomingHeaderProcessor.go | 21 +++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/process/block/sovereign/incomingHeader/extendedHeaderProcessor.go b/process/block/sovereign/incomingHeader/extendedHeaderProcessor.go index 7bb0329cc75..7733478339a 100644 --- a/process/block/sovereign/incomingHeader/extendedHeaderProcessor.go +++ b/process/block/sovereign/incomingHeader/extendedHeaderProcessor.go @@ -8,10 +8,13 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + + "github.com/multiversx/mx-chain-go/process" ) type extendedHeaderProcessor struct { headersPool HeadersPool + txPool TransactionPool marshaller marshal.Marshalizer hasher hashing.Hasher } @@ -80,15 +83,24 @@ func (ehp *extendedHeaderProcessor) addPreGenesisExtendedHeaderToPool(incomingHe IncomingEvents: []*transaction.Event{}, } - return ehp.addExtendedHeaderToPool(extendedHeader) + return ehp.addExtendedHeaderAndSCRsToPool(extendedHeader, make([]*scrInfo, 0)) } -func (ehp *extendedHeaderProcessor) addExtendedHeaderToPool(extendedHeader data.ShardHeaderExtendedHandler) error { +func (ehp *extendedHeaderProcessor) addExtendedHeaderAndSCRsToPool(extendedHeader data.ShardHeaderExtendedHandler, scrs []*scrInfo) error { extendedHeaderHash, err := core.CalculateHash(ehp.marshaller, ehp.hasher, extendedHeader) if err != nil { return err } + ehp.addSCRsToPool(scrs) ehp.headersPool.AddHeaderInShard(extendedHeaderHash, extendedHeader, core.MainChainShardId) return nil } + +func (ehp *extendedHeaderProcessor) addSCRsToPool(scrs []*scrInfo) { + cacheID := process.ShardCacherIdentifier(core.MainChainShardId, core.SovereignChainShardId) + + for _, scrData := range scrs { + ehp.txPool.AddData(scrData.hash, scrData.scr, scrData.scr.Size(), cacheID) + } +} diff --git a/process/block/sovereign/incomingHeader/incomingHeaderProcessor.go b/process/block/sovereign/incomingHeader/incomingHeaderProcessor.go index 33487db640b..597c6b68abd 100644 --- a/process/block/sovereign/incomingHeader/incomingHeaderProcessor.go +++ b/process/block/sovereign/incomingHeader/incomingHeaderProcessor.go @@ -3,10 +3,6 @@ package incomingHeader import ( "encoding/hex" - sovereignBlock "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/sovereign" - "github.com/multiversx/mx-chain-go/errors" - "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" @@ -14,6 +10,9 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" logger "github.com/multiversx/mx-chain-logger-go" + + sovereignBlock "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/sovereign" + "github.com/multiversx/mx-chain-go/errors" ) var log = logger.GetOrCreate("headerSubscriber") @@ -34,7 +33,6 @@ type incomingHeaderProcessor struct { eventsProc *incomingEventsProcessor extendedHeaderProc *extendedHeaderProcessor - txPool TransactionPool outGoingPool sovereignBlock.OutGoingOperationsPool mainChainNotarizationStartRound uint64 } @@ -74,6 +72,7 @@ func NewIncomingHeaderProcessor(args ArgsIncomingHeaderProcessor) (*incomingHead extendedHearProc := &extendedHeaderProcessor{ headersPool: args.HeadersPool, + txPool: args.TxPool, marshaller: args.Marshaller, hasher: args.Hasher, } @@ -83,7 +82,6 @@ func NewIncomingHeaderProcessor(args ArgsIncomingHeaderProcessor) (*incomingHead return &incomingHeaderProcessor{ eventsProc: eventsProc, extendedHeaderProc: extendedHearProc, - txPool: args.TxPool, outGoingPool: args.OutGoingOperationsPool, mainChainNotarizationStartRound: args.MainChainNotarizationStartRound, }, nil @@ -127,24 +125,15 @@ func (ihp *incomingHeaderProcessor) AddHeader(headerHash []byte, header sovereig return err } - err = ihp.extendedHeaderProc.addExtendedHeaderToPool(extendedHeader) + err = ihp.extendedHeaderProc.addExtendedHeaderAndSCRsToPool(extendedHeader, res.scrs) if err != nil { return err } ihp.addConfirmedBridgeOpsToPool(res.confirmedBridgeOps) - ihp.addSCRsToPool(res.scrs) return nil } -func (ihp *incomingHeaderProcessor) addSCRsToPool(scrs []*scrInfo) { - cacheID := process.ShardCacherIdentifier(core.MainChainShardId, core.SovereignChainShardId) - - for _, scrData := range scrs { - ihp.txPool.AddData(scrData.hash, scrData.scr, scrData.scr.Size(), cacheID) - } -} - func (ihp *incomingHeaderProcessor) addConfirmedBridgeOpsToPool(ops []*confirmedBridgeOp) { for _, op := range ops { // This is not a critical error. This might just happen when a leader tries to re-send unconfirmed confirmation From 87f00bcbdebc400a0899c222651a7af537825566 Mon Sep 17 00:00:00 2001 From: MariusC Date: Mon, 28 Oct 2024 16:53:17 +0200 Subject: [PATCH 4/5] FIX: After review --- epochStart/bootstrap/bootStrapSovereignShardProcessor.go | 2 +- epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/epochStart/bootstrap/bootStrapSovereignShardProcessor.go b/epochStart/bootstrap/bootStrapSovereignShardProcessor.go index a969ee80c7d..9dc0d6fbd29 100644 --- a/epochStart/bootstrap/bootStrapSovereignShardProcessor.go +++ b/epochStart/bootstrap/bootStrapSovereignShardProcessor.go @@ -292,7 +292,7 @@ func (sbp *sovereignBootStrapShardProcessor) createEpochStartInterceptorsContain func (bp *sovereignBootStrapShardProcessor) createCrossHeaderRequester() (updateSync.CrossHeaderRequester, error) { extendedHeaderRequester, castOk := bp.requestHandler.(updateSync.ExtendedShardHeaderRequestHandler) if !castOk { - return nil, fmt.Errorf("%w in sovereignBootStrapShardProcessor.createHeadersSyncer for extendedHeaderRequester", process.ErrWrongTypeAssertion) + return nil, fmt.Errorf("%w in sovereignBootStrapShardProcessor.createCrossHeaderRequester for extendedHeaderRequester", process.ErrWrongTypeAssertion) } return updateSync.NewExtendedHeaderRequester(extendedHeaderRequester) diff --git a/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go b/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go index 2e191ca926e..91b23585144 100644 --- a/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go +++ b/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go @@ -294,7 +294,7 @@ func TestBootStrapSovereignShardProcessor_createEpochStartInterceptorsContainers require.Zero(t, fullContainer.Len()) } -func TestBootStrapSovereignShardProcessor_createHeadersSyncer(t *testing.T) { +func TestBootStrapSovereignShardProcessor_createCrossHeaderRequester(t *testing.T) { t.Parallel() sovProc := createSovBootStrapProc() From fa6a353d74140a2fcb444efcebcc69de8c0ed790 Mon Sep 17 00:00:00 2001 From: MariusC Date: Mon, 28 Oct 2024 16:59:47 +0200 Subject: [PATCH 5/5] FIX: Linter --- epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go b/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go index 91b23585144..0cab9273ed4 100644 --- a/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go +++ b/epochStart/bootstrap/bootStrapSovereignShardProcessor_test.go @@ -307,6 +307,6 @@ func TestBootStrapSovereignShardProcessor_createCrossHeaderRequester(t *testing. sovProc.requestHandler = &testscommon.ExtendedShardHeaderRequestHandlerStub{} requester, err = sovProc.createCrossHeaderRequester() - require.NotNil(t, requester) + require.Nil(t, err) require.Equal(t, "*sync.extendedHeaderRequester", fmt.Sprintf("%T", requester)) }