consensus

package
v0.9.7-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: Apache-2.0, MIT Imports: 58 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

func VerifyVRF

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

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 {
	// contains filtered or unexported fields
}

func NewBlockValidator added in v0.9.1

func NewBlockValidator(tv TicketValidator,
	bstore blockstore.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

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

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) (err error)

func (*BlockValidator) ValidateMsgMeta added in v0.9.1

func (bv *BlockValidator) ValidateMsgMeta(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 {
	GetChainRandomness(ctx context.Context, tsk types.TipSetKey, pers acrypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte, lookback bool) ([]byte, error)
	GetBeaconRandomness(ctx context.Context, tsk types.TipSetKey, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, lookback bool) (abi.Randomness, error)
}

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.UnsignedMessage) 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) *DefaultProcessor

NewConfiguredProcessor creates a default processor with custom validation and rewards.

func NewDefaultProcessor

func NewDefaultProcessor(syscalls vm.SyscallsImpl) *DefaultProcessor

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

func (*DefaultProcessor) ProcessImplicitMessage

func (p *DefaultProcessor) ProcessImplicitMessage(ctx context.Context, msg *types.UnsignedMessage, vmOption vm.VmOption) (ret *vm.Ret, err error)

func (*DefaultProcessor) ProcessMessage added in v0.9.1

func (p *DefaultProcessor) ProcessMessage(ctx context.Context, msg types.ChainMsg, vmOption vm.VmOption) (ret *vm.Ret, err error)

ProcessTipSet computes the state transition specified by the messages.

func (*DefaultProcessor) ProcessTipSet

func (p *DefaultProcessor) ProcessTipSet(ctx context.Context,
	parent, ts *types.TipSet,
	msgs []types.BlockMessagesInfo,
	vmOption vm.VmOption,
) (cid.Cid, []types.MessageReceipt, error)

ProcessTipSet computes the state transition specified by the messages in all blocks in a TipSet.

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 blockstore.Blockstore,
	bt time.Duration,
	chainState chainReader,
	rnd ChainRandomness,
	messageStore *chain.MessageStore,
	fork fork.IFork,
	config *config.NetworkParamsConfig,
	gasPirceSchedule *gas.PricesSchedule,
	proofVerifier ffiwrapper.Verifier,
	blockValidator *BlockValidator,
) *Expected

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

func (*Expected) BlockTime

func (c *Expected) BlockTime() time.Duration

BlockTime returns the block time used by the consensus protocol.

func (*Expected) Call

func (c *Expected) Call(ctx context.Context, msg *types.UnsignedMessage, ts *types.TipSet) (*vm.Ret, error)

func (*Expected) CallWithGas

func (c *Expected) CallWithGas(ctx context.Context, msg *types.UnsignedMessage, priorMsgs []types.ChainMsg, ts *types.TipSet) (*vm.Ret, error)

func (*Expected) RunStateTransition

func (c *Expected) RunStateTransition(ctx context.Context,
	ts *types.TipSet,
	parentStateRoot cid.Cid,
) (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.UnsignedMessage) 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 {
	Chain ChainRandomness
	Head  types.TipSetKey
}

A Chain randomness source with a fixed Head tipset key.

func (*HeadRandomness) GetBeaconRandomnessLookingBack added in v0.9.7

func (h *HeadRandomness) GetBeaconRandomnessLookingBack(ctx context.Context, pers acrypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error)

func (*HeadRandomness) GetBeaconRandomnessLookingForward added in v0.9.7

func (h *HeadRandomness) GetBeaconRandomnessLookingForward(ctx context.Context, pers acrypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error)

func (*HeadRandomness) GetChainRandomnessLookingBack added in v0.9.7

func (h *HeadRandomness) GetChainRandomnessLookingBack(ctx context.Context, tag acrypto.DomainSeparationTag, epoch abi.ChainEpoch, entropy []byte) ([]byte, error)

func (*HeadRandomness) GetChainRandomnessLookingForward added in v0.9.7

func (h *HeadRandomness) GetChainRandomnessLookingForward(ctx context.Context, tag acrypto.DomainSeparationTag, epoch abi.ChainEpoch, entropy []byte) ([]byte, error)

type MessagePenaltyChecker

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

MessageSelectionChecker checks for miner penalties on signed messages

func NewMessagePenaltyChecker

func NewMessagePenaltyChecker(api penaltyCheckerAPI) *MessagePenaltyChecker

func (*MessagePenaltyChecker) PenaltyCheck

func (v *MessagePenaltyChecker) PenaltyCheck(ctx context.Context, msg *types.UnsignedMessage) error

PenaltyCheck checks that a message is semantically valid for processing without causing miner penality. It treats any miner penalty condition as an 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 {
	// ProcessTipSet processes all messages in a tip set.
	ProcessTipSet(context.Context, *types.TipSet, *types.TipSet, []types.BlockMessagesInfo, vm.VmOption) (cid.Cid, []types.MessageReceipt, error)
	ProcessMessage(context.Context, types.ChainMsg, vm.VmOption) (*vm.Ret, error)
	ProcessImplicitMessage(context.Context, *types.UnsignedMessage, vm.VmOption) (*vm.Ret, error)
}

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

type ProofVerifier

type ProofVerifier interface {
	VerifySeal(info proof5.SealVerifyInfo) (bool, error)
	VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) (bool, error)
	VerifyWinningPoSt(ctx context.Context, info proof5.WinningPoStVerifyInfo) (bool, error)
	VerifyWindowPoSt(ctx context.Context, info proof5.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 Protocol

type Protocol 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, parentStateRoot cid.Cid) (root cid.Cid, receipt cid.Cid, err error)

	// BlockTime returns the block time used by the consensus protocol.
	BlockTime() time.Duration

	Call(ctx context.Context, msg *types.UnsignedMessage, ts *types.TipSet) (*vm.Ret, error)

	CallWithGas(ctx context.Context, msg *types.UnsignedMessage, priorMsgs []types.ChainMsg, ts *types.TipSet) (*vm.Ret, error)
}

Protocol is an interface defining a blockchain consensus protocol. The methods here were arrived at after significant work fitting consensus into the system and the implementation level. The method set is not necessarily the most theoretically obvious or pleasing and should not be considered finalized.

type SignFunc

type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, 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(sampler ChainSampler, 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