Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/message_validation_optimization'…
Browse files Browse the repository at this point in the history
… into message_validation_optimization
  • Loading branch information
cristure committed Oct 3, 2024
2 parents 8451f62 + 0deeb37 commit 130e115
Show file tree
Hide file tree
Showing 63 changed files with 10,900 additions and 1,253 deletions.
6 changes: 4 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,10 @@ const (
ChainParametersOrder
// NodesCoordinatorOrder defines the order in which NodesCoordinator is notified of a start of epoch event
NodesCoordinatorOrder
// ConsensusOrder defines the order in which Consensus is notified of a start of epoch event
ConsensusOrder
// ConsensusHandlerOrder defines the order in which ConsensusHandler is notified of a start of epoch event
ConsensusHandlerOrder
// ConsensusStartRoundOrder defines the order in which Consensus StartRound subround is notified of a start of epoch event
ConsensusStartRoundOrder
// NetworkShardingOrder defines the order in which the network sharding subsystem is notified of a start of epoch event
NetworkShardingOrder
// IndexerOrder defines the order in which indexer is notified of a start of epoch event
Expand Down
19 changes: 10 additions & 9 deletions consensus/chronology/chronology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/chronology"
"github.com/multiversx/mx-chain-go/consensus/mock"
consensusMocks "github.com/multiversx/mx-chain-go/testscommon/consensus"
statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler"
)

Expand Down Expand Up @@ -117,7 +118,7 @@ func TestChronology_StartRoundShouldReturnWhenRoundIndexIsNegative(t *testing.T)
t.Parallel()

arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
roundHandlerMock.IndexCalled = func() int64 {
return -1
}
Expand Down Expand Up @@ -151,7 +152,7 @@ func TestChronology_StartRoundShouldReturnWhenDoWorkReturnsFalse(t *testing.T) {
t.Parallel()

arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
roundHandlerMock.UpdateRound(roundHandlerMock.TimeStamp(), roundHandlerMock.TimeStamp().Add(roundHandlerMock.TimeDuration()))
arg.RoundHandler = roundHandlerMock
chr, _ := chronology.NewChronology(arg)
Expand All @@ -168,7 +169,7 @@ func TestChronology_StartRoundShouldWork(t *testing.T) {
t.Parallel()

arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
roundHandlerMock.UpdateRound(roundHandlerMock.TimeStamp(), roundHandlerMock.TimeStamp().Add(roundHandlerMock.TimeDuration()))
arg.RoundHandler = roundHandlerMock
chr, _ := chronology.NewChronology(arg)
Expand Down Expand Up @@ -221,7 +222,7 @@ func TestChronology_InitRoundShouldNotSetSubroundWhenRoundIndexIsNegative(t *tes
t.Parallel()

arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
arg.RoundHandler = roundHandlerMock
arg.GenesisTime = arg.SyncTimer.CurrentTime()
chr, _ := chronology.NewChronology(arg)
Expand All @@ -242,7 +243,7 @@ func TestChronology_InitRoundShouldSetSubroundWhenRoundIndexIsPositive(t *testin
t.Parallel()

arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
roundHandlerMock.UpdateRound(roundHandlerMock.TimeStamp(), roundHandlerMock.TimeStamp().Add(roundHandlerMock.TimeDuration()))
arg.RoundHandler = roundHandlerMock
arg.GenesisTime = arg.SyncTimer.CurrentTime()
Expand All @@ -259,7 +260,7 @@ func TestChronology_StartRoundShouldNotUpdateRoundWhenCurrentRoundIsNotFinished(
t.Parallel()

arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
arg.RoundHandler = roundHandlerMock
arg.GenesisTime = arg.SyncTimer.CurrentTime()
chr, _ := chronology.NewChronology(arg)
Expand All @@ -273,7 +274,7 @@ func TestChronology_StartRoundShouldNotUpdateRoundWhenCurrentRoundIsNotFinished(
func TestChronology_StartRoundShouldUpdateRoundWhenCurrentRoundIsFinished(t *testing.T) {
t.Parallel()
arg := getDefaultChronologyArg()
roundHandlerMock := &mock.RoundHandlerMock{}
roundHandlerMock := &consensusMocks.RoundHandlerMock{}
arg.RoundHandler = roundHandlerMock
arg.GenesisTime = arg.SyncTimer.CurrentTime()
chr, _ := chronology.NewChronology(arg)
Expand Down Expand Up @@ -317,8 +318,8 @@ func TestChronology_CheckIfStatusHandlerWorks(t *testing.T) {
func getDefaultChronologyArg() chronology.ArgChronology {
return chronology.ArgChronology{
GenesisTime: time.Now(),
RoundHandler: &mock.RoundHandlerMock{},
SyncTimer: &mock.SyncTimerMock{},
RoundHandler: &consensusMocks.RoundHandlerMock{},
SyncTimer: &consensusMocks.SyncTimerMock{},
AppStatusHandler: statusHandlerMock.NewAppStatusHandlerMock(),
Watchdog: &mock.WatchdogMock{},
}
Expand Down
1 change: 1 addition & 0 deletions consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
crypto "github.com/multiversx/mx-chain-crypto-go"

"github.com/multiversx/mx-chain-go/p2p"
)

Expand Down
20 changes: 11 additions & 9 deletions consensus/round/round_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"time"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/consensus/mock"

"github.com/multiversx/mx-chain-go/consensus/round"
consensusMocks "github.com/multiversx/mx-chain-go/testscommon/consensus"

"github.com/stretchr/testify/assert"
)

Expand All @@ -28,7 +30,7 @@ func TestRound_NewRoundShouldWork(t *testing.T) {

genesisTime := time.Now()

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

rnd, err := round.NewRound(genesisTime, genesisTime, roundTimeDuration, syncTimerMock, 0)

Expand All @@ -41,7 +43,7 @@ func TestRound_UpdateRoundShouldNotChangeAnything(t *testing.T) {

genesisTime := time.Now()

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

rnd, _ := round.NewRound(genesisTime, genesisTime, roundTimeDuration, syncTimerMock, 0)
oldIndex := rnd.Index()
Expand All @@ -61,7 +63,7 @@ func TestRound_UpdateRoundShouldAdvanceOneRound(t *testing.T) {

genesisTime := time.Now()

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

rnd, _ := round.NewRound(genesisTime, genesisTime, roundTimeDuration, syncTimerMock, 0)
oldIndex := rnd.Index()
Expand All @@ -76,7 +78,7 @@ func TestRound_IndexShouldReturnFirstIndex(t *testing.T) {

genesisTime := time.Now()

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

rnd, _ := round.NewRound(genesisTime, genesisTime, roundTimeDuration, syncTimerMock, 0)
rnd.UpdateRound(genesisTime, genesisTime.Add(roundTimeDuration/2))
Expand All @@ -90,7 +92,7 @@ func TestRound_TimeStampShouldReturnTimeStampOfTheNextRound(t *testing.T) {

genesisTime := time.Now()

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

rnd, _ := round.NewRound(genesisTime, genesisTime, roundTimeDuration, syncTimerMock, 0)
rnd.UpdateRound(genesisTime, genesisTime.Add(roundTimeDuration+roundTimeDuration/2))
Expand All @@ -104,7 +106,7 @@ func TestRound_TimeDurationShouldReturnTheDurationOfOneRound(t *testing.T) {

genesisTime := time.Now()

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

rnd, _ := round.NewRound(genesisTime, genesisTime, roundTimeDuration, syncTimerMock, 0)
timeDuration := rnd.TimeDuration()
Expand All @@ -117,7 +119,7 @@ func TestRound_RemainingTimeInCurrentRoundShouldReturnPositiveValue(t *testing.T

genesisTime := time.Unix(0, 0)

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

timeElapsed := int64(roundTimeDuration - 1)

Expand All @@ -138,7 +140,7 @@ func TestRound_RemainingTimeInCurrentRoundShouldReturnNegativeValue(t *testing.T

genesisTime := time.Unix(0, 0)

syncTimerMock := &mock.SyncTimerMock{}
syncTimerMock := &consensusMocks.SyncTimerMock{}

timeElapsed := int64(roundTimeDuration + 1)

Expand Down
22 changes: 11 additions & 11 deletions consensus/spos/bls/blsWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/multiversx/mx-chain-go/consensus/spos"
)

// peerMaxMessagesPerSec defines how many messages can be propagated by a pid in a round. The value was chosen by
// PeerMaxMessagesPerSec defines how many messages can be propagated by a pid in a round. The value was chosen by
// following the next premises:
// 1. a leader can propagate as maximum as 3 messages per round: proposed header block + proposed body + final info;
// 2. due to the fact that a delayed signature of the proposer (from previous round) can be received in the current round
Expand All @@ -16,15 +16,15 @@ import (
//
// Validators only send one signature message in a round, treating the edge case of a delayed message, will need at most
// 2 messages per round (which is ok as it is below the set value of 5)
const peerMaxMessagesPerSec = uint32(6)
const PeerMaxMessagesPerSec = uint32(6)

// defaultMaxNumOfMessageTypeAccepted represents the maximum number of the same message type accepted in one round to be
// DefaultMaxNumOfMessageTypeAccepted represents the maximum number of the same message type accepted in one round to be
// received from the same public key for the default message types
const defaultMaxNumOfMessageTypeAccepted = uint32(1)
const DefaultMaxNumOfMessageTypeAccepted = uint32(1)

// maxNumOfMessageTypeSignatureAccepted represents the maximum number of the signature message type accepted in one round to be
// MaxNumOfMessageTypeSignatureAccepted represents the maximum number of the signature message type accepted in one round to be
// received from the same public key
const maxNumOfMessageTypeSignatureAccepted = uint32(2)
const MaxNumOfMessageTypeSignatureAccepted = uint32(2)

// worker defines the data needed by spos to communicate between nodes which are in the validators group
type worker struct {
Expand Down Expand Up @@ -52,17 +52,17 @@ func (wrk *worker) InitReceivedMessages() map[consensus.MessageType][]*consensus

// GetMaxMessagesInARoundPerPeer returns the maximum number of messages a peer can send per round for BLS
func (wrk *worker) GetMaxMessagesInARoundPerPeer() uint32 {
return peerMaxMessagesPerSec
return PeerMaxMessagesPerSec
}

// GetStringValue gets the name of the messageType
func (wrk *worker) GetStringValue(messageType consensus.MessageType) string {
return getStringValue(messageType)
return GetStringValue(messageType)
}

// GetSubroundName gets the subround name for the subround id provided
func (wrk *worker) GetSubroundName(subroundId int) string {
return getSubroundName(subroundId)
return GetSubroundName(subroundId)
}

// IsMessageWithBlockBodyAndHeader returns if the current messageType is about block body and header
Expand Down Expand Up @@ -151,10 +151,10 @@ func (wrk *worker) CanProceed(consensusState *spos.ConsensusState, msgType conse
// GetMaxNumOfMessageTypeAccepted returns the maximum number of accepted consensus message types per round, per public key
func (wrk *worker) GetMaxNumOfMessageTypeAccepted(msgType consensus.MessageType) uint32 {
if msgType == MtSignature {
return maxNumOfMessageTypeSignatureAccepted
return MaxNumOfMessageTypeSignatureAccepted
}

return defaultMaxNumOfMessageTypeAccepted
return DefaultMaxNumOfMessageTypeAccepted
}

// IsInterfaceNil returns true if there is no value under the interface
Expand Down
Loading

0 comments on commit 130e115

Please sign in to comment.