Skip to content

Commit

Permalink
FEAT: Extend sov header with EpochStartChainDataHandler interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Oct 18, 2024
1 parent c92f909 commit f6bd53c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
66 changes: 65 additions & 1 deletion data/block/sovereignChainHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ 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
Expand All @@ -657,6 +657,15 @@ func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler {
}
}

// 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 @@ -719,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
}
2 changes: 1 addition & 1 deletion data/block/sovereignChainHeader.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "metaBlock.proto";

// EpochStart holds the block information for end-of-epoch
message EpochStartSovereign {
Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false];
Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false];
EpochStartCrossChainData LastFinalizedCrossChainHeader = 2 [(gogoproto.jsontag) = "lastFinalizedCrossChainHeader", (gogoproto.nullable) = false];
}

Expand Down
20 changes: 14 additions & 6 deletions data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type SovereignChainHeaderHandler interface {
GetEpochStartHandler() EpochStartHandler
GetShardInfoHandlers() []ShardDataHandler
SetShardInfoHandlers(shardInfo []ShardDataHandler) error
GetLastFinalizedCrossChainHeaderHandler() EpochStartChainDataHandler
}

// OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header
Expand Down Expand Up @@ -243,23 +244,30 @@ type ShardDataHandler interface {
ShallowClone() ShardDataHandler
}

// EpochStartShardDataHandler defines setters and getters for EpochStartShardData
type EpochStartShardDataHandler interface {
// EpochStartChainDataHandler defines setters and getters for basic information related to epoch start data
type EpochStartChainDataHandler interface {
GetShardID() uint32
GetEpoch() uint32
GetRound() uint64
GetNonce() uint64
GetHeaderHash() []byte
GetRootHash() []byte
GetFirstPendingMetaBlock() []byte
GetLastFinishedMetaBlock() []byte
GetPendingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler

SetShardID(uint32) error
SetEpoch(uint32) error
SetRound(uint64) error
SetNonce(uint64) error
SetHeaderHash([]byte) error
}

// EpochStartShardDataHandler defines setters and getters for EpochStartShardData
type EpochStartShardDataHandler interface {
EpochStartChainDataHandler

GetRootHash() []byte
GetFirstPendingMetaBlock() []byte
GetLastFinishedMetaBlock() []byte
GetPendingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler

SetRootHash([]byte) error
SetFirstPendingMetaBlock([]byte) error
SetLastFinishedMetaBlock([]byte) error
Expand Down

0 comments on commit f6bd53c

Please sign in to comment.