consensus

package
v0.4.7-beta Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2015 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DatabaseFilename contains the filename of the database that will be used
	// when managing consensus.
	DatabaseFilename = "consensus.db"
)
View Source
const (
	// 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 = 10
)

Variables

View Source
var (

	// BlockHeight is a bucket that stores the current block height.
	//
	// Generally we would just look at BlockPath.Stats(), but there is an error
	// in boltdb that prevents the bucket stats from updating until a tx is
	// committed. Wasn't a problem until we started doing the entire block as
	// one tx.
	//
	// DEPRECATED.
	BlockHeight = []byte("BlockHeight")

	// BlockMap is a database bucket containing all of the processed blocks,
	// keyed by their id. This includes blocks that are not currently in the
	// consensus set, and blocks that may not have been fully validated yet.
	BlockMap = []byte("BlockMap")

	// BlockPath is a database bucket containing a mapping from the height of a
	// block to the id of the block at that height. BlockPath only includes
	// blocks in the current path.
	BlockPath = []byte("BlockPath")

	// Consistency is a database bucket with a flag indicating whether
	// inconsistencies within the database have been detected.
	Consistency = []byte("Consistency")

	// SiacoinOutputs is a database bucket that contains all of the unspent
	// siacoin outputs.
	SiacoinOutputs = []byte("SiacoinOutputs")

	// FileContracts is a database bucket that contains all of the open file
	// contracts.
	FileContracts = []byte("FileContracts")

	// SiafundOutputs is a database bucket that contains all of the unspent
	// siafund outputs.
	SiafundOutputs = []byte("SiafundOutputs")

	// SiafundPool is a database bucket storing the current value of the
	// siafund pool.
	SiafundPool = []byte("SiafundPool")
)
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 ConsensusSet added in v1.0.0

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, persistDir string) (*ConsensusSet, error)

New returns a new ConsensusSet, containing at least the genesis block. If there is an existing block database present in the persist directory, it will be loaded.

func (*ConsensusSet) AcceptBlock added in v1.0.0

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) BlockAtHeight added in v1.0.0

func (cs *ConsensusSet) BlockAtHeight(height types.BlockHeight) (block types.Block, exists bool)

BlockAtHeight returns the block at a given height.

func (*ConsensusSet) ChildTarget added in v1.0.0

func (cs *ConsensusSet) ChildTarget(id types.BlockID) (target types.Target, exists bool)

ChildTarget returns the target for the child of a block.

func (*ConsensusSet) Close added in v1.0.0

func (cs *ConsensusSet) Close() error

Close safely closes the block database.

func (*ConsensusSet) ConsensusChange

func (cs *ConsensusSet) ConsensusChange(i int) (cc modules.ConsensusChange, err 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) ConsensusSetDigestSubscribe

func (cs *ConsensusSet) ConsensusSetDigestSubscribe(subscriber modules.ConsensusSetDigestSubscriber)

ConsensusSetDigestSubscribe accepts a new digest subscriber who will receive a call to ProcessConsensusDigest every time there is a change in the consensus set.

func (*ConsensusSet) ConsensusSetSubscribe added in v1.0.0

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) EarliestChildTimestamp

func (cs *ConsensusSet) EarliestChildTimestamp(id 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 (cs *ConsensusSet) GenesisBlock() types.Block

GenesisBlock returns the genesis block.

func (*ConsensusSet) InCurrentPath added in v1.0.0

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) StorageProofSegment added in v1.0.0

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 added in v1.0.0

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.

Jump to

Keyboard shortcuts

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