Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sovereign] Save last notarized cross chain headers in epoch start data #329

Open
wants to merge 2 commits into
base: feat/sovereign
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions data/block/sovereignChainHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"

"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-core-go/data/headerVersionData"
Expand Down Expand Up @@ -631,18 +632,40 @@ func (sch *SovereignChainHeader) SetAccumulatedFeesInEpoch(value *big.Int) error
return nil
}

// GetEpochStartHandler returns epoch start header handler as for metachain, but without last finalized headers
// GetEpochStartHandler returns epoch start header handler as for metachain, but with last finalized headers from main chain, if found.
func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler {
if sch == nil {
return nil
}

lastFinalizedCrossChainHeaderData := EpochStartShardData{
ShardID: sch.EpochStart.LastFinalizedCrossChainHeader.ShardID,
Epoch: sch.EpochStart.LastFinalizedCrossChainHeader.Epoch,
Round: sch.EpochStart.LastFinalizedCrossChainHeader.Round,
Nonce: sch.EpochStart.LastFinalizedCrossChainHeader.Nonce,
HeaderHash: sch.EpochStart.LastFinalizedCrossChainHeader.HeaderHash,
}

epochStartShardData := make([]EpochStartShardData, 0)
if lastFinalizedCrossChainHeaderData.ShardID == core.MainChainShardId {
epochStartShardData = append(epochStartShardData, lastFinalizedCrossChainHeaderData)
}

return &EpochStart{
LastFinalizedHeaders: make([]EpochStartShardData, 0),
LastFinalizedHeaders: epochStartShardData,
Economics: sch.EpochStart.Economics,
}
}

// GetLastFinalizedCrossChainHeaderHandler returns the last finalized cross chain header data
func (sch *SovereignChainHeader) GetLastFinalizedCrossChainHeaderHandler() data.EpochStartChainDataHandler {
if sch == nil {
return nil
}

return &sch.EpochStart.LastFinalizedCrossChainHeader
}

// GetShardInfoHandlers returns empty slice
func (sch *SovereignChainHeader) GetShardInfoHandlers() []data.ShardDataHandler {
if sch == nil {
Expand Down Expand Up @@ -705,3 +728,58 @@ func (omb *OutGoingMiniBlockHeader) SetAggregatedSignatureOutGoingOperations(sig
func (omb *OutGoingMiniBlockHeader) IsInterfaceNil() bool {
return omb == nil
}

// SetShardID sets the epoch start shardID
func (essd *EpochStartCrossChainData) SetShardID(shardID uint32) error {
if essd == nil {
return data.ErrNilPointerReceiver
}

essd.ShardID = shardID

return nil
}

// SetEpoch sets the epoch start epoch
func (essd *EpochStartCrossChainData) SetEpoch(epoch uint32) error {
if essd == nil {
return data.ErrNilPointerReceiver
}

essd.Epoch = epoch

return nil
}

// SetRound sets the epoch start round
func (essd *EpochStartCrossChainData) SetRound(round uint64) error {
if essd == nil {
return data.ErrNilPointerReceiver
}

essd.Round = round

return nil
}

// SetNonce sets the epoch start nonce
func (essd *EpochStartCrossChainData) SetNonce(nonce uint64) error {
if essd == nil {
return data.ErrNilPointerReceiver
}

essd.Nonce = nonce

return nil
}

// SetHeaderHash sets the epoch start header hash
func (essd *EpochStartCrossChainData) SetHeaderHash(hash []byte) error {
if essd == nil {
return data.ErrNilPointerReceiver
}

essd.HeaderHash = hash

return nil
}
Loading
Loading