types

package
v1.6.2-rc.0-nomain Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: MIT Imports: 23 Imported by: 27

Documentation

Overview

nolint

nolint

nolint

nolint

nolint

Package types defines the types used by go-spacemesh consensus algorithms and structs

nolint

nolint

nolint

nolint

nolint

Index

Constants

View Source
const (
	// AddressLength is the expected length of the address.
	AddressLength = 24
	// AddressReservedSpace define how much bytes from top is reserved in address for future.
	AddressReservedSpace = 4
)
View Source
const (
	Hash32Length = 32
	Hash20Length = 20
)
View Source
const (
	EdSignatureSize  = 64
	VrfSignatureSize = 80
)
View Source
const (
	// ATXIDSize in bytes.
	ATXIDSize = Hash32Length
)
View Source
const (
	// BallotIDSize in bytes.
	// FIXME(dshulyak) why do we cast to hash32 when returning bytes?
	BallotIDSize = Hash32Length
)
View Source
const (
	// BeaconSize in bytes.
	BeaconSize = 4
)
View Source
const (
	// BlockIDSize in bytes.
	// FIXME(dshulyak) why do we cast to hash32 when returning bytes?
	// probably required for fetching by hash between peers.
	BlockIDSize = Hash32Length
)
View Source
const (
	// FirstRound is convenient for initializing the index in a loop.
	FirstRound = RoundID(0)
)
View Source
const (
	// NodeIDSize in bytes.
	NodeIDSize = Hash32Length
)
View Source
const (
	// ProposalIDSize in bytes.
	// FIXME(dshulyak) why do we cast to hash32 when returning bytes?
	// probably required for fetching by hash between peers.
	ProposalIDSize = Hash32Length
)
View Source
const (
	// TransactionIDSize in bytes.
	TransactionIDSize = Hash32Length
)

Variables

View Source
var (
	// ErrWrongAddressLength is returned when the length of the address is not correct.
	ErrWrongAddressLength = errors.New("wrong address length")
	// ErrUnsupportedNetwork is returned when a network is not supported.
	ErrUnsupportedNetwork = errors.New("unsupported network")
	// ErrDecodeBech32 is returned when an error occurs during decoding bech32.
	ErrDecodeBech32 = errors.New("error decoding bech32")
	// ErrMissingReservedSpace is returned if top bytes of address is not 0.
	ErrMissingReservedSpace = errors.New("missing reserved space")
)
View Source
var EmptyATXID = ATXID{}

EmptyATXID is a canonical empty ATXID.

View Source
var EmptyBallotID = BallotID{}

EmptyBallotID is a canonical empty BallotID.

View Source
var EmptyBeacon = Beacon{}

EmptyBeacon is a canonical empty Beacon.

View Source
var EmptyBlockID = BlockID{}

EmptyBlockID is a canonical empty BlockID.

View Source
var (

	// EmptyHash32 is the zero hash.
	EmptyHash32 = Hash32{}
)
View Source
var (

	// EmptyLayerHash is the layer hash for an empty layer.
	EmptyLayerHash = EmptyHash32
)
View Source
var EmptyPoetProofRef = PoetProofRef{}

EmptyPoetProofRef is an empty PoET proof reference.

View Source
var EmptyProposalID = ProposalID{}

EmptyProposalID is a canonical empty ProposalID.

View Source
var MaxEpochActiveSetSize = scale.MustGetMaxElements[EpochActiveSet]("Set")

Functions

func GetLayersPerEpoch added in v1.0.0

func GetLayersPerEpoch() uint32

GetLayersPerEpoch returns number of layers per epoch.

func NetworkHRP added in v1.0.0

func NetworkHRP() string

func RandomBytes added in v1.0.0

func RandomBytes(size int) []byte

RandomBytes generates random data in bytes for testing.

func SetEffectiveGenesis added in v1.0.0

func SetEffectiveGenesis(layer uint32)

func SetLayersPerEpoch added in v0.1.15

func SetLayersPerEpoch(layers uint32)

SetLayersPerEpoch sets global parameter of layers per epoch, all conversions from layer to epoch use this param.

func SetNetworkHRP added in v1.0.0

func SetNetworkHRP(update string)

Types

type ATXID added in v0.1.11

type ATXID Hash32

ATXID is a 32 byte hash used to identify an activation transaction.

func BytesToATXID added in v1.3.0

func BytesToATXID(buf []byte) (id ATXID)

BytesToATXID is a helper to copy buffer into a ATXID.

func RandomATXID added in v1.0.0

func RandomATXID() ATXID

RandomATXID generates a random ATXID for testing.

func RandomActiveSet added in v1.0.0

func RandomActiveSet(size int) []ATXID

RandomActiveSet generates a random set of ATXIDs of the specified size.

func ToATXIDs added in v1.0.0

func ToATXIDs(atxs []*ActivationTx) []ATXID

ToATXIDs returns a slice of ATXID corresponding to the given activation tx.

func (ATXID) Bytes added in v0.1.11

func (t ATXID) Bytes() []byte

Bytes returns the ATXID as a byte slice.

func (*ATXID) DecodeScale added in v1.0.0

func (t *ATXID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*ATXID) EncodeScale added in v1.0.0

func (t *ATXID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (ATXID) Field added in v0.1.11

func (t ATXID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (ATXID) Hash32 added in v0.1.11

func (t ATXID) Hash32() Hash32

Hash32 returns the ATXID as a Hash32.

func (*ATXID) MarshalText added in v1.0.0

func (t *ATXID) MarshalText() ([]byte, error)

func (ATXID) ShortString added in v0.1.11

func (t ATXID) ShortString() string

ShortString returns the first few characters of the ID, for logging purposes.

func (ATXID) String added in v1.0.0

func (t ATXID) String() string

String implements stringer interface.

func (*ATXID) UnmarshalText added in v1.0.0

func (t *ATXID) UnmarshalText(buf []byte) error

type ATXIDList added in v1.0.0

type ATXIDList []ATXID

ATXIDList defines ATX ID list.

func (ATXIDList) Hash added in v1.0.0

func (atxList ATXIDList) Hash() Hash32

Hash returns ATX ID list hash.

type ATXIDs added in v1.1.2

type ATXIDs []ATXID

func (ATXIDs) MarshalLogArray added in v1.1.2

func (ids ATXIDs) MarshalLogArray(enc log.ArrayEncoder) error

impl zap's ArrayMarshaler interface.

type ATXMetadata added in v1.0.0

type ATXMetadata struct {
	PublishEpoch EpochID
	MsgHash      Hash32 // Hash of InnerActivationTx (returned by HashInnerBytes)
}

ATXMetadata is the data of ActivationTx that is signed. It is also used for Malfeasance proofs.

func (*ATXMetadata) DecodeScale added in v1.0.0

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

func (*ATXMetadata) EncodeScale added in v1.0.0

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

func (*ATXMetadata) MarshalLogObject added in v1.0.0

func (m *ATXMetadata) MarshalLogObject(encoder log.ObjectEncoder) error

type Account added in v1.0.0

type Account struct {
	Layer           LayerID
	Address         Address
	NextNonce       uint64
	Balance         uint64
	TemplateAddress *Address
	State           []byte `scale:"max=10000"`
}

Account represents account state at a certain layer.

func (*Account) DecodeScale added in v1.0.0

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

func (*Account) EncodeScale added in v1.0.0

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

func (*Account) MarshalLogObject added in v1.0.0

func (a *Account) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements encoding for the account state.

type AccountSnapshot added in v1.0.0

type AccountSnapshot struct {
	Address  []byte `json:"address"`
	Balance  uint64 `json:"balance"`
	Nonce    uint64 `json:"nonce"`
	Template []byte `json:"template"`
	State    []byte `json:"state"`
}

type ActivationTx

type ActivationTx struct {
	PublishEpoch EpochID
	// Sequence number counts the number of ancestors of the ATX. It sequentially increases for each ATX in the chain.
	// Two ATXs with the same sequence number from the same miner can be used as the proof of malfeasance against
	// that miner.
	Sequence uint64
	// the previous ATX's ID (for all but the first in the sequence)
	PrevATXID ATXID

	// CommitmentATX is the ATX used in the commitment for initializing the PoST of the node.
	CommitmentATX  *ATXID
	Coinbase       Address
	NumUnits       uint32 // the minimum number of space units in this and the previous ATX
	BaseTickHeight uint64
	TickCount      uint64
	VRFNonce       VRFPostIndex
	SmesherID      NodeID

	AtxBlob
	// contains filtered or unexported fields
}

ActivationTx is a full, signed activation transaction. It includes (or references) everything a miner needs to prove they are eligible to actively participate in the Spacemesh protocol in the next epoch.

func NewActivationTx

func NewActivationTx(
	challenge NIPostChallenge,
	coinbase Address,
	numUnits uint32,
) *ActivationTx

NewActivationTx returns a new activation transaction. The ATXID is calculated and cached. NOTE: this function is deprecated and used in a few tests only. Create a new ActivationTx with ActivationTx{...}, setting the fields manually.

func (*ActivationTx) GetWeight added in v1.6.0

func (atx *ActivationTx) GetWeight() uint64

Weight of the ATX. The total weight of the epoch is expected to fit in a uint64 and is sum(atx.NumUnits * atx.TickCount for each ATX in a given epoch). Space Units sizes are chosen such that NumUnits for all ATXs in an epoch is expected to be < 10^6. PoETs should produce ~10k ticks at genesis, but are expected due to technological advances to produce more over time. A uint64 should be large enough to hold the total weight of an epoch, for at least the first few years.

func (*ActivationTx) Golden added in v1.0.0

func (atx *ActivationTx) Golden() bool

Golden returns true if atx is from a checkpoint snapshot. a golden ATX is not verifiable, and is only allowed to be prev atx or positioning atx.

func (*ActivationTx) ID added in v1.0.0

func (atx *ActivationTx) ID() ATXID

ID returns the ATX's ID.

func (*ActivationTx) MarshalLogObject added in v1.0.0

func (atx *ActivationTx) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

func (*ActivationTx) Published added in v1.6.0

func (atx *ActivationTx) Published() EpochID

func (*ActivationTx) Received added in v1.0.0

func (atx *ActivationTx) Received() time.Time

func (*ActivationTx) SetGolden added in v1.0.0

func (atx *ActivationTx) SetGolden()

SetGolden set atx to golden.

func (*ActivationTx) SetID added in v1.0.0

func (atx *ActivationTx) SetID(id ATXID)

SetID sets the ATXID in this ATX's cache.

func (*ActivationTx) SetReceived added in v1.0.0

func (atx *ActivationTx) SetReceived(received time.Time)

func (*ActivationTx) SetValidity added in v1.4.0

func (atx *ActivationTx) SetValidity(validity Validity)

func (*ActivationTx) ShortString added in v1.0.0

func (atx *ActivationTx) ShortString() string

ShortString returns the first 5 characters of the ID, for logging purposes.

func (*ActivationTx) TargetEpoch added in v1.4.5

func (atx *ActivationTx) TargetEpoch() EpochID

TargetEpoch returns the target epoch of the ATX. This is the epoch in which the miner is eligible to participate thanks to the ATX.

func (*ActivationTx) TickHeight added in v1.6.0

func (atx *ActivationTx) TickHeight() uint64

TickHeight returns a sum of base tick height and tick count.

func (*ActivationTx) TotalNumUnits added in v1.6.0

func (atx *ActivationTx) TotalNumUnits() uint32

func (*ActivationTx) Validity added in v1.4.0

func (atx *ActivationTx) Validity() Validity

type Address

type Address [AddressLength]byte

Address represents the address of a spacemesh account with AddressLength length.

func GenerateAddress added in v1.0.0

func GenerateAddress(publicKey []byte) Address

GenerateAddress generates an address from a public key.

func StringToAddress

func StringToAddress(src string) (Address, error)

StringToAddress returns a new Address from a given string like `sm1abc...`.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (*Address) DecodeScale added in v1.0.0

func (a *Address) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*Address) EncodeScale added in v1.0.0

func (a *Address) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (Address) Field added in v0.1.15

func (a Address) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Address) GetHRPNetwork added in v1.0.0

func (a Address) GetHRPNetwork() string

GetHRPNetwork returns the Human-Readable-Part of bech32 addresses for a networkID.

func (Address) IsEmpty added in v1.0.0

func (a Address) IsEmpty() bool

IsEmpty checks if address is empty.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

type AddressNonce added in v1.0.0

type AddressNonce struct {
	Address Address
	Nonce   Nonce
}

AddressNonce is an (address, nonce) named tuple.

type AnyReward added in v1.0.0

type AnyReward struct {
	AtxID  ATXID
	Weight RatNum
}

AnyReward contains the reward information by ATXID.

func (*AnyReward) DecodeScale added in v1.0.0

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

func (*AnyReward) EncodeScale added in v1.0.0

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

type AtxBlob added in v1.6.0

type AtxBlob struct {
	Blob    []byte
	Version AtxVersion
}

type AtxSnapshot added in v1.0.0

type AtxSnapshot struct {
	ID             []byte `json:"id"`
	Epoch          uint32 `json:"epoch"`
	CommitmentAtx  []byte `json:"commitmentAtx"`
	VrfNonce       uint64 `json:"vrfNonce"`
	NumUnits       uint32 `json:"numUnits"`
	BaseTickHeight uint64 `json:"baseTickHeight"`
	TickCount      uint64 `json:"tickCount"`
	PublicKey      []byte `json:"publicKey"`
	Sequence       uint64 `json:"sequence"`
	Coinbase       []byte `json:"coinbase"`
}

type AtxVersion added in v1.6.0

type AtxVersion uint
const (
	AtxV1   AtxVersion = 1
	AtxV2   AtxVersion = 2
	AtxVMAX AtxVersion = AtxV2
)

func (AtxVersion) String added in v1.6.0

func (v AtxVersion) String() string

type Ballot added in v1.0.0

type Ballot struct {
	InnerBallot
	// smeshers signature on InnerBallot
	Signature EdSignature
	// the public key of the smesher that produced this ballot.
	SmesherID NodeID
	// Votes field is not signed.
	Votes Votes
	// the proof of the smeshers eligibility to vote and propose block content in this epoch.
	// Eligibilities must be produced in the ascending order.
	// the proofs are vrf signatures and need not be included in the ballot's signature.
	//
	// The number of eligibility proofs depends on the smeshers weight and the total weight of the network.
	// For epoch 16 the largest smesher had 1 337 SUs and the total weight of the network was ~20.2 Mio SUs.
	// This means that the largest smesher received 1 337 / 26 481 043 SU = 0.005% of all eligibility slots for the
	// epoch.
	// There are 4032 layers in an epoch and 50 eligibility slots per layer, so the largest smesher received
	// 0.005% * 4032 * 50 = ~10 eligibility slots.
	//
	// Assuming the largest smesher won't control more than 10% of space in the network, we can assume that the
	// highest number of eligibilities in a single ballot will be below 25000. (10% of 4032 * 50 = 20160)
	EligibilityProofs []VotingEligibility `scale:"max=25000"`
	// from the smesher's view, the set of ATXs eligible to vote and propose block content in this epoch
	// only present in smesher's first ballot of the epoch
	// this field isn't actually used any more (replaced by InnerBallot.EpochData)
	// TODO (mafa): remove this field in Ballot v2
	ActiveSet []ATXID `scale:"max=1"`
	// contains filtered or unexported fields
}

Ballot contains the smeshers signed vote on the mesh history.

func NewExistingBallot added in v1.0.0

func NewExistingBallot(id BallotID, sig EdSignature, nodeId NodeID, layer LayerID) Ballot

NewExistingBallot creates ballot from stored data.

func RandomBallot added in v1.0.0

func RandomBallot() *Ballot

RandomBallot generates a Ballot with random content for testing.

func (*Ballot) DecodeScale added in v1.0.0

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

func (*Ballot) EncodeScale added in v1.0.0

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

func (Ballot) Equal added in v1.0.0

func (b Ballot) Equal(other Ballot) bool

func (*Ballot) HashInnerBytes added in v1.0.0

func (b *Ballot) HashInnerBytes() []byte

HashInnerBytes returns the hash of the InnerBallot.

func (*Ballot) ID added in v1.0.0

func (b *Ballot) ID() BallotID

ID returns the BallotID.

func (*Ballot) Initialize added in v1.0.0

func (b *Ballot) Initialize() error

Initialize calculates and sets the Ballot's cached ballotID and smesherID. this should be called once all the other fields of the Ballot are set.

func (*Ballot) IsMalicious added in v1.0.0

func (b *Ballot) IsMalicious() bool

IsMalicious returns true if ballot is malicious.

func (*Ballot) MarshalLogObject added in v1.0.0

func (b *Ballot) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging encoder for Ballot.

func (*Ballot) SetID added in v1.0.0

func (b *Ballot) SetID(id BallotID)

SetID from stored data.

func (*Ballot) SetMalicious added in v1.0.0

func (b *Ballot) SetMalicious()

SetMalicious sets ballot as malicious.

func (*Ballot) SignedBytes added in v1.0.0

func (b *Ballot) SignedBytes() []byte

SignedBytes returns the serialization of the BallotMetadata for signing.

func (*Ballot) ToTortoiseData added in v1.0.0

func (b *Ballot) ToTortoiseData() *BallotTortoiseData

type BallotID added in v1.0.0

type BallotID Hash20

BallotID is a 20-byte blake3 sum of the serialized ballot used to identify a Ballot.

func RandomBallotID added in v1.0.0

func RandomBallotID() BallotID

RandomBallotID generates a random BallotID for testing.

func ToBallotIDs added in v1.0.0

func ToBallotIDs(ballots []*Ballot) []BallotID

ToBallotIDs turns a list of Ballot into a list of BallotID.

func (BallotID) AsHash32 added in v1.0.0

func (id BallotID) AsHash32() Hash32

AsHash32 returns a Hash32 whose first 20 bytes are the bytes of this BallotID, it is right-padded with zeros.

func (BallotID) Bytes added in v1.0.0

func (id BallotID) Bytes() []byte

Bytes returns the BallotID as a byte slice.

func (BallotID) Compare added in v1.0.0

func (id BallotID) Compare(other BallotID) bool

Compare returns true if other (the given BallotID) is less than this BallotID, by lexicographic comparison.

func (*BallotID) DecodeScale added in v1.0.0

func (id *BallotID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*BallotID) EncodeScale added in v1.0.0

func (id *BallotID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (BallotID) Field added in v1.0.0

func (id BallotID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (*BallotID) MarshalText added in v1.0.0

func (id *BallotID) MarshalText() ([]byte, error)

func (BallotID) String added in v1.0.0

func (id BallotID) String() string

String returns a short prefix of the hex representation of the ID.

func (*BallotID) UnmarshalText added in v1.0.0

func (id *BallotID) UnmarshalText(buf []byte) error

type BallotMetadata added in v1.0.0

type BallotMetadata struct {
	Layer   LayerID // the layer ID in which this ballot is eligible for. this will be validated via EligibilityProof
	MsgHash Hash32  // Hash of InnerBallot (returned by HashInnerBytes)
}

BallotMetadata is the signed part of Ballot.

func (*BallotMetadata) DecodeScale added in v1.0.0

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

func (*BallotMetadata) EncodeScale added in v1.0.0

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

func (*BallotMetadata) MarshalLogObject added in v1.0.0

func (m *BallotMetadata) MarshalLogObject(encoder log.ObjectEncoder) error

type BallotTortoiseData added in v1.0.0

type BallotTortoiseData struct {
	ID            BallotID       `json:"id"`
	Smesher       NodeID         `json:"node"`
	Layer         LayerID        `json:"lid"`
	Eligibilities uint32         `json:"elig"`
	AtxID         ATXID          `json:"atxid"`
	Opinion       Opinion        `json:"opinion"`
	EpochData     *ReferenceData `json:"epochdata"`
	Ref           *BallotID      `json:"ref"`
	Malicious     bool           `json:"mal"`
}

func (*BallotTortoiseData) MarshalLogObject added in v1.0.0

func (b *BallotTortoiseData) MarshalLogObject(encoder log.ObjectEncoder) error

func (*BallotTortoiseData) SetMalicious added in v1.0.0

func (b *BallotTortoiseData) SetMalicious()

type Base64Enc added in v1.4.0

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

func Base64FromString added in v1.4.0

func Base64FromString(s string) (Base64Enc, error)

func MustBase64FromString added in v1.4.0

func MustBase64FromString(s string) Base64Enc

func NewBase64Enc added in v1.4.0

func NewBase64Enc(b []byte) Base64Enc

func (*Base64Enc) Bytes added in v1.4.0

func (b *Base64Enc) Bytes() []byte

func (Base64Enc) MarshalJSON added in v1.4.0

func (b Base64Enc) MarshalJSON() ([]byte, error)

func (*Base64Enc) UnmarshalJSON added in v1.4.0

func (b *Base64Enc) UnmarshalJSON(data []byte) error

func (*Base64Enc) UnmarshalText added in v1.4.0

func (b *Base64Enc) UnmarshalText(text []byte) error

type Beacon added in v1.0.0

type Beacon [BeaconSize]byte

Beacon defines the beacon value. A beacon is generated once per epoch and is used to - verify smesher's VRF signature for proposal/ballot eligibility - determine good ballots in verifying tortoise.

func BytesToBeacon added in v1.0.0

func BytesToBeacon(b []byte) Beacon

BytesToBeacon sets the first BeaconSize bytes of b to the Beacon's data.

func HexToBeacon added in v1.0.0

func HexToBeacon(s string) Beacon

HexToBeacon sets byte representation of s to a Beacon.

func RandomBeacon added in v1.0.0

func RandomBeacon() Beacon

RandomBeacon generates random beacon in bytes for testing.

func (Beacon) Bytes added in v1.0.0

func (b Beacon) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Beacon) Field added in v1.0.0

func (b Beacon) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (Beacon) Hex added in v1.0.0

func (b Beacon) Hex() string

Hex converts a hash to a hex string.

func (*Beacon) MarshalText added in v1.0.0

func (b *Beacon) MarshalText() ([]byte, error)

func (Beacon) ShortString added in v1.0.0

func (b Beacon) ShortString() string

ShortString returns the first 10 characters of the Beacon, usually for logging purposes.

func (Beacon) String added in v1.0.0

func (b Beacon) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (*Beacon) UnmarshalText added in v1.0.0

func (b *Beacon) UnmarshalText(buf []byte) error

type Block

type Block struct {
	InnerBlock
	// contains filtered or unexported fields
}

Block contains the content of a layer on the mesh history.

func NewExistingBlock

func NewExistingBlock(id BlockID, inner InnerBlock) *Block

NewExistingBlock creates a block from existing data.

func (*Block) Bytes

func (b *Block) Bytes() []byte

Bytes returns the serialization of the InnerBlock.

func (*Block) DecodeScale added in v1.0.0

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

func (*Block) EncodeScale added in v1.0.0

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

func (Block) Equal added in v1.0.0

func (b Block) Equal(other Block) bool

func (*Block) ID added in v0.1.11

func (b *Block) ID() BlockID

ID returns the BlockID.

func (*Block) Initialize added in v0.1.2

func (b *Block) Initialize()

Initialize calculates and sets the Block's cached blockID.

func (*Block) MarshalLogObject added in v1.0.0

func (b *Block) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging encoder for Block.

func (*Block) ToVote added in v1.0.0

func (b *Block) ToVote() Vote

ToVote creates Vote struct from block.

type BlockContextualValidity added in v1.0.0

type BlockContextualValidity struct {
	ID       BlockID
	Validity bool
}

BlockContextualValidity represents the contextual validity of a block.

type BlockHeader

type BlockHeader struct {
	ID      BlockID `json:"id"`
	LayerID LayerID `json:"lid"`
	Height  uint64  `json:"height"`
}

func (*BlockHeader) DecodeScale added in v1.0.0

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

func (*BlockHeader) EncodeScale added in v1.0.0

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

func (*BlockHeader) MarshalLogObject added in v1.0.0

func (header *BlockHeader) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

type BlockID

type BlockID Hash20

BlockID is a 20-byte blake3 sum of the serialized block used to identify a Block.

func RandomBlockID added in v0.1.16

func RandomBlockID() BlockID

RandomBlockID generates a random ProposalID for testing.

func SortBlockIDs added in v0.1.11

func SortBlockIDs(ids blockIDs) []BlockID

SortBlockIDs sorts a list of BlockID in lexicographic order, in-place.

func ToBlockIDs added in v1.0.0

func ToBlockIDs(blocks []*Block) []BlockID

ToBlockIDs returns a slice of BlockID corresponding to the given list of Block.

func (BlockID) AsHash32

func (id BlockID) AsHash32() Hash32

AsHash32 returns a Hash32 whose first 20 bytes are the bytes of this BlockID, it is right-padded with zeros.

func (BlockID) Bytes added in v0.1.15

func (id BlockID) Bytes() []byte

Bytes returns the BlockID as a byte slice.

func (BlockID) Compare

func (id BlockID) Compare(other BlockID) bool

Compare returns true if other (the given BlockID) is less than this BlockID, by lexicographic comparison.

func (*BlockID) DecodeScale added in v1.0.0

func (id *BlockID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*BlockID) EncodeScale added in v1.0.0

func (id *BlockID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (BlockID) Field added in v0.1.2

func (id BlockID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (*BlockID) IsEmpty added in v1.0.0

func (id *BlockID) IsEmpty() bool

func (*BlockID) MarshalText added in v1.0.0

func (id *BlockID) MarshalText() ([]byte, error)

func (BlockID) String

func (id BlockID) String() string

String implements the Stringer interface.

func (*BlockID) UnmarshalText added in v1.0.0

func (id *BlockID) UnmarshalText(buf []byte) error

type Certificate added in v1.0.0

type Certificate struct {
	BlockID    BlockID
	Signatures []CertifyMessage `scale:"max=1000"` // the max. size depends on HARE.N config parameter + safety buffer
}

Certificate represents a certified block.

func (*Certificate) DecodeScale added in v1.0.0

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

func (*Certificate) EncodeScale added in v1.0.0

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

type CertifyContent added in v1.0.0

type CertifyContent struct {
	LayerID LayerID
	BlockID BlockID
	// EligibilityCnt is the number of eligibility of a NodeID on the given Layer
	// as a hare output certifier.
	EligibilityCnt uint16
	// Proof is the role proof for being a hare output certifier on the given Layer.
	Proof VrfSignature
}

CertifyContent is actual content the node would sign to certify a hare output.

func (*CertifyContent) DecodeScale added in v1.0.0

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

func (*CertifyContent) EncodeScale added in v1.0.0

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

type CertifyMessage added in v1.0.0

type CertifyMessage struct {
	CertifyContent

	Signature EdSignature
	SmesherID NodeID
}

CertifyMessage is generated by a node that's eligible to certify the hare output and is gossiped to the network.

func (*CertifyMessage) Bytes added in v1.0.0

func (cm *CertifyMessage) Bytes() []byte

Bytes returns the actual data being signed in a CertifyMessage.

func (*CertifyMessage) DecodeScale added in v1.0.0

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

func (*CertifyMessage) EncodeScale added in v1.0.0

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

type Checkpoint added in v1.0.0

type Checkpoint struct {
	Command string    `json:"command"`
	Version string    `json:"version"`
	Data    InnerData `json:"data"`
}

type CoinbaseReward added in v1.0.0

type CoinbaseReward struct {
	SmesherID NodeID
	Coinbase  Address
	Weight    RatNum
}

CoinbaseReward contains the reward information by coinbase and smesher, used as an interface to VM.

type EdSignature added in v1.0.0

type EdSignature [EdSignatureSize]byte
var EmptyEdSignature EdSignature

EmptyEdSignature is a canonical empty EdSignature.

func RandomEdSignature added in v1.0.0

func RandomEdSignature() EdSignature

RandomEdSignature generates a random (not necessarily valid) EdSignature for testing.

func (*EdSignature) Bytes added in v1.0.0

func (s *EdSignature) Bytes() []byte

Bytes returns the byte representation of the Signature.

func (*EdSignature) DecodeScale added in v1.0.0

func (s *EdSignature) DecodeScale(decoder *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*EdSignature) EncodeScale added in v1.0.0

func (s *EdSignature) EncodeScale(encoder *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (EdSignature) String added in v1.0.0

func (s EdSignature) String() string

String returns a string representation of the Signature, for logging purposes. It implements the Stringer interface.

type EligibilityType added in v1.0.0

type EligibilityType uint16
const (
	EligibilityBeacon EligibilityType = iota + 1
	EligibilityHare
	EligibilityVoting
	EligibilityBeaconWC
)

type EpochActiveSet added in v1.1.5

type EpochActiveSet struct {
	Epoch EpochID
	Set   []ATXID `scale:"max=7000000"` // to be in line with `EpochData` in fetch/wire_types.go
}

func (*EpochActiveSet) DecodeScale added in v1.1.5

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

func (*EpochActiveSet) EncodeScale added in v1.1.5

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

type EpochData added in v1.0.0

type EpochData struct {
	ActiveSetHash Hash32
	// the beacon value the smesher recorded for this epoch
	Beacon Beacon
	// total number of ballots the smesher is eligible in this epoch.
	EligibilityCount uint32
}

EpochData contains information that cannot be changed mid-epoch.

func (*EpochData) DecodeScale added in v1.0.0

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

func (*EpochData) EncodeScale added in v1.0.0

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

type EpochID added in v0.1.11

type EpochID uint32

EpochID is the running epoch number. It's zero-based, so the genesis epoch has EpochID == 0.

func (EpochID) Add added in v1.0.0

func (e EpochID) Add(epochs uint32) EpochID

Add Epochs to the EpochID. Panics on wraparound.

func (*EpochID) DecodeScale added in v1.0.0

func (e *EpochID) DecodeScale(dec *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (EpochID) EncodeScale added in v1.0.0

func (e EpochID) EncodeScale(enc *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (EpochID) Field added in v0.1.11

func (e EpochID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (EpochID) FirstLayer added in v0.1.11

func (e EpochID) FirstLayer() LayerID

FirstLayer returns the layer ID of the first layer in the epoch.

func (EpochID) String added in v1.0.0

func (e EpochID) String() string

String returns string representation of the epoch id numeric value.

func (EpochID) Uint32 added in v1.0.0

func (e EpochID) Uint32() uint32

type EpochMinimalActiveWeight added in v1.3.0

type EpochMinimalActiveWeight struct {
	Epoch  EpochID
	Weight uint64
}

type HareEligibility added in v1.0.0

type HareEligibility struct {
	// VRF signature of EligibilityType, beacon, layer, round
	Proof VrfSignature
	// the eligibility count for this layer, round
	Count uint16
}

HareEligibility includes the required values that, along with the smesher's VRF public key, allow non-interactive eligibility validation for hare round participation.

func (*HareEligibility) DecodeScale added in v1.0.0

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

func (*HareEligibility) EncodeScale added in v1.0.0

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

func (*HareEligibility) MarshalLogObject added in v1.0.0

func (e *HareEligibility) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

type HareEligibilityGossip added in v1.0.0

type HareEligibilityGossip struct {
	Layer       LayerID
	Round       uint32
	NodeID      NodeID
	Eligibility HareEligibility
}

func (*HareEligibilityGossip) DecodeScale added in v1.0.0

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

func (*HareEligibilityGossip) EncodeScale added in v1.0.0

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

func (*HareEligibilityGossip) MarshalLogObject added in v1.0.0

func (hg *HareEligibilityGossip) MarshalLogObject(encoder log.ObjectEncoder) error

type Hash20

type Hash20 [Hash20Length]byte

Hash20 represents the 20-byte blake3 hash of arbitrary data.

func CalcHash20 added in v1.5.0

func CalcHash20(data []byte) Hash20

CalcHash20 returns the 20-byte blake3 sum of the given data.

func (Hash20) Bytes

func (h Hash20) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash20) Field added in v0.1.2

func (h Hash20) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (Hash20) Format

func (h Hash20) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash20) MarshalText

func (h Hash20) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash20) SetBytes

func (h *Hash20) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash20) ShortString

func (h Hash20) ShortString() string

ShortString returns a the first 5 hex-encoded bytes of the hash, for logging purposes.

func (Hash20) String

func (h Hash20) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash20) ToHash32

func (h Hash20) ToHash32() (h32 Hash32)

ToHash32 returns a Hash32 whose first 20 bytes are the bytes of this Hash20, it is right-padded with zeros.

func (*Hash20) UnmarshalJSON

func (h *Hash20) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash20) UnmarshalText

func (h *Hash20) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type Hash32

type Hash32 [Hash32Length]byte

Hash32 represents the 32-byte blake3 hash of arbitrary data.

func ATXIDsToHashes added in v1.0.0

func ATXIDsToHashes(ids []ATXID) []Hash32

ATXIDsToHashes turns a list of ATXID into their Hash32 representation.

func BallotIDsToHashes added in v1.0.0

func BallotIDsToHashes(ids []BallotID) []Hash32

BallotIDsToHashes turns a list of BallotID into their Hash32 representation.

func BlockIDsToHashes added in v1.0.0

func BlockIDsToHashes(ids []BlockID) []Hash32

BlockIDsToHashes turns a list of BlockID into their Hash32 representation.

func BytesToHash

func BytesToHash(b []byte) Hash32

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func CalcBlockHash32Presorted

func CalcBlockHash32Presorted(sortedView []BlockID, additionalBytes []byte) Hash32

CalcBlockHash32Presorted returns the 32-byte blake3 sum of the IDs, in the order given. The pre-image is prefixed with additionalBytes.

func CalcHash32

func CalcHash32(data []byte) Hash32

CalcHash32 returns the 32-byte blake3 sum of the given data.

func CalcProposalHash32Presorted added in v1.0.0

func CalcProposalHash32Presorted(sortedView []ProposalID, additionalBytes []byte) Hash32

CalcProposalHash32Presorted returns the 32-byte blake3 sum of the IDs, in the order given. The pre-image is prefixed with additionalBytes.

func CalcProposalsHash32 added in v1.0.0

func CalcProposalsHash32(view []ProposalID, additionalBytes []byte) Hash32

CalcProposalsHash32 returns the 32-byte blake3 sum of the IDs, sorted in lexicographic order. The pre-image is prefixed with additionalBytes.

func HexToHash32

func HexToHash32(s string) Hash32

HexToHash32 sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func NodeIDsToHashes added in v1.0.0

func NodeIDsToHashes(ids []NodeID) []Hash32

NodeIDsToHashes turns a list of NodeID into their Hash32 representation.

func ProposalIDsToHashes added in v1.0.0

func ProposalIDsToHashes(ids []ProposalID) []Hash32

ProposalIDsToHashes turns a list of ProposalID into their Hash32 representation.

func RandomHash added in v1.0.0

func RandomHash() Hash32

RandomHash generates random Hash32 for testing.

func TransactionIDsToHashes added in v1.0.0

func TransactionIDsToHashes(ids []TransactionID) []Hash32

TransactionIDsToHashes turns a list of TransactionID into their Hash32 representation.

func (Hash32) Bytes

func (h Hash32) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*Hash32) DecodeScale added in v1.0.0

func (h *Hash32) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*Hash32) EncodeScale added in v1.0.0

func (h *Hash32) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (Hash32) Field added in v0.1.2

func (h Hash32) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (Hash32) Format

func (h Hash32) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash32) MarshalText

func (h Hash32) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash32) SetBytes

func (h *Hash32) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash32) ShortString

func (h Hash32) ShortString() string

ShortString returns the first 5 hex-encoded bytes of the hash, for logging purposes.

func (Hash32) String

func (h Hash32) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash32) ToHash20

func (h Hash32) ToHash20() (h20 Hash20)

ToHash20 returns a Hash20, whose the 20-byte prefix of this Hash32.

func (*Hash32) UnmarshalJSON

func (h *Hash32) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash32) UnmarshalText

func (h *Hash32) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type IdentityDescriptor added in v1.4.0

type IdentityDescriptor interface {
	Name() string
	NodeID() NodeID
}

type InnerBallot added in v1.0.0

type InnerBallot struct {
	Layer LayerID
	// the smeshers ATX in the epoch this ballot is cast.
	AtxID ATXID
	// OpinionHash is a aggregated opinion on all previous layers.
	// It is included into transferred data explicitly, so that signature
	// can be verified before decoding votes.
	OpinionHash Hash32

	// the first Ballot the smesher cast in the epoch. this Ballot is a special Ballot that contains information
	// that cannot be changed mid-epoch.
	RefBallot BallotID
	EpochData *EpochData
}

InnerBallot contains all info about a smeshers votes on the mesh history. this structure is serialized and signed to produce the signature in Ballot.

func (*InnerBallot) DecodeScale added in v1.0.0

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

func (*InnerBallot) EncodeScale added in v1.0.0

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

type InnerBlock added in v1.0.0

type InnerBlock struct {
	LayerIndex LayerID
	TickHeight uint64
	// Rewards are the rewards for the block.
	//
	// 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 = 7 201 600 slots.
	// Since these are randomly distributed across the epoch, we can expect an average of n * p =
	// 7 201 600 / 4032 = 1786.1 rewards in a block with a standard deviation of sqrt(n * p * (1 - p)) =
	// sqrt(7 201 600 * 1/4032 * 4031/4032) = 42.3
	//
	// This means that we can expect a maximum of 1786.1 + 6*42.3 = 2039.7 rewards per block with
	// > 99.9997% probability.
	Rewards []AnyReward     `scale:"max=2050"`
	TxIDs   []TransactionID `scale:"max=100000"`
}

InnerBlock contains the transactions and rewards of a block.

func (*InnerBlock) DecodeScale added in v1.0.0

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

func (*InnerBlock) EncodeScale added in v1.0.0

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

type InnerData added in v1.0.0

type InnerData struct {
	CheckpointId string            `json:"id"`
	Atxs         []AtxSnapshot     `json:"atxs"`
	Accounts     []AccountSnapshot `json:"accounts"`
}

type InnerProposal added in v1.0.0

type InnerProposal struct {
	// smesher's votes on the mesh history
	Ballot
	// smesher's content proposal for a layer
	TxIDs []TransactionID `scale:"max=100000"`
	// aggregated hash up to the layer before this proposal.
	MeshHash Hash32
}

InnerProposal contains a smesher's content proposal for layer and its votes on the mesh history. this structure is serialized and signed to produce the signature in Proposal.

func (*InnerProposal) DecodeScale added in v1.0.0

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

func (*InnerProposal) EncodeScale added in v1.0.0

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

type Layer

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

Layer contains a list of proposals and their corresponding LayerID.

func NewExistingLayer

func NewExistingLayer(idx LayerID, ballots []*Ballot, blocks []*Block) *Layer

NewExistingLayer returns a new layer with the given list of blocks without validation.

func NewLayer

func NewLayer(layerIndex LayerID) *Layer

NewLayer returns a layer with no proposals.

func (*Layer) AddBallot added in v1.0.0

func (l *Layer) AddBallot(b *Ballot)

AddBallot adds a ballot to this layer. Panics if the ballot's index doesn't match the layer.

func (*Layer) AddBlock

func (l *Layer) AddBlock(b *Block)

AddBlock adds a block to this layer. Panics if the block's index doesn't match the layer.

func (*Layer) BallotIDs added in v1.0.0

func (l *Layer) BallotIDs() []BallotID

BallotIDs returns the list of IDs for ballots in this layer.

func (*Layer) Ballots added in v1.0.0

func (l *Layer) Ballots() []*Ballot

Ballots returns the list of ballots in this layer.

func (*Layer) Blocks

func (l *Layer) Blocks() []*Block

Blocks returns the list of Block in this layer.

func (*Layer) BlocksIDs added in v1.0.0

func (l *Layer) BlocksIDs() []BlockID

BlocksIDs returns the list of IDs for blocks in this layer.

func (*Layer) Field added in v0.1.15

func (l *Layer) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (*Layer) Index

func (l *Layer) Index() LayerID

Index returns the layer's ID.

func (*Layer) SetBallots added in v1.0.0

func (l *Layer) SetBallots(ballots []*Ballot)

SetBallots sets the list of ballots for the layer without validation.

func (*Layer) SetBlocks

func (l *Layer) SetBlocks(blocks []*Block)

SetBlocks sets the list of blocks for the layer without validation.

type LayerID

type LayerID uint32

LayerID is representing a layer number. Zero value is safe to use, and means 0. Internally it is a simple wrapper over uint32 and should be considered immutable the same way as any integer.

func FirstEffectiveGenesis added in v1.0.0

func FirstEffectiveGenesis() LayerID

FirstEffectiveGenesis returns the first effective genesis layer.

func GetEffectiveGenesis added in v0.1.15

func GetEffectiveGenesis() LayerID

GetEffectiveGenesis returns the last layer of genesis. this value can change after a checkpoint recovery.

func (LayerID) Add

func (l LayerID) Add(layers uint32) LayerID

Add layers to the layer. Panics on wraparound.

func (LayerID) After added in v1.0.0

func (l LayerID) After(other LayerID) bool

After returns true if this layer is higher than the other.

func (LayerID) Before added in v1.0.0

func (l LayerID) Before(other LayerID) bool

Before returns true if this layer is lower than the other.

func (*LayerID) DecodeScale added in v1.0.0

func (l *LayerID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (LayerID) Difference added in v1.0.0

func (l LayerID) Difference(other LayerID) uint32

Difference returns the difference between current and other layer.

func (LayerID) EncodeScale added in v1.0.0

func (l LayerID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (LayerID) Field added in v0.1.2

func (l LayerID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (LayerID) FirstInEpoch added in v1.0.0

func (l LayerID) FirstInEpoch() bool

FirstInEpoch returns whether this LayerID is first in epoch.

func (LayerID) GetEpoch

func (l LayerID) GetEpoch() EpochID

GetEpoch returns the epoch number of this LayerID.

func (LayerID) Mul added in v1.0.0

func (l LayerID) Mul(layers uint32) LayerID

Mul layer by the layers. Panics on wraparound.

func (LayerID) OrdinalInEpoch added in v1.0.0

func (l LayerID) OrdinalInEpoch() uint32

OrdinalInEpoch returns layer ordinal in epoch.

func (LayerID) String added in v1.0.0

func (l LayerID) String() string

String returns string representation of the layer id numeric value.

func (LayerID) Sub added in v1.0.0

func (l LayerID) Sub(layers uint32) LayerID

Sub layers from the layer. Panics on wraparound.

func (LayerID) Uint32 added in v1.0.0

func (l LayerID) Uint32() uint32

Uint32 returns the LayerID as a uint32.

type LayerLimits added in v1.0.0

type LayerLimits struct {
	Min, Max uint32
}

LayerLimits if defined restricts in what layers transaction may be applied.

func (*LayerLimits) DecodeScale added in v1.0.0

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

func (*LayerLimits) EncodeScale added in v1.0.0

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

type MerkleProof added in v1.0.0

type MerkleProof struct {
	// Nodes on path from leaf to root (not including leaf)
	Nodes     []Hash32 `scale:"max=32"`
	LeafIndex uint64
}

Merkle proof proving that a given leaf is included in the root of merkle tree.

func (*MerkleProof) DecodeScale added in v1.0.0

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

func (*MerkleProof) EncodeScale added in v1.0.0

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

type MeshTransaction added in v1.0.0

type MeshTransaction struct {
	Transaction
	LayerID  LayerID
	BlockID  BlockID
	State    TXState
	Received time.Time
}

MeshTransaction is stored in the mesh and included in the block.

type MultiMerkleProof added in v1.6.0

type MultiMerkleProof struct {
	// Nodes on path from leaf to root (not including leaf)
	Nodes       []Hash32 `scale:"max=32"`
	LeafIndices []uint64
}

type NIPost added in v1.0.0

type NIPost struct {
	// Membership proves that the challenge for the PoET, which is
	// constructed from fields in the activation transaction,
	// is a member of the poet's proof.
	// Proof.Root must match the Poet's POSW statement.
	Membership MerkleProof

	// Post is the proof that the prover data is still stored (or was recomputed) at
	// the time he learned the challenge constructed from the PoET.
	Post *Post

	// PostMetadata is the Post metadata, associated with the proof.
	// The proof should be verified upon the metadata during the syntactic validation,
	// while the metadata should be verified during the contextual validation.
	PostMetadata *PostMetadata
}

NIPost is Non-Interactive Proof of Space-Time. Given an id, a space parameter S, a duration D and a challenge C, it can convince a verifier that (1) the prover expended S * D space-time after learning the challenge C. (2) the prover did not know the NIPost until D time after the prover learned C.

type NIPostChallenge added in v1.0.0

type NIPostChallenge struct {
	PublishEpoch EpochID
	// Sequence number counts the number of ancestors of the ATX. It sequentially increases for each ATX in the chain.
	// Two ATXs with the same sequence number from the same miner can be used as the proof of malfeasance against
	// that miner.
	Sequence uint64
	// the previous ATX's ID (for all but the first in the sequence)
	PrevATXID      ATXID
	PositioningATX ATXID

	// CommitmentATX is the ATX used in the commitment for initializing the PoST of the node.
	CommitmentATX *ATXID
	InitialPost   *Post
}

NIPostChallenge is the set of fields that's serialized, hashed and submitted to the PoET service to be included in the PoET membership proof.

func (*NIPostChallenge) MarshalLogObject added in v1.0.0

func (c *NIPostChallenge) MarshalLogObject(encoder log.ObjectEncoder) error

func (*NIPostChallenge) TargetEpoch added in v1.0.0

func (challenge *NIPostChallenge) TargetEpoch() EpochID

TargetEpoch returns the target epoch of the NIPostChallenge. This is the epoch in which the miner is eligible to participate thanks to the ATX.

type NodeID added in v0.1.11

type NodeID Hash32

NodeID contains a miner's public key.

var EmptyNodeID NodeID

EmptyNodeID is a canonical empty NodeID.

func BytesToNodeID added in v0.1.28

func BytesToNodeID(buf []byte) (id NodeID)

BytesToNodeID is a helper to copy buffer into a NodeID.

func RandomNodeID added in v1.0.0

func RandomNodeID() NodeID

RandomNodeID generates a random NodeID for testing.

func (NodeID) Bytes added in v1.0.0

func (id NodeID) Bytes() []byte

Bytes returns the byte representation of the Edwards public key.

func (*NodeID) DecodeScale added in v1.0.0

func (id *NodeID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*NodeID) EncodeScale added in v1.0.0

func (id *NodeID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (NodeID) Field added in v0.1.11

func (id NodeID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (*NodeID) MarshalText added in v1.0.0

func (id *NodeID) MarshalText() ([]byte, error)

func (NodeID) ShortString added in v0.1.11

func (id NodeID) ShortString() string

ShortString returns a the first 3 hex-encoded bytes of the ID, for logging purposes.

func (NodeID) String added in v0.1.11

func (id NodeID) String() string

String returns a string representation of the NodeID, for logging purposes. It implements the Stringer interface.

func (*NodeID) UnmarshalText added in v1.0.0

func (id *NodeID) UnmarshalText(buf []byte) error

type Nonce added in v1.0.0

type Nonce = uint64

Nonce alias to uint64.

type Opinion added in v1.0.0

type Opinion struct {
	Hash  Hash32 `json:"hash"`
	Votes `       json:",inline"`
}

Opinion is a tuple from opinion hash and votes that decode to opinion hash.

func (*Opinion) DecodeScale added in v1.0.0

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

func (*Opinion) EncodeScale added in v1.0.0

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

func (*Opinion) MarshalLogObject added in v1.0.0

func (o *Opinion) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

type PoetProof

type PoetProof struct {
	poetShared.MerkleProof
	LeafCount uint64
}

PoetProof is the full PoET service proof of elapsed time. It includes the number of leaves produced and the actual PoET Merkle proof.

func (*PoetProof) DecodeScale added in v1.0.0

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

func (*PoetProof) EncodeScale added in v1.0.0

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

func (*PoetProof) MarshalLogObject added in v1.0.0

func (p *PoetProof) MarshalLogObject(encoder log.ObjectEncoder) error

func (*PoetProof) Ref added in v1.5.2

func (p *PoetProof) Ref() (PoetProofRef, error)

Ref returns the reference to the PoET proof message. It's the blake3 sum of the entire proof.

type PoetProofMessage

type PoetProofMessage struct {
	PoetProof
	PoetServiceID []byte `scale:"max=32"` // public key of the PoET service
	RoundID       string `scale:"max=32"` // TODO(mafa): convert to uint64
	// The input to Poet's POSW.
	// It's the root of a merkle tree built from all of the members
	// that are included in the proof.
	Statement Hash32
	Signature EdSignature
}

PoetProofMessage is the envelope which includes the PoetProof, service ID, round ID and signature.

func (*PoetProofMessage) DecodeScale added in v1.0.0

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

func (*PoetProofMessage) EncodeScale added in v1.0.0

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

func (*PoetProofMessage) MarshalLogObject added in v1.0.0

func (p *PoetProofMessage) MarshalLogObject(encoder log.ObjectEncoder) error

type PoetProofRef added in v1.0.0

type PoetProofRef Hash32

func (*PoetProofRef) String added in v1.6.1

func (r *PoetProofRef) String() string

type PoetRound

type PoetRound struct {
	ID  string `scale:"max=32"`
	End time.Time
}

PoetRound includes the PoET's round ID.

type PoetServer added in v1.4.0

type PoetServer struct {
	Address string    `mapstructure:"address" json:"address"`
	Pubkey  Base64Enc `mapstructure:"pubkey" json:"pubkey"`
}

type Post added in v1.0.0

type Post shared.Proof

Post is an alias to postShared.Proof.

func (*Post) MarshalLogObject added in v1.0.0

func (p *Post) MarshalLogObject(encoder log.ObjectEncoder) error

type PostInfo added in v1.3.0

type PostInfo struct {
	NodeID        NodeID
	CommitmentATX ATXID
	Nonce         *VRFPostIndex

	NumUnits      uint32
	LabelsPerUnit uint64
}

PostInfo contains information about the PoST as returned by the service.

type PostMetadata added in v1.0.0

type PostMetadata struct {
	Challenge     []byte
	LabelsPerUnit uint64
}

PostMetadata is similar postShared.ProofMetadata, but without the fields which can be derived elsewhere in a given ATX (eg. NodeID, NumUnits).

func (*PostMetadata) MarshalLogObject added in v1.0.0

func (m *PostMetadata) MarshalLogObject(encoder log.ObjectEncoder) error

type PostState added in v1.4.0

type PostState int
const (
	// PostStateIdle is the state of a PoST service that is not currently proving.
	PostStateIdle PostState = iota
	// PostStateProving is the state of a PoST service that is currently proving.
	PostStateProving
)

func (PostState) String added in v1.4.0

func (s PostState) String() string

type Proposal added in v1.0.0

type Proposal struct {
	// the content proposal for a given layer and the votes on the mesh history
	InnerProposal
	// the smesher's signature on the InnerProposal
	Signature EdSignature
	// contains filtered or unexported fields
}

Proposal contains the smesher's signed content proposal for a given layer and vote on the mesh history. Proposal is ephemeral and will be discarded after the unified content block is created. the Ballot within the Proposal will remain in the mesh.

func (*Proposal) Beacon added in v1.4.0

func (p *Proposal) Beacon() Beacon

func (*Proposal) DecodeScale added in v1.0.0

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

func (*Proposal) EncodeScale added in v1.0.0

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

func (Proposal) Equal added in v1.0.0

func (p Proposal) Equal(other Proposal) bool

func (*Proposal) HashInnerProposal added in v1.0.8

func (p *Proposal) HashInnerProposal() []byte

HashInnerProposal returns the hash of the InnerProposal.

func (*Proposal) ID added in v1.0.0

func (p *Proposal) ID() ProposalID

ID returns the ProposalID.

func (*Proposal) Initialize added in v1.0.0

func (p *Proposal) Initialize() error

Initialize calculates and sets the Proposal's cached proposalID. this should be called once all the other fields of the Proposal are set.

func (*Proposal) MarshalLogObject added in v1.0.0

func (p *Proposal) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

func (*Proposal) MustInitialize added in v1.2.2

func (p *Proposal) MustInitialize()

func (*Proposal) SetBeacon added in v1.4.0

func (p *Proposal) SetBeacon(beacon Beacon)

func (*Proposal) SetID added in v1.0.0

func (p *Proposal) SetID(pid ProposalID)

SetID set the ProposalID.

func (*Proposal) SignedBytes added in v1.0.0

func (p *Proposal) SignedBytes() []byte

SignedBytes returns the serialization of the InnerProposal.

type ProposalID added in v1.0.0

type ProposalID Hash20

ProposalID is a 20-byte blake3 sum of the serialized ballot used to identify a Proposal.

func RandomProposalID added in v1.0.0

func RandomProposalID() ProposalID

RandomProposalID generates a random ProposalID for testing.

func SortProposalIDs added in v1.0.0

func SortProposalIDs(ids []ProposalID) []ProposalID

SortProposalIDs sorts a list of ProposalID in lexicographic order, in-place.

func ToProposalIDs added in v1.0.0

func ToProposalIDs(proposals []*Proposal) []ProposalID

ToProposalIDs returns a slice of ProposalID corresponding to the given proposals.

func (ProposalID) AsHash32 added in v1.0.0

func (id ProposalID) AsHash32() Hash32

AsHash32 returns a Hash32 whose first 20 bytes are the bytes of this ProposalID, it is right-padded with zeros.

func (ProposalID) Bytes added in v1.0.0

func (id ProposalID) Bytes() []byte

Bytes returns the ProposalID as a byte slice.

func (ProposalID) Compare added in v1.0.0

func (id ProposalID) Compare(other ProposalID) bool

Compare returns true if other (the given ProposalID) is less than this ProposalID, by lexicographic comparison.

func (*ProposalID) DecodeScale added in v1.0.0

func (id *ProposalID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*ProposalID) EncodeScale added in v1.0.0

func (id *ProposalID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (ProposalID) Field added in v1.0.0

func (id ProposalID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (ProposalID) String added in v1.0.0

func (id ProposalID) String() string

String returns a short prefix of the hex representation of the ID.

type RatNum added in v1.0.0

type RatNum struct {
	Num, Denom uint64
}

RatNum represents a rational number with the numerator and denominator. note: RatNum aims to be a generic representation of a rational number and parse-able by different programming languages. for doing math around weight inside go-spacemesh codebase, use util.Weight.

func RatNumFromBigRat added in v1.0.0

func RatNumFromBigRat(r *big.Rat) RatNum

func (*RatNum) DecodeScale added in v1.0.0

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

func (*RatNum) EncodeScale added in v1.0.0

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

func (*RatNum) String added in v1.0.0

func (r *RatNum) String() string

String implements fmt.Stringer interface for RatNum.

func (*RatNum) ToBigRat added in v1.0.0

func (r *RatNum) ToBigRat() *big.Rat

ToBigRat creates big.Rat instance.

type RatVar added in v1.0.0

type RatVar big.Rat

RatVar is a wrapper for big.Rat to use it with the pflag package.

func (*RatVar) Set added in v1.0.0

func (r *RatVar) Set(s string) error

Set sets the value of big.Rat to a string.

func (*RatVar) String added in v1.0.0

func (r *RatVar) String() string

String returns a string representation of big.Rat.

func (*RatVar) Type added in v1.0.0

func (r *RatVar) Type() string

Type returns *big.Rat type.

type RawTx added in v1.0.0

type RawTx struct {
	ID  TransactionID
	Raw []byte `scale:"max=4096"` // transactions should always be less than 4kb
}

RawTx stores an identity and a pointer to raw bytes.

func NewRawTx added in v1.0.0

func NewRawTx(raw []byte) RawTx

NewRawTx computes id from raw bytes and returns the object.

func (*RawTx) DecodeScale added in v1.0.0

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

func (*RawTx) EncodeScale added in v1.0.0

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

type ReferenceData added in v1.0.0

type ReferenceData struct {
	Beacon        Beacon `json:"beacon"`
	Eligibilities uint32 `json:"elig"`
}

func (*ReferenceData) MarshalLogObject added in v1.0.0

func (r *ReferenceData) MarshalLogObject(encoder log.ObjectEncoder) error

type Reward

type Reward struct {
	Layer       LayerID
	TotalReward uint64
	LayerReward uint64
	Coinbase    Address
	SmesherID   NodeID
}

Reward is a virtual reward transaction, which the node keeps track of for the gRPC api.

func (*Reward) DecodeScale added in v1.0.0

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

func (*Reward) EncodeScale added in v1.0.0

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

type RoundID added in v1.0.0

type RoundID uint32

RoundID is the round ID used to run any protocol that requires multiple rounds.

func (RoundID) Field added in v1.0.0

func (r RoundID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

type TXState added in v1.0.0

type TXState uint32

TXState describes the state of a transaction.

const (
	// PENDING represents the state when a transaction is syntactically valid, but its nonce and
	// the principal's ability to cover gas have not been verified yet.
	PENDING TXState = iota
	// MEMPOOL represents the state when a transaction is in mempool.
	MEMPOOL
	// APPLIED represents the state when a transaction is applied to the state.
	APPLIED
)

type Transaction

type Transaction struct {
	RawTx
	*TxHeader
}

Transaction is an alias to RawTx.

func (*Transaction) DecodeScale added in v1.0.0

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

func (*Transaction) EncodeScale added in v1.0.0

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

func (Transaction) GetRaw added in v1.0.0

func (t Transaction) GetRaw() RawTx

GetRaw returns raw bytes of the transaction with id.

func (*Transaction) Hash32

func (t *Transaction) Hash32() Hash32

Hash32 returns the TransactionID as a Hash32.

func (*Transaction) ShortString

func (t *Transaction) ShortString() string

ShortString returns the first 5 characters of the ID, for logging purposes.

func (Transaction) Verified added in v1.0.0

func (t Transaction) Verified() bool

Verified returns true if header is set.

type TransactionID added in v0.1.11

type TransactionID Hash32

TransactionID is a 32-byte blake3 sum of the transaction, used as an identifier.

func RandomTXSet added in v1.0.0

func RandomTXSet(size int) []TransactionID

RandomTXSet generates a random set of TransactionID of the specified size.

func RandomTransactionID added in v1.0.0

func RandomTransactionID() TransactionID

RandomTransactionID generates a random TransactionID for testing.

func ToTransactionIDs added in v1.0.0

func ToTransactionIDs(txs []*Transaction) []TransactionID

ToTransactionIDs returns a slice of TransactionID corresponding to the given transactions.

func (TransactionID) Bytes added in v0.1.11

func (id TransactionID) Bytes() []byte

Bytes returns the TransactionID as a byte slice.

func (TransactionID) Compare added in v1.0.0

func (id TransactionID) Compare(other TransactionID) bool

Compare returns true if other (the given TransactionID) is less than this TransactionID, by lexicographic comparison.

func (*TransactionID) DecodeScale added in v1.0.0

func (id *TransactionID) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*TransactionID) EncodeScale added in v1.0.0

func (id *TransactionID) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (TransactionID) Field added in v0.1.11

func (id TransactionID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (TransactionID) Hash32 added in v0.1.11

func (id TransactionID) Hash32() Hash32

Hash32 returns the TransactionID as a Hash32.

func (TransactionID) ShortString added in v0.1.11

func (id TransactionID) ShortString() string

ShortString returns a the first 10 characters of the ID, for logging purposes.

func (TransactionID) String added in v0.1.11

func (id TransactionID) String() string

String returns a hexadecimal representation of the TransactionID with "0x" prepended, for logging purposes. It implements the fmt.Stringer interface.

type TransactionResult added in v1.0.0

type TransactionResult struct {
	Status  TransactionStatus
	Message string `scale:"max=1024"` // TODO(mafa): human readable error message, convert to error code
	Gas     uint64
	Fee     uint64
	Block   BlockID
	Layer   LayerID
	// Addresses contains all updated addresses.
	Addresses []Address `scale:"max=10"` // we expect 1-3 addresses to be updated in a transaction
}

TransactionResult is created after consuming transaction.

func (*TransactionResult) DecodeScale added in v1.0.0

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

func (*TransactionResult) EncodeScale added in v1.0.0

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

func (*TransactionResult) MarshalLogObject added in v1.0.0

func (h *TransactionResult) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements encoding for the tx result.

type TransactionStatus added in v1.0.0

type TransactionStatus uint8

TransactionStatus ...

const (
	// TransactionSuccess is a status for successfully applied transaction.
	TransactionSuccess TransactionStatus = iota
	// TransactionFailure is a status for failed but consumed transaction.
	TransactionFailure
)

func (TransactionStatus) String added in v1.0.0

func (t TransactionStatus) String() string

String implements human readable representation of the status.

type TransactionWithResult added in v1.0.0

type TransactionWithResult struct {
	Transaction
	TransactionResult
}

TransactionWithResult is a transaction with attached result.

func (*TransactionWithResult) DecodeScale added in v1.0.0

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

func (*TransactionWithResult) EncodeScale added in v1.0.0

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

type TxHeader added in v1.0.0

type TxHeader struct {
	Principal       Address
	TemplateAddress Address
	Method          uint8
	Nonce           Nonce
	LayerLimits     LayerLimits
	MaxGas          uint64
	GasPrice        uint64
	MaxSpend        uint64
}

TxHeader is a transaction header, with some of the fields defined directly in the tx and the rest is computed by the template based on immutable state and method arguments.

func (*TxHeader) DecodeScale added in v1.0.0

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

func (*TxHeader) EncodeScale added in v1.0.0

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

func (*TxHeader) Fee added in v1.0.0

func (h *TxHeader) Fee() uint64

Fee is a MaxGas multiplied by a GasPrice.

func (*TxHeader) MarshalLogObject added in v1.0.0

func (h *TxHeader) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements encoding for the tx header.

func (*TxHeader) Spending added in v1.0.0

func (h *TxHeader) Spending() uint64

Spending is Fee() + MaxSpend.

type VRFPostIndex added in v1.0.0

type VRFPostIndex uint64

VRFPostIndex is the nonce generated using Pow during post initialization. It is used as a mitigation for grinding of identities for VRF eligibility.

func (VRFPostIndex) Field added in v1.0.0

func (v VRFPostIndex) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

type Validity added in v1.4.0

type Validity int
const (
	Unknown Validity = iota
	Valid
	Invalid
)

type Vote added in v1.0.0

type Vote = BlockHeader

Vote additionally carries layer id and height in order for the tortoise to count votes without downloading block body.

type Votes added in v1.0.0

type Votes struct {
	// Base ballot.
	Base BallotID `json:"base"`
	// Support block id at a particular layer and height.
	// sliding vote window size is 10k layers, vote for one block per layer
	Support []Vote `json:"support,omitempty" scale:"max=10000"`
	// Against previously supported block.
	// sliding vote window size is 10k layers, vote for one block per layer
	Against []Vote `json:"against,omitempty" scale:"max=10000"`
	// Abstain on layers until they are terminated.
	// sliding vote window size is 10k layers, vote to abstain on any layer
	Abstain []LayerID `json:"abstain,omitempty" scale:"max=10000"`
}

Votes is for encoding local votes to send over the wire.

a smesher creates votes in the following steps: - select a Ballot in the past as a base Ballot - calculate the opinion difference on history between the smesher and the base Ballot - encode the opinion difference in 3 list:

  • ForDiff contains blocks we support while the base ballot did not support (i.e. voted against) for blocks we support in layers later than the base ballot, we also add them to this list
  • AgainstDiff contains blocks we vote against while the base ballot explicitly supported
  • NeutralDiff contains layers we vote neutral while the base ballot explicitly supported or voted against

example: layer | unified content block -----------------------------------------------------------------------------------------------

N   | UCB_A (genesis)

-----------------------------------------------------------------------------------------------

N+1  | UCB_B base:UCB_A, for:[UCB_A], against:[], neutral:[]

-----------------------------------------------------------------------------------------------

N+2  | UCB_C base:UCB_B, for:[UCB_B], against:[], neutral:[]

-----------------------------------------------------------------------------------------------

(hare hasn't terminated for N+2)
N+3  | UCB_D base:UCB_B, for:[UCB_B], against:[], neutral:[N+2]

-----------------------------------------------------------------------------------------------

(hare succeeded for N+2 but failed for N+3)
N+4  | UCB_E base:UCB_C, for:[UCB_C], against:[], neutral:[]

----------------------------------------------------------------------------------------------- NOTE on neutral votes: a base block is by default neutral on all blocks and layers that come after it, so there's no need to explicitly add neutral votes for more recent layers.

TODO: maybe collapse Support and Against into a single list.

see https://github.com/spacemeshos/go-spacemesh/issues/2369.

func (*Votes) DecodeScale added in v1.0.0

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

func (*Votes) EncodeScale added in v1.0.0

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

func (*Votes) MarshalLogObject added in v1.0.0

func (v *Votes) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

type VotingEligibility added in v1.0.0

type VotingEligibility struct {
	// the counter value used to generate this eligibility proof. if the value of J is 3, this is the smeshers
	// eligibility proof of the 3rd ballot/proposal in the epoch.
	J uint32
	// the VRF signature of some epoch specific data and J. one can derive a Ballot's layerID from this signature.
	Sig VrfSignature
}

VotingEligibility includes the required values that, along with the smeshers VRF public key, allow non-interactive voting eligibility validation. this proof provides eligibility for both voting and making proposals.

func (*VotingEligibility) DecodeScale added in v1.0.0

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

func (*VotingEligibility) EncodeScale added in v1.0.0

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

func (*VotingEligibility) MarshalLogObject added in v1.0.0

func (v *VotingEligibility) MarshalLogObject(encoder log.ObjectEncoder) error

MarshalLogObject implements logging interface.

type VrfSignature added in v1.0.0

type VrfSignature [VrfSignatureSize]byte
var EmptyVrfSignature VrfSignature

EmptyVrfSignature is a canonical empty VrfSignature.

func RandomVrfSignature added in v1.0.0

func RandomVrfSignature() VrfSignature

RandomVrfSignature generates a random VrfSignature for testing.

func (*VrfSignature) Bytes added in v1.0.0

func (s *VrfSignature) Bytes() []byte

Bytes returns the byte representation of the Signature.

func (*VrfSignature) Cmp added in v1.0.0

func (s *VrfSignature) Cmp(x *VrfSignature) int

Cmp compares s and x and returns:

-1 if s <  x
 0 if s == x
+1 if s >  x

The comparison is done in little endian order. Additionally, if x is nil, -1 is returned.

func (*VrfSignature) LSB added in v1.0.0

func (s *VrfSignature) LSB() byte

LSB returns the least significant bit of the signature, so either 0 or 1.

func (VrfSignature) String added in v1.0.0

func (s VrfSignature) String() string

String returns a string representation of the Signature, for logging purposes. It implements the Stringer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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