consensus

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2015 License: MIT Imports: 14 Imported by: 64

Documentation

Index

Constants

View Source
const (
	MaxCatchUpBlocks          = 50
	MaxSynchronizeAttempts    = 8
	ResynchronizePeerTimeout  = time.Second * 30
	ResynchronizeBatchTimeout = time.Minute * 3
)

Variables

View Source
var (
	ErrDoSBlock               = errors.New("block is known to be invalid")
	ErrBlockKnown             = errors.New("block exists in block map")
	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")
	ErrOrphan                 = errors.New("block has no known parent")
	ErrLargeBlock             = errors.New("block is too large to be accepted")
	ErrBadMinerPayouts        = errors.New("miner payout sum does not equal block subsidy")
	ErrMissedTarget           = errors.New("block does not meet target")
)
View Source
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")
)
View Source
var (
	ErrInvalidStorageProof                = errors.New("provided storage proof is invalid")
	ErrLowRevisionNumber                  = errors.New("transaction has a file contract with an outdated revision number")
	ErrMissingSiacoinOutput               = errors.New("transaction spends a nonexisting siacoin output")
	ErrMissingFileContract                = errors.New("transaction terminates a nonexisting file contract")
	ErrMissingSiafundOutput               = errors.New("transaction spends a nonexisting siafund output")
	ErrSiacoinInputOutputMismatch         = errors.New("siacoin inputs do not equal siacoin 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")
	ErrWrongSiacoinOutputUnlockConditions = errors.New("transaction contains a siacoin output with incorrect unlock conditions")
)
View Source
var (
	ErrNilGateway = errors.New("cannot have a nil gateway as input")
)
View Source
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 State

type State struct {
	// contains filtered or unexported fields
}

The State 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) (*State, error)

New returns a new State, 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 (*State) AcceptBlock

func (cs *State) 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 (*State) ChildTarget

func (s *State) ChildTarget(bid types.BlockID) (target types.Target, exists bool)

ChildTarget does not need a lock, as the values being read are not changed once they have been created.

func (*State) Close

func (cs *State) Close() error

Close safely closes the block database.

func (*State) ConsensusSetNotify

func (s *State) ConsensusSetNotify() <-chan struct{}

ConsensusSetNotify returns a channel that will be sent an empty struct every time the consensus set changes.

func (*State) ConsensusSetSubscribe

func (s *State) ConsensusSetSubscribe(subscriber modules.ConsensusSetSubscriber)

ConsensusSetSubscribe accepts a new subscriber who will receive a call to ReceiveConsensusSetUpdate every time there is a change in the consensus set.

func (*State) CurrentBlock

func (s *State) CurrentBlock() types.Block

CurrentBlock returns the highest block on the tallest fork.

func (*State) EarliestChildTimestamp

func (s *State) 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 (*State) GenesisBlock added in v0.3.3

func (s *State) GenesisBlock() types.Block

GenesisBlock returns the genesis block.

func (*State) Height

func (s *State) Height() types.BlockHeight

Height returns the height of the current blockchain (the longest fork).

func (*State) InCurrentPath added in v0.3.2

func (s *State) InCurrentPath(bid types.BlockID) bool

InCurrentPath returns true if the block presented is in the current path, false otherwise.

func (*State) RelayBlock

func (cs *State) RelayBlock(conn modules.PeerConn) error

RelayBlock is an RPC that accepts a block from a peer.

func (*State) StorageProofSegment

func (s *State) 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 (*State) Synchronize

func (s *State) Synchronize(peer modules.NetAddress) error

Synchronize synchronizes the local consensus set (i.e. the blockchain) with the network consensus set. The process is as follows: synchronize asks a peer for new blocks. The requester sends 32 block IDs, starting with the 12 most recent and then progressing exponentially backwards to the genesis block. The receiver uses these blocks to find the most recent block seen by both peers. From this starting height, it transmits blocks sequentially. The requester then integrates these blocks into its consensus set. Multiple such transmissions may be required to fully synchronize.

TODO: Synchronize is a blocking call that involved network traffic. This seems to break convention, but I'm not certain. It does seem weird though.

func (*State) TryTransactions added in v0.3.2

func (s *State) TryTransactions(txns []types.Transaction) error

TryTransactions 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.

func (*State) ValidStorageProofs

func (s *State) ValidStorageProofs(t types.Transaction) (err error)

ValidStorageProofs checks that the storage proofs are valid in the context of the consensus set.

type StateInfo

type StateInfo struct {
	CurrentBlock types.BlockID
	Height       types.BlockHeight
	Target       types.Target
}

StateInfo contains basic information about the State.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL