Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package tendermint
|
|
|
|
import (
|
|
"time"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
cmtbytes "github.com/cometbft/cometbft/libs/bytes"
|
|
cmttypes "github.com/cometbft/cometbft/types"
|
|
|
|
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
|
|
commitmenttypes "github.com/cosmos/ibc-go/v10/modules/core/23-commitment/types"
|
|
"github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
)
|
|
|
|
var _ exported.ConsensusState = (*ConsensusState)(nil)
|
|
|
|
// SentinelRoot is used as a stand-in root value for the consensus state set at the upgrade height
|
|
const SentinelRoot = "sentinel_root"
|
|
|
|
// NewConsensusState creates a new ConsensusState instance.
|
|
func NewConsensusState(
|
|
timestamp time.Time, root commitmenttypes.MerkleRoot, nextValsHash cmtbytes.HexBytes,
|
|
) *ConsensusState {
|
|
return &ConsensusState{
|
|
Timestamp: timestamp,
|
|
Root: root,
|
|
NextValidatorsHash: nextValsHash,
|
|
}
|
|
}
|
|
|
|
// ClientType returns Tendermint
|
|
func (ConsensusState) ClientType() string {
|
|
return exported.Tendermint
|
|
}
|
|
|
|
// GetRoot returns the commitment Root for the specific
|
|
func (cs ConsensusState) GetRoot() exported.Root {
|
|
return cs.Root
|
|
}
|
|
|
|
// GetTimestamp returns block time in nanoseconds of the header that created consensus state
|
|
func (cs ConsensusState) GetTimestamp() uint64 {
|
|
return uint64(cs.Timestamp.UnixNano())
|
|
}
|
|
|
|
// ValidateBasic defines a basic validation for the tendermint consensus state.
|
|
// NOTE: ProcessedTimestamp may be zero if this is an initial consensus state passed in by relayer
|
|
// as opposed to a consensus state constructed by the chain.
|
|
func (cs ConsensusState) ValidateBasic() error {
|
|
if cs.Root.Empty() {
|
|
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "root cannot be empty")
|
|
}
|
|
if err := cmttypes.ValidateHash(cs.NextValidatorsHash); err != nil {
|
|
return errorsmod.Wrap(err, "next validators hash is invalid")
|
|
}
|
|
if cs.Timestamp.Unix() <= 0 {
|
|
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time")
|
|
}
|
|
return nil
|
|
}
|