Skip to content

Commit

Permalink
Merge branch 'feat/equivalent-messages' into add-custom-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 authored Feb 7, 2025
2 parents a9f4607 + 3909d04 commit 6389b29
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 28 deletions.
8 changes: 8 additions & 0 deletions epochStart/shardchain/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,14 @@ func (t *trigger) receivedProof(headerProof data.HeaderProofHandler) {
// upon receiving checks if trigger can be updated
func (t *trigger) receivedMetaBlock(headerHandler data.HeaderHandler, metaBlockHash []byte) {
if t.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, headerHandler.GetEpoch()) {
proof, err := t.proofsPool.GetProof(headerHandler.GetShardID(), metaBlockHash)
if err != nil {
return
}

t.mutTrigger.Lock()
t.checkMetaHeaderForEpochTriggerEquivalentProofs(headerHandler, proof.GetHeaderHash())
t.mutTrigger.Unlock()
return
}

Expand Down
2 changes: 2 additions & 0 deletions factory/consensus/consensusComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ func (ccf *consensusComponentsFactory) createShardBootstrapper() (process.Bootst
EpochNotifier: ccf.coreComponents.EpochNotifier(),
ProcessedMiniBlocksTracker: ccf.processComponents.ProcessedMiniBlocksTracker(),
AppStatusHandler: ccf.statusCoreComponents.AppStatusHandler(),
EnableEpochsHandler: ccf.coreComponents.EnableEpochsHandler(),
}

argsShardStorageBootstrapper := storageBootstrap.ArgsShardStorageBootstrapper{
Expand Down Expand Up @@ -606,6 +607,7 @@ func (ccf *consensusComponentsFactory) createMetaChainBootstrapper() (process.Bo
EpochNotifier: ccf.coreComponents.EpochNotifier(),
ProcessedMiniBlocksTracker: ccf.processComponents.ProcessedMiniBlocksTracker(),
AppStatusHandler: ccf.statusCoreComponents.AppStatusHandler(),
EnableEpochsHandler: ccf.coreComponents.EnableEpochsHandler(),
}

argsMetaStorageBootstrapper := storageBootstrap.ArgsMetaStorageBootstrapper{
Expand Down
8 changes: 8 additions & 0 deletions factory/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ForkDetectorMock struct {
ResetProbableHighestNonceCalled func()
SetFinalToLastCheckpointCalled func()
ReceivedProofCalled func(proof data.HeaderProofHandler)
AddCheckpointCalled func(nonce uint64, round uint64, hash []byte)
}

// RestoreToGenesis -
Expand Down Expand Up @@ -120,6 +121,13 @@ func (fdm *ForkDetectorMock) ReceivedProof(proof data.HeaderProofHandler) {
}
}

// AddCheckpoint -
func (fdm *ForkDetectorMock) AddCheckpoint(nonce uint64, round uint64, hash []byte) {
if fdm.AddCheckpointCalled != nil {
fdm.AddCheckpointCalled(nonce, round, hash)
}
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorMock) IsInterfaceNil() bool {
return fdm == nil
Expand Down
8 changes: 8 additions & 0 deletions integrationTests/mock/forkDetectorStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ForkDetectorStub struct {
ResetProbableHighestNonceCalled func()
SetFinalToLastCheckpointCalled func()
ReceivedProofCalled func(proof data.HeaderProofHandler)
AddCheckpointCalled func(nonce uint64, round uint64, hash []byte)
}

// RestoreToGenesis -
Expand Down Expand Up @@ -123,6 +124,13 @@ func (fdm *ForkDetectorStub) ReceivedProof(proof data.HeaderProofHandler) {
}
}

// AddCheckpoint -
func (fdm *ForkDetectorStub) AddCheckpoint(nonce uint64, round uint64, hash []byte) {
if fdm.AddCheckpointCalled != nil {
fdm.AddCheckpointCalled(nonce, round, hash)
}
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorStub) IsInterfaceNil() bool {
return fdm == nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ func testNodeStartsInEpoch(t *testing.T, shardID uint32, expectedHighestRound ui
EpochNotifier: genericEpochNotifier,
ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{},
AppStatusHandler: &statusHandlerMock.AppStatusHandlerMock{},
EnableEpochsHandler: enableEpochsHandler,
}

bootstrapper, err := getBootstrapper(shardID, argsBaseBootstrapper)
Expand Down
8 changes: 8 additions & 0 deletions node/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ForkDetectorMock struct {
ResetProbableHighestNonceCalled func()
SetFinalToLastCheckpointCalled func()
ReceivedProofCalled func(proof data.HeaderProofHandler)
AddCheckpointCalled func(nonce uint64, round uint64, hash []byte)
}

// RestoreToGenesis -
Expand Down Expand Up @@ -82,6 +83,13 @@ func (fdm *ForkDetectorMock) ResetProbableHighestNonce() {
}
}

// AddCheckpoint -
func (fdm *ForkDetectorMock) AddCheckpoint(nonce uint64, round uint64, hash []byte) {
if fdm.AddCheckpointCalled != nil {
fdm.AddCheckpointCalled(nonce, round, hash)
}
}

// SetFinalToLastCheckpoint -
func (fdm *ForkDetectorMock) SetFinalToLastCheckpoint() {
if fdm.SetFinalToLastCheckpointCalled != nil {
Expand Down
1 change: 1 addition & 0 deletions process/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ type ForkDetector interface {
RestoreToGenesis()
GetNotarizedHeaderHash(nonce uint64) []byte
ResetProbableHighestNonce()
AddCheckpoint(nonce uint64, round uint64, hash []byte)
SetFinalToLastCheckpoint()
ReceivedProof(proof data.HeaderProofHandler)
IsInterfaceNil() bool
Expand Down
8 changes: 8 additions & 0 deletions process/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ForkDetectorMock struct {
ResetProbableHighestNonceCalled func()
SetFinalToLastCheckpointCalled func()
ReceivedProofCalled func(proof data.HeaderProofHandler)
AddCheckpointCalled func(nonce uint64, round uint64, hash []byte)
}

// RestoreToGenesis -
Expand Down Expand Up @@ -123,6 +124,13 @@ func (fdm *ForkDetectorMock) ReceivedProof(proof data.HeaderProofHandler) {
}
}

// AddCheckpoint -
func (fdm *ForkDetectorMock) AddCheckpoint(nonce uint64, round uint64, hash []byte) {
if fdm.AddCheckpointCalled != nil {
fdm.AddCheckpointCalled(nonce, round, hash)
}
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorMock) IsInterfaceNil() bool {
return fdm == nil
Expand Down
10 changes: 10 additions & 0 deletions process/sync/baseForkDetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ func (bfd *baseForkDetector) addCheckpoint(checkpoint *checkpointInfo) {
bfd.mutFork.Unlock()
}

// AddCheckpoint adds a new checkpoint in the list
func (bfd *baseForkDetector) AddCheckpoint(nonce uint64, round uint64, hash []byte) {
checkpoint := &checkpointInfo{
nonce: nonce,
round: round,
hash: hash,
}
bfd.addCheckpoint(checkpoint)
}

func (bfd *baseForkDetector) lastCheckpoint() *checkpointInfo {
bfd.mutFork.RLock()
lastIndex := len(bfd.fork.checkpoint) - 1
Expand Down
1 change: 1 addition & 0 deletions process/sync/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

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

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

Expand Down
16 changes: 15 additions & 1 deletion process/sync/storageBootstrap/baseStorageBootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/typeConverters"
"github.com/multiversx/mx-chain-core-go/marshal"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block/bootstrapStorage"
Expand All @@ -17,7 +20,6 @@ import (
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/storage"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("process/sync")
Expand All @@ -44,6 +46,7 @@ type ArgsBaseStorageBootstrapper struct {
EpochNotifier process.EpochNotifier
ProcessedMiniBlocksTracker process.ProcessedMiniBlocksTracker
AppStatusHandler core.AppStatusHandler
EnableEpochsHandler common.EnableEpochsHandler
}

// ArgsShardStorageBootstrapper is structure used to create a new storage bootstrapper for shard
Expand Down Expand Up @@ -79,6 +82,7 @@ type storageBootstrapper struct {
epochNotifier process.EpochNotifier
processedMiniBlocksTracker process.ProcessedMiniBlocksTracker
appStatusHandler core.AppStatusHandler
enableEpochsHandler common.EnableEpochsHandler
}

func (st *storageBootstrapper) loadBlocks() error {
Expand Down Expand Up @@ -445,7 +449,14 @@ func (st *storageBootstrapper) applyBlock(headerHash []byte, header data.HeaderH
}

st.blkc.SetCurrentBlockHeaderHash(headerHash)
if !st.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, header.GetEpoch()) {
return nil
}

st.forkDetector.AddCheckpoint(header.GetNonce(), header.GetRound(), headerHash)
if header.GetShardID() == core.MetachainShardId || !check.IfNilReflect(header.GetPreviousProof()) {
st.forkDetector.SetFinalToLastCheckpoint()
}
return nil
}

Expand Down Expand Up @@ -513,6 +524,9 @@ func checkBaseStorageBootstrapperArguments(args ArgsBaseStorageBootstrapper) err
if check.IfNil(args.AppStatusHandler) {
return process.ErrNilAppStatusHandler
}
if check.IfNil(args.EnableEpochsHandler) {
return process.ErrNilEnableEpochsHandler
}

return nil
}
Expand Down
Loading

0 comments on commit 6389b29

Please sign in to comment.