consensus

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 11 Imported by: 63

Documentation

Overview

Package consensus implements the Sia consensus algorithms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyBlock

func ApplyBlock(s State, store Store, b types.Block) (State, BlockDiff)

ApplyBlock applies b to s, returning the resulting state and effects.

Types

type BlockDiff

type BlockDiff struct {
	Transactions          []TransactionDiff
	DelayedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput
	MaturedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput
	MissedFileContracts   map[types.FileContractID]types.FileContract
}

A BlockDiff represents the changes to an ElementStore resulting from the application of a block.

type Checkpoint

type Checkpoint struct {
	Block types.Block
	State State
}

A Checkpoint pairs a block with its resulting chain state.

type State

type State struct {
	Index                     types.ChainIndex `json:"index"`
	PrevTimestamps            [11]time.Time    `json:"prevTimestamps"`
	Depth                     types.BlockID    `json:"depth"`
	ChildTarget               types.BlockID    `json:"childTarget"`
	OakTarget                 types.BlockID    `json:"oakTarget"`
	OakTime                   time.Duration    `json:"oakTime"`
	GenesisTimestamp          time.Time        `json:"genesisTimestamp"`
	SiafundPool               types.Currency   `json:"siafundPool"`
	FoundationPrimaryAddress  types.Address    `json:"foundationPrimaryAddress"`
	FoundationFailsafeAddress types.Address    `json:"foundationFailsafeAddress"`
}

State represents the constant-size state of the chain as of a particular block.

func (State) BlockInterval

func (s State) BlockInterval() time.Duration

BlockInterval is the expected wall clock time between consecutive blocks.

func (State) BlockReward

func (s State) BlockReward() types.Currency

BlockReward returns the reward for mining a child block.

func (State) BlockWeight

func (s State) BlockWeight(txns []types.Transaction) uint64

BlockWeight computes the combined weight of a block's txns.

func (*State) DecodeFrom

func (s *State) DecodeFrom(d *types.Decoder)

DecodeFrom implements types.DecoderFrom.

func (State) EncodeTo

func (s State) EncodeTo(e *types.Encoder)

EncodeTo implements types.EncoderTo.

func (State) FileContractTax

func (s State) FileContractTax(fc types.FileContract) types.Currency

FileContractTax computes the tax levied on a given contract.

func (State) FoundationSubsidy

func (s State) FoundationSubsidy() (sco types.SiacoinOutput)

FoundationSubsidy returns the Foundation subsidy output for the child block. If no subsidy is due, the returned output has a value of zero.

func (State) MaturityHeight

func (s State) MaturityHeight() uint64

MaturityHeight is the height at which various outputs created in the child block will "mature" (become spendable).

func (State) MaxBlockWeight

func (s State) MaxBlockWeight() int

MaxBlockWeight is the maximum "weight" of a valid child block.

func (State) NonceFactor

func (s State) NonceFactor() uint64

NonceFactor is the factor by which all block nonces must be divisible.

func (State) PartialSigHash

func (s State) PartialSigHash(txn types.Transaction, cf types.CoveredFields) types.Hash256

PartialSigHash computes the hash of the transaction data specified by cf. It panics if cf references fields not present in txn.

func (State) SiafundCount

func (s State) SiafundCount() uint64

SiafundCount is the number of siafunds in existence.

func (State) StorageProofLeafIndex

func (s State) StorageProofLeafIndex(filesize uint64, windowStart types.ChainIndex, fcid types.FileContractID) uint64

StorageProofLeafIndex returns the leaf index used when computing or validating a storage proof.

func (State) TransactionWeight

func (s State) TransactionWeight(txn types.Transaction) uint64

TransactionWeight computes the weight of a txn.

func (State) WholeSigHash

func (s State) WholeSigHash(txn types.Transaction, parentID types.Hash256, pubkeyIndex uint64, timelock uint64, coveredSigs []uint64) types.Hash256

WholeSigHash computes the hash of transaction data covered by the WholeTransaction flag.

type Store

type Store interface {
	BestIndex(height uint64) (types.ChainIndex, bool)
	AncestorTimestamp(id types.BlockID, n uint64) time.Time
	SiacoinOutput(id types.SiacoinOutputID) (types.SiacoinOutput, bool)
	SiafundOutput(id types.SiafundOutputID) (types.SiafundOutput, types.Currency, bool)
	FileContract(id types.FileContractID) (types.FileContract, bool)
	MaturedSiacoinOutputs(height uint64) []types.SiacoinOutputID
	MaturedSiacoinOutput(height uint64, id types.SiacoinOutputID) (types.SiacoinOutput, bool)
	MissedFileContracts(height uint64) []types.FileContractID
}

A Store stores blocks, siacoin outputs, siafund outputs, and file contracts.

type TransactionDiff

type TransactionDiff struct {
	CreatedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput
	DelayedSiacoinOutputs map[types.SiacoinOutputID]types.SiacoinOutput
	CreatedSiafundOutputs map[types.SiafundOutputID]types.SiafundOutput
	CreatedFileContracts  map[types.FileContractID]types.FileContract

	SpentSiacoinOutputs  map[types.SiacoinOutputID]types.SiacoinOutput
	SpentSiafundOutputs  map[types.SiafundOutputID]types.SiafundOutput
	RevisedFileContracts map[types.FileContractID]types.FileContract
	ValidFileContracts   map[types.FileContractID]types.FileContract
}

A TransactionDiff represents the changes to an ElementStore resulting from the application of a transaction.

type ValidationContext

type ValidationContext struct {
	State State
	Store Store
}

A ValidationContext contains all of the information necessary to validate a block.

func (ValidationContext) MaxFutureTimestamp

func (vc ValidationContext) MaxFutureTimestamp(currentTime time.Time) time.Time

MaxFutureTimestamp returns the maximum allowed timestamp for a block.

func (ValidationContext) ValidateBlock

func (vc ValidationContext) ValidateBlock(b types.Block) error

ValidateBlock validates b in the context of vc.

This function does not check whether the header's timestamp is too far in the future. That check should be performed at the time the block is received, e.g. in p2p networking code; see MaxFutureTimestamp.

func (ValidationContext) ValidateTransactionSet

func (vc ValidationContext) ValidateTransactionSet(txns []types.Transaction) error

ValidateTransactionSet validates txns within the context of vc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