hare4

package
v1.7.0-citest.0-nomain Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	PROTOCOL_NAME     = "hare4/full_exchange"
	MAX_EXCHANGE_SIZE = 1_000_000 // protect against a malicious allocation of too much space.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body struct {
	Layer types.LayerID
	IterRound
	Value       Value
	Eligibility types.HareEligibility
}

func (*Body) DecodeScale

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

func (*Body) EncodeScale

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

type CommitteeUpgrade

type CommitteeUpgrade struct {
	Layer types.LayerID
	Size  uint16
}

type CompactIdRequest

type CompactIdRequest struct {
	MsgId types.Hash32
}

func (*CompactIdRequest) DecodeScale

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

func (*CompactIdRequest) EncodeScale

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

type CompactIdResponse

type CompactIdResponse struct {
	Ids []types.ProposalID `scale:"max=2050"`
}

func (*CompactIdResponse) DecodeScale

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

func (*CompactIdResponse) EncodeScale

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

type Config

type Config struct {
	Enable           bool          `mapstructure:"enable"`
	EnableLayer      types.LayerID `mapstructure:"enable-layer"`
	DisableLayer     types.LayerID `mapstructure:"disable-layer"`
	Committee        uint16        `mapstructure:"committee"`
	CommitteeUpgrade *CommitteeUpgrade
	Leaders          uint16        `mapstructure:"leaders"`
	IterationsLimit  uint8         `mapstructure:"iterations-limit"`
	PreroundDelay    time.Duration `mapstructure:"preround-delay"`
	RoundDuration    time.Duration `mapstructure:"round-duration"`
	// LogStats if true will log iteration statistics with INFO level at the start of the next iteration.
	// This requires additional computation and should be used for debugging only.
	LogStats     bool   `mapstructure:"log-stats"`
	ProtocolName string `mapstructure:"protocolname"`
}

func DefaultConfig

func DefaultConfig() Config

func (*Config) CommitteeFor

func (cfg *Config) CommitteeFor(layer types.LayerID) uint16

func (*Config) MarshalLogObject

func (cfg *Config) MarshalLogObject(encoder zapcore.ObjectEncoder) error

func (*Config) Validate

func (cfg *Config) Validate(zdist time.Duration) error

type ConsensusOutput

type ConsensusOutput struct {
	Layer     types.LayerID
	Proposals []types.ProposalID
}

type Hare

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

func New

func New(
	nodeclock nodeclock,
	pubsub pubsub.PublishSubsciber,
	db *sql.Database,
	atxsdata *atxsdata.Data,
	proposals *store.Store,
	verif verifier,
	oracle oracle,
	sync system.SyncStateProvider,
	patrol *layerpatrol.LayerPatrol,
	host server.Host,
	opts ...Opt,
) *Hare

func (*Hare) Coins

func (h *Hare) Coins() <-chan WeakCoinOutput

func (*Hare) Handler

func (h *Hare) Handler(ctx context.Context, peer p2p.Peer, buf []byte) error

func (*Hare) IsKnown

func (h *Hare) IsKnown(layer types.LayerID, proposal types.ProposalID) bool

func (*Hare) OnProposal

func (h *Hare) OnProposal(p *types.Proposal) error

OnProposal is a hook which gets called when we get a proposal.

func (*Hare) Register

func (h *Hare) Register(sig *signing.EdSigner)

func (*Hare) Results

func (h *Hare) Results() <-chan ConsensusOutput

func (*Hare) Running

func (h *Hare) Running() int

func (*Hare) Start

func (h *Hare) Start()

func (*Hare) Stop

func (h *Hare) Stop()

type IterRound

type IterRound struct {
	Iter  uint8
	Round Round
}

func (IterRound) Absolute

func (ir IterRound) Absolute() uint32

func (*IterRound) DecodeScale

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

func (IterRound) Delay

func (ir IterRound) Delay(since IterRound) uint32

Delay returns number of network delays since specified iterround.

func (*IterRound) EncodeScale

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

func (IterRound) Grade

func (ir IterRound) Grade(since IterRound) grade

func (IterRound) IsMessageRound

func (ir IterRound) IsMessageRound() bool

type MalfeasanceHandler

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

func NewMalfeasanceHandler

func NewMalfeasanceHandler(
	db sql.Executor,
	edVerifier *signing.EdVerifier,
	opt ...MalfeasanceOpt,
) *MalfeasanceHandler

func (*MalfeasanceHandler) ReportInvalidProof

func (mh *MalfeasanceHandler) ReportInvalidProof(numInvalidProofs *prometheus.CounterVec)

func (*MalfeasanceHandler) ReportProof

func (mh *MalfeasanceHandler) ReportProof(numProofs *prometheus.CounterVec)

func (*MalfeasanceHandler) Validate

func (mh *MalfeasanceHandler) Validate(ctx context.Context, data wire.ProofData) (types.NodeID, error)

type MalfeasanceOpt

type MalfeasanceOpt func(*MalfeasanceHandler)

func WithMalfeasanceLogger

func WithMalfeasanceLogger(logger *zap.Logger) MalfeasanceOpt

type Message

type Message struct {
	Body
	Sender    types.NodeID
	Signature types.EdSignature
}

func (*Message) DecodeScale

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

func (*Message) EncodeScale

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

func (*Message) MarshalLogObject

func (m *Message) MarshalLogObject(encoder zapcore.ObjectEncoder) error

func (*Message) ToBytes

func (m *Message) ToBytes() []byte

func (*Message) ToHash

func (m *Message) ToHash() types.Hash32

func (*Message) ToMalfeasanceProof

func (m *Message) ToMalfeasanceProof() wire.HareProofMsg

func (*Message) ToMetadata

func (m *Message) ToMetadata() wire.HareMetadata

func (*Message) Validate

func (m *Message) Validate() error

type Opt

type Opt func(*Hare)

func WithConfig

func WithConfig(cfg Config) Opt

func WithLogger

func WithLogger(logger *zap.Logger) Opt

func WithResultsChan

func WithResultsChan(c chan ConsensusOutput) Opt

WithResultsChan overrides the default result channel with a different one. This is only needed for the migration period between hare3 and hare4.

func WithServer

func WithServer(s streamRequester) Opt

func WithTracer

func WithTracer(tracer Tracer) Opt

func WithWallclock

func WithWallclock(clock clockwork.Clock) Opt

type Round

type Round uint8

func (Round) String

func (r Round) String() string

type Tracer

type Tracer interface {
	OnStart(types.LayerID)
	OnStop(types.LayerID)
	OnActive([]*types.HareEligibility)
	OnMessageSent(*Message)
	OnMessageReceived(*Message)
	OnCompactIdRequest(*CompactIdRequest)
	OnCompactIdResponse(*CompactIdResponse)
}

type Value

type Value struct {
	// Proposals is set in messages for preround and propose rounds.
	//
	// Worst case scenario is that a single smesher identity has > 99.97% of the total weight of the network.
	// In this case they will get all 50 available slots in all 4032 layers of the epoch.
	// Additionally every other identity on the network that successfully published an ATX will get 1 slot.
	//
	// If we expect 7.0 Mio ATXs that would be a total of 7.0 Mio + 50 * 4032 = 8 201 600 slots.
	// Since these are randomly distributed across the epoch, we can expect an average of n * p =
	// 8 201 600 / 4032 = 2034.1 eligibilities in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
	// sqrt(8 201 600 * 1/4032 * 4031/4032) = 45.1
	//
	// This means that we can expect a maximum of 2034.1 + 6*45.1 = 2304.7 eligibilities in a layer with
	// > 99.9997% probability.
	Proposals []types.ProposalID `scale:"max=2350"`
	// Reference is set in messages for commit and notify rounds.
	Reference *types.Hash32
	// CompactProposals is the array of compacted proposals IDs which are represented as truncated
	// eligibility hashes.
	CompactProposals []types.CompactProposalID `scale:"max=2350"`
}

func (*Value) DecodeScale

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

func (*Value) EncodeScale

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

type WeakCoinOutput

type WeakCoinOutput struct {
	Layer types.LayerID
	Coin  bool
}

Directories

Path Synopsis
Package eligibility is a generated GoMock package.
Package eligibility is a generated GoMock package.
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