activation

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InitIdle = 1 + iota
	InitInProgress
	InitDone
)
View Source
const AtxProtocol = "AtxGossip"
View Source
const PoetProofProtocol = "PoetProof"

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() config.Config

func ExtractPublicKey

func ExtractPublicKey(signedAtx *types.ActivationTx) (*signing.PublicKey, error)

ExtractPublicKey extracts public key from message and verifies public key exists in IdStore, this is how we validate ATX signature. If this is the first ATX it is considered valid anyways and ATX syntactic validation will determine ATX validity

func NewNIPSTWithChallenge

func NewNIPSTWithChallenge(challenge *types.Hash32, poetRef []byte) *types.NIPST

func SignAtx

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

Types

type ATXDBProvider

type ATXDBProvider interface {
	GetAtxHeader(id types.AtxId) (*types.ActivationTxHeader, error)
	CalcActiveSetFromView(view []types.BlockID, pubEpoch types.EpochId) (uint32, error)
	GetNodeLastAtxId(nodeId types.NodeId) (types.AtxId, error)
	GetPosAtxId() (types.AtxId, error)
	AwaitAtx(id types.AtxId) chan struct{}
	UnsubscribeAtx(id types.AtxId)
}

type ActivationDb

type ActivationDb struct {
	sync.RWMutex
	//todo: think about whether we need one db or several
	IdStore

	LayersPerEpoch uint16
	// contains filtered or unexported fields
}

func NewActivationDb

func NewActivationDb(dbstore database.Database, idstore IdStore, meshDb *mesh.MeshDB, layersPerEpoch uint16, nipstValidator NipstValidator, log log.Log) *ActivationDb

func (*ActivationDb) AwaitAtx

func (db *ActivationDb) AwaitAtx(id types.AtxId) chan struct{}

func (*ActivationDb) CalcActiveSetFromView

func (db *ActivationDb) CalcActiveSetFromView(view []types.BlockID, pubEpoch types.EpochId) (uint32, error)

CalcActiveSetFromView traverses the view found in a - the activation tx and counts number of active ids published in the epoch prior to the epoch that a was published at, this number is the number of active ids in the next epoch the function returns error if the view is not found

func (*ActivationDb) CalcActiveSetSize

func (db *ActivationDb) CalcActiveSetSize(epoch types.EpochId, blocks map[types.BlockID]struct{}) (map[string]struct{}, error)

CalcActiveSetSize - returns the active set size that matches the view of the contextually valid blocks in the provided layer

func (*ActivationDb) ContextuallyValidateAtx

func (db *ActivationDb) ContextuallyValidateAtx(atx *types.ActivationTxHeader) 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 (*ActivationDb) GetAtxHeader

func (db *ActivationDb) GetAtxHeader(id types.AtxId) (*types.ActivationTxHeader, error)

GetAtxHeader returns the ATX header by the given ID. This function is thread safe and will return an error if the ID is not found in the ATX DB.

func (*ActivationDb) GetFullAtx

func (db *ActivationDb) GetFullAtx(id types.AtxId) (*types.ActivationTx, error)

func (*ActivationDb) GetNodeAtxIdForEpoch

func (db *ActivationDb) GetNodeAtxIdForEpoch(nodeId types.NodeId, targetEpoch types.EpochId) (types.AtxId, error)

func (*ActivationDb) GetNodeLastAtxId

func (db *ActivationDb) GetNodeLastAtxId(nodeId types.NodeId) (types.AtxId, error)

GetNodeLastAtxId returns the last atx id that was received for node nodeId

func (*ActivationDb) GetPosAtxId

func (db *ActivationDb) GetPosAtxId() (types.AtxId, error)

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

func (*ActivationDb) ProcessAtx

func (db *ActivationDb) ProcessAtx(atx *types.ActivationTx) 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 (*ActivationDb) ProcessAtxs

func (db *ActivationDb) ProcessAtxs(atxs []*types.ActivationTx) error

func (*ActivationDb) StoreAtx

func (db *ActivationDb) StoreAtx(ech types.EpochId, atx *types.ActivationTx) error

StoreAtx stores an atx for epoh ech, it stores atx for the current epoch and adds the atx for the nodeid that created it in a sorted manner by the sequence id. this function does not validate the atx and assumes all data is correct and that all associated atx exist in the db. will return error if writing to db failed

func (*ActivationDb) SyntacticallyValidateAtx

func (db *ActivationDb) SyntacticallyValidateAtx(atx *types.ActivationTx) 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 ATX's sequence number.
  • If the sequence number is zero: PrevATX is empty.
  • Positioning ATX points to a syntactically valid ATX.
  • NIPST challenge is a hash of the serialization of the following fields: NodeID, SequenceNumber, PrevATXID, LayerID, StartTick, PositioningATX.
  • The NIPST is valid.
  • ATX LayerID is NipstLayerTime or less after the PositioningATX LayerID.
  • The ATX view of the previous epoch contains ActiveSetSize activations.

func (*ActivationDb) UnsubscribeAtx

func (db *ActivationDb) UnsubscribeAtx(id types.AtxId)

func (*ActivationDb) ValidateSignedAtx

func (db *ActivationDb) ValidateSignedAtx(pubKey signing.PublicKey, signedAtx *types.ActivationTx) error

ValidateSignedAtx extracts public key from message and verifies public key exists in IdStore, this is how we validate ATX signature. If this is the first ATX it is considered valid anyways and ATX syntactic validation will determine ATX validity

type ActivesetCache

type ActivesetCache struct {
	*lru.Cache
}

func NewActivesetCache

func NewActivesetCache(size int) ActivesetCache

func (*ActivesetCache) Add

func (bc *ActivesetCache) Add(view types.Hash12, setSize uint32)

func (ActivesetCache) Get

func (bc ActivesetCache) Get(view types.Hash12) (uint32, bool)

type AtxCache

type AtxCache struct {
	*lru.Cache
}

func NewAtxCache

func NewAtxCache(size int) AtxCache

func (*AtxCache) Add

func (bc *AtxCache) Add(id types.AtxId, atxHeader *types.ActivationTxHeader)

func (AtxCache) Get

type Broadcaster

type Broadcaster interface {
	Broadcast(channel string, data []byte) error
}

type Builder

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

func NewBuilder

func NewBuilder(nodeId types.NodeId, coinbaseAccount types.Address, signer Signer, db ATXDBProvider, net Broadcaster, mesh MeshProvider, layersPerEpoch uint16, nipstBuilder NipstBuilder, postProver PostProverClient, layerClock LayerClock, syncer Syncer, store BytesStore, log log.Log) *Builder

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

func (*Builder) GetPositioningAtx

func (b *Builder) GetPositioningAtx() (*types.ActivationTxHeader, error)

GetPositioningAtx return the latest atx to be used as a positioning atx

func (*Builder) GetPrevAtx

func (b *Builder) GetPrevAtx(node types.NodeId) (*types.ActivationTxHeader, error)

func (*Builder) MiningStats

func (b *Builder) MiningStats() (int, uint64, string, string)

MiningStats returns state of post init, coinbase reward account and data directory path for post commitment

func (*Builder) PublishActivationTx

func (b *Builder) PublishActivationTx() error

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

func (*Builder) SetCoinbaseAccount

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

func (Builder) SignAtx

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

func (*Builder) Start

func (b *Builder) Start()

Start 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

func (*Builder) StartPost

func (b *Builder) StartPost(rewardAddress types.Address, dataDir string, space uint64) error

func (*Builder) Stop

func (b *Builder) Stop()

Stop stops the atx builder.

type BytesStore

type BytesStore interface {
	Put(key []byte, buf []byte) error
	Get(key []byte) ([]byte, error)
}

type EpochProvider

type EpochProvider interface {
	Epoch(l types.LayerID) types.EpochId
}

type ErrAtxNotFound

type ErrAtxNotFound error

type GetInfoResponse

