Skip to content

Commit

Permalink
Merge branch 'feat/equivalent-messages' into consensus-v2-integration…
Browse files Browse the repository at this point in the history
…-tests
  • Loading branch information
sstanculeanu authored Feb 6, 2025
2 parents e5eb36a + 308bb27 commit 14e6645
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 16 deletions.
9 changes: 9 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"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"
"github.com/multiversx/mx-chain-go/consensus"
)

// IsValidRelayedTxV3 returns true if the provided transaction is a valid transaction of type relayed v3
Expand Down Expand Up @@ -39,6 +40,14 @@ func IsEpochChangeBlockForFlagActivation(header data.HeaderHandler, enableEpochs
return isStartOfEpochBlock && isBlockInActivationEpoch
}

// IsEpochStartProofForFlagActivation returns true if the provided proof is the proof of the epoch start block on the activation epoch of equivalent messages
func IsEpochStartProofForFlagActivation(proof consensus.ProofHandler, enableEpochsHandler EnableEpochsHandler) bool {
isStartOfEpochProof := proof.GetIsStartOfEpoch()
isProofInActivationEpoch := proof.GetHeaderEpoch() == enableEpochsHandler.GetActivationEpoch(EquivalentMessagesFlag)

return isStartOfEpochProof && isProofInActivationEpoch
}

// isFlagEnabledAfterEpochsStartBlock returns true if the flag is enabled for the header, but it is not the epoch start block
func isFlagEnabledAfterEpochsStartBlock(header data.HeaderHandler, enableEpochsHandler EnableEpochsHandler, flag core.EnableEpochFlag) bool {
isFlagEnabled := enableEpochsHandler.IsFlagEnabledInEpoch(flag, header.GetEpoch())
Expand Down
1 change: 1 addition & 0 deletions consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,5 @@ type ProofHandler interface {
GetHeaderEpoch() uint32
GetHeaderNonce() uint64
GetHeaderShardId() uint32
GetIsStartOfEpoch() bool
}
3 changes: 2 additions & 1 deletion integrationTests/chainSimulator/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) {
Signature: []byte("signature"),
})

time.Sleep(2 * time.Second)
// Allow the eviction to complete (even if it's quite fast).
time.Sleep(3 * time.Second)

expectedNumTransactionsInPool := 300_000 + 1 + 1 - int(storage.TxPoolSourceMeNumItemsToPreemptivelyEvict)
require.Equal(t, expectedNumTransactionsInPool, getNumTransactionsInPool(simulator, shard))
Expand Down
4 changes: 2 additions & 2 deletions integrationTests/chainSimulator/mempool/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
var (
oneEGLD = big.NewInt(1000000000000000000)
oneQuarterOfEGLD = big.NewInt(250000000000000000)
durationWaitAfterSendMany = 1500 * time.Millisecond
durationWaitAfterSendSome = 50 * time.Millisecond
durationWaitAfterSendMany = 3000 * time.Millisecond
durationWaitAfterSendSome = 300 * time.Millisecond
)

func startChainSimulator(t *testing.T, alterConfigsFunction func(cfg *config.Configs)) testsChainSimulator.ChainSimulator {
Expand Down
7 changes: 7 additions & 0 deletions integrationTests/vm/wasm/queries/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/integrationTests"
Expand Down Expand Up @@ -132,6 +133,9 @@ func deploy(t *testing.T, network *integrationTests.MiniNetwork, sender []byte,
)
require.NoError(t, err)

// Allow the transaction to reach the mempool.
time.Sleep(100 * time.Millisecond)

scAddress, _ := network.ShardNode.BlockchainHook.NewAddress(sender, 0, factory.WasmVirtualMachine)
return scAddress
}
Expand All @@ -148,6 +152,9 @@ func setState(t *testing.T, network *integrationTests.MiniNetwork, scAddress []b
)

require.NoError(t, err)

// Allow the transaction to reach the mempool.
time.Sleep(100 * time.Millisecond)
}

