feat: add header and comet info service (#15850)
Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
Package comet defines the Comet Service interface and BlockInfo types which applications
|
||||
should use in order to get access to the current block's evidence, validators hash, proposer address.
|
||||
|
||||
This information is specific to Comet
|
||||
*/
|
||||
package comet
|
||||
@@ -0,0 +1,68 @@
|
||||
package comet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BlockInfoService is an interface that can be used to get information specific to Comet
|
||||
type BlockInfoService interface {
|
||||
GetCometBlockInfo(context.Context) BlockInfo
|
||||
}
|
||||
|
||||
// BlockInfo is the information comet provides apps in ABCI
|
||||
type BlockInfo interface {
|
||||
GetEvidence() EvidenceList // Evidence misbehavior of the block
|
||||
// ValidatorsHash returns the hash of the validators
|
||||
// For Comet, it is the hash of the next validator set
|
||||
GetValidatorsHash() []byte
|
||||
GetProposerAddress() []byte // ProposerAddress returns the address of the block proposer
|
||||
GetLastCommit() CommitInfo // DecidedLastCommit returns the last commit info
|
||||
}
|
||||
|
||||
// MisbehaviorType is the type of misbehavior for a validator
|
||||
type MisbehaviorType int32
|
||||
|
||||
const (
|
||||
Unknown MisbehaviorType = 0
|
||||
DuplicateVote MisbehaviorType = 1
|
||||
LightClientAttack MisbehaviorType = 2
|
||||
)
|
||||
|
||||
// Validator is the validator information of ABCI
|
||||
type Validator interface {
|
||||
Address() []byte
|
||||
Power() int64
|
||||
}
|
||||
|
||||
type EvidenceList interface {
|
||||
Len() int
|
||||
Get(int) Evidence
|
||||
}
|
||||
|
||||
// Evidence is the misbehavior information of ABCI
|
||||
type Evidence interface {
|
||||
Type() MisbehaviorType
|
||||
Validator() Validator
|
||||
Height() int64
|
||||
Time() time.Time
|
||||
TotalVotingPower() int64
|
||||
}
|
||||
|
||||
// CommitInfo is the commit information of ABCI
|
||||
type CommitInfo interface {
|
||||
Round() int32
|
||||
Votes() VoteInfos
|
||||
}
|
||||
|
||||
// VoteInfos is an interface to get specific votes in a efficient way
|
||||
type VoteInfos interface {
|
||||
Len() int
|
||||
Get(int) VoteInfo
|
||||
}
|
||||
|
||||
// VoteInfo is the vote information of ABCI
|
||||
type VoteInfo interface {
|
||||
Validator() Validator
|
||||
SignedLastBlock() bool
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
Package header defines a generalized Header type that all consensus & networking layers must provide.
|
||||
|
||||
If modules need access to the current block header information, like height, hash, time, or chain ID
|
||||
they should use the Header Service interface.
|
||||
*/
|
||||
package header
|
||||
@@ -0,0 +1,19 @@
|
||||
package header
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Service defines the interface in which you can get header information
|
||||
type Service interface {
|
||||
GetHeaderInfo(context.Context) Info
|
||||
}
|
||||
|
||||
// Info defines a struct that contains information about the header
|
||||
type Info struct {
|
||||
Height int64 // Height returns the height of the block
|
||||
Hash []byte // Hash returns the hash of the block header
|
||||
Time time.Time // Time returns the time of the block
|
||||
ChainID string // ChainId returns the chain ID of the block
|
||||
}
|
||||
Reference in New Issue
Block a user