activation

package
v0.2.19-beta.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package activation is responsible for creating activation transactions and running the mining flow, coordinating Post building, sending proofs to PoET and building NIPost structs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStopRequested is returned when builder is stopped.
	ErrStopRequested = errors.New("builder: stop requested")
	// ErrATXChallengeExpired is returned when atx missed its publication window and needs to be regenerated.
	ErrATXChallengeExpired = errors.New("builder: atx expired")
	// ErrPoetServiceUnstable is returned when poet quality of service is low.
	ErrPoetServiceUnstable = &PoetSvcUnstableError{}
	// ErrPoetProofNotReceived is returned when no poet proof was received.
	ErrPoetProofNotReceived = errors.New("builder: didn't receive any poet proof")
)

Functions

func DefaultPostConfig added in v1.0.0

func DefaultPostConfig() atypes.PostConfig

DefaultPostConfig defines the default configuration for Post.

func DefaultPostSetupOpts added in v1.0.0

func DefaultPostSetupOpts() atypes.PostSetupOpts

DefaultPostSetupOpts defines the default options for Post setup.

func GetCommitmentBytes

func GetCommitmentBytes(id types.NodeID, commitmentAtx types.ATXID) []byte

func SignAtx

func SignAtx(signer signer, atx *types.ActivationTx) error

SignAtx signs the atx with specified signer and assigns the signature into atx.Sig this function returns an error if atx could not be converted to bytes.

Types

type Builder

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

Builder struct is the struct that orchestrates the creation of activation transactions it is responsible for initializing post, receiving poet proof and orchestrating nipst. after which it will calculate total weight and providing relevant view as proof.

func NewBuilder

func NewBuilder(conf Config, nodeID types.NodeID, signer signer, cdb *datastore.CachedDB, hdlr atxHandler, publisher pubsub.Publisher,
	nipostBuilder nipostBuilder, postSetupProvider PostSetupProvider, layerClock layerClock,
	syncer syncer, log log.Log, opts ...BuilderOption,
) *Builder

NewBuilder returns an atx builder that will start a routine that will attempt to create an atx upon each new layer.

func (*Builder) Coinbase added in v1.0.0

func (b *Builder) Coinbase() types.Address

Coinbase returns the current coinbase address.

func (*Builder) GetPositioningAtxInfo

func (b *Builder) GetPositioningAtxInfo() (types.ATXID, types.LayerID, error)

GetPositioningAtxInfo returns id and publication layer from the best observed atx.

func (*Builder) PublishActivationTx

func (b *Builder) PublishActivationTx(ctx context.Context) error

PublishActivationTx attempts to publish an atx, it returns an error if an atx cannot be created.

func (*Builder) SetCoinbase added in v1.0.0

func (b *Builder) SetCoinbase(rewardAddress types.Address)

SetCoinbase sets the address rewardAddress to be the coinbase account written into the activation transaction the rewards for blocks made by this miner will go to this address.

func (*Builder) SignAtx

func (b *Builder) SignAtx(atx *types.ActivationTx) error

SignAtx signs the atx and assigns the signature into atx.Sig this function returns an error if atx could not be converted to bytes.

func (*Builder) SmesherID added in v1.0.0

func (b *Builder) SmesherID() types.NodeID

SmesherID returns the ID of the smesher that created this activation.

func (*Builder) Smeshing added in v1.0.0

func (b *Builder) Smeshing() bool

Smeshing returns true iff atx builder is smeshing.

func (*Builder) StartSmeshing added in v1.0.0

func (b *Builder) StartSmeshing(coinbase types.Address, opts atypes.PostSetupOpts) error

StartSmeshing is the main entry point of the atx builder. It runs the main loop of the builder and shouldn't be called more than once. If the post data is incomplete or missing, data creation session will be preceded. Changing of the post potions (e.g., number of labels), after initial setup, is supported.

func (*Builder) StopSmeshing added in v1.0.0

func (b *Builder) StopSmeshing(deleteFiles bool) error

StopSmeshing stops the atx builder. It doesn't wait for the smeshing to stop.

func (*Builder) UpdatePoETServers added in v1.0.0

