Documentation
¶
Index ¶
- Constants
- type Chain
- type DBLoader
- func (l *DBLoader) Append(blk *block.Block) error
- func (l *DBLoader) BlockAt(searchingHeight uint64) (block.Block, error)
- func (l *DBLoader) CheckBlock(prevBlock block.Block, blk block.Block) error
- func (l *DBLoader) Clear() error
- func (l *DBLoader) Close(driver string) error
- func (l *DBLoader) Height() (uint64, error)
- func (l *DBLoader) LoadTip() (*block.Block, error)
- func (l *DBLoader) PerformSanityCheck(startAt, firstBlocksAmount, lastBlocksAmount uint64) error
- type Loader
- type MockLoader
- func (m *MockLoader) Append(blk *block.Block) error
- func (m *MockLoader) BlockAt(index uint64) (block.Block, error)
- func (m *MockLoader) Clear() error
- func (m *MockLoader) Close(driver string) error
- func (m *MockLoader) Height() (uint64, error)
- func (m *MockLoader) LoadTip() (*block.Block, error)
- func (m *MockLoader) PerformSanityCheck(uint64, uint64, uint64) error
- type MockVerifier
- type Verifier
Constants ¶
const ( // SanityCheckHeight is the suggested amount of blocks to check when // calling Loader.PerformSanityCheck SanityCheckHeight uint64 = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain represents the nodes blockchain This struct will be aware of the current state of the node.
func New ¶
func New(eventBus *eventbus.EventBus, rpcBus *rpcbus.RPCBus, counter *chainsync.Counter, loader Loader, verifier Verifier) (*Chain, error)
New returns a new chain object. It accepts the EventBus (for messages coming from (remote) consensus components, the RPCBus for dispatching synchronous data related to Certificates, Blocks, Rounds and progress. It also accepts a counter to manage the synchronization process and the hash of the genesis block TODO: the counter should be encapsulated in a specific component for synchronization
func (*Chain) AcceptBlock ¶
AcceptBlock will accept a block if 1. We have not seen it before 2. All stateless and statefull checks are true Returns nil, if checks passed and block was successfully saved
type DBLoader ¶ added in v0.3.0
type DBLoader struct {
// contains filtered or unexported fields
}
DBLoader performs database prefetching and sanityChecks at node startup
func NewDBLoader ¶ added in v0.3.0
NewDBLoader returns a Loader which gets the Chain Tip from the DB
func (*DBLoader) CheckBlock ¶ added in v0.3.0
CheckBlock will verify whether a block is valid according to the rules of the consensus returns nil if a block is valid
func (*DBLoader) Height ¶ added in v0.3.0
Height returns the height of the blockchain stored in the DB
func (*DBLoader) PerformSanityCheck ¶ added in v0.3.0
PerformSanityCheck checks the head and the tail of the blockchain to avoid inconsistencies and a faulty bootstrap
type Loader ¶ added in v0.3.0
type Loader interface {
// LoadTip of the chain
LoadTip() (*block.Block, error)
// Clear removes everything from the DB
Clear() error
// Close the Loader and finalizes any pending connection
Close(string) error
// Height returns the current height as stored in the loader
Height() (uint64, error)
// BlockAt returns the block at a given height
BlockAt(uint64) (block.Block, error)
// Append a block on the storage
Append(*block.Block) error
}
Loader is an interface which abstracts away the storage used by the Chain to store the blockchain
func NewMockLoader ¶ added in v0.3.0
func NewMockLoader() Loader
NewMockLoader creates a Mockup of the Loader interface
type MockLoader ¶ added in v0.3.0
type MockLoader struct {
// contains filtered or unexported fields
}
MockLoader is the mock of the DB loader to help testing the chain
func (*MockLoader) Append ¶ added in v0.3.0
func (m *MockLoader) Append(blk *block.Block) error
Append the block to the internal blockchain representation
func (*MockLoader) BlockAt ¶ added in v0.3.0
func (m *MockLoader) BlockAt(index uint64) (block.Block, error)
BlockAt the block to the internal blockchain representation
func (*MockLoader) Close ¶ added in v0.3.0
func (m *MockLoader) Close(driver string) error
Close the mock
func (*MockLoader) Height ¶ added in v0.3.0
func (m *MockLoader) Height() (uint64, error)
Height returns the height currently known by the Loader
func (*MockLoader) LoadTip ¶ added in v0.3.0
func (m *MockLoader) LoadTip() (*block.Block, error)
LoadTip of the chain
func (*MockLoader) PerformSanityCheck ¶ added in v0.3.0
func (m *MockLoader) PerformSanityCheck(uint64, uint64, uint64) error
PerformSanityCheck on first N blocks and M last blocks
type MockVerifier ¶ added in v0.3.0
type MockVerifier struct {
}
MockVerifier is a mock for the chain.Verifier interface
func (*MockVerifier) CheckBlock ¶ added in v0.3.0
CheckBlock will verify whether a block is valid according to the rules of the consensus
func (*MockVerifier) PerformSanityCheck ¶ added in v0.3.0
func (v *MockVerifier) PerformSanityCheck(uint64, uint64, uint64) error
PerformSanityCheck on first N blocks and M last blocks
type Verifier ¶ added in v0.3.0
type Verifier interface {
// PerformSanityCheck on first N blocks and M last blocks
PerformSanityCheck(uint64, uint64, uint64) error
// CheckBlock will verify whether a block is valid according to the rules of the consensus
CheckBlock(prevBlock block.Block, blk block.Block) error
}
Verifier performs checks on the blockchain and potentially new incoming block