Documentation ¶
Index ¶
- Constants
- Variables
- type ConsensusSet
- func (cs *ConsensusSet) AcceptBlock(b types.Block) error
- func (s *ConsensusSet) ChildTarget(bid types.BlockID) (target types.Target, exists bool)
- func (cs *ConsensusSet) Close() error
- func (cs *ConsensusSet) ConsensusChange(i int) (modules.ConsensusChange, error)
- func (cs *ConsensusSet) ConsensusSetSubscribe(subscriber modules.ConsensusSetSubscriber)
- func (s *ConsensusSet) CurrentBlock() types.Block
- func (cs *ConsensusSet) EarliestChildTimestamp(bid types.BlockID) (timestamp types.Timestamp, exists bool)
- func (s *ConsensusSet) GenesisBlock() types.Block
- func (s *ConsensusSet) Height() types.BlockHeight
- func (s *ConsensusSet) InCurrentPath(bid types.BlockID) bool
- func (cs *ConsensusSet) RelayBlock(conn modules.PeerConn) error
- func (cs *ConsensusSet) StorageProofSegment(fcid types.FileContractID) (index uint64, err error)
- func (cs *ConsensusSet) TryTransactionSet(txns []types.Transaction) (modules.ConsensusChange, error)
- func (cs *ConsensusSet) ValidStorageProofs(t types.Transaction) (err error)
- type ConsensusSetInfo
Constants ¶
const ( MaxCatchUpBlocks = 10 MaxSynchronizeAttempts = 8 )
Variables ¶
var ( ErrBadMinerPayouts = errors.New("miner payout sum does not equal block subsidy") ErrDoSBlock = errors.New("block is known to be invalid") ErrEarlyTimestamp = errors.New("block timestamp is too early") ErrExtremeFutureTimestamp = errors.New("block timestamp too far in future, discarded") ErrFutureTimestamp = errors.New("block timestamp too far in future, but saved for later use") ErrInconsistentSet = errors.New("consensus set is not in a consistent state") ErrLargeBlock = errors.New("block is too large to be accepted") ErrMissedTarget = errors.New("block does not meet target") ErrOrphan = errors.New("block has no known parent") )
var ( ErrDuplicateValidProofOutput = errors.New("applying a storage proof created a duplicate proof output") ErrMisuseApplySiacoinInput = errors.New("applying a transaction with an invalid unspent siacoin output") ErrMisuseApplySiacoinOutput = errors.New("applying a transaction with an invalid siacoin output") ErrMisuseApplyFileContracts = errors.New("applying a transaction with an invalid file contract") ErrMisuseApplyFileContractRevisions = errors.New("applying a revision for a nonexistant file contract") ErrMisuseApplySiafundInput = errors.New("applying a transaction with invalid siafund input") ErrMisuseApplySiafundOutput = errors.New("applying a transaction with an invalid siafund output") ErrNonexistentStorageProof = errors.New("applying a storage proof for a nonexistent file contract") )
var ( ConsistencyGuard = []byte("ConsistencyGuard") GuardStart = []byte("GuardStart") GuardEnd = []byte("GuardEnd") BlockPath = []byte("BlockPath") BlockMap = []byte("BlockMap") SiacoinOutputs = []byte("SiacoinOutputs") FileContracts = []byte("FileContracts") FileContractExpirations = []byte("FileContractExpirations") SiafundOutputs = []byte("SiafundOutputs") SiafundPool = []byte("SiafundPool") DSCOBuckets = []byte("DSCOBuckets") )
var ( ErrAlteredRevisionPayouts = errors.New("file contract revision has altered payout volume") ErrInvalidStorageProof = errors.New("provided storage proof is invalid") ErrLateRevision = errors.New("file contract revision submitted after deadline") ErrLowRevisionNumber = errors.New("transaction has a file contract with an outdated revision number") ErrMissingSiacoinOutput = errors.New("transaction spends a nonexisting siacoin output") ErrMissingSiafundOutput = errors.New("transaction spends a nonexisting siafund output") ErrSiacoinInputOutputMismatch = errors.New("siacoin inputs do not equal siacoin outputs for transaction") ErrSiafundInputOutputMismatch = errors.New("siafund inputs do not equal siafund outputs for transaction") ErrUnfinishedFileContract = errors.New("file contract window has not yet openend") ErrUnrecognizedFileContractID = errors.New("cannot fetch storage proof segment for unknown file contract") ErrWrongUnlockConditions = errors.New("transaction contains incorrect unlock conditions") )
var (
ErrNilGateway = errors.New("cannot have a nil gateway as input")
)
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(gateway modules.Gateway, saveDir string) (*ConsensusSet, error)
New returns a new ConsensusSet, containing at least the genesis block. If there is an existing block database present in saveDir, it will be loaded. Otherwise, a new database will be created.
func (*ConsensusSet) AcceptBlock ¶
func (cs *ConsensusSet) AcceptBlock(b types.Block) error
AcceptBlock will add a block to the state, forking the blockchain if it is on a fork that is heavier than the current fork. If the block is accepted, it will be relayed to connected peers. This function should only be called for new, untrusted blocks.
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 block database.
func (*ConsensusSet) ConsensusChange ¶
func (cs *ConsensusSet) ConsensusChange(i int) (modules.ConsensusChange, error)
ConsensusChange returns the consensus change that occured at index 'i', returning an error if the input is out of bounds. For example, ConsensusChange(5) will return the 6th consensus change that was issued to subscribers. ConsensusChanges can be assumed to be consecutive.
func (*ConsensusSet) ConsensusSetSubscribe ¶
func (cs *ConsensusSet) ConsensusSetSubscribe(subscriber modules.ConsensusSetSubscriber)
ConsensusSetSubscribe accepts a new subscriber who will receive a call to ProcessConsensusChange every time there is a change in the consensus set.
func (*ConsensusSet) CurrentBlock ¶
func (s *ConsensusSet) CurrentBlock() types.Block
CurrentBlock returns the highest block on the tallest fork.
func (*ConsensusSet) EarliestChildTimestamp ¶
func (cs *ConsensusSet) EarliestChildTimestamp(bid types.BlockID) (timestamp types.Timestamp, exists bool)
EarliestChildTimestamp returns the earliest timestamp that the next block can have in order for it to be considered valid.
func (*ConsensusSet) GenesisBlock ¶
func (s *ConsensusSet) GenesisBlock() types.Block
GenesisBlock returns the genesis block.
func (*ConsensusSet) Height ¶
func (s *ConsensusSet) Height() types.BlockHeight
Height returns the height of the current blockchain (the longest fork).
func (*ConsensusSet) InCurrentPath ¶
func (s *ConsensusSet) InCurrentPath(bid types.BlockID) bool
InCurrentPath returns true if the block presented is in the current path, false otherwise.
func (*ConsensusSet) RelayBlock ¶
func (cs *ConsensusSet) RelayBlock(conn modules.PeerConn) error
RelayBlock is an RPC that accepts a block from a peer.
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) 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 IFF 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 transaciton set would have.
func (*ConsensusSet) ValidStorageProofs ¶
func (cs *ConsensusSet) ValidStorageProofs(t types.Transaction) (err error)
ValidStorageProofs checks that the storage proofs are valid in the context of the consensus set.
type ConsensusSetInfo ¶
type ConsensusSetInfo struct { CurrentBlock types.BlockID Height types.BlockHeight Target types.Target }
ConsensusSetInfo contains basic information about the ConsensusSet.