weakcoin

package
v0.2.20-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Epoch     types.EpochID
	Round     types.RoundID
	Unit      uint64
	MinerPK   []byte
	Signature []byte
}

Message defines weak coin message format.

func (*Message) DecodeScale

func (t *Message) DecodeScale(dec *scale.Decoder) (total int, err error)

DecodeScale implements scale codec interface.

func (*Message) EncodeScale

func (t *Message) EncodeScale(enc *scale.Encoder) (total int, err error)

EncodeScale implements scale codec interface.

type Option

type Option func(*WeakCoin)

Option for optional configuration adjustments.

func WithLog

func WithLog(logger log.Log) Option

WithLog changes logger.

func WithMaxRound

func WithMaxRound(round types.RoundID) Option

WithMaxRound changes max round.

func WithNextRoundBufferSize

func WithNextRoundBufferSize(size int) Option

WithNextRoundBufferSize changes size of the buffer for messages from future rounds.

func WithThreshold

func WithThreshold(threshold []byte) Option

WithThreshold changes signature threshold.

func WithVerifier

func WithVerifier(v signing.Verifier) Option

WithVerifier changes the verifier of the weakcoin messages.

type UnitAllowances

type UnitAllowances map[string]uint64

UnitAllowances is a map from miner identifier to the number of units of spacetime.

type WeakCoin

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

WeakCoin implementation of the protocol.

func New

func New(
	publisher pubsub.Publisher,
	signer signing.Signer,
	opts ...Option,
) *WeakCoin

New creates an instance of weak coin protocol.

func (*WeakCoin) FinishEpoch

func (wc *WeakCoin) FinishEpoch(ctx context.Context, epoch types.EpochID)

FinishEpoch completes epoch. After it is called Get for this epoch will panic.

func (*WeakCoin) FinishRound

func (wc *WeakCoin) FinishRound(ctx context.Context)

FinishRound computes coinflip based on proposals received in this round. After it is called new proposals for this round won't be accepted.

func (*WeakCoin) Get

func (wc *WeakCoin) Get(ctx context.Context, epoch types.EpochID, round types.RoundID) bool

Get the result of the coin flip in this round. It is only valid in between StartEpoch/EndEpoch and only after CompleteRound was called.

func (*WeakCoin) HandleProposal

func (wc *WeakCoin) HandleProposal(ctx context.Context, peer p2p.Peer, msg []byte) pubsub.ValidationResult

HandleProposal defines method to handle Beacon Weak Coin Messages from gossip.

func (*WeakCoin) StartEpoch

func (wc *WeakCoin) StartEpoch(ctx context.Context, epoch types.EpochID, allowances UnitAllowances)

StartEpoch notifies that epoch is started and we can accept messages for this epoch.

func (*WeakCoin) StartRound

func (wc *WeakCoin) StartRound(ctx context.Context, round types.RoundID) error

StartRound process any buffered messages for this round and broadcast our proposal.

Jump to

Keyboard shortcuts

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