Skip to content

Commit

Permalink
FEAT: Ugly version force round config at genesis cross chain hdr
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Oct 9, 2024
1 parent d10f1aa commit e87ab70
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
6 changes: 5 additions & 1 deletion cmd/sovereignnode/incomingHeader/incomingHeaderProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func (ihp *incomingHeaderProcessor) AddHeader(headerHash []byte, header sovereig
return data.ErrNilHeader
}

log.Info("received incoming header", "hash", hex.EncodeToString(headerHash), "nonce", header.GetHeaderHandler().GetNonce())
log.Info("received incoming header",
"hash", hex.EncodeToString(headerHash),
"nonce", header.GetHeaderHandler().GetNonce(),
"round", header.GetHeaderHandler().GetRound(),
)

round := header.GetHeaderHandler().GetRound()
if round < ihp.mainChainNotarizationStartRound {
Expand Down
2 changes: 1 addition & 1 deletion factory/runType/sovereignRunTypeComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (rcf *sovereignRunTypeComponentsFactory) Create() (*runTypeComponents, erro
return nil, fmt.Errorf("sovereignRunTypeComponentsFactory - NewSovereignForkDetectorFactory failed: %w", err)
}

blockTrackerFactory, err := track.NewSovereignBlockTrackerFactory(rtc.blockTrackerCreator)
blockTrackerFactory, err := track.NewSovereignBlockTrackerFactory(rtc.blockTrackerCreator, rcf.sovConfig.MainChainNotarization.MainChainNotarizationStartRound)
if err != nil {
return nil, fmt.Errorf("sovereignRunTypeComponentsFactory - NewSovereignBlockTrackerFactory failed: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions process/block/sovereignChainBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,14 @@ func (scbp *sovereignChainBlockProcessor) checkExtendedShardHeadersValidity() er
return err
}

log.Trace("checkExtendedShardHeadersValidity", "lastCrossNotarizedHeader nonce", lastCrossNotarizedHeader.GetNonce())
log.Error("checkExtendedShardHeadersValidity", "lastCrossNotarizedHeader nonce", lastCrossNotarizedHeader.GetNonce())
extendedShardHdrs := scbp.sortExtendedShardHeadersForCurrentBlockByNonce()
if len(extendedShardHdrs) == 0 {
return nil
}

for _, extendedShardHdr := range extendedShardHdrs {
log.Trace("checkExtendedShardHeadersValidity", "extendedShardHeader nonce", extendedShardHdr.GetNonce())
log.Error("checkExtendedShardHeadersValidity", "extendedShardHeader nonce", extendedShardHdr.GetNonce())
err = scbp.headerValidator.IsHeaderConstructionValid(extendedShardHdr, lastCrossNotarizedHeader)
if err != nil {
return fmt.Errorf("%w : checkExtendedShardHeadersValidity -> isHdrConstructionValid", err)
Expand Down
10 changes: 6 additions & 4 deletions process/track/sovereignBlockTrackerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import (
)

type sovereignBlockTrackerFactory struct {
blockTrackerCreator BlockTrackerCreator
blockTrackerCreator BlockTrackerCreator
mainChainNotarizationStartRound uint64
}

// NewSovereignBlockTrackerFactory creates a new shard block tracker factory for sovereign chain
func NewSovereignBlockTrackerFactory(btc BlockTrackerCreator) (*sovereignBlockTrackerFactory, error) {
func NewSovereignBlockTrackerFactory(btc BlockTrackerCreator, mainChainNotarizationStartRound uint64) (*sovereignBlockTrackerFactory, error) {
if check.IfNil(btc) {
return nil, process.ErrNilBlockTrackerCreator
}
return &sovereignBlockTrackerFactory{
blockTrackerCreator: btc,
blockTrackerCreator: btc,
mainChainNotarizationStartRound: mainChainNotarizationStartRound,
}, nil
}

Expand All @@ -30,7 +32,7 @@ func (sbtcf *sovereignBlockTrackerFactory) CreateBlockTracker(argBaseTracker Arg
return nil, process.ErrWrongTypeAssertion
}

return NewSovereignChainShardBlockTrack(shardBlockTracker)
return NewSovereignChainShardBlockTrack(shardBlockTracker, sbtcf.mainChainNotarizationStartRound)
}

// IsInterfaceNil returns true if there is no value under the interface
Expand Down
19 changes: 16 additions & 3 deletions process/track/sovereignChainShardBlockTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import (

type sovereignChainShardBlockTrack struct {
*shardBlockTrack
mainChainNotarizationStartRound uint64
}

// NewSovereignChainShardBlockTrack creates an object for tracking the received shard blocks
func NewSovereignChainShardBlockTrack(shardBlockTrack *shardBlockTrack) (*sovereignChainShardBlockTrack, error) {
func NewSovereignChainShardBlockTrack(shardBlockTrack *shardBlockTrack, mainChainNotarizationStartRound uint64) (*sovereignChainShardBlockTrack, error) {
if shardBlockTrack == nil {
return nil, process.ErrNilBlockTracker
}

scsbt := &sovereignChainShardBlockTrack{
shardBlockTrack,
mainChainNotarizationStartRound,
}

bp, ok := scsbt.blockProcessor.(*blockProcessor)
Expand Down Expand Up @@ -108,8 +110,19 @@ func (scsbt *sovereignChainShardBlockTrack) receivedExtendedShardHeader(

// TODO: This condition will permit to the sovereign chain to follow the main chain headers starting with a header
// having a nonce higher than nonce 1 (the first block after genesis)
if scsbt.isGenesisLastCrossNotarizedHeader() {
scsbt.crossNotarizer.AddNotarizedHeader(core.MainChainShardId, extendedShardHeaderHandler, extendedShardHeaderHash)
if scsbt.isGenesisLastCrossNotarizedHeader() && extendedShardHeaderHandler.GetRound() == scsbt.mainChainNotarizationStartRound {
startHdr := map[uint32]data.HeaderHandler{
core.MainChainShardId: extendedShardHeaderHandler,
}

log.Error("ADDED GENESIS HEADER")

err := scsbt.crossNotarizer.InitNotarizedHeaders(startHdr)
if err != nil {
log.Error("sovereignChainShardBlockTrack.receivedExtendedShardHeader.InitNotarizedHeaders", "error", err)
return
}
//scsbt.crossNotarizer.AddNotarizedHeader(core.MainChainShardId, extendedShardHeaderHandler, extendedShardHeaderHash)
}

if !scsbt.shouldAddExtendedShardHeader(extendedShardHeaderHandler) {
Expand Down

0 comments on commit e87ab70

Please sign in to comment.