Documentation ¶
Overview ¶
Package snowman is a generated GoMock package.
Index ¶
- Variables
- type Block
- type Consensus
- type Factory
- type MockBlock
- func (m *MockBlock) Accept(arg0 context.Context) error
- func (m *MockBlock) Bytes() []byte
- func (m *MockBlock) EXPECT() *MockBlockMockRecorder
- func (m *MockBlock) Height() uint64
- func (m *MockBlock) ID() ids.ID
- func (m *MockBlock) Parent() ids.ID
- func (m *MockBlock) Reject(arg0 context.Context) error
- func (m *MockBlock) Status() choices.Status
- func (m *MockBlock) Timestamp() time.Time
- func (m *MockBlock) Verify(arg0 context.Context) error
- func (m *MockBlock) VerifyProposer(arg0 context.Context) error
- type MockBlockMockRecorder
- func (mr *MockBlockMockRecorder) Accept(arg0 interface{}) *gomock.Call
- func (mr *MockBlockMockRecorder) Bytes() *gomock.Call
- func (mr *MockBlockMockRecorder) Height() *gomock.Call
- func (mr *MockBlockMockRecorder) ID() *gomock.Call
- func (mr *MockBlockMockRecorder) Parent() *gomock.Call
- func (mr *MockBlockMockRecorder) Reject(arg0 interface{}) *gomock.Call
- func (mr *MockBlockMockRecorder) Status() *gomock.Call
- func (mr *MockBlockMockRecorder) Timestamp() *gomock.Call
- func (mr *MockBlockMockRecorder) Verify(arg0 interface{}) *gomock.Call
- func (mr *MockBlockMockRecorder) VerifyProposer(arg0 interface{}) *gomock.Call
- type OracleBlock
- type TestBlock
- func (b *TestBlock) Bytes() []byte
- func (b *TestBlock) Height() uint64
- func (b *TestBlock) Less(other *TestBlock) bool
- func (b *TestBlock) Parent() ids.ID
- func (b *TestBlock) Timestamp() time.Time
- func (b *TestBlock) Verify(context.Context) error
- func (b *TestBlock) VerifyProposer(context.Context) error
- type Topological
- func (ts *Topological) Add(ctx context.Context, blk Block) error
- func (ts *Topological) Decided(blk Block) bool
- func (ts *Topological) HealthCheck(context.Context) (interface{}, error)
- func (ts *Topological) Initialize(ctx *snow.ConsensusContext, params snowball.Parameters, lastAcceptedID ids.ID, ...) error
- func (ts *Topological) IsPreferred(blk Block) bool
- func (ts *Topological) LastAccepted() (ids.ID, uint64)
- func (ts *Topological) NumProcessing() int
- func (ts *Topological) Preference() ids.ID
- func (ts *Topological) PreferenceAtHeight(height uint64) (ids.ID, bool)
- func (ts *Topological) Processing(blkID ids.ID) bool
- func (ts *Topological) RecordPoll(ctx context.Context, voteBag bag.Bag[ids.ID]) error
- type TopologicalFactory
Constants ¶
This section is empty.
Variables ¶
var ErrNotOracle = errors.New("block isn't an oracle")
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block interface { choices.Decidable // Parent returns the ID of this block's parent. Parent() ids.ID VerifyProposer(context.Context) error // Verify that the state transition this block would make if accepted is // valid. If the state transition is invalid, a non-nil error should be // returned. // // It is guaranteed that the Parent has been successfully verified. // // If nil is returned, it is guaranteed that either Accept or Reject will be // called on this block, unless the VM is shut down. Verify(context.Context) error // Bytes returns the binary representation of this block. // // This is used for sending blocks to peers. The bytes should be able to be // parsed into the same block on another node. Bytes() []byte // Height returns the height of this block in the chain. Height() uint64 // Time this block was proposed at. This value should be consistent across // all nodes. If this block hasn't been successfully verified, any value can // be returned. If this block is the last accepted block, the timestamp must // be returned correctly. Otherwise, accepted blocks can return any value. Timestamp() time.Time }
Block is a possible decision that dictates the next canonical block.
Blocks are guaranteed to be Verified, Accepted, and Rejected in topological order. Specifically, if Verify is called, then the parent has already been verified. If Accept is called, then the parent has already been accepted. If Reject is called, the parent has already been accepted or rejected.
If the status of the block is Unknown, ID is assumed to be able to be called. If the status of the block is Accepted or Rejected; Parent, Verify, Accept, and Reject will never be called.
type Consensus ¶
type Consensus interface { health.Checker // Takes in the context, snowball parameters, and the last accepted block. Initialize( ctx *snow.ConsensusContext, params snowball.Parameters, lastAcceptedID ids.ID, lastAcceptedHeight uint64, lastAcceptedTime time.Time, ) error // Returns the number of blocks processing NumProcessing() int // Adds a new decision. Assumes the dependency has already been added. // Returns if a critical error has occurred. Add(context.Context, Block) error // Decided returns true if the block has been decided. Decided(Block) bool // Processing returns true if the block ID is currently processing. Processing(ids.ID) bool // IsPreferred returns true if the block is currently on the preferred // chain. IsPreferred(Block) bool // Returns the ID and height of the last accepted decision. LastAccepted() (ids.ID, uint64) // Returns the ID of the tail of the strongly preferred sequence of // decisions. Preference() ids.ID // Returns the ID of the strongly preferred decision with the provided // height. Only the last accepted decision and processing decisions are // tracked. PreferenceAtHeight(height uint64) (ids.ID, bool) // RecordPoll collects the results of a network poll. Assumes all decisions // have been previously added. Returns if a critical error has occurred. RecordPoll(context.Context, bag.Bag[ids.ID]) error }
Consensus represents a general snowman instance that can be used directly to process a series of dependent operations.
type Factory ¶
type Factory interface {
New() Consensus
}
Factory returns new instances of Consensus
type MockBlock ¶ added in v1.8.3
type MockBlock struct {
// contains filtered or unexported fields
}
MockBlock is a mock of Block interface.
func NewMockBlock ¶ added in v1.8.3
func NewMockBlock(ctrl *gomock.Controller) *MockBlock
NewMockBlock creates a new mock instance.
func (*MockBlock) EXPECT ¶ added in v1.8.3
func (m *MockBlock) EXPECT() *MockBlockMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockBlockMockRecorder ¶ added in v1.8.3
type MockBlockMockRecorder struct {
// contains filtered or unexported fields
}
MockBlockMockRecorder is the mock recorder for MockBlock.
func (*MockBlockMockRecorder) Accept ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Accept(arg0 interface{}) *gomock.Call
Accept indicates an expected call of Accept.
func (*MockBlockMockRecorder) Bytes ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Bytes() *gomock.Call
Bytes indicates an expected call of Bytes.
func (*MockBlockMockRecorder) Height ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Height() *gomock.Call
Height indicates an expected call of Height.
func (*MockBlockMockRecorder) ID ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) ID() *gomock.Call
ID indicates an expected call of ID.
func (*MockBlockMockRecorder) Parent ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Parent() *gomock.Call
Parent indicates an expected call of Parent.
func (*MockBlockMockRecorder) Reject ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Reject(arg0 interface{}) *gomock.Call
Reject indicates an expected call of Reject.
func (*MockBlockMockRecorder) Status ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Status() *gomock.Call
Status indicates an expected call of Status.
func (*MockBlockMockRecorder) Timestamp ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Timestamp() *gomock.Call
Timestamp indicates an expected call of Timestamp.
func (*MockBlockMockRecorder) Verify ¶ added in v1.8.3
func (mr *MockBlockMockRecorder) Verify(arg0 interface{}) *gomock.Call
Verify indicates an expected call of Verify.
func (*MockBlockMockRecorder) VerifyProposer ¶
func (mr *MockBlockMockRecorder) VerifyProposer(arg0 interface{}) *gomock.Call
VerifyProposer indicates an expected call of VerifyProposer.
type OracleBlock ¶ added in v1.6.0
type OracleBlock interface { Block // Options returns the possible children of this block in the order this // validator prefers the blocks. // Options is guaranteed to only be called on a verified block. Options(context.Context) ([2]Block, error) }
OracleBlock is a block that only has two valid children. The children should be returned in preferential order.
This ordering does not need to be deterministically created from the chain state.
type TestBlock ¶ added in v0.8.0
type TestBlock struct { choices.TestDecidable ParentV ids.ID HeightV uint64 TimestampV time.Time VerifyProposerV error VerifyV error BytesV []byte }
TestBlock is a useful test block
type Topological ¶
type Topological struct {
// contains filtered or unexported fields
}
Topological implements the Snowman interface by using a tree tracking the strongly preferred branch. This tree structure amortizes network polls to vote on more than just the next block.
func (*Topological) Decided ¶ added in v1.7.5
func (ts *Topological) Decided(blk Block) bool
func (*Topological) HealthCheck ¶ added in v1.2.2
func (ts *Topological) HealthCheck(context.Context) (interface{}, error)
HealthCheck returns information about the consensus health.
func (*Topological) Initialize ¶
func (ts *Topological) Initialize( ctx *snow.ConsensusContext, params snowball.Parameters, lastAcceptedID ids.ID, lastAcceptedHeight uint64, lastAcceptedTime time.Time, ) error
func (*Topological) IsPreferred ¶ added in v1.2.1
func (ts *Topological) IsPreferred(blk Block) bool
func (*Topological) LastAccepted ¶ added in v1.9.6
func (ts *Topological) LastAccepted() (ids.ID, uint64)
func (*Topological) NumProcessing ¶ added in v1.2.0
func (ts *Topological) NumProcessing() int
func (*Topological) Preference ¶
func (ts *Topological) Preference() ids.ID
func (*Topological) PreferenceAtHeight ¶ added in v1.10.12
func (ts *Topological) PreferenceAtHeight(height uint64) (ids.ID, bool)
func (*Topological) Processing ¶ added in v1.7.5
func (ts *Topological) Processing(blkID ids.ID) bool
func (*Topological) RecordPoll ¶
The votes bag contains at most K votes for blocks in the tree. If there is a vote for a block that isn't in the tree, the vote is dropped.
Votes are propagated transitively towards the genesis. All blocks in the tree that result in at least Alpha votes will record the poll on their children. Every other block will have an unsuccessful poll registered.
After collecting which blocks should be voted on, the polls are registered and blocks are accepted/rejected as needed. The tail is then updated to equal the leaf on the preferred branch.
To optimize the theoretical complexity of the vote propagation, a topological sort is done over the blocks that are reachable from the provided votes. During the sort, votes are pushed towards the genesis. To prevent interating over all blocks that had unsuccessful polls, we set a flag on the block to know that any future traversal through that block should register an unsuccessful poll on that block and every descendant block.
The complexity of this function is: - Runtime = 4 * |live set| + |votes| - Space = 2 * |live set| + |votes|
type TopologicalFactory ¶
type TopologicalFactory struct{}
TopologicalFactory implements Factory by returning a topological struct
func (TopologicalFactory) New ¶
func (TopologicalFactory) New() Consensus