type GetInfoResponse struct {
	OpenRoundId        string
	ExecutingRoundsIds []string
	ServicePubKey      []byte
}

type HTTPPoetClient

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

HTTPPoetClient implements PoetProvingServiceClient interface.

func NewHTTPPoetClient

func NewHTTPPoetClient(target string, ctx context.Context) *HTTPPoetClient

NewHTTPPoetClient returns new instance of HTTPPoetClient for the specified target.

func (*HTTPPoetClient) PoetServiceId

func (c *HTTPPoetClient) PoetServiceId() ([]byte, error)

func (*HTTPPoetClient) Start

func (c *HTTPPoetClient) Start(gatewayAddresses []string) error

func (*HTTPPoetClient) Submit

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

type HTTPPoetHarness

type HTTPPoetHarness struct {
	*HTTPPoetClient
	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 IdStore

type IdStore interface {
	StoreNodeIdentity(id types.NodeId) error
	GetIdentity(id string) (types.NodeId, error)
}

type IdentityStore

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

func NewIdentityStore

func NewIdentityStore(db database.Database) *IdentityStore

func (*IdentityStore) GetIdentity

func (s *IdentityStore) GetIdentity(id string) (types.NodeId, error)

func (*IdentityStore) StoreNodeIdentity

func (s *IdentityStore) StoreNodeIdentity(id types.NodeId) error

type LayerClock

type LayerClock interface {
	AwaitLayer(layerId types.LayerID) chan struct{}
	GetCurrentLayer() types.LayerID
}

type MeshProvider

type MeshProvider interface {
	GetOrphanBlocksBefore(l types.LayerID) ([]types.BlockID, error)
	LatestLayer() types.LayerID
}

type NIPSTBuilder

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

func NewNIPSTBuilder

func NewNIPSTBuilder(id []byte, postProver PostProverClient, poetProver PoetProvingServiceClient, poetDb PoetDbApi, store BytesStore, log log.Log) *NIPSTBuilder

func (*NIPSTBuilder) BuildNIPST

func (nb *NIPSTBuilder) BuildNIPST(challenge *types.Hash32, atxExpired chan struct{}, stop chan struct{}) (*types.NIPST, error)

type NipstBuilder

type NipstBuilder interface {
	BuildNIPST(challenge *types.Hash32, timeout chan struct{}, stop chan struct{}) (*types.NIPST, error)
}

type NipstValidator

type NipstValidator interface {
	Validate(id signing.PublicKey, nipst *types.NIPST, expectedChallenge types.Hash32) error
	VerifyPost(id signing.PublicKey, proof *types.PostProof, space uint64) error
}

type PoETNumberOfTickProvider

type PoETNumberOfTickProvider struct {
}

func (*PoETNumberOfTickProvider) NumOfTicks

func (provider *PoETNumberOfTickProvider) NumOfTicks() uint64

type PoetDb

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

func NewPoetDb

func NewPoetDb(store database.Database, log log.Log) *PoetDb

func (*PoetDb) GetMembershipMap

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

func (*PoetDb) GetProofMessage

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

func (*PoetDb) HasProof

func (db *PoetDb) HasProof(proofRef []byte) bool

func (*PoetDb) SubscribeToProofRef

func (db *PoetDb) SubscribeToProofRef(poetId []byte, roundId string) chan []byte

func (*PoetDb) UnsubscribeFromProofRef

func (db *PoetDb) UnsubscribeFromProofRef(poetId []byte, roundId string)

func (*PoetDb) Validate

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

func (*PoetDb) ValidateAndStore

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

type PoetDbApi

type PoetDbApi interface {
	SubscribeToProofRef(poetId []byte, roundId string) chan []byte
	GetMembershipMap(proofRef []byte) (map[types.Hash32]bool, error)
	UnsubscribeFromProofRef(poetId []byte, roundId string)
}

type PoetListener

type PoetListener struct {
	Log log.Log
	// contains filtered or unexported fields
}

func NewPoetListener

func NewPoetListener(net service.Service, poetDb PoetValidatorPersistor, logger log.Log) *PoetListener

func (*PoetListener) Close

func (l *PoetListener) Close()

func (*PoetListener) Start

func (l *PoetListener) Start()

type PoetProvingServiceClient

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

	PoetServiceId() ([]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 PoetValidatorPersistor

type PoetValidatorPersistor interface {
	Validate(proof types.PoetProof, poetId []byte, roundId string, signature []byte) error
	// contains filtered or unexported methods
}

type PostClient

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

func NewPostClient

func NewPostClient(cfg *config.Config, id []byte) (*PostClient, error)

func (*PostClient) Cfg

func (c *PostClient) Cfg() *config.Config

func (*PostClient) Execute

func (c *PostClient) Execute(challenge []byte) (*types.PostProof, error)

func (*PostClient) Initialize

func (c *PostClient) Initialize() (commitment *types.PostProof, err error)

func (*PostClient) IsInitialized

func (c *PostClient) IsInitialized() (bool, uint64, error)

func (*PostClient) Reset

func (c *PostClient) Reset() error

func (*PostClient) SetLogger

func (c *PostClient) SetLogger(logger shared.Logger)

func (*PostClient) SetParams

func (c *PostClient) SetParams(dataDir string, space uint64) error

func (*PostClient) VerifyInitAllowed

func (c *PostClient) VerifyInitAllowed() error

type PostProverClient

type PostProverClient interface {
	// initialize is the process in which the prover commits
	// to store some data, by having its storage being filled with
	// pseudo-random data with respect to a specific id.
	// This data is the result of a computationally-expensive operation.
	Initialize() (commitment *types.PostProof, err error)

	// Execute is the phase in which the prover received a challenge,
	// and proves that his data is still stored (or was recomputed).
	// This phase can be repeated arbitrarily many times without repeating initialization;
	// thus despite the initialization essentially serving as a proof-of-work,
	// the amortized computational complexity can be made arbitrarily small.
	Execute(challenge []byte) (proof *types.PostProof, err error)

	// Reset removes the initialization phase files.
	Reset() error

	// IsInitialized indicates whether the initialization phase has been completed.
	IsInitialized() (initComplete bool, remainingBytes uint64, err error)

	// VerifyInitAllowed indicates whether the preconditions for starting
	// the initialization phase are met.
	VerifyInitAllowed() error

	// SetParams updates the datadir and space params in the client config, to be used in the initialization
	// and the execution phases. It overrides the config which the client was instantiated with.
	SetParams(datadir string, space uint64) error

	// SetLogger sets a logger for the client.
	SetLogger(logger shared.Logger)

	// Cfg returns the the client latest config.
	Cfg() *config.Config
}

PostProverClient provides proving functionality for PoST.

type Signer

type Signer interface {
	Sign(m []byte) []byte
}

type StartRequest

type StartRequest struct {
	GatewayAddresses       []string `json:"gatewayAddresses,omitempty"`
	DisableBroadcast       bool     `json:"disableBroadcast,omitempty"`
	ConnAcksThreshold      int      `json:"connAcksThreshold,omitempty"`
	BroadcastAcksThreshold int      `json:"broadcastAcksThreshold,omitempty"`
}

type StopRequestedError

type StopRequestedError struct{}

func (StopRequestedError) Error

func (s StopRequestedError) Error() string

type SubmitRequest

type SubmitRequest struct {
	Challenge []byte `json:"challenge,omitempty"`
}

type SubmitResponse

type SubmitResponse struct {
	RoundId string
}

type Syncer

type Syncer interface {
	Await() chan struct{}
}

type Validator

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

func NewValidator

func NewValidator(postCfg *config.Config, poetDb PoetDbApi) *Validator

func (*Validator) Validate

func (v *Validator) Validate(id signing.PublicKey, nipst *types.NIPST, expectedChallenge types.Hash32) error

func (*Validator) VerifyPost

func (v *Validator) VerifyPost(id signing.PublicKey, proof *types.PostProof, space uint64) error

Jump to

Keyboard shortcuts

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