consensus

package
v1.8.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0, MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const AllowableClockDriftSecs = uint64(1)

Variables

View Source
var (
	ErrExpensiveFork = errors.New("refusing explicit call due to state fork at epoch")
	// ErrStateRootMismatch is returned when the computed state root doesn't match the expected result.
	ErrStateRootMismatch = errors.New("blocks state root does not match computed result")
	// ErrUnorderedTipSets is returned when weight and minticket are the same between two tipsets.
	ErrUnorderedTipSets = errors.New("trying to order two identical tipsets")
	// ErrReceiptRootMismatch is returned when the block's receipt root doesn't match the receipt root computed for the parent tipset.
	ErrReceiptRootMismatch = errors.New("blocks receipt root does not match parent tip set")
)
View Source
var ErrInsufficientPower = errors.New("incoming block's miner does not have minimum power")
View Source
var ErrSoftFailure = errors.New("soft validation failure")
View Source
var ErrTemporal = errors.New("temporal error")

Functions

func MakeFakeTicketForTest

func MakeFakeTicketForTest() *types.Ticket

MakeFakeTicketForTest creates a fake ticket

func MakeFakeVRFProofForTest

func MakeFakeVRFProofForTest() []byte

MakeFakeVRFProofForTest creates a fake election proof

func RequireNewTipSet

func RequireNewTipSet(require *require.Assertions, blks ...*types.BlockHeader) *types.TipSet

RequireNewTipSet instantiates and returns a new tipset of the given blocks and requires that the setup validation succeed.

func VerifyElectionPoStVRF

func VerifyElectionPoStVRF(ctx context.Context, worker address.Address, rand []byte, evrf []byte) error

VerifyElectionPoStVRF verify election post value in block

func VerifyVRF

func VerifyVRF(ctx context.Context, worker address.Address, vrfBase, vrfproof []byte) error

VerifyVRF checkout block vrf value

Types

type ApplicationResult

type ApplicationResult struct {
	Receipt        *types.MessageReceipt
	ExecutionError error
}

ApplicationResult contains the result of successfully applying one message. ExecutionError might be set and the message can still be applied successfully. See ApplyMessage() for details.

type ApplyMessageResult

type ApplyMessageResult struct {
	ApplicationResult        // Application-level result, if error is nil.
	Failure            error // Failure to apply the message
	FailureIsPermanent bool  // Whether failure is permanent, has no chance of succeeding later.
}

ApplyMessageResult is the result of applying a single message.

type BlockValidator

type BlockValidator struct {
	Stmgr StateTransformer
	// contains filtered or unexported fields
}

BlockValidator used to validate a block is ok or not

func NewBlockValidator added in v0.9.1

func NewBlockValidator(tv TicketValidator,
	bstore blockstoreutil.Blockstore,
	messageStore *chain.MessageStore,
	drand beacon.Schedule,
	cstore cbor.IpldStore,
	proofVerifier ProofVerifier,
	state StateViewer,
	chainState chainReader,
	chainSelector *ChainSelector,
	fork fork.IFork,
	config *config.NetworkParamsConfig,
	gasPirceSchedule *gas.PricesSchedule) *BlockValidator

NewBlockValidator create a new block validator

func (*BlockValidator) MinerEligibleToMine added in v0.9.1

func (bv *BlockValidator) MinerEligibleToMine(ctx context.Context, addr address.Address, parentStateRoot cid.Cid, parentHeight abi.ChainEpoch, lookbackTS *types.TipSet) (bool, error)

func (*BlockValidator) ValidateBlockBeacon added in v0.9.1

func (bv *BlockValidator) ValidateBlockBeacon(blk *types.BlockHeader, parentEpoch abi.ChainEpoch, prevEntry *types.BeaconEntry) error

func (*BlockValidator) ValidateBlockMsg added in v0.9.1

func (bv *BlockValidator) ValidateBlockMsg(ctx context.Context, blk *types.BlockMsg) pubsub.ValidationResult

ValidateBlockMsg used to validate block from incoming. check message, signature , wincount. if give a reject error. local node reject this block. if give a ignore error. recheck this block in latest notify

func (*BlockValidator) ValidateBlockWinner added in v0.9.1

func (bv *BlockValidator) ValidateBlockWinner(ctx context.Context, waddr address.Address, lbTS *types.TipSet, lbRoot cid.Cid, baseTS *types.TipSet, baseRoot cid.Cid,
	blk *types.BlockHeader, prevEntry *types.BeaconEntry) error

func (*BlockValidator) ValidateFullBlock added in v0.9.1

func (bv *BlockValidator) ValidateFullBlock(ctx context.Context, blk *types.BlockHeader) error

ValidateFullBlock should match up with 'Semantical Validation' in validation.md in the spec

func (*BlockValidator) ValidateMsgMeta added in v0.9.1

func (bv *BlockValidator) ValidateMsgMeta(ctx context.Context, fblk *types.FullBlock) error

ValidateMsgMeta performs structural and content hash validation of the messages within this block. If validation passes, it stores the messages in the underlying IPLD block store.

func (*BlockValidator) VerifyWinningPoStProof added in v0.9.1

func (bv *BlockValidator) VerifyWinningPoStProof(ctx context.Context, nv network.Version, blk *types.BlockHeader, prevBeacon *types.BeaconEntry, lbst cid.Cid) error

type ChainRandomness

type ChainRandomness interface {
	StateGetRandomnessFromBeacon(ctx context.Context, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
	StateGetRandomnessFromTickets(ctx context.Context, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
}

ChainRandomness define randomness method in filecoin

type ChainSampler

type ChainSampler interface {
	SampleTicket(ctx context.Context, head types.TipSetKey, epoch abi.ChainEpoch, lookback bool) (types.Ticket, error)
}

type ChainSelector

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

ChainSelector weighs and compares chains.

func NewChainSelector

func NewChainSelector(cs cbor.IpldStore, state StateViewer) *ChainSelector

NewChainSelector is the constructor for Chain selection module.

func (*ChainSelector) IsHeavier

func (c *ChainSelector) IsHeavier(ctx context.Context, a, b *types.TipSet) (bool, error)

IsHeavier returns true if tipset a is heavier than tipset b, and false vice versa. In the rare case where two tipsets have the same weight ties are broken by taking the tipset with more blocks.

func (*ChainSelector) Weight

func (c *ChainSelector) Weight(ctx context.Context, ts *types.TipSet) (fbig.Int, error)

Weight returns the EC weight of this TipSet as a filecoin big int.

type DefaultMessageSyntaxValidator

type DefaultMessageSyntaxValidator struct{}

DefaultMessageSyntaxValidator checks basic conditions independent of current state

func NewMessageSyntaxValidator

func NewMessageSyntaxValidator() *DefaultMessageSyntaxValidator

func (*DefaultMessageSyntaxValidator) ValidateSignedMessageSyntax

func (v *DefaultMessageSyntaxValidator) ValidateSignedMessageSyntax(ctx context.Context, smsg *types.SignedMessage) error

ValidateSignedMessageSyntax validates signed message syntax and state-independent invariants. Used for incoming messages over pubsub and secp messages included in blocks.

func (*DefaultMessageSyntaxValidator) ValidateUnsignedMessageSyntax

func (v *DefaultMessageSyntaxValidator) ValidateUnsignedMessageSyntax(ctx context.Context, msg *types.Message) error

ValidateUnsignedMessageSyntax validates unisigned message syntax and state-independent invariants. Used for bls messages included in blocks.

type DefaultProcessor

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

DefaultProcessor handles all block processing.

func NewConfiguredProcessor

func NewConfiguredProcessor(actors vm.ActorCodeLoader, syscalls vm.SyscallsImpl, circulatingSupplyCalculator chain.ICirculatingSupplyCalcualtor) *DefaultProcessor

NewConfiguredProcessor creates a default processor with custom validation and rewards.

func NewDefaultProcessor

func NewDefaultProcessor(syscalls vm.SyscallsImpl, circulatingSupplyCalculator chain.ICirculatingSupplyCalcualtor) *DefaultProcessor

NewDefaultProcessor creates a default processor from the given state tree and vms.

func (*DefaultProcessor) ApplyBlocks added in v1.6.0

func (p *DefaultProcessor) ApplyBlocks(ctx context.Context,
	blocks []types.BlockMessagesInfo,
	ts *types.TipSet,
	pstate cid.Cid,
	parentEpoch, epoch abi.ChainEpoch,
	vmOpts vm.VmOption,
	cb vm.ExecCallBack) (cid.Cid, []types.MessageReceipt, error)

type DefaultStateViewer

type DefaultStateViewer struct {
	*appstate.Viewer
}

DefaultStateViewer a state viewer to the power state view interface.

func AsDefaultStateViewer

func AsDefaultStateViewer(v *appstate.Viewer) DefaultStateViewer

Todo Delete view just use state.Viewer AsDefaultStateViewer adapts a state viewer to a power state viewer.

func (*DefaultStateViewer) FaultStateView

func (v *DefaultStateViewer) FaultStateView(root cid.Cid) appstate.FaultStateView

FaultStateView returns a fault state view for a state root.

func (*DefaultStateViewer) PowerStateView

func (v *DefaultStateViewer) PowerStateView(root cid.Cid) appstate.PowerStateView

PowerStateView returns a power state view for a state root.

type Expected

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

Expected implements expected consensus.

func NewExpected

func NewExpected(cs cbor.IpldStore,
	bs blockstoreutil.Blockstore,
	chainState *chain.Store,
	rnd ChainRandomness,
	messageStore *chain.MessageStore,
	fork fork.IFork,
	gasPirceSchedule *gas.PricesSchedule,
	blockValidator *BlockValidator,
	syscalls vm.SyscallsImpl,
	circulatingSupplyCalculator chain.ICirculatingSupplyCalcualtor,
) *Expected

NewExpected is the constructor for the Expected consenus.Protocol module.

func (*Expected) RunStateTransition

func (c *Expected) RunStateTransition(ctx context.Context, ts *types.TipSet) (cid.Cid, cid.Cid, error)

RunStateTransition applies the messages in a tipset to a state, and persists that new state. It errors if the tipset was not mined according to the EC rules, or if any of the messages in the tipset results in an error.

type FailingTicketValidator

type FailingTicketValidator struct{}

FailingTicketValidator marks all tickets as invalid

func (*FailingTicketValidator) IsValidTicket

func (ftv *FailingTicketValidator) IsValidTicket(ctx context.Context, base types.TipSetKey, entry *types.BeaconEntry, newPeriod bool,
	epoch abi.ChainEpoch, miner address.Address, workerSigner address.Address, ticket types.Ticket) error

IsValidTicket always returns false

type FakeChainRandomness

type FakeChainRandomness struct {
	Seed uint
}

FakeChainRandomness generates deterministic values that are a function of a seed and the provided tag, epoch, and entropy (but *not* the Chain Head key).

func (*FakeChainRandomness) GetBeaconRandomness added in v0.9.7

func (s *FakeChainRandomness) GetBeaconRandomness(ctx context.Context, tsk types.TipSetKey, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, _ bool) (abi.Randomness, error)

func (*FakeChainRandomness) GetChainRandomness added in v0.9.7

func (s *FakeChainRandomness) GetChainRandomness(ctx context.Context, tsk types.TipSetKey, pers acrypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte, _ bool) ([]byte, error)

type FakeConsensusStateViewer

type FakeConsensusStateViewer struct {
	Views map[cid.Cid]*state.FakeStateView
}

FakeConsensusStateViewer is a fake power state viewer.

func (*FakeConsensusStateViewer) FaultStateView

func (f *FakeConsensusStateViewer) FaultStateView(root cid.Cid) state.FaultStateView

FaultStateView returns the state view for a root.

func (*FakeConsensusStateViewer) PowerStateView

func (f *FakeConsensusStateViewer) PowerStateView(root cid.Cid) state.PowerStateView

PowerStateView returns the state view for a root.

type FakeMessageValidator

type FakeMessageValidator struct{}

FakeMessageValidator is a validator that doesn't validate to simplify message creation in tests.

func (*FakeMessageValidator) ValidateSignedMessageSyntax

func (mv *FakeMessageValidator) ValidateSignedMessageSyntax(ctx context.Context, smsg *types.SignedMessage) error

func (*FakeMessageValidator) ValidateUnsignedMessageSyntax

func (mv *FakeMessageValidator) ValidateUnsignedMessageSyntax(ctx context.Context, msg *types.Message) error

type FakeSampler

type FakeSampler struct {
	Seed uint
}

func (*FakeSampler) SampleTicket

func (s *FakeSampler) SampleTicket(_ context.Context, _ types.TipSetKey, epoch abi.ChainEpoch, _ bool) (types.Ticket, error)

type FakeTicketMachine

type FakeTicketMachine struct{}

FakeTicketMachine generates fake tickets and verifies all tickets

func (*FakeTicketMachine) IsValidTicket

func (ftm *FakeTicketMachine) IsValidTicket(ctx context.Context, base types.TipSetKey, entry *types.BeaconEntry, newPeriod bool,
	epoch abi.ChainEpoch, miner address.Address, workerSigner address.Address, ticket types.Ticket) error

IsValidTicket always returns true

func (*FakeTicketMachine) MakeTicket

func (ftm *FakeTicketMachine) MakeTicket(ctx context.Context, base types.TipSetKey, epoch abi.ChainEpoch, miner address.Address, entry *types.BeaconEntry, newPeriod bool, worker address.Address, signer types.Signer) (types.Ticket, error)

MakeTicket returns a fake ticket

type HeadRandomness

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

A Chain randomness source with a fixed Head tipset key.

func NewHeadRandomness added in v1.1.0

func NewHeadRandomness(chain ChainRandomness, head types.TipSetKey) *HeadRandomness

func (HeadRandomness) ChainGetRandomnessFromBeacon added in v1.1.0

func (h HeadRandomness) ChainGetRandomnessFromBeacon(ctx context.Context, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)

func (HeadRandomness) ChainGetRandomnessFromTickets added in v1.1.0

func (h HeadRandomness) ChainGetRandomnessFromTickets(ctx context.Context, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)

type MessageSignatureValidator

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

MessageSignatureValidator validates message signatures

func NewMessageSignatureValidator

func NewMessageSignatureValidator(api signatureValidatorAPI) *MessageSignatureValidator

func (*MessageSignatureValidator) Validate

Validate validates the signed message signature. Errors probably mean the

validation failed, but possibly indicate a failure to retrieve state.

type Processor

type Processor interface {
	// ApplyBlocks processes all messages in a tip set.
	ApplyBlocks(ctx context.Context, blocks []types.BlockMessagesInfo, ts *types.TipSet, pstate cid.Cid, parentEpoch, epoch abi.ChainEpoch, vmOpts vm.VmOption, cb vm.ExecCallBack) (cid.Cid, []types.MessageReceipt, error)
}

A Processor processes all the messages in a block or tip set.

type ProofVerifier

type ProofVerifier interface {
	VerifySeal(proof7.SealVerifyInfo) (bool, error)
	VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error)
	VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error)
	VerifyWinningPoSt(ctx context.Context, info proof7.WinningPoStVerifyInfo) (bool, error)
	VerifyWindowPoSt(ctx context.Context, info proof7.WindowPoStVerifyInfo) (bool, error)

	GenerateWinningPoStSectorChallenge(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, eligibleSectorCount uint64) ([]uint64, error)
}

Interface to PoSt verification, modify by force EPoStVerifier -> ProofVerifier

type SignFunc

type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, error)

SignFunc common interface for sign

type StateTransformer added in v1.2.0

type StateTransformer interface {
	// RunStateTransition returns the state root CID resulting from applying the input ts to the
	// prior `stateID`.  It returns an error if the transition is invalid.
	// RunStateTransition(ctx context.Context, ts *types.TipSet) (root cid.Cid, receipt cid.Cid, err error)
	RunStateTransition(ctx context.Context, ts *types.TipSet) (root cid.Cid, receipt cid.Cid, err error)
}

type StateViewer

type StateViewer interface {
	PowerStateView(root cid.Cid) appstate.PowerStateView
	FaultStateView(root cid.Cid) appstate.FaultStateView
}

StateViewer provides views into the Chain state.

type TestElectionPoster

type TestElectionPoster struct{}

TestElectionPoster generates and verifies electoin PoSts

func (*TestElectionPoster) GenerateWinningPoSt

func (ep *TestElectionPoster) GenerateWinningPoSt(ctx context.Context,
	minerID abi.ActorID,
	sectorInfo []builtin.SectorInfo,
	randomness abi.PoStRandomness) ([]builtin.PoStProof, error)

type TicketMachine

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

TicketMachine uses a VRF and VDF to generate deterministic, unpredictable and time delayed tickets and validates these tickets.

func NewTicketMachine

func NewTicketMachine(tipsetLoader tipsetLoader) *TicketMachine

func (TicketMachine) IsValidTicket

func (tm TicketMachine) IsValidTicket(ctx context.Context, base types.TipSetKey, entry *types.BeaconEntry, bSmokeHeight bool,
	epoch abi.ChainEpoch, miner address.Address, workerSigner address.Address, ticket types.Ticket) error

IsValidTicket verifies that the ticket's proof of randomness is valid with respect to its parent.

func (TicketMachine) MakeTicket

func (tm TicketMachine) MakeTicket(ctx context.Context, base types.TipSetKey, epoch abi.ChainEpoch, miner address.Address, entry *types.BeaconEntry, newPeriod bool, worker address.Address, signer types.Signer) (types.Ticket, error)

MakeTicket creates a new ticket from a Chain and target epoch by running a verifiable randomness function on the prior ticket.

type TicketValidator

type TicketValidator interface {
	IsValidTicket(ctx context.Context, base types.TipSetKey, entry *types.BeaconEntry, newPeriod bool, epoch abi.ChainEpoch, miner address.Address, workerSigner address.Address, ticket types.Ticket) error
}

TicketValidator validates that an input ticket is valid.

Jump to

Keyboard shortcuts

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