Documentation
¶
Index ¶
- Variables
- func ForEachHostAnnouncement(b types.Block, fn func(types.PublicKey, HostAnnouncement))
- 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)
- 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) Flush() 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 HostAnnouncement
- type Manager
- func (m *Manager) AddBlocks(blocks []types.Block) error
- func (m *Manager) AddPoolTransactions(txns []types.Transaction) (known bool, err 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, maxBlocks uint64) ([]types.Block, uint64, error)
- func (m *Manager) History() ([32]types.BlockID, error)
- func (m *Manager) OnReorg(fn func(types.ChainIndex)) (cancel func())
- 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) 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) UpdatesSince(index types.ChainIndex, maxBlocks int) (rus []RevertUpdate, aus []ApplyUpdate, err error)
- func (m *Manager) V2PoolTransaction(id types.TransactionID) (types.V2Transaction, bool)
- func (m *Manager) V2PoolTransactions() []types.V2Transaction
- type MemDB
- type RevertUpdate
- type Store
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 ¶
func ForEachHostAnnouncement ¶ added in v0.0.2
func ForEachHostAnnouncement(b types.Block, fn func(types.PublicKey, HostAnnouncement))
ForEachHostAnnouncement calls fn on each host announcement in a block.
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 ¶
func (db *DBStore) AddBlock(b types.Block, bs *consensus.V1BlockSupplement)
AddBlock implements Store.
func (*DBStore) AncestorTimestamp ¶
AncestorTimestamp implements Store.
func (*DBStore) ApplyBlock ¶
func (db *DBStore) ApplyBlock(s consensus.State, cau consensus.ApplyUpdate)
ApplyBlock implements Store.
func (*DBStore) BestIndex ¶
func (db *DBStore) BestIndex(height uint64) (index types.ChainIndex, ok bool)
BestIndex implements Store.
func (*DBStore) RevertBlock ¶
func (db *DBStore) RevertBlock(s consensus.State, cru consensus.RevertUpdate)
RevertBlock implements Store.
func (*DBStore) SupplementTipBlock ¶
func (db *DBStore) SupplementTipBlock(b types.Block) (bs consensus.V1BlockSupplement)
SupplementTipBlock implements Store.
func (*DBStore) SupplementTipTransaction ¶
func (db *DBStore) SupplementTipTransaction(txn types.Transaction) (ts consensus.V1TransactionSupplement)
SupplementTipTransaction implements Store.
type HostAnnouncement ¶ added in v0.0.2
type HostAnnouncement struct {
NetAddress string
}
A HostAnnouncement represents a signed announcement of a host's network address. Announcements may be made via arbitrary data (in a v1 transaction) or via attestation (in a v2 transaction).
func (HostAnnouncement) ToArbitraryData ¶ added in v0.0.2
func (ha HostAnnouncement) ToArbitraryData(sk types.PrivateKey) []byte
ToArbitraryData encodes a host announcement as arbitrary data.
func (HostAnnouncement) ToAttestation ¶ added in v0.0.2
func (ha HostAnnouncement) ToAttestation(cs consensus.State, sk types.PrivateKey) types.Attestation
ToAttestation encodes a host announcement as an attestation.
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 ¶
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) AddV2PoolTransactions ¶
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 and none of their memory is retained.
func (*Manager) BestIndex ¶
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, maxBlocks 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) OnReorg ¶ added in v0.0.4
func (m *Manager) OnReorg(fn func(types.ChainIndex)) (cancel func())
OnReorg adds fn to the set of functions that are called whenever the best chain changes. It returns a function that removes fn from the set.
The supplied function must not block or call any Manager methods.
func (*Manager) PoolTransaction ¶
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 ¶
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 ¶
RecommendedFee returns the recommended fee (per weight unit) to ensure a high probability of inclusion in the next block.
func (*Manager) Tip ¶
func (m *Manager) Tip() types.ChainIndex
Tip returns the tip of the best known valid chain.
func (*Manager) TransactionsForPartialBlock ¶
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 ¶
func (m *Manager) UnconfirmedParents(txn types.Transaction) []types.Transaction
UnconfirmedParents returns the transactions in the txpool that are referenced by txn.
func (*Manager) UpdatesSince ¶ added in v0.0.4
func (m *Manager) UpdatesSince(index types.ChainIndex, maxBlocks int) (rus []RevertUpdate, aus []ApplyUpdate, err error)
UpdatesSince returns at most max updates on the path between index and the Manager's current tip.
func (*Manager) V2PoolTransaction ¶
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 ¶
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 ¶
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) // ApplyBlock and RevertBlock are free to commit whenever they see fit. ApplyBlock(s consensus.State, cau consensus.ApplyUpdate) RevertBlock(s consensus.State, cru consensus.RevertUpdate) Flush() error }
A Store durably commits Manager-related data to storage. I/O errors must be handled internally, e.g. by panicking or calling os.Exit.