Documentation ¶
Index ¶
- Variables
- func Mainnet() (*consensus.Network, types.Block)
- func TestnetZen() (*consensus.Network, types.Block)
- type ApplyUpdate
- type DB
- type DBBucket
- type DBStore
- func (db *DBStore) AddBlock(b types.Block, bs *consensus.V1BlockSupplement)
- func (db *DBStore) AddState(cs consensus.State)
- func (db *DBStore) AncestorTimestamp(id types.BlockID) (t time.Time, ok bool)
- func (db *DBStore) ApplyBlock(s consensus.State, cau consensus.ApplyUpdate, mustCommit bool) (committed bool)
- func (db *DBStore) BestIndex(height uint64) (index types.ChainIndex, ok bool)
- func (db *DBStore) Block(id types.BlockID) (types.Block, *consensus.V1BlockSupplement, bool)
- func (db *DBStore) Close() error
- func (db *DBStore) RevertBlock(s consensus.State, cru consensus.RevertUpdate)
- func (db *DBStore) State(id types.BlockID) (consensus.State, bool)
- func (db *DBStore) SupplementTipBlock(b types.Block) (bs consensus.V1BlockSupplement)
- func (db *DBStore) SupplementTipTransaction(txn types.Transaction) (ts consensus.V1TransactionSupplement)
- type Manager
- func (m *Manager) AddBlocks(blocks []types.Block) error
- func (m *Manager) AddPoolTransactions(txns []types.Transaction) (known bool, err error)
- func (m *Manager) AddSubscriber(s Subscriber, tip types.ChainIndex) error
- func (m *Manager) AddV2PoolTransactions(basis types.ChainIndex, txns []types.V2Transaction) (known bool, _ error)
- func (m *Manager) BestIndex(height uint64) (types.ChainIndex, bool)
- func (m *Manager) Block(id types.BlockID) (types.Block, bool)
- func (m *Manager) BlocksForHistory(history []types.BlockID, max uint64) ([]types.Block, uint64, error)
- func (m *Manager) History() ([32]types.BlockID, error)
- func (m *Manager) PoolTransaction(id types.TransactionID) (types.Transaction, bool)
- func (m *Manager) PoolTransactions() []types.Transaction
- func (m *Manager) RecommendedFee() types.Currency
- func (m *Manager) RemoveSubscriber(s Subscriber)
- func (m *Manager) State(id types.BlockID) (consensus.State, bool)
- func (m *Manager) Tip() types.ChainIndex
- func (m *Manager) TipState() consensus.State
- func (m *Manager) TransactionsForPartialBlock(missing []types.Hash256) (txns []types.Transaction, v2txns []types.V2Transaction)
- func (m *Manager) UnconfirmedParents(txn types.Transaction) []types.Transaction
- func (m *Manager) V2PoolTransaction(id types.TransactionID) (types.V2Transaction, bool)
- func (m *Manager) V2PoolTransactions() []types.V2Transaction
- type MemDB
- type RevertUpdate
- type Store
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFutureBlock is returned when a block's timestamp is too far in the future. ErrFutureBlock = errors.New("block's timestamp is too far in the future") )
Functions ¶
Types ¶
type ApplyUpdate ¶
type ApplyUpdate struct { consensus.ApplyUpdate Block types.Block State consensus.State // post-application }
An ApplyUpdate reflects the changes to the blockchain resulting from the addition of a block.
type DB ¶
type DB interface { Bucket(name []byte) DBBucket CreateBucket(name []byte) (DBBucket, error) Flush() error Cancel() }
A DB is a generic key-value database.
type DBBucket ¶
type DBBucket interface { Get(key []byte) []byte Put(key, value []byte) error Delete(key []byte) error }
A DBBucket is a set of key-value pairs.
type DBStore ¶
type DBStore struct {
// contains filtered or unexported fields
}
DBStore implements Store using a key-value database.
func NewDBStore ¶
func NewDBStore(db DB, n *consensus.Network, genesisBlock types.Block) (_ *DBStore, _ consensus.State, err error)
NewDBStore creates a new DBStore using the provided database. The tip state is also returned.
func (*DBStore) AddBlock ¶ added in v0.1.12
func (db *DBStore) AddBlock(b types.Block, bs *consensus.V1BlockSupplement)
AddBlock implements Store.
func (*DBStore) AncestorTimestamp ¶ added in v0.1.12
AncestorTimestamp implements Store.
func (*DBStore) ApplyBlock ¶ added in v0.1.12
func (db *DBStore) ApplyBlock(s consensus.State, cau consensus.ApplyUpdate, mustCommit bool) (committed bool)
ApplyBlock implements Store.
func (*DBStore) BestIndex ¶
func (db *DBStore) BestIndex(height uint64) (index types.ChainIndex, ok bool)
BestIndex implements Store.
func (*DBStore) RevertBlock ¶ added in v0.1.12
func (db *DBStore) RevertBlock(s consensus.State, cru consensus.RevertUpdate)
RevertBlock implements Store.
func (*DBStore) SupplementTipBlock ¶ added in v0.1.12
func (db *DBStore) SupplementTipBlock(b types.Block) (bs consensus.V1BlockSupplement)
SupplementTipBlock implements Store.
func (*DBStore) SupplementTipTransaction ¶ added in v0.1.12
func (db *DBStore) SupplementTipTransaction(txn types.Transaction) (ts consensus.V1TransactionSupplement)
SupplementTipTransaction implements Store.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
A Manager tracks multiple blockchains and identifies the best valid chain.
func NewManager ¶
NewManager returns a Manager initialized with the provided Store and State.
func (*Manager) AddBlocks ¶
AddBlocks adds a sequence of blocks to a tracked chain. If the blocks are valid, the chain may become the new best chain, triggering a reorg.
func (*Manager) AddPoolTransactions ¶ added in v0.1.11
func (m *Manager) AddPoolTransactions(txns []types.Transaction) (known bool, err error)
AddPoolTransactions validates a transaction set and adds it to the txpool. If any transaction references an element (SiacoinOutput, SiafundOutput, or FileContract) not present in the blockchain, that element must be created by a previous transaction in the set.
If any transaction in the set is invalid, the entire set is rejected and none of the transactions are added to the pool. If all of the transactions are already known to the pool, AddPoolTransactions returns true.
func (*Manager) AddSubscriber ¶
func (m *Manager) AddSubscriber(s Subscriber, tip types.ChainIndex) error
AddSubscriber subscribes s to m, ensuring that it will receive updates when the best chain changes. If tip does not match the Manager's current tip, s is updated accordingly.
func (*Manager) AddV2PoolTransactions ¶ added in v0.1.12
func (m *Manager) AddV2PoolTransactions(basis types.ChainIndex, txns []types.V2Transaction) (known bool, _ error)
AddV2PoolTransactions validates a transaction set and adds it to the txpool. If any transaction references an element (SiacoinOutput, SiafundOutput, or FileContract) not present in the blockchain, that element must be created by a previous transaction in the set.
If any transaction in the set is invalid, the entire set is rejected and none of the transactions are added to the pool. If all of the transactions are already known to the pool, AddV2PoolTransactions returns true.
Since v2 transactions include Merkle proofs, AddV2PoolTransactions takes an index specifying the accumulator state for which those proofs are assumed to be valid. If that index differs from the Manager's current tip, the Merkle proofs will be updated accordingly. The original transactions are not modified.
func (*Manager) BestIndex ¶ added in v0.1.12
func (m *Manager) BestIndex(height uint64) (types.ChainIndex, bool)
BestIndex returns the index of the block at the specified height within the best chain.
func (*Manager) BlocksForHistory ¶
func (m *Manager) BlocksForHistory(history []types.BlockID, max uint64) ([]types.Block, uint64, error)
BlocksForHistory returns up to max consecutive blocks from the best chain, starting from the "attach point" -- the first ID in the history that is present in the best chain (or, if no match is found, genesis). It also returns the number of blocks between the end of the returned slice and the current tip.
func (*Manager) History ¶
History returns a set of block IDs that span the best chain, beginning with the 10 most-recent blocks, and subsequently spaced exponentionally farther apart until reaching the genesis block.
func (*Manager) PoolTransaction ¶ added in v0.1.11
func (m *Manager) PoolTransaction(id types.TransactionID) (types.Transaction, bool)
PoolTransaction returns the transaction with the specified ID, if it is currently in the pool.
func (*Manager) PoolTransactions ¶ added in v0.1.11
func (m *Manager) PoolTransactions() []types.Transaction
PoolTransactions returns the transactions currently in the txpool. Any prefix of the returned slice constitutes a valid transaction set.
func (*Manager) RecommendedFee ¶ added in v0.1.11
RecommendedFee returns the recommended fee (per weight unit) to ensure a high probability of inclusion in the next block.
func (*Manager) RemoveSubscriber ¶ added in v0.1.12
func (m *Manager) RemoveSubscriber(s Subscriber)
RemoveSubscriber unsubscribes s from m.
func (*Manager) Tip ¶
func (m *Manager) Tip() types.ChainIndex
Tip returns the tip of the best known valid chain.
func (*Manager) TransactionsForPartialBlock ¶ added in v0.1.12
func (m *Manager) TransactionsForPartialBlock(missing []types.Hash256) (txns []types.Transaction, v2txns []types.V2Transaction)
TransactionsForPartialBlock returns the transactions in the txpool with the specified hashes.
func (*Manager) UnconfirmedParents ¶ added in v0.1.11
func (m *Manager) UnconfirmedParents(txn types.Transaction) []types.Transaction
UnconfirmedParents returns the transactions in the txpool that are referenced by txn.
func (*Manager) V2PoolTransaction ¶ added in v0.1.12
func (m *Manager) V2PoolTransaction(id types.TransactionID) (types.V2Transaction, bool)
V2PoolTransaction returns the v2 transaction with the specified ID, if it is currently in the pool.
func (*Manager) V2PoolTransactions ¶ added in v0.1.12
func (m *Manager) V2PoolTransactions() []types.V2Transaction
V2PoolTransactions returns the v2 transactions currently in the txpool. Any prefix of the returned slice constitutes a valid transaction set.
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
MemDB implements DB with an in-memory map.
func (*MemDB) CreateBucket ¶ added in v0.1.12
CreateBucket implements DB.
type RevertUpdate ¶
type RevertUpdate struct { consensus.RevertUpdate Block types.Block State consensus.State // post-reversion, i.e. pre-application }
A RevertUpdate reflects the changes to the blockchain resulting from the removal of a block.
type Store ¶
type Store interface { BestIndex(height uint64) (types.ChainIndex, bool) SupplementTipTransaction(txn types.Transaction) consensus.V1TransactionSupplement SupplementTipBlock(b types.Block) consensus.V1BlockSupplement Block(id types.BlockID) (types.Block, *consensus.V1BlockSupplement, bool) AddBlock(b types.Block, bs *consensus.V1BlockSupplement) State(id types.BlockID) (consensus.State, bool) AddState(cs consensus.State) AncestorTimestamp(id types.BlockID) (time.Time, bool) // Except when mustCommit is set, ApplyBlock and RevertBlock are free to // commit whenever they see fit. ApplyBlock(s consensus.State, cau consensus.ApplyUpdate, mustCommit bool) (committed bool) RevertBlock(s consensus.State, cru consensus.RevertUpdate) }
A Store durably commits Manager-related data to storage. I/O errors must be handled internally, e.g. by panicking or calling os.Exit.
type Subscriber ¶
type Subscriber interface { // Implementations MUST not commit updates to persistent storage unless mayCommit is set. ProcessChainApplyUpdate(cau *ApplyUpdate, mayCommit bool) error ProcessChainRevertUpdate(cru *RevertUpdate) error }
A Subscriber processes updates to the blockchain. Implementations must not modify or retain the provided update object.