-
Notifications
You must be signed in to change notification settings - Fork 0
/
consensus_state.go
53 lines (45 loc) · 1.58 KB
/
consensus_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package celestia_da_light_client
import (
"fmt"
"time"
cmtbytes "github.com/cometbft/cometbft/libs/bytes"
cmttypes "github.com/cometbft/cometbft/types"
)
// 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 []byte, nextValsHash cmtbytes.HexBytes,
) *ConsensusState {
return &ConsensusState{
Timestamp: timestamp,
Root: root,
NextValidatorsHash: nextValsHash,
}
}
func (ConsensusState) ClientType() string {
return ModuleName
}
// GetRoot returns the commitment Root for the specific
func (cs ConsensusState) GetRoot() []byte {
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 len(cs.Root) == 0 {
return fmt.Errorf("err invalid consensus, root cannot be empty")
}
if err := cmttypes.ValidateHash(cs.NextValidatorsHash); err != nil {
return fmt.Errorf("error, next validator hash is invalid")
}
if cs.Timestamp.Unix() <= 0 {
return fmt.Errorf("err invalid consensus, timestamp must be a positive Unix time")
}
return nil
}