Skip to content

Commit

Permalink
feat: update header and validate basic in consensus state to compatib…
Browse files Browse the repository at this point in the history
…le with new consensus state struct
  • Loading branch information
dale-smartosc committed May 9, 2024
1 parent 93210db commit 2381429
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
28 changes: 19 additions & 9 deletions cosmos/sidechain/x/clients/mithril/consensus_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ const SentinelRoot = "sentinel_root"
// NewConsensusState creates a new ConsensusState instance.
func NewConsensusState(
timestamp uint64,
mithrilStakeDistributionCertificateHash string,
transactionSnapshotCertificateHash string,
fcHashLatestEpochMsd string,
latestCertHashMsd string,
fcHashLatestEpochTs string,
latestCertHashTs string,
) *ConsensusState {
return &ConsensusState{
Timestamp: timestamp,
MithrilStakeDistributionCertificateHash: mithrilStakeDistributionCertificateHash,
TransactionSnapshotCertificateHash: transactionSnapshotCertificateHash,
Timestamp: timestamp,
FcHashLatestEpochMsd: fcHashLatestEpochMsd,
LatestCertHashMsd: latestCertHashMsd,
FcHashLatestEpochTs: fcHashLatestEpochTs,
LatestCertHashTs: latestCertHashTs,
}
}

Expand All @@ -45,11 +49,17 @@ func (cs ConsensusState) GetTime() time.Time {

// ValidateBasic defines a basic validation for the mithril consensus state.
func (cs ConsensusState) ValidateBasic() error {
if err := cmttypes.ValidateHash([]byte(cs.MithrilStakeDistributionCertificateHash)); err != nil {
return errorsmod.Wrap(err, "mithril stake distribution certificate hash is invalid")
if err := cmttypes.ValidateHash([]byte(cs.FcHashLatestEpochMsd)); err != nil {
return errorsmod.Wrap(err, "first certificate hash of latest epoch of mithril stake distribution is invalid")
}
if err := cmttypes.ValidateHash([]byte(cs.TransactionSnapshotCertificateHash)); err != nil {
return errorsmod.Wrap(err, "transaction snapshot certificate hash is invalid")
if err := cmttypes.ValidateHash([]byte(cs.LatestCertHashMsd)); err != nil {
return errorsmod.Wrap(err, "latest certificate hash of mithril stake distribution is invalid")
}
if err := cmttypes.ValidateHash([]byte(cs.FcHashLatestEpochTs)); err != nil {
return errorsmod.Wrap(err, "first certificate hash of latest epoch of transaction snapshot is invalid")
}
if err := cmttypes.ValidateHash([]byte(cs.LatestCertHashTs)); err != nil {
return errorsmod.Wrap(err, "latest certificate hash of transaction snapshot is invalid")
}
if cs.Timestamp <= 0 {
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time")
Expand Down
6 changes: 3 additions & 3 deletions cosmos/sidechain/x/clients/mithril/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var _ exported.ClientMessage = (*MithrilHeader)(nil)
// ConsensusState returns the updated consensus state associated with the header
func (h MithrilHeader) ConsensusState() *ConsensusState {
return &ConsensusState{
Timestamp: h.GetTimestamp(),
MithrilStakeDistributionCertificateHash: h.MithrilStakeDistributionCertificate.Hash,
TransactionSnapshotCertificateHash: h.TransactionSnapshotCertificate.Hash,
Timestamp: h.GetTimestamp(),
LatestCertHashMsd: h.MithrilStakeDistributionCertificate.Hash,
LatestCertHashTs: h.TransactionSnapshotCertificate.Hash,
}
}

Expand Down

0 comments on commit 2381429

Please sign in to comment.