func getState(t *testing.T, node *integrationTests.TestProcessorNode, scAddress []byte, blockNonce core.OptionalUint64) int {
Expand Down
6 changes: 6 additions & 0 deletions process/block/interceptedBlocks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ func checkMetaShardInfo(
return err
}

isSelfMeta := coordinator.SelfId() == core.MetachainShardId
isHeaderFromSelf := sd.GetShardID() == coordinator.SelfId()
if !(isSelfMeta || isHeaderFromSelf) {
continue
}

wgProofsVerification.Add(1)
checkProofAsync(sd.GetPreviousProof(), headerSigVerifier, &wgProofsVerification, errChan)
}
Expand Down
29 changes: 16 additions & 13 deletions process/headerCheck/headerSignatureVerify.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func (hsv *HeaderSigVerifier) getConsensusSignersForEquivalentProofs(proof data.
epochForConsensus,
proof.GetHeaderShardId(),
)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -315,7 +314,7 @@ func (hsv *HeaderSigVerifier) VerifyHeaderWithProof(header data.HeaderHandler) e
}

prevProof := header.GetPreviousProof()
if prevProof.GetIsStartOfEpoch() {
if common.IsEpochStartProofForFlagActivation(prevProof, hsv.enableEpochsHandler) {
return hsv.verifyHeaderProofAtTransition(prevProof)
}

Expand All @@ -332,33 +331,33 @@ func (hsv *HeaderSigVerifier) getHeaderForProof(proof data.HeaderProofHandler) (
return process.GetHeader(proof.GetHeaderHash(), hsv.headersPool, headersStorer, hsv.marshalizer, proof.GetHeaderShardId())
}

func (hsv *HeaderSigVerifier) verifyHeaderProofAtTransition(prevProof data.HeaderProofHandler) error {
if check.IfNilReflect(prevProof) {
func (hsv *HeaderSigVerifier) verifyHeaderProofAtTransition(proof data.HeaderProofHandler) error {
if check.IfNilReflect(proof) {
return process.ErrNilHeaderProof
}
header, err := hsv.getHeaderForProof(prevProof)
header, err := hsv.getHeaderForProof(proof)
if err != nil {
return err
}

consensusPubKeys, err := hsv.getConsensusSigners(
header.GetPrevRandSeed(),
prevProof.GetHeaderShardId(),
prevProof.GetHeaderEpoch(),
prevProof.GetIsStartOfEpoch(),
prevProof.GetHeaderRound(),
prevProof.GetHeaderHash(),
prevProof.GetPubKeysBitmap())
proof.GetHeaderShardId(),
proof.GetHeaderEpoch(),
proof.GetIsStartOfEpoch(),
proof.GetHeaderRound(),
proof.GetHeaderHash(),
proof.GetPubKeysBitmap())
if err != nil {
return err
}

multiSigVerifier, err := hsv.multiSigContainer.GetMultiSigner(prevProof.GetHeaderEpoch())
multiSigVerifier, err := hsv.multiSigContainer.GetMultiSigner(proof.GetHeaderEpoch())
if err != nil {
return err
}

return multiSigVerifier.VerifyAggregatedSig(consensusPubKeys, prevProof.GetHeaderHash(), prevProof.GetAggregatedSignature())
return multiSigVerifier.VerifyAggregatedSig(consensusPubKeys, proof.GetHeaderHash(), proof.GetAggregatedSignature())
}

// VerifyHeaderProof checks if the proof is correct for the header
Expand All @@ -370,6 +369,10 @@ func (hsv *HeaderSigVerifier) VerifyHeaderProof(proofHandler data.HeaderProofHan
return fmt.Errorf("%w for flag %s", process.ErrFlagNotActive, common.EquivalentMessagesFlag)
}

if common.IsEpochStartProofForFlagActivation(proofHandler, hsv.enableEpochsHandler) {
return hsv.verifyHeaderProofAtTransition(proofHandler)
}

multiSigVerifier, err := hsv.multiSigContainer.GetMultiSigner(proofHandler.GetHeaderEpoch())
if err != nil {
return err
Expand Down
Loading

0 comments on commit 14e6645

Please sign in to comment.