consensus

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2018 License: MIT Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DatabaseFilename contains the filename of the database that will be used
	// when managing consensus.
	DatabaseFilename = modules.ConsensusDir + ".db"
)
View Source
const (

	// MaxDownloadSingleBlockDuration is the timeout time for each download go routine
	MaxDownloadSingleBlockDuration = 5 * time.Minute
)

Variables

View Source
var (
	// ChangeLog contains a list of atomic changes that have happened to the
	// consensus set so that subscribers can subscribe from the most recent
	// change they have seen.
	ChangeLog = []byte("ChangeLog")

	// HeaderChangeLog contains a list of atomic changes that have happened to the
	// headers so that subscribers can subscribe from the most recent
	// change they have seen.
	HeaderChangeLog = []byte("HeaderChangeLog")

	// ChangeLogTailID is a key that points to the id of the current changelog
	// tail.
	ChangeLogTailID = []byte("ChangeLogTailID")
)
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 - block.Stats() should be sufficient to determine the block
	// height, but currently stats are only computed after committing a
	// transaction, therefore cannot be assumed reliable.
	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")

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

	// 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")

	// BucketOak is the database bucket that contains all of the fields related
	// to the oak difficulty adjustment algorithm. The cumulative difficulty and
	// time values are stored for each block id, and then the key "OakInit"
	// contains the value "true" if the oak fields have been properly
	// initialized.
	BucketOak = []byte("Oak")

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

	// FileContractUnlockHashMap is a database bucket that contains a mapping
	// from all contract ids to a map of blockheights with relevant unlock
	// hashes as values. This is used by full nodes when building filters for
	// SPV clients. When a storage proof or file contract revision is posted,
	// the host needs to specify the filter to include all previously related
	// UnlockHashes (which can change between revisions, but probably in
	// practice don't).
	//
	// TODO: this is currently unimplemented and so light nodes would break
	// under this weird case.
	FileContractUnlockHashMap = []byte("FileContractUnlockHashMap")

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

	// SiacoinOutputs is a database bucket that contains all of the unspent
	// siacoin outputs.
	SiacoinOutputs = []byte("SiacoinOutputs")
)
View Source
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 = build.Select(build.Var{
		Standard: types.BlockHeight(10),
		Dev:      types.BlockHeight(50),
		Testing:  types.BlockHeight(3),
	}).(types.BlockHeight)

	// MaxDownloadSingleBlockRequest is the node count we concurrently try to fetch
	MaxDownloadSingleBlockRequest = build.Select(build.Var{
		Standard: int(3),
		Dev:      int(1),
		Testing:  int(1),
	}).(int)
)
View Source
var (
	// FieldOakInit is a field in BucketOak that gets set to "true" after the
	// oak initialiation process has completed.
	FieldOakInit = []byte("OakInit")
)
View Source
var (
	// ValueOakInit is the value that the oak init field is set to if the oak
	// difficulty adjustment fields have been correctly intialized.
	ValueOakInit = []byte("true")
)

Functions

func NewBlockValidator

func NewBlockValidator() stdBlockValidator

NewBlockValidator creates a new stdBlockValidator with default settings.

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, bootstrap bool, persistDir string, spv bool) (*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 NewCustomConsensusSet

func NewCustomConsensusSet(gateway modules.Gateway, bootstrap bool, persistDir string, deps modules.Dependencies, spv bool) (*ConsensusSet, error)

NewCustomConsensusSet 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

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

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

BlockAtHeight returns the block at a given height.

func (*ConsensusSet) BlockByID

func (cs *ConsensusSet) BlockByID(id types.BlockID) (block types.Block, height types.BlockHeight, exists bool)

BlockByID returns the block for a given BlockID.

func (*ConsensusSet) ChildTarget

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

func (cs *ConsensusSet) Close() error

Close safely closes the block database.

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) CurrentHeader added in v0.2.1

func (cs *ConsensusSet) CurrentHeader() (header types.BlockHeader)

CurrentHeader returns the latest header in the heaviest known blockchain.

func (*ConsensusSet) Db

func (cs *ConsensusSet) Db() *persist.BoltDatabase

Db returns the database associated with the ConsensusSet

func (*ConsensusSet) Flush

func (cs *ConsensusSet) Flush() error

Flush will block until the consensus set has finished all in-progress routines.

func (*ConsensusSet) HeaderConsensusSetSubscribe

func (cs *ConsensusSet) HeaderConsensusSetSubscribe(subscriber modules.HeaderConsensusSetSubscriber, start modules.ConsensusChangeID,
	cancel <-chan struct{}) error

HeaderConsensusSetSubscribe will send change to subscriber from start

func (*ConsensusSet) HeaderUnsubscribe

func (cs *ConsensusSet) HeaderUnsubscribe(subscriber modules.HeaderConsensusSetSubscriber)

HeaderUnsubscribe will unsubscribe from the header change

func (*ConsensusSet) Height

func (cs *ConsensusSet) Height() (height types.BlockHeight)

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 types.Timestamp, exists bool)

MinimumValidChildTimestamp returns the earliest timestamp that the next block can have in order for it to be considered valid.

func (*ConsensusSet) SetGetWalletKeysFunc

func (cs *ConsensusSet) SetGetWalletKeysFunc(f func() ([][]byte, error))

SetGetWalletKeysFunc set the getWalletKeysFunc callback

func (*ConsensusSet) SpvMode

func (cs *ConsensusSet) SpvMode() bool

SpvMode return true if in spv mode

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

Jump to

Keyboard shortcuts

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