func (b *Builder) UpdatePoETServers(ctx context.Context, endpoints []string) error

UpdatePoETServer updates poet client. Context is used to verify that the target is responsive.

type BuilderOption added in v1.0.0

type BuilderOption func(*Builder)

BuilderOption ...

func WithContext added in v1.0.0

func WithContext(ctx context.Context) BuilderOption

WithContext modifies parent context for background job.

func WithPoETClientInitializer added in v1.0.0

func WithPoETClientInitializer(initializer PoETClientInitializer) BuilderOption

WithPoETClientInitializer modifies initialization logic for PoET client. Used during client update.

func WithPoetConfig added in v1.0.0

func WithPoetConfig(c PoetConfig) BuilderOption

WithPoetConfig sets the poet config.

func WithPoetRetryInterval added in v1.0.0

func WithPoetRetryInterval(interval time.Duration) BuilderOption

WithPoetRetryInterval modifies time that builder will have to wait before retrying ATX build process if it failed due to issues with PoET server.

type Config added in v0.1.28

type Config struct {
	CoinbaseAccount types.Address
	GoldenATXID     types.ATXID
	LayersPerEpoch  uint32
}

Config defines configuration for Builder.

type HTTPPoetClient

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

HTTPPoetClient implements PoetProvingServiceClient interface.

func NewHTTPPoetClient

func NewHTTPPoetClient(target string) *HTTPPoetClient

NewHTTPPoetClient returns new instance of HTTPPoetClient for the specified target.

func (*HTTPPoetClient) PoetServiceID added in v0.1.11

func (c *HTTPPoetClient) PoetServiceID(ctx context.Context) ([]byte, error)

PoetServiceID returns the public key of the PoET proving service.

func (*HTTPPoetClient) Start

func (c *HTTPPoetClient) Start(ctx context.Context, gatewayAddresses []string) error

Start is an administrative endpoint of the proving service that tells it to start. This is mostly done in tests, since it requires administrative permissions to the proving service.

func (*HTTPPoetClient) Submit

func (c *HTTPPoetClient) Submit(ctx context.Context, challenge types.Hash32) (*types.PoetRound, error)

Submit registers a challenge in the proving service current open round.

type HTTPPoetHarness

type HTTPPoetHarness struct {
	*HTTPPoetClient
	Stdout   io.Reader
	Stderr   io.Reader
	ErrChan  <-chan error
	Teardown func(cleanup bool) error
	// contains filtered or unexported fields
}

HTTPPoetHarness utilizes a local self-contained poet server instance targeted by an HTTP client, in order to exercise functionality.

func NewHTTPPoetHarness

func NewHTTPPoetHarness(disableBroadcast bool) (*HTTPPoetHarness, error)

NewHTTPPoetHarness returns a new instance of HTTPPoetHarness.

type Handler added in v1.0.0

type Handler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Handler processes the atxs received from all nodes and their validity status.

func NewHandler added in v1.0.0

func NewHandler(cdb *datastore.CachedDB, fetcher system.Fetcher, layersPerEpoch uint32, tickSize uint64, goldenATXID types.ATXID, nipostValidator nipostValidator, atxReceiver atxReceiver, log log.Log) *Handler

NewHandler returns a data handler for ATX.

func (*Handler) AwaitAtx added in v1.0.0

func (h *Handler) AwaitAtx(id types.ATXID) chan struct{}

AwaitAtx returns a channel that will receive notification when the specified atx with id is received via gossip.

func (*Handler) ContextuallyValidateAtx added in v1.0.0

func (h *Handler) ContextuallyValidateAtx(atx *types.VerifiedActivationTx) error

ContextuallyValidateAtx ensures that the previous ATX referenced is the last known ATX for the referenced miner ID. If a previous ATX is not referenced, it validates that indeed there's no previous known ATX for that miner ID.

func (*Handler) FetchAtxReferences added in v1.0.0

func (h *Handler) FetchAtxReferences(ctx context.Context, atx *types.ActivationTx) error

FetchAtxReferences fetches positioning and prev atxs from peers if they are not found in db.

func (*Handler) GetEpochAtxs added in v1.0.0

func (h *Handler) GetEpochAtxs(epochID types.EpochID) (ids []types.ATXID, err error)

GetEpochAtxs returns all valid ATXs received in the epoch epochID.

func (*Handler) GetPosAtxID

func (h *Handler) GetPosAtxID() (types.ATXID, error)

GetPosAtxID returns the best (highest layer id), currently known to this node, pos atx id.

func (*Handler) HandleAtxData added in v1.0.0

func (h *Handler) HandleAtxData(ctx context.Context, data []byte) error

HandleAtxData handles atxs received either by gossip or sync.

func (*Handler) HandleGossipAtx added in v1.0.0

func (h *Handler) HandleGossipAtx(ctx context.Context, _ p2p.Peer, msg []byte) pubsub.ValidationResult

HandleGossipAtx handles the atx gossip data channel.

func (*Handler) ProcessAtx added in v1.0.0

func (h *Handler) ProcessAtx(ctx context.Context, atx *types.VerifiedActivationTx) error

ProcessAtx validates the active set size declared in the atx, and contextually validates the atx according to atx validation rules it then stores the atx with flag set to validity of the atx.

ATXs received as input must be already syntactically valid. Only contextual validation is performed.

func (*Handler) StoreAtx

func (h *Handler) StoreAtx(ctx context.Context, atx *types.VerifiedActivationTx) error

StoreAtx stores an ATX and notifies subscribers of the ATXID.

func (*Handler) SyntacticallyValidateAtx added in v1.0.0

func (h *Handler) SyntacticallyValidateAtx(ctx context.Context, atx *types.ActivationTx) (*types.VerifiedActivationTx, error)

SyntacticallyValidateAtx ensures the following conditions apply, otherwise it returns an error.

  • If the sequence number is non-zero: PrevATX points to a syntactically valid ATX whose sequence number is one less than the current ATXs sequence number.
  • If the sequence number is zero: PrevATX is empty.
  • Positioning ATX points to a syntactically valid ATX.
  • NIPost challenge is a hash of the serialization of the following fields: NodeID, SequenceNumber, PrevATXID, LayerID, StartTick, PositioningATX.
  • The NIPost is valid.
  • ATX LayerID is NIPostLayerTime or less after the PositioningATX LayerID.
  • The ATX view of the previous epoch contains ActiveSetSize activations.

func (*Handler) UnsubscribeAtx added in v1.0.0

func (h *Handler) UnsubscribeAtx(id types.ATXID)

UnsubscribeAtx un subscribes the waiting for a specific atx with atx id id to arrive via gossip.

type NIPostBuilder added in v1.0.0

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

NIPostBuilder holds the required state and dependencies to create Non-Interactive Proofs of Space-Time (NIPost).

func NewNIPostBuilder added in v1.0.0

func NewNIPostBuilder(
	minerID types.NodeID,
	postSetupProvider PostSetupProvider,
	poetProvers []PoetProvingServiceClient,
	poetDB poetDbAPI,
	db *sql.Database,
	log log.Log,
) *NIPostBuilder

NewNIPostBuilder returns a NIPostBuilder.

func (*NIPostBuilder) BuildNIPost added in v1.0.0

func (nb *NIPostBuilder) BuildNIPost(ctx context.Context, challenge *types.Hash32, commitmentAtx types.ATXID, poetProofDeadline time.Time) (*types.NIPost, time.Duration, error)

BuildNIPost uses the given challenge to build a NIPost. The process can take considerable time, because it includes waiting for the poet service to publish a proof - a process that takes about an epoch.

type PoETClientInitializer added in v1.0.0

type PoETClientInitializer func(string) PoetProvingServiceClient

PoETClientInitializer interfaces for creating PoetProvingServiceClient.

type PoetConfig added in v1.0.0

type PoetConfig struct {
	PhaseShift  time.Duration `mapstructure:"phase-shift"`
	CycleGap    time.Duration `mapstructure:"cycle-gap"`
	GracePeriod time.Duration `mapstructure:"grace-period"`
}

PoetConfig is the configuration to interact with the poet server.

func DefaultPoetConfig added in v1.0.0

func DefaultPoetConfig() PoetConfig

type PoetDb

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

PoetDb is a database for PoET proofs.

func NewPoetDb

func NewPoetDb(db *sql.Database, log log.Log) *PoetDb

NewPoetDb returns a new PoET handler.

func (*PoetDb) GetMembershipMap

func (db *PoetDb) GetMembershipMap(proofRef types.PoetProofRef) (map[types.Hash32]bool, error)

GetMembershipMap returns the map of memberships in the requested PoET proof.

func (*PoetDb) GetProof added in v1.0.0

func (db *PoetDb) GetProof(proofRef types.PoetProofRef) (*types.PoetProof, error)

GetProof returns full proof.

func (*PoetDb) GetProofMessage

func (db *PoetDb) GetProofMessage(proofRef types.PoetProofRef) ([]byte, error)

GetProofMessage returns the originally received PoET proof message.

func (*PoetDb) GetProofRef added in v1.0.0

func (db *PoetDb) GetProofRef(poetID []byte, roundID string) (types.PoetProofRef, error)

func (*PoetDb) HasProof

func (db *PoetDb) HasProof(proofRef types.PoetProofRef) bool

HasProof returns true if the database contains a proof with the given reference, or false otherwise.

func (*PoetDb) StoreProof added in v1.0.0

func (db *PoetDb) StoreProof(ref types.PoetProofRef, proofMessage *types.PoetProofMessage) error

StoreProof saves the poet proof in local db.

func (*PoetDb) Validate

func (db *PoetDb) Validate(proof types.PoetProof, poetID []byte, roundID string, signature []byte) error

Validate validates a new PoET proof.

func (*PoetDb) ValidateAndStore

func (db *PoetDb) ValidateAndStore(proofMessage *types.PoetProofMessage) error

ValidateAndStore validates and stores a new PoET proof.

func (*PoetDb) ValidateAndStoreMsg added in v0.1.16

func (db *PoetDb) ValidateAndStoreMsg(data []byte) error

ValidateAndStoreMsg validates and stores a new PoET proof.

type PoetListener

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

PoetListener handles PoET gossip messages.

func NewPoetListener

func NewPoetListener(poetDb poetValidatorPersister, logger log.Log) *PoetListener

NewPoetListener returns a new PoetListener.

func (*PoetListener) HandlePoetProofMessage

func (l *PoetListener) HandlePoetProofMessage(ctx context.Context, _ p2p.Peer, msg []byte) pubsub.ValidationResult

HandlePoetProofMessage is a receiver for broadcast messages.

type PoetProvingServiceClient

type PoetProvingServiceClient interface {
	// Submit registers a challenge in the proving service current open round.
	Submit(ctx context.Context, challenge types.Hash32) (*types.PoetRound, error)

	// PoetServiceID returns the public key of the PoET proving service.
	PoetServiceID(context.Context) ([]byte, error)
}

PoetProvingServiceClient provides a gateway to a trust-less public proving service, which may serve many PoET proving clients, and thus enormously reduce the cost-per-proof for PoET since each additional proof adds only a small number of hash evaluations to the total cost.

type PoetSvcUnstableError added in v1.0.0

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

PoetSvcUnstableError means there was a problem communicating with a Poet service. It wraps the source error.

func (*PoetSvcUnstableError) Error added in v1.0.0

func (e *PoetSvcUnstableError) Error() string

func (*PoetSvcUnstableError) Is added in v1.0.0

func (e *PoetSvcUnstableError) Is(target error) bool

func (*PoetSvcUnstableError) Unwrap added in v1.0.0

func (e *PoetSvcUnstableError) Unwrap() error

type PostSetupManager added in v1.0.0

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

PostSetupManager implements the PostProvider interface.

func NewPostSetupManager added in v1.0.0

func NewPostSetupManager(id types.NodeID, cfg atypes.PostConfig, logger log.Log, db *datastore.CachedDB, goldenATXID types.ATXID) (*PostSetupManager, error)

NewPostSetupManager creates a new instance of PostSetupManager.

func (*PostSetupManager) Benchmark added in v1.0.0

Benchmark runs a short benchmarking session for a given provider to evaluate its performance.

func (*PostSetupManager) BestProvider added in v1.0.0

func (mgr *PostSetupManager) BestProvider() (*atypes.PostSetupComputeProvider, error)

BestProvider returns the most performant compute provider based on a short benchmarking session.

func (*PostSetupManager) ComputeProviders

func (mgr *PostSetupManager) ComputeProviders() []atypes.PostSetupComputeProvider

ComputeProviders returns a list of available compute providers for Post setup.

func (*PostSetupManager) Config added in v1.0.0

func (mgr *PostSetupManager) Config() atypes.PostConfig

Config returns the Post protocol config.

func (*PostSetupManager) GenerateProof added in v1.0.0

func (mgr *PostSetupManager) GenerateProof(challenge []byte, commitmentAtx types.ATXID) (*types.Post, *types.PostMetadata, error)

GenerateProof generates a new Post.

func (*PostSetupManager) LastError

func (mgr *PostSetupManager) LastError() error

LastError returns the Post setup last error.

func (*PostSetupManager) LastOpts added in v1.0.0

func (mgr *PostSetupManager) LastOpts() *atypes.PostSetupOpts

LastOpts returns the Post setup last session options.

func (*PostSetupManager) StartSession added in v1.0.0

func (mgr *PostSetupManager) StartSession(opts atypes.PostSetupOpts, commitmentAtx types.ATXID) (chan struct{}, error)

StartSession starts (or continues) a data creation session. It supports resuming a previously started session, as well as changing the Post setup options (e.g., number of units) after initial setup.

func (*PostSetupManager) Status added in v1.0.0

func (mgr *PostSetupManager) Status() *atypes.PostSetupStatus

Status returns the setup current status.

func (*PostSetupManager) StopSession

func (mgr *PostSetupManager) StopSession(deleteFiles bool) error

StopSession stops the current Post setup data creation session and optionally attempts to delete the data file(s).

type PostSetupProvider added in v1.0.0

type PostSetupProvider interface {
	Status() *atypes.PostSetupStatus
	ComputeProviders() []atypes.PostSetupComputeProvider
	Benchmark(p atypes.PostSetupComputeProvider) (int, error)
	StartSession(opts atypes.PostSetupOpts, commitmentAtx types.ATXID) (chan struct{}, error)
	StopSession(deleteFiles bool) error
	GenerateProof(challenge []byte, commitmentAtx types.ATXID) (*types.Post, *types.PostMetadata, error)
	LastError() error
	LastOpts() *atypes.PostSetupOpts
	Config() atypes.PostConfig
}

PostSetupProvider defines the functionality required for Post setup.

type SmeshingProvider added in v1.0.0

type SmeshingProvider interface {
	Smeshing() bool
	StartSmeshing(types.Address, atypes.PostSetupOpts) error
	StopSmeshing(bool) error
	SmesherID() types.NodeID
	Coinbase() types.Address
	SetCoinbase(coinbase types.Address)
}

SmeshingProvider defines the functionality required for the node's Smesher API.

type Validator

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

Validator contains the dependencies required to validate NIPosts.

func NewValidator

func NewValidator(poetDb poetDbAPI, cfg atypes.PostConfig) *Validator

NewValidator returns a new NIPost validator.

func (*Validator) Validate

func (v *Validator) Validate(commitment []byte, nipost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32) (uint64, error)

Validate validates a NIPost, given a miner id and expected challenge. It returns an error if an issue is found or nil if the NIPost is valid. Some of the Post metadata fields validation values is ought to eventually be derived from consensus instead of local configuration. If so, their validation should be removed to contextual validation, while still syntactically-validate them here according to locally configured min/max values.

func (*Validator) ValidatePost

func (v *Validator) ValidatePost(commitment []byte, PoST *types.Post, PostMetadata *types.PostMetadata, numUnits uint32) error

ValidatePost validates a Proof of Space-Time (PoST). It returns nil if validation passed or an error indicating why validation failed.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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