Skip to content

Commit

Permalink
Merge branch 'adapt_notarization' of https://github.com/multiversx/mx…
Browse files Browse the repository at this point in the history
…-chain-go into feat-equivalent-proofs-tmp1
  • Loading branch information
sstanculeanu committed Dec 4, 2024
2 parents 0bc7751 + 10c8d22 commit fe5fe2e
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 110 deletions.
4 changes: 0 additions & 4 deletions factory/processing/blockProcessorCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (pcf *processComponentsFactory) newBlockProcessor(
blockCutoffProcessingHandler cutoff.BlockProcessingCutoffHandler,
missingTrieNodesNotifier common.MissingTrieNodesNotifier,
sentSignaturesTracker process.SentSignaturesTracker,
headerSigVerifier process.InterceptedHeaderSigVerifier,
) (*blockProcessorAndVmFactories, error) {
shardCoordinator := pcf.bootstrapComponents.ShardCoordinator()
if shardCoordinator.SelfId() < shardCoordinator.NumberOfShards() {
Expand Down Expand Up @@ -106,7 +105,6 @@ func (pcf *processComponentsFactory) newBlockProcessor(
receiptsRepository,
blockCutoffProcessingHandler,
sentSignaturesTracker,
headerSigVerifier,
)
}

Expand Down Expand Up @@ -480,7 +478,6 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor(
receiptsRepository mainFactory.ReceiptsRepository,
blockProcessingCutoffhandler cutoff.BlockProcessingCutoffHandler,
sentSignaturesTracker process.SentSignaturesTracker,
headerSigVerifier process.InterceptedHeaderSigVerifier,
) (*blockProcessorAndVmFactories, error) {
builtInFuncFactory, err := pcf.createBuiltInFunctionContainer(pcf.state.AccountsAdapter(), make(map[string]struct{}))
if err != nil {
Expand Down Expand Up @@ -972,7 +969,6 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor(
EpochValidatorInfoCreator: validatorInfoCreator,
ValidatorStatisticsProcessor: validatorStatisticsProcessor,
EpochSystemSCProcessor: epochStartSystemSCProcessor,
HeaderSigVerifier: headerSigVerifier,
}

metaProcessor, err := block.NewMetaProcessor(arguments)
Expand Down
3 changes: 0 additions & 3 deletions factory/processing/blockProcessorCreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/testscommon/consensus"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -59,7 +58,6 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) {
&testscommon.BlockProcessingCutoffStub{},
&testscommon.MissingTrieNodesNotifierStub{},
&testscommon.SentSignatureTrackerStub{},
&consensus.HeaderSigVerifierMock{},
)

require.NoError(t, err)
Expand Down Expand Up @@ -187,7 +185,6 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) {
&testscommon.BlockProcessingCutoffStub{},
&testscommon.MissingTrieNodesNotifierStub{},
&testscommon.SentSignatureTrackerStub{},
&consensus.HeaderSigVerifierMock{},
)

require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions factory/processing/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor(
blockProcessingCutoff cutoff.BlockProcessingCutoffHandler,
missingTrieNodesNotifier common.MissingTrieNodesNotifier,
sentSignaturesTracker process.SentSignaturesTracker,
headerSigVerifier process.InterceptedHeaderSigVerifier,
) (process.BlockProcessor, process.EpochStartSystemSCProcessor, error) {
blockProcessorComponents, err := pcf.newBlockProcessor(
requestHandler,
Expand All @@ -43,7 +42,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor(
blockProcessingCutoff,
missingTrieNodesNotifier,
sentSignaturesTracker,
headerSigVerifier,
)
if err != nil {
return nil, nil, err
Expand Down
1 change: 0 additions & 1 deletion factory/processing/processComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) {
blockCutoffProcessingHandler,
pcf.state.MissingTrieNodesNotifier(),
sentSignaturesTracker,
headerSigVerifier,
)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e
github.com/multiversx/mx-chain-core-go v1.2.21-0.20241121144233-ffcdfdf55403
github.com/multiversx/mx-chain-core-go v1.2.21-0.20241204105459-ddd46264c030
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e h1:Tsmwhu+UleE+l3buPuqXSKTqfu5FbPmzQ4MjMoUvCWA=
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e/go.mod h1:2yXl18wUbuV3cRZr7VHxM1xo73kTaC1WUcu2kx8R034=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20241121144233-ffcdfdf55403 h1:Xwp3jdaOyQ0ZnfspN04aqMuODnRsqvGOtmqg3RIWzMo=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20241121144233-ffcdfdf55403/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20241204105459-ddd46264c030 h1:4XI4z1ceZC3OUXxTeMQD+6gmTgu9I934nsYlV6P8X4A=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20241204105459-ddd46264c030/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4=
Expand Down
1 change: 0 additions & 1 deletion integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,6 @@ func (tpn *TestProcessorNode) initBlockProcessor() {
EpochValidatorInfoCreator: epochStartValidatorInfo,
ValidatorStatisticsProcessor: tpn.ValidatorStatisticsProcessor,
EpochSystemSCProcessor: epochStartSystemSCProcessor,
HeaderSigVerifier: tpn.HeaderSigVerifier,
}

tpn.BlockProcessor, err = block.NewMetaProcessor(arguments)
Expand Down
1 change: 0 additions & 1 deletion integrationTests/testSyncNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func (tpn *TestProcessorNode) initBlockProcessorWithSync() {
},
},
EpochSystemSCProcessor: &testscommon.EpochStartSystemSCStub{},
HeaderSigVerifier: tpn.HeaderSigVerifier,
}

tpn.BlockProcessor, err = block.NewMetaProcessor(arguments)
Expand Down
2 changes: 0 additions & 2 deletions integrationTests/vm/staking/metaBlockProcessorCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/consensus"
"github.com/multiversx/mx-chain-go/testscommon/dblookupext"
factory2 "github.com/multiversx/mx-chain-go/testscommon/factory"
"github.com/multiversx/mx-chain-go/testscommon/integrationtests"
Expand Down Expand Up @@ -118,7 +117,6 @@ func createMetaBlockProcessor(
EpochValidatorInfoCreator: valInfoCreator,
ValidatorStatisticsProcessor: validatorsInfoCreator,
EpochSystemSCProcessor: systemSCProcessor,
HeaderSigVerifier: &consensus.HeaderSigVerifierMock{},
}

metaProc, _ := blproc.NewMetaProcessor(args)
Expand Down
1 change: 0 additions & 1 deletion process/block/argProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,4 @@ type ArgMetaProcessor struct {
EpochValidatorInfoCreator process.EpochStartValidatorInfoCreator
EpochSystemSCProcessor process.EpochStartSystemSCProcessor
ValidatorStatisticsProcessor process.ValidatorStatisticsProcessor
HeaderSigVerifier process.InterceptedHeaderSigVerifier
}
49 changes: 29 additions & 20 deletions process/block/interceptedBlocks/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package interceptedBlocks

import (
"fmt"
"sync"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
Expand Down Expand Up @@ -93,7 +93,14 @@ func checkHeaderHandler(hdr data.HeaderHandler, enableEpochsHandler common.Enabl
return hdr.CheckFieldsForNil()
}

func checkMetaShardInfo(shardInfo []data.ShardDataHandler, coordinator sharding.Coordinator) error {
func checkMetaShardInfo(
shardInfo []data.ShardDataHandler,
coordinator sharding.Coordinator,
headerSigVerifier process.InterceptedHeaderSigVerifier,
) error {
wgProofsVerification := sync.WaitGroup{}
wgProofsVerification.Add(len(shardInfo))
errChan := make(chan error, len(shardInfo))
for _, sd := range shardInfo {
if sd.GetShardID() >= coordinator.NumberOfShards() && sd.GetShardID() != core.MetachainShardId {
return process.ErrInvalidShardId
Expand All @@ -104,30 +111,32 @@ func checkMetaShardInfo(shardInfo []data.ShardDataHandler, coordinator sharding.
return err
}

err = checkProofs(sd)
if err != nil {
return err
}
checkProofAsync(sd.GetPreviousProof(), headerSigVerifier, &wgProofsVerification, errChan)
}

return nil
}
wgProofsVerification.Wait()
close(errChan)

func checkProofs(shardData data.ShardDataHandler) error {
err := checkProof(shardData.GetPreviousProof())
if err != nil {
return fmt.Errorf("%w for previous block", err)
}
return <-errChan
}

err = checkProof(shardData.GetCurrentProof())
if err != nil {
return fmt.Errorf("%w for current block", err)
}
func checkProofAsync(
proof data.HeaderProofHandler,
headerSigVerifier process.InterceptedHeaderSigVerifier,
wg *sync.WaitGroup,
errChan chan error,
) {
go func(proof data.HeaderProofHandler) {
errCheckProof := checkProof(proof, headerSigVerifier)
if errCheckProof != nil {
errChan <- errCheckProof
}

return nil
wg.Done()
}(proof)
}

func checkProof(proof data.HeaderProofHandler) error {
func checkProof(proof data.HeaderProofHandler, headerSigVerifier process.InterceptedHeaderSigVerifier) error {
if check.IfNilReflect(proof) {
return nil
}
Expand All @@ -136,7 +145,7 @@ func checkProof(proof data.HeaderProofHandler) error {
return process.ErrInvalidHeaderProof
}

return nil
return headerSigVerifier.VerifyHeaderProof(proof)
}

func isIncompleteProof(proof data.HeaderProofHandler) bool {
Expand Down
65 changes: 57 additions & 8 deletions process/block/interceptedBlocks/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package interceptedBlocks

import (
"errors"
"strconv"
"sync"
"testing"

"github.com/multiversx/mx-chain-core-go/data"
Expand Down Expand Up @@ -337,8 +339,8 @@ func TestCheckMetaShardInfo_WithNilOrEmptyShouldReturnNil(t *testing.T) {

shardCoordinator := mock.NewOneShardCoordinatorMock()

err1 := checkMetaShardInfo(nil, shardCoordinator)
err2 := checkMetaShardInfo(make([]data.ShardDataHandler, 0), shardCoordinator)
err1 := checkMetaShardInfo(nil, shardCoordinator, &consensus.HeaderSigVerifierMock{})
err2 := checkMetaShardInfo(make([]data.ShardDataHandler, 0), shardCoordinator, &consensus.HeaderSigVerifierMock{})

assert.Nil(t, err1)
assert.Nil(t, err2)
Expand All @@ -356,7 +358,7 @@ func TestCheckMetaShardInfo_WrongShardIdShouldErr(t *testing.T) {
TxCount: 0,
}

err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator)
err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator, &consensus.HeaderSigVerifierMock{})

assert.Equal(t, process.ErrInvalidShardId, err)
}
Expand All @@ -380,7 +382,7 @@ func TestCheckMetaShardInfo_WrongMiniblockSenderShardIdShouldErr(t *testing.T) {
TxCount: 0,
}

err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator)
err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator, &consensus.HeaderSigVerifierMock{})

assert.Equal(t, process.ErrInvalidShardId, err)
}
Expand All @@ -404,7 +406,7 @@ func TestCheckMetaShardInfo_WrongMiniblockReceiverShardIdShouldErr(t *testing.T)
TxCount: 0,
}

err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator)
err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator, &consensus.HeaderSigVerifierMock{})

assert.Equal(t, process.ErrInvalidShardId, err)
}
Expand All @@ -428,7 +430,7 @@ func TestCheckMetaShardInfo_ReservedPopulatedShouldErr(t *testing.T) {
TxCount: 0,
}

err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator)
err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator, &consensus.HeaderSigVerifierMock{})

assert.Equal(t, process.ErrReservedFieldInvalid, err)
}
Expand All @@ -451,15 +453,62 @@ func TestCheckMetaShardInfo_OkValsShouldWork(t *testing.T) {
TxCount: 0,
}

err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator)
err := checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator, &consensus.HeaderSigVerifierMock{})
assert.Nil(t, err)

miniBlock.Reserved = []byte("r")
sd.ShardMiniBlockHeaders = []block.MiniBlockHeader{miniBlock}
err = checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator)
err = checkMetaShardInfo([]data.ShardDataHandler{&sd}, shardCoordinator, &consensus.HeaderSigVerifierMock{})
assert.Nil(t, err)
}

func TestCheckMetaShardInfo_OkValsShouldWorkMultipleShardData(t *testing.T) {
t.Parallel()

shardCoordinator := mock.NewOneShardCoordinatorMock()
miniBlock := block.MiniBlockHeader{
Hash: make([]byte, 0),
ReceiverShardID: shardCoordinator.SelfId(),
SenderShardID: shardCoordinator.SelfId(),
TxCount: 0,
}

calledCnt := 0
mutCalled := sync.Mutex{}
providedRandomError := errors.New("random error")
sigVerifier := &consensus.HeaderSigVerifierMock{
VerifyHeaderProofCalled: func(proofHandler data.HeaderProofHandler) error {
mutCalled.Lock()
defer mutCalled.Unlock()

calledCnt++
if calledCnt%5 == 0 {
return providedRandomError
}

return nil
},
}

numShardData := 1000
shardData := make([]data.ShardDataHandler, numShardData)
for i := 0; i < numShardData; i++ {
shardData[i] = &block.ShardData{
ShardID: shardCoordinator.SelfId(),
HeaderHash: []byte("hash" + strconv.Itoa(i)),
ShardMiniBlockHeaders: []block.MiniBlockHeader{miniBlock},
PreviousShardHeaderProof: &block.HeaderProof{
PubKeysBitmap: []byte("bitmap"),
AggregatedSignature: []byte("sig" + strconv.Itoa(i)),
HeaderHash: []byte("hash" + strconv.Itoa(i)),
},
}
}

err := checkMetaShardInfo(shardData, shardCoordinator, sigVerifier)
assert.Equal(t, providedRandomError, err)
}

//------- checkMiniBlocksHeaders

func TestCheckMiniBlocksHeaders_WithNilOrEmptyShouldReturnNil(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (imh *InterceptedMetaHeader) integrity() error {
return err
}

err = checkMetaShardInfo(imh.hdr.GetShardInfoHandlers(), imh.shardCoordinator)
err = checkMetaShardInfo(imh.hdr.GetShardInfoHandlers(), imh.shardCoordinator, imh.sigVerifier)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit fe5fe2e

Please sign in to comment.