Documentation ¶
Index ¶
- Variables
- type ConsensusSet
- func (cs *ConsensusSet) AcceptBlock(b types.Block) error
- func (c *ConsensusSet) Alerts() (crit, err, warn, info []modules.Alert)
- func (cs *ConsensusSet) BlockAtHeight(height uint64) (block types.Block, exists bool)
- func (cs *ConsensusSet) BlockByID(id types.BlockID) (block types.Block, height uint64, exists bool)
- func (cs *ConsensusSet) ChildTarget(id types.BlockID) (target modules.Target, exists bool)
- func (cs *ConsensusSet) Close() error
- func (cs *ConsensusSet) ConsensusSetSubscribe(subscriber modules.ConsensusSetSubscriber, start modules.ConsensusChangeID, ...) error
- func (cs *ConsensusSet) CurrentBlock() (block types.Block)
- func (cs *ConsensusSet) FoundationUnlockHashes() (primary, failsafe types.Address)
- func (cs *ConsensusSet) Height() (height uint64)
- func (cs *ConsensusSet) InCurrentPath(id types.BlockID) (inPath bool)
- func (cs *ConsensusSet) LockedTryTransactionSet(fn func(func(txns []types.Transaction) (modules.ConsensusChange, error)) error) error
- func (cs *ConsensusSet) MinimumValidChildTimestamp(id types.BlockID) (timestamp time.Time, exists bool)
- func (cs *ConsensusSet) StorageProofSegment(fcid types.FileContractID) (index uint64, err error)
- func (cs *ConsensusSet) Synced() bool
- func (cs *ConsensusSet) TryTransactionSet(txns []types.Transaction) (modules.ConsensusChange, error)
- func (cs *ConsensusSet) Unsubscribe(subscriber modules.ConsensusSetSubscriber)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadMinerPayouts is returned when the miner payout does not equal the // block subsidy. ErrBadMinerPayouts = errors.New("miner payout sum does not equal block subsidy") // ErrEarlyTimestamp is returned when the block's timestamp is too early. ErrEarlyTimestamp = errors.New("block timestamp is too early") // ErrExtremeFutureTimestamp is returned when the block's timestamp is too // far in the future. ErrExtremeFutureTimestamp = errors.New("block timestamp too far in future, discarded") // ErrFutureTimestamp is returned when the block's timestamp is too far in // the future to be used now but it's saved for future use. ErrFutureTimestamp = errors.New("block timestamp too far in future, but saved for later use") // ErrLargeBlock is returned when the block is too large to be accepted. ErrLargeBlock = errors.New("block is too large to be accepted") )
var ( // MaxCatchUpBlocks is the maxiumum number of blocks that can be given to // the consensus set in a single iteration during the initial blockchain // download. MaxCatchUpBlocks = uint64(10) )
var SurpassThreshold = big.NewRat(20, 100)
SurpassThreshold is a percentage that dictates how much heavier a competing chain has to be before the node will switch to mining on that chain. This is not a consensus rule. This percentage is only applied to the most recent block, not the entire chain; see blockNode.heavierThan.
If no threshold were in place, it would be possible to manipulate a block's timestamp to produce a sufficiently heavier block.
Functions ¶
This section is empty.
Types ¶
type ConsensusSet ¶
type ConsensusSet struct {
// contains filtered or unexported fields
}
The ConsensusSet is the object responsible for tracking the current status of the blockchain. Broadly speaking, it is responsible for maintaining consensus. It accepts blocks and constructs a blockchain, forking when necessary.
func New ¶
func New(db *sql.DB, gateway modules.Gateway, bootstrap bool, dir string) (*ConsensusSet, <-chan error)
New returns a new ConsensusSet, containing at least the genesis block. If there is an existing block database, it will be loaded.
func (*ConsensusSet) AcceptBlock ¶
func (cs *ConsensusSet) AcceptBlock(b types.Block) error
AcceptBlock will try to add a block to the consensus set. If the block does not extend the longest currently known chain, an error is returned but the block is still kept in memory. If the block extends a fork such that the fork becomes the longest currently known chain, the consensus set will reorganize itself to recognize the new longest fork. If a block is accepted without error, it will be relayed to all connected peers. This function should only be called for new blocks.
func (*ConsensusSet) Alerts ¶
func (c *ConsensusSet) Alerts() (crit, err, warn, info []modules.Alert)
Alerts implements the Alerter interface for the consensusset.
func (*ConsensusSet) BlockAtHeight ¶
func (cs *ConsensusSet) BlockAtHeight(height uint64) (block types.Block, exists bool)
BlockAtHeight returns the block at a given height.
func (*ConsensusSet) ChildTarget ¶
ChildTarget returns the target for the child of a block.
func (*ConsensusSet) Close ¶
func (cs *ConsensusSet) Close() error
Close safely closes the consensus set.
func (*ConsensusSet) ConsensusSetSubscribe ¶
func (cs *ConsensusSet) ConsensusSetSubscribe(subscriber modules.ConsensusSetSubscriber, start modules.ConsensusChangeID, cancel <-chan struct{}) error
ConsensusSetSubscribe adds a subscriber to the list of subscribers, and gives them every consensus change that has occurred since the change with the provided id.
As a special case, using an empty id as the start will have all the changes sent to the modules starting with the genesis block.
func (*ConsensusSet) CurrentBlock ¶
func (cs *ConsensusSet) CurrentBlock() (block types.Block)
CurrentBlock returns the latest block in the heaviest known blockchain.
func (*ConsensusSet) FoundationUnlockHashes ¶
func (cs *ConsensusSet) FoundationUnlockHashes() (primary, failsafe types.Address)
FoundationUnlockHashes returns the current primary and failsafe Foundation UnlockHashes.
func (*ConsensusSet) Height ¶
func (cs *ConsensusSet) Height() (height uint64)
Height returns the height of the consensus set.
func (*ConsensusSet) InCurrentPath ¶
func (cs *ConsensusSet) InCurrentPath(id types.BlockID) (inPath bool)
InCurrentPath returns true if the block presented is in the current path, false otherwise.
func (*ConsensusSet) LockedTryTransactionSet ¶
func (cs *ConsensusSet) LockedTryTransactionSet(fn func(func(txns []types.Transaction) (modules.ConsensusChange, error)) error) error
LockedTryTransactionSet calls fn while under read-lock, passing it a version of TryTransactionSet that can be called under read-lock. This fixes an edge case in the transaction pool.
func (*ConsensusSet) MinimumValidChildTimestamp ¶
func (cs *ConsensusSet) MinimumValidChildTimestamp(id types.BlockID) (timestamp time.Time, exists bool)
MinimumValidChildTimestamp returns the earliest timestamp that the next block can have in order for it to be considered valid.
func (*ConsensusSet) StorageProofSegment ¶
func (cs *ConsensusSet) StorageProofSegment(fcid types.FileContractID) (index uint64, err error)
StorageProofSegment returns the segment to be used in the storage proof for a given file contract.
func (*ConsensusSet) Synced ¶
func (cs *ConsensusSet) Synced() bool
Synced returns true if the consensus set is synced with the network.
func (*ConsensusSet) TryTransactionSet ¶
func (cs *ConsensusSet) TryTransactionSet(txns []types.Transaction) (modules.ConsensusChange, error)
TryTransactionSet applies the input transactions to the consensus set to determine if they are valid. An error is returned IF they are not a valid set in the current consensus set. The size of the transactions and the set is not checked. After the transactions have been validated, a consensus change is returned detailing the diffs that the transactions set would have.
func (*ConsensusSet) Unsubscribe ¶
func (cs *ConsensusSet) Unsubscribe(subscriber modules.ConsensusSetSubscriber)
Unsubscribe removes a subscriber from the list of subscribers, allowing for garbage collection and rescanning. If the subscriber is not found in the subscriber database, no action is taken.