Documentation
¶
Overview ¶
Package consensus implements the Sia consensus algorithms.
Index ¶
- func ApplyBlock(s State, store Store, b types.Block) (State, BlockDiff)
- type BlockDiff
- type Checkpoint
- type State
- func (s State) BlockInterval() time.Duration
- func (s State) BlockReward() types.Currency
- func (s State) BlockWeight(txns []types.Transaction) uint64
- func (s *State) DecodeFrom(d *types.Decoder)
- func (s State) EncodeTo(e *types.Encoder)
- func (s State) FileContractTax(fc types.FileContract) types.Currency
- func (s State) FoundationSubsidy() (sco types.SiacoinOutput)
- func (s State) MaturityHeight() uint64
- func (s State) MaxBlockWeight() int
- func (s State) NonceFactor() uint64
- func (s State) PartialSigHash(txn types.Transaction, cf types.CoveredFields) types.Hash256
- func (s State) SiafundCount() uint64
- func (s State) StorageProofLeafIndex(filesize uint64, windowStart types.ChainIndex, fcid types.FileContractID) uint64
- func (s State) TransactionWeight(txn types.Transaction) uint64
- func (s State) WholeSigHash(txn types.Transaction, parentID types.Hash256, pubkeyIndex uint64, ...) types.Hash256
- type Store
- type TransactionDiff
- type ValidationContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BlockDiff ¶
type BlockDiff struct { Transactions []TransactionDiff DelayedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput MaturedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput MissedFileContracts map[types.FileContractID]types.FileContract }
A BlockDiff represents the changes to an ElementStore resulting from the application of a block.
type Checkpoint ¶
A Checkpoint pairs a block with its resulting chain state.
type State ¶
type State struct { Index types.ChainIndex `json:"index"` PrevTimestamps [11]time.Time `json:"prevTimestamps"` Depth types.BlockID `json:"depth"` ChildTarget types.BlockID `json:"childTarget"` OakTarget types.BlockID `json:"oakTarget"` OakTime time.Duration `json:"oakTime"` GenesisTimestamp time.Time `json:"genesisTimestamp"` SiafundPool types.Currency `json:"siafundPool"` FoundationPrimaryAddress types.Address `json:"foundationPrimaryAddress"` FoundationFailsafeAddress types.Address `json:"foundationFailsafeAddress"` }
State represents the constant-size state of the chain as of a particular block.
func (State) BlockInterval ¶
BlockInterval is the expected wall clock time between consecutive blocks.
func (State) BlockReward ¶
BlockReward returns the reward for mining a child block.
func (State) BlockWeight ¶
func (s State) BlockWeight(txns []types.Transaction) uint64
BlockWeight computes the combined weight of a block's txns.
func (*State) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (State) FileContractTax ¶
func (s State) FileContractTax(fc types.FileContract) types.Currency
FileContractTax computes the tax levied on a given contract.
func (State) FoundationSubsidy ¶
func (s State) FoundationSubsidy() (sco types.SiacoinOutput)
FoundationSubsidy returns the Foundation subsidy output for the child block. If no subsidy is due, the returned output has a value of zero.
func (State) MaturityHeight ¶
MaturityHeight is the height at which various outputs created in the child block will "mature" (become spendable).
func (State) MaxBlockWeight ¶
MaxBlockWeight is the maximum "weight" of a valid child block.
func (State) NonceFactor ¶
NonceFactor is the factor by which all block nonces must be divisible.
func (State) PartialSigHash ¶
func (s State) PartialSigHash(txn types.Transaction, cf types.CoveredFields) types.Hash256
PartialSigHash computes the hash of the transaction data specified by cf. It panics if cf references fields not present in txn.
func (State) SiafundCount ¶
SiafundCount is the number of siafunds in existence.
func (State) StorageProofLeafIndex ¶
func (s State) StorageProofLeafIndex(filesize uint64, windowStart types.ChainIndex, fcid types.FileContractID) uint64
StorageProofLeafIndex returns the leaf index used when computing or validating a storage proof.
func (State) TransactionWeight ¶
func (s State) TransactionWeight(txn types.Transaction) uint64
TransactionWeight computes the weight of a txn.
type Store ¶
type Store interface { BestIndex(height uint64) (types.ChainIndex, bool) AncestorTimestamp(id types.BlockID, n uint64) time.Time SiacoinOutput(id types.SiacoinOutputID) (types.SiacoinOutput, bool) SiafundOutput(id types.SiafundOutputID) (types.SiafundOutput, types.Currency, bool) FileContract(id types.FileContractID) (types.FileContract, bool) MaturedSiacoinOutputs(height uint64) []types.SiacoinOutputID MaturedSiacoinOutput(height uint64, id types.SiacoinOutputID) (types.SiacoinOutput, bool) MissedFileContracts(height uint64) []types.FileContractID }
A Store stores blocks, siacoin outputs, siafund outputs, and file contracts.
type TransactionDiff ¶
type TransactionDiff struct { CreatedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput DelayedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput CreatedSiafundOutputs map[types.SiafundOutputID]types.SiafundOutput CreatedFileContracts map[types.FileContractID]types.FileContract SpentSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput SpentSiafundOutputs map[types.SiafundOutputID]types.SiafundOutput RevisedFileContracts map[types.FileContractID]types.FileContract ValidFileContracts map[types.FileContractID]types.FileContract }
A TransactionDiff represents the changes to an ElementStore resulting from the application of a transaction.
type ValidationContext ¶
A ValidationContext contains all of the information necessary to validate a block.
func (ValidationContext) MaxFutureTimestamp ¶
func (vc ValidationContext) MaxFutureTimestamp(currentTime time.Time) time.Time
MaxFutureTimestamp returns the maximum allowed timestamp for a block.
func (ValidationContext) ValidateBlock ¶
func (vc ValidationContext) ValidateBlock(b types.Block) error
ValidateBlock validates b in the context of vc.
This function does not check whether the header's timestamp is too far in the future. That check should be performed at the time the block is received, e.g. in p2p networking code; see MaxFutureTimestamp.
func (ValidationContext) ValidateTransactionSet ¶
func (vc ValidationContext) ValidateTransactionSet(txns []types.Transaction) error
ValidateTransactionSet validates txns within the context of vc.