consensus

package
v0.4.0-beta Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2015 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCatchUpBlocks       = 10
	MaxSynchronizeAttempts = 8
)

Variables

View Source
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")
)
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 (
	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")
)
View Source
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")
)
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 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, 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 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) ChildTarget added in v1.0.0

func (s *ConsensusSet) ChildTarget(bid 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) (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 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) CurrentBlock added in v1.0.0

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

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

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

func (*ConsensusSet) InCurrentPath added in v1.0.0

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

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.

Jump to

Keyboard shortcuts

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