Skip to content

Commit

Permalink
use EpochNotifier instead of EpochStartNotifier to transition to the …
Browse files Browse the repository at this point in the history
…new consensus version
  • Loading branch information
AdoAdoAdo committed Dec 19, 2024
1 parent f9527f6 commit be02d30
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 376 deletions.
5 changes: 3 additions & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

# ChainParametersByEpoch defines chain operation configurable values that can be modified based on epochs
ChainParametersByEpoch = [
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 7, ShardMinNumNodes = 10, MetachainConsensusGroupSize = 10, MetachainMinNumNodes = 10, Hysteresis = 0.2, Adaptivity = false }
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 2, ShardMinNumNodes = 2, MetachainConsensusGroupSize = 2, MetachainMinNumNodes = 2, Hysteresis = 0.2, Adaptivity = false },
{ EnableEpoch = 4, RoundDuration = 6000, ShardConsensusGroupSize = 2, ShardMinNumNodes = 2, MetachainConsensusGroupSize = 2, MetachainMinNumNodes = 2, Hysteresis = 0.2, Adaptivity = false }
]

[HardwareRequirements]
Expand Down Expand Up @@ -628,7 +629,7 @@
[EpochStartConfig]
GenesisEpoch = 0
MinRoundsBetweenEpochs = 20
RoundsPerEpoch = 200
RoundsPerEpoch = 40
# Min and Max ShuffledOutRestartThreshold represents the minimum and maximum duration of an epoch (in percentage) after a node which
# has been shuffled out has to restart its process in order to start in a new shard
MinShuffledOutRestartThreshold = 0.05
Expand Down
329 changes: 0 additions & 329 deletions cmd/node/config/nodesSetup.json

Large diffs are not rendered by default.

32 changes: 8 additions & 24 deletions consensus/spos/bls/proxy/subroundsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proxy
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"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
Expand Down Expand Up @@ -57,6 +56,13 @@ type SubroundsHandler struct {
currentConsensusType consensusStateMachineType
}

func (s *SubroundsHandler) EpochConfirmed(epoch uint32, _ uint64) {
err := s.initSubroundsForEpoch(epoch)
if err != nil {
log.Error("SubroundsHandler.EpochStartAction: cannot initialize subrounds", "error", err)
}
}

const (
consensusNone consensusStateMachineType = iota
consensusV1
Expand Down Expand Up @@ -85,7 +91,7 @@ func NewSubroundsHandler(args *SubroundsHandlerArgs) (*SubroundsHandler, error)
currentConsensusType: consensusNone,
}

subroundHandler.consensusCoreHandler.EpochStartRegistrationHandler().RegisterHandler(subroundHandler)
subroundHandler.consensusCoreHandler.EpochNotifier().RegisterNotifyHandler(subroundHandler)

return subroundHandler, nil
}
Expand Down Expand Up @@ -189,28 +195,6 @@ func (s *SubroundsHandler) initSubroundsForEpoch(epoch uint32) error {
return nil
}

// EpochStartAction is called when the epoch starts
func (s *SubroundsHandler) EpochStartAction(hdr data.HeaderHandler) {
if check.IfNil(hdr) {
log.Error("SubroundsHandler.EpochStartAction: nil header")
return
}

err := s.initSubroundsForEpoch(hdr.GetEpoch())
if err != nil {
log.Error("SubroundsHandler.EpochStartAction: cannot initialize subrounds", "error", err)
}
}

// EpochStartPrepare prepares the subrounds handler for the epoch start
func (s *SubroundsHandler) EpochStartPrepare(_ data.HeaderHandler, _ data.BodyHandler) {
}

// NotifyOrder returns the order of the subrounds handler
func (s *SubroundsHandler) NotifyOrder() uint32 {
return common.ConsensusHandlerOrder
}

// IsInterfaceNil returns true if there is no value under the interface
func (s *SubroundsHandler) IsInterfaceNil() bool {
return s == nil
Expand Down
19 changes: 3 additions & 16 deletions consensus/spos/bls/proxy/subroundsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/stretchr/testify/require"

chainCommon "github.com/multiversx/mx-chain-go/common"
mock2 "github.com/multiversx/mx-chain-go/consensus/mock"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/bootstrapperStubs"
Expand Down Expand Up @@ -384,18 +383,6 @@ func TestSubroundsHandler_Start(t *testing.T) {
})
}

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

handlerArgs, _ := getDefaultArgumentsSubroundHandler()
sh, err := NewSubroundsHandler(handlerArgs)
require.Nil(t, err)
require.NotNil(t, sh)

order := sh.NotifyOrder()
require.Equal(t, uint32(chainCommon.ConsensusHandlerOrder), order)
}

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

Expand All @@ -417,7 +404,7 @@ func TestSubroundsHandler_IsInterfaceNil(t *testing.T) {
})
}

func TestSubroundsHandler_EpochStartAction(t *testing.T) {
func TestSubroundsHandler_EpochConfirmed(t *testing.T) {
t.Parallel()

t.Run("nil handler does not panic", func(t *testing.T) {
Expand All @@ -431,7 +418,7 @@ func TestSubroundsHandler_EpochStartAction(t *testing.T) {
handlerArgs, _ := getDefaultArgumentsSubroundHandler()
sh, err := NewSubroundsHandler(handlerArgs)
require.Nil(t, err)
sh.EpochStartAction(&testscommon.HeaderHandlerStub{})
sh.EpochConfirmed(0, 0)
})

// tested through initSubroundsForEpoch
Expand Down Expand Up @@ -460,7 +447,7 @@ func TestSubroundsHandler_EpochStartAction(t *testing.T) {
require.NotNil(t, sh)

sh.currentConsensusType = consensusNone
sh.EpochStartAction(&testscommon.HeaderHandlerStub{})
sh.EpochConfirmed(0, 0)
require.Nil(t, err)
require.Equal(t, consensusV1, sh.currentConsensusType)
require.Equal(t, int32(1), startCalled.Load())
Expand Down
9 changes: 9 additions & 0 deletions consensus/spos/consensusCore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"

"github.com/multiversx/mx-chain-go/common"
cryptoCommon "github.com/multiversx/mx-chain-go/common/crypto"
"github.com/multiversx/mx-chain-go/consensus"
Expand Down Expand Up @@ -41,6 +42,7 @@ type ConsensusCore struct {
signingHandler consensus.SigningHandler
enableEpochsHandler common.EnableEpochsHandler
equivalentProofsPool consensus.EquivalentProofsPool
epochNotifier process.EpochNotifier
}

// ConsensusCoreArgs store all arguments that are needed to create a ConsensusCore object
Expand Down Expand Up @@ -69,6 +71,7 @@ type ConsensusCoreArgs struct {
SigningHandler consensus.SigningHandler
EnableEpochsHandler common.EnableEpochsHandler
EquivalentProofsPool consensus.EquivalentProofsPool
EpochNotifier process.EpochNotifier
}

// NewConsensusCore creates a new ConsensusCore instance
Expand Down Expand Up @@ -100,6 +103,7 @@ func NewConsensusCore(
signingHandler: args.SigningHandler,
enableEpochsHandler: args.EnableEpochsHandler,
equivalentProofsPool: args.EquivalentProofsPool,
epochNotifier: args.EpochNotifier,
}

err := ValidateConsensusCore(consensusCore)
Expand Down Expand Up @@ -180,6 +184,11 @@ func (cc *ConsensusCore) EpochStartRegistrationHandler() epochStart.Registration
return cc.epochStartRegistrationHandler
}

// EpochNotifier returns the epoch notifier
func (cc *ConsensusCore) EpochNotifier() process.EpochNotifier {
return cc.epochNotifier
}

// PeerHonestyHandler will return the peer honesty handler which will be used in subrounds
func (cc *ConsensusCore) PeerHonestyHandler() consensus.PeerHonestyHandler {
return cc.peerHonestyHandler
Expand Down
3 changes: 3 additions & 0 deletions consensus/spos/consensusCoreValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func ValidateConsensusCore(container ConsensusCoreHandler) error {
if check.IfNil(container.EquivalentProofsPool()) {
return ErrNilEquivalentProofPool
}
if check.IfNil(container.EpochNotifier()) {
return ErrNilEpochNotifier
}

return nil
}
3 changes: 3 additions & 0 deletions consensus/spos/consensusCoreValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/cryptoMocks"
"github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
epochNotifierMock "github.com/multiversx/mx-chain-go/testscommon/epochNotifier"
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
"github.com/multiversx/mx-chain-go/testscommon/shardingMocks"
)
Expand Down Expand Up @@ -41,6 +42,7 @@ func initConsensusDataContainer() *ConsensusCore {
signingHandler := &consensusMocks.SigningHandlerStub{}
enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{}
proofsPool := &dataRetriever.ProofsPoolMock{}
epochNotifier := &epochNotifierMock.EpochNotifierStub{}

return &ConsensusCore{
blockChain: blockChain,
Expand All @@ -66,6 +68,7 @@ func initConsensusDataContainer() *ConsensusCore {
signingHandler: signingHandler,
enableEpochsHandler: enableEpochsHandler,
equivalentProofsPool: proofsPool,
epochNotifier: epochNotifier,
}
}

Expand Down
1 change: 1 addition & 0 deletions consensus/spos/consensusCore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func createDefaultConsensusCoreArgs() *spos.ConsensusCoreArgs {
SigningHandler: consensusCoreMock.SigningHandler(),
EnableEpochsHandler: consensusCoreMock.EnableEpochsHandler(),
EquivalentProofsPool: consensusCoreMock.EquivalentProofsPool(),
EpochNotifier: consensusCoreMock.EpochNotifier(),
}
return args
}
Expand Down
3 changes: 3 additions & 0 deletions consensus/spos/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,6 @@ var ErrHeaderProofNotExpected = errors.New("header proof not expected")

// ErrConsensusMessageNotExpected signals that a consensus message was not expected
var ErrConsensusMessageNotExpected = errors.New("consensus message not expected")

// ErrNilEpochNotifier signals that a nil epoch notifier has been provided
var ErrNilEpochNotifier = errors.New("nil epoch notifier")
1 change: 1 addition & 0 deletions consensus/spos/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ConsensusCoreHandler interface {
SigningHandler() consensus.SigningHandler
EnableEpochsHandler() common.EnableEpochsHandler
EquivalentProofsPool() consensus.EquivalentProofsPool
EpochNotifier() process.EpochNotifier
IsInterfaceNil() bool
}

Expand Down
3 changes: 2 additions & 1 deletion epochStart/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/state"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

// TriggerHandler defines the functionalities for an start of epoch trigger
Expand Down
3 changes: 2 additions & 1 deletion epochStart/metachain/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
"github.com/multiversx/mx-chain-core-go/display"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("epochStart/metachain")
Expand Down
1 change: 1 addition & 0 deletions epochStart/notifier/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package notifier

import (
"github.com/multiversx/mx-chain-core-go/data"

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

Expand Down
1 change: 1 addition & 0 deletions epochStart/notifier/epochStartSubscriptionHandler.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/check"
"github.com/multiversx/mx-chain-core-go/data"

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

Expand Down
1 change: 1 addition & 0 deletions factory/consensus/consensusComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func (ccf *consensusComponentsFactory) Create() (*consensusComponents, error) {
SigningHandler: ccf.cryptoComponents.ConsensusSigningHandler(),
EnableEpochsHandler: ccf.coreComponents.EnableEpochsHandler(),
EquivalentProofsPool: ccf.dataComponents.Datapool().Proofs(),
EpochNotifier: ccf.coreComponents.EpochNotifier(),
}

consensusDataContainer, err := spos.NewConsensusCore(
Expand Down
1 change: 1 addition & 0 deletions factory/mock/epochStartNotifierStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mock

import (
"github.com/multiversx/mx-chain-core-go/data"

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

Expand Down
1 change: 1 addition & 0 deletions integrationTests/mock/epochStartNotifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mock

import (
"github.com/multiversx/mx-chain-core-go/data"

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

Expand Down
1 change: 1 addition & 0 deletions node/mock/epochStartNotifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mock

import (
"github.com/multiversx/mx-chain-core-go/data"

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

Expand Down
7 changes: 5 additions & 2 deletions process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package block
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"math/big"
"sync"
Expand All @@ -13,6 +14,8 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/headerVersionData"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/holders"
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand All @@ -22,7 +25,6 @@ import (
"github.com/multiversx/mx-chain-go/process/block/helpers"
"github.com/multiversx/mx-chain-go/process/block/processedMb"
"github.com/multiversx/mx-chain-go/state"
logger "github.com/multiversx/mx-chain-logger-go"
)

const firstHeaderNonce = uint64(1)
Expand Down Expand Up @@ -202,7 +204,7 @@ func (mp *metaProcessor) ProcessBlock(

err := mp.checkBlockValidity(headerHandler, bodyHandler)
if err != nil {
if err == process.ErrBlockHashDoesNotMatch {
if errors.Is(err, process.ErrBlockHashDoesNotMatch) {
log.Debug("requested missing meta header",
"hash", headerHandler.GetPrevHash(),
"for shard", headerHandler.GetShardID(),
Expand Down Expand Up @@ -2463,6 +2465,7 @@ func (mp *metaProcessor) CreateNewHeader(round uint64, nonce uint64) (data.Heade
}

mp.roundNotifier.CheckRound(header)
mp.epochNotifier.CheckEpoch(header)

err = metaHeader.SetNonce(nonce)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions sharding/chainParametersHolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

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

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
)
Expand Down
8 changes: 7 additions & 1 deletion testscommon/consensus/consensusDataContainerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
)

// TODO: remove this mock component; implement setters for main component in export_test.go
// ConsensusCoreMock -
// TODO: remove this mock component; implement setters for main component in export_test.go
type ConsensusCoreMock struct {
blockChain data.ChainHandler
blockProcessor process.BlockProcessor
Expand All @@ -43,6 +43,7 @@ type ConsensusCoreMock struct {
signingHandler consensus.SigningHandler
enableEpochsHandler common.EnableEpochsHandler
equivalentProofsPool consensus.EquivalentProofsPool
epochNotifier process.EpochNotifier
}

// GetAntiFloodHandler -
Expand Down Expand Up @@ -295,6 +296,11 @@ func (ccm *ConsensusCoreMock) SetEquivalentProofsPool(proofPool consensus.Equiva
ccm.equivalentProofsPool = proofPool
}

// EpochNotifier -
func (ccm *ConsensusCoreMock) EpochNotifier() process.EpochNotifier {
return ccm.epochNotifier
}

// IsInterfaceNil returns true if there is no value under the interface
func (ccm *ConsensusCoreMock) IsInterfaceNil() bool {
return ccm == nil
Expand Down
Loading

0 comments on commit be02d30

Please sign in to comment.