badger

package
v0.29.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBootstrapped

func IsBootstrapped(db *badger.DB) (bool, error)

IsBootstrapped returns whether or not the database contains a bootstrapped state

func IsValidRootSnapshot

func IsValidRootSnapshot(snap protocol.Snapshot, verifyResultID bool) error

IsValidRootSnapshot checks internal consistency of root state snapshot if verifyResultID allows/disallows Result ID verification

func IsValidRootSnapshotQCs

func IsValidRootSnapshotQCs(snap protocol.Snapshot) error

IsValidRootSnapshotQCs checks internal consistency of QCs that are included in the root state snapshot It verifies QCs for main consensus and for each collection cluster.

func SkipNetworkAddressValidation

func SkipNetworkAddressValidation(conf *BootstrapConfig)

Types

type BootstrapConfig

type BootstrapConfig struct {
	// SkipNetworkAddressValidation flags allows skipping all the network address related validations not needed for
	// an unstaked node
	SkipNetworkAddressValidation bool
}

type BootstrapConfigOptions

type BootstrapConfigOptions func(conf *BootstrapConfig)

type Config

type Config struct {
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() Config

type EpochQuery

type EpochQuery struct {
	// contains filtered or unexported fields
}

EpochQuery encapsulates querying epochs w.r.t. a snapshot.

func (*EpochQuery) Current

func (q *EpochQuery) Current() protocol.Epoch

Current returns the current epoch.

func (*EpochQuery) Next

func (q *EpochQuery) Next() protocol.Epoch

Next returns the next epoch, if it is available.

func (*EpochQuery) Previous

func (q *EpochQuery) Previous() protocol.Epoch

Previous returns the previous epoch. During the first epoch after the root block, this returns a sentinel error (since there is no previous epoch). For all other epochs, returns the previous epoch.

type FollowerState

type FollowerState struct {
	*State
	// contains filtered or unexported fields
}

FollowerState implements a lighter version of a mutable protocol state. When extending the state, it performs hardly any checks on the block payload. Instead, the FollowerState relies on the consensus nodes to run the full payload check. Consequently, a block B should only be considered valid, if a child block with a valid header is known. The child block's header includes quorum certificate, which proves that a super-majority of consensus nodes consider block B as valid.

The FollowerState allows non-consensus nodes to execute fork-aware queries against the protocol state, while minimizing the amount of payload checks the non-consensus nodes have to perform.

func NewFollowerState

func NewFollowerState(
	state *State,
	index storage.Index,
	payloads storage.Payloads,
	tracer module.Tracer,
	consumer protocol.Consumer,
	blockTimer protocol.BlockTimer,
) (*FollowerState, error)

NewFollowerState initializes a light-weight version of a mutable protocol state. This implementation is suitable only for NON-Consensus nodes.

func (*FollowerState) Extend

func (m *FollowerState) Extend(ctx context.Context, candidate *flow.Block) error

Extend extends the protocol state of a CONSENSUS FOLLOWER. While it checks the validity of the header; it does _not_ check the validity of the payload. Instead, the consensus follower relies on the consensus participants to validate the full payload. Therefore, a follower a QC (i.e. a child block) as proof that a block is valid.

func (*FollowerState) Finalize

func (m *FollowerState) Finalize(ctx context.Context, blockID flow.Identifier) error

Finalize marks the specified block as finalized. This method only finalizes one block at a time. Hence, the parent of `blockID` has to be the last finalized block.

func (*FollowerState) MarkValid

func (m *FollowerState) MarkValid(blockID flow.Identifier) error

MarkValid marks the block as valid in protocol state, and triggers `BlockProcessable` event to notify that its parent block is processable.

Why is the parent block processable, not the block itself? because a block having a child block means it has been verified by the majority of consensus participants. Hence, if a block has passed the header validity check, its parent block must have passed both the header validity check and the body validity check. So that consensus followers can skip the block body validity checks and wait for its child to arrive, and if the child passes the header validity check, it means the consensus participants have done a complete check on its parent block, so consensus followers can trust consensus nodes did the right job, and start processing the parent block.

NOTE: since a parent can have multiple children, `BlockProcessable` event could be triggered multiple times for the same block. NOTE: BlockProcessable should not be blocking, otherwise, it will block the follower

type MutableState

type MutableState struct {
	*FollowerState
	// contains filtered or unexported fields
}

MutableState implements a mutable protocol state. When extending the state with a new block, it checks the _entire_ block payload.

func NewFullConsensusState

func NewFullConsensusState(
	state *State,
	index storage.Index,
	payloads storage.Payloads,
	tracer module.Tracer,
	consumer protocol.Consumer,
	blockTimer protocol.BlockTimer,
	receiptValidator module.ReceiptValidator,
	sealValidator module.SealValidator,
) (*MutableState, error)

NewFullConsensusState initializes a new mutable protocol state backed by a badger database. When extending the state with a new block, it checks the _entire_ block payload. Consensus nodes should use the FullConsensusState, while other node roles can use the lighter FollowerState.

func (*MutableState) Extend

func (m *MutableState) Extend(ctx context.Context, candidate *flow.Block) error

Extend extends the protocol state of a CONSENSUS PARTICIPANT. It checks the validity of the _entire block_ (header and full payload).

type Params

type Params struct {
	// contains filtered or unexported fields
}

func (*Params) ChainID

func (p *Params) ChainID() (flow.ChainID, error)

func (*Params) ProtocolVersion

func (p *Params) ProtocolVersion() (uint, error)

func (*Params) Root

func (p *Params) Root() (*flow.Header, error)

func (*Params) Seal

func (p *Params) Seal() (*flow.Seal, error)

func (*Params) SporkID

func (p *Params) SporkID() (flow.Identifier, error)

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot implements the protocol.Snapshot interface. It represents a read-only immutable snapshot of the protocol state at the block it is constructed with. It allows efficient access to data associated directly with blocks at a given state (finalized, sealed), such as the related header, commit, seed or descending blocks. A block snapshot can lazily convert to an epoch snapshot in order to make data associated directly with epochs accessible through its API.

func NewSnapshot

func NewSnapshot(state *State, blockID flow.Identifier) *Snapshot

func (*Snapshot) Commit

func (s *Snapshot) Commit() (flow.StateCommitment, error)

Commit retrieves the latest execution state commitment at the current block snapshot. This commitment represents the execution state as currently finalized.

func (*Snapshot) Descendants

func (s *Snapshot) Descendants() ([]flow.Identifier, error)

func (*Snapshot) Epochs

func (s *Snapshot) Epochs() protocol.EpochQuery

func (*Snapshot) Head

func (s *Snapshot) Head() (*flow.Header, error)

func (*Snapshot) Identities

func (s *Snapshot) Identities(selector flow.IdentityFilter) (flow.IdentityList, error)

func (*Snapshot) Identity

func (s *Snapshot) Identity(nodeID flow.Identifier) (*flow.Identity, error)

func (*Snapshot) Params

func (s *Snapshot) Params() protocol.GlobalParams

func (*Snapshot) Phase

func (s *Snapshot) Phase() (flow.EpochPhase, error)

func (*Snapshot) QuorumCertificate

func (s *Snapshot) QuorumCertificate() (*flow.QuorumCertificate, error)

QuorumCertificate (QC) returns a valid quorum certificate pointing to the header at this snapshot. With the exception of the root block, a valid child block must be which contains the desired QC. The sentinel error state.NoValidChildBlockError is returned if the the QC is unknown.

For root block snapshots, returns the root quorum certificate. For all other blocks, generates a quorum certificate from a valid child, if one exists.

func (*Snapshot) RandomSource

func (s *Snapshot) RandomSource() ([]byte, error)

RandomSource returns the seed for the current block snapshot. Expected error returns: * state.NoValidChildBlockError if no valid child is known

func (*Snapshot) SealedResult

func (s *Snapshot) SealedResult() (*flow.ExecutionResult, *flow.Seal, error)

func (*Snapshot) SealingSegment

func (s *Snapshot) SealingSegment() (*flow.SealingSegment, error)

SealingSegment will walk through the chain backward until we reach the block referenced by the latest seal and build a SealingSegment. As we visit each block we check each execution receipt in the block's payload to make sure we have a corresponding execution result, any execution results missing from blocks are stored in the SealingSegment.ExecutionResults field.

func (*Snapshot) ValidDescendants

func (s *Snapshot) ValidDescendants() ([]flow.Identifier, error)

type State

type State struct {
	// contains filtered or unexported fields
}

func Bootstrap

func Bootstrap(
	metrics module.ComplianceMetrics,
	db *badger.DB,
	headers storage.Headers,
	seals storage.Seals,
	results storage.ExecutionResults,
	blocks storage.Blocks,
	setups storage.EpochSetups,
	commits storage.EpochCommits,
	statuses storage.EpochStatuses,
	root protocol.Snapshot,
	options ...BootstrapConfigOptions,
) (*State, error)

func OpenState

func OpenState(
	metrics module.ComplianceMetrics,
	db *badger.DB,
	headers storage.Headers,
	seals storage.Seals,
	results storage.ExecutionResults,
	blocks storage.Blocks,
	setups storage.EpochSetups,
	commits storage.EpochCommits,
	statuses storage.EpochStatuses,
) (*State, error)

func (*State) AtBlockID

func (state *State) AtBlockID(blockID flow.Identifier) protocol.Snapshot

func (*State) AtHeight

func (state *State) AtHeight(height uint64) protocol.Snapshot

func (*State) Final

func (state *State) Final() protocol.Snapshot

func (*State) Params

func (state *State) Params() protocol.Params

func (*State) Sealed

func (state *State) Sealed() protocol.Snapshot

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL