message

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const EMPTY = "EMPTY"

EMPTY represents a empty message, used by the StopConsensus call.

Variables

This section is empty.

Functions

func ConvBool added in v0.4.0

func ConvBool(p payload.Safe) (bool, error)

ConvBool converts a Safe into a bool.

func ConvI added in v0.4.0

func ConvI(p payload.Safe) (int, error)

ConvI converts a Safe into an int.

func ConvI16 added in v0.4.0

func ConvI16(p payload.Safe) (int16, error)

ConvI16 converts a Safe into an int16.

func ConvI32 added in v0.4.0

func ConvI32(p payload.Safe) (int32, error)

ConvI32 converts a Safe into an int32.

func ConvI64 added in v0.4.0

func ConvI64(p payload.Safe) (int64, error)

ConvI64 converts a Safe into an int64.

func ConvI8 added in v0.4.0

func ConvI8(p payload.Safe) (int8, error)

ConvI8 converts a Safe into an int8.

func ConvStr added in v0.4.0

func ConvStr(p payload.Safe) (string, error)

ConvStr converts a Safe into a string.

func ConvU added in v0.4.0

func ConvU(p payload.Safe) (uint, error)

ConvU converts a Safe into a uint.

func ConvU16 added in v0.4.0

func ConvU16(p payload.Safe) (uint16, error)

ConvU16 converts a Safe into a uint16.

func ConvU32 added in v0.4.0

func ConvU32(p payload.Safe) (uint32, error)

ConvU32 converts a Safe into a uint32.

func ConvU64 added in v0.4.0

func ConvU64(p payload.Safe) (uint64, error)

ConvU64 converts a Safe into a uint64.

func ConvU8 added in v0.4.0

func ConvU8(p payload.Safe) (uint8, error)

ConvU8 converts a Safe into a uint8.

func Marshal

func Marshal(s Message) (bytes.Buffer, error)

Marshal a Message into a buffer. The buffer *does* include its Category (so if this is undesired, the client of this call needs to explicitly call topics.Extract on the resulting buffer. TODO: interface - once the Gossip preprocessing is removed from the Coordinator, there won't be a need for marshalBuffer.

func MarshalAggrAgreement added in v0.4.4

func MarshalAggrAgreement(r *bytes.Buffer, aggr AggrAgreement) error

MarshalAggrAgreement marshal the AggrAgreement into a Buffer.

func MarshalAgreement

func MarshalAgreement(r *bytes.Buffer, a Agreement) error

MarshalAgreement marshals an Agreement event into a buffer.

func MarshalBlock

func MarshalBlock(r *bytes.Buffer, b *block.Block) error

MarshalBlock marshals a block into a binary buffer.

func MarshalCertificate

func MarshalCertificate(r *bytes.Buffer, c *block.Certificate) error

MarshalCertificate marshals a certificate.

func MarshalHashable

func MarshalHashable(r *bytes.Buffer, h *block.Header) error

MarshalHashable marshals the hashable part of the block into a binary buffer.

func MarshalHeader

func MarshalHeader(r *bytes.Buffer, h *block.Header) error

MarshalHeader marshals the header of a block into a binary buffer.

func MarshalNewBlock added in v0.4.4

func MarshalNewBlock(r *bytes.Buffer, sev NewBlock) error

MarshalNewBlock the buffer into a committee Event. Field order is the following: * Blind Bid Fields [Score, Proof, Z, BidList, Seed, Candidate Block Hash].

func MarshalReduction

func MarshalReduction(r *bytes.Buffer, bev Reduction) error

MarshalReduction a Reduction event into a buffer.

func MarshalStepVotes

func MarshalStepVotes(r *bytes.Buffer, vote *StepVotes) error

MarshalStepVotes marshals the aggregated form of the BLS PublicKey and Signature for an ordered set of votes.

func MarshalVoteSet

func MarshalVoteSet(r *bytes.Buffer, evs []Reduction) error

MarshalVoteSet marshals a slice of Reduction events to a buffer.

func MarshalVotes

func MarshalVotes(r *bytes.Buffer, votes []*StepVotes) error

MarshalVotes marshals an array of StepVotes.

func SignAgreement

func SignAgreement(a *Agreement, keys key.Keys) error

SignAgreement signs an aggregated agreement event. XXX: either use this function or delete it!! Right now it is not used.

func UnmarshalAddrMessage added in v0.4.3

func UnmarshalAddrMessage(r *bytes.Buffer, m SerializableMessage)

UnmarshalAddrMessage into a SerializableMessage.

func UnmarshalAggrAgreement added in v0.4.4

func UnmarshalAggrAgreement(r *bytes.Buffer, a *AggrAgreement) error

UnmarshalAggrAgreement unmarshals the buffer into an AggrAgreement.

func UnmarshalAggrAgreementMessage added in v0.4.4

func UnmarshalAggrAgreementMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalAggrAgreementMessage unmarshal a network inbound AggrAgreement.

func UnmarshalAgreement

func UnmarshalAgreement(r *bytes.Buffer, a *Agreement) error

UnmarshalAgreement unmarshals the buffer into an Agreement. Field order is the following: * Header [BLS Public Key; Round; Step] * Agreement [Signed Vote Set; Vote Set; BlockHash].

func UnmarshalAgreementMessage

func UnmarshalAgreementMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalAgreementMessage unmarshal a network inbound Agreement.

func UnmarshalBlock

func UnmarshalBlock(r *bytes.Buffer, b *block.Block) error

UnmarshalBlock unmarshals a block from a binary buffer.

func UnmarshalBlockMessage added in v0.4.0

func UnmarshalBlockMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalBlockMessage unmarshals a block from a binary buffer into a SerializableMessage.

func UnmarshalCertificate

func UnmarshalCertificate(r *bytes.Buffer, c *block.Certificate) error

UnmarshalCertificate unmarshals a certificate.

func UnmarshalChallengeMessage added in v0.4.3

func UnmarshalChallengeMessage(r *bytes.Buffer, m SerializableMessage)

UnmarshalChallengeMessage into a SerializableMessage.

func UnmarshalGetBlocksMessage added in v0.4.0

func UnmarshalGetBlocksMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalGetBlocksMessage unmarshals a GetBlocks message into a SerializableMessage.

func UnmarshalGetCandidateMessage added in v0.4.0

func UnmarshalGetCandidateMessage(r *bytes.Buffer, m SerializableMessage)

UnmarshalGetCandidateMessage into a SerializableMessage.

func UnmarshalHeader

func UnmarshalHeader(r *bytes.Buffer, h *block.Header) error

UnmarshalHeader unmarshal a block header from a binary buffer.

func UnmarshalInvMessage added in v0.4.0

func UnmarshalInvMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalInvMessage into a SerializableMessage.

func UnmarshalNewBlock added in v0.4.4

func UnmarshalNewBlock(r *bytes.Buffer, sev *NewBlock) error

UnmarshalNewBlock unmarshals the buffer into a NewBlock Event. Field order is the following: * Score Payload [score, proof, Z, BidList, Seed, Block Candidate Hash].

func UnmarshalNewBlockMessage added in v0.4.4

func UnmarshalNewBlockMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalNewBlockMessage unmarshal a NewBlockMessage from a buffer.

func UnmarshalReduction

func UnmarshalReduction(r *bytes.Buffer, bev *Reduction) error

UnmarshalReduction unmarshals the buffer into a Reduction event.

func UnmarshalReductionMessage

func UnmarshalReductionMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalReductionMessage unmarshals a serialization from a buffer.

func UnmarshalResponseMessage added in v0.4.3

func UnmarshalResponseMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalResponseMessage into a SerializableMessage.

func UnmarshalTxMessage

func UnmarshalTxMessage(r *bytes.Buffer, m SerializableMessage) error

UnmarshalTxMessage unmarshals a Message carrying a tx from a buffer.

func UnmarshalVotes

func UnmarshalVotes(r *bytes.Buffer, votes []*StepVotes) error

UnmarshalVotes unmarshals the array of StepVotes for a single Agreement.

Types

type Addr added in v0.4.3

type Addr struct {
	NetAddr string
}

Addr contains a network address of a peer.

func (Addr) Copy added in v0.4.3

func (a Addr) Copy() payload.Safe

Copy an Addr. Implements the payload.Safe interface.

type AggrAgreement added in v0.4.4

type AggrAgreement struct {
	Agreement
	Bitset  uint64
	AggrSig []byte
}

AggrAgreement stores an agreement (with the provisioners) and the bitset representing those who voted in favor.

func NewAggrAgreement added in v0.4.4

func NewAggrAgreement(payload Agreement, bitset uint64, aggrSig []byte) AggrAgreement

NewAggrAgreement creates an AggrAgreement message with the given fields.

func (AggrAgreement) Copy added in v0.4.4

func (a AggrAgreement) Copy() payload.Safe

Copy deeply a AggrAgreement.

func (AggrAgreement) String added in v0.4.4

func (a AggrAgreement) String() string

String returns a string representation of a AggrAgreement message.

type Agreement

type Agreement struct {
	VotesPerStep []*StepVotes
	Repr         *big.Int
	// contains filtered or unexported fields
}

Agreement is the Event created at the end of the Reduction process. It includes the aggregated compressed signatures of all voters.

func MockAgreement

func MockAgreement(hash []byte, round uint64, step uint8, keys []key.Keys, p *user.Provisioners, iterativeIdx ...int) Agreement

MockAgreement returns a mocked Agreement Event, to be used for testing purposes. It includes a vararg iterativeIdx to help avoiding duplicates when testing.

func NewAgreement

func NewAgreement(hdr header.Header) *Agreement

NewAgreement returns an empty Agreement event. It is supposed to be used by the (secondstep reducer) for creating Agreement messages.

func (Agreement) Cmp

func (a Agreement) Cmp(other Agreement) int

Cmp compares the big.Int representation of two agreement messages.

func (Agreement) Copy added in v0.4.0

func (a Agreement) Copy() payload.Safe

Copy the Agreement is somewhat more expensive than the other structures since it involves Marshaling and Unmarshaling. This is necessary since we do not have access to the underlying BLS structs.

func (Agreement) Equal

func (a Agreement) Equal(aev Agreement) bool

Equal checks if two agreement messages are the same.

func (Agreement) GenerateCertificate

func (a Agreement) GenerateCertificate() *block.Certificate

GenerateCertificate is used by the Chain component.

func (Agreement) Sender

func (a Agreement) Sender() []byte

Sender returns the BLS public key of the Sender.

func (*Agreement) SetSignature

func (a *Agreement) SetSignature(signature []byte)

SetSignature set a signature to the Agreement.

func (Agreement) Signature added in v0.4.4

func (a Agreement) Signature() []byte

Signature returns the signed vote.

func (Agreement) State

func (a Agreement) State() header.Header

State returns the message header. This is to comply to the consensus.Message interface.

func (Agreement) String

func (a Agreement) String() string

String representation of the Agreement.

type Challenge added in v0.4.3

type Challenge struct {
	ChallengeString []byte
}

Challenge represents a challenge sent by a voucher seeder on connection.

func (Challenge) Copy added in v0.4.3

func (c Challenge) Copy() payload.Safe

Copy a Challenge. Implements the payload.Safe interface.

type GetBlocks added in v0.4.0

type GetBlocks struct {
	Locators [][]byte
}

GetBlocks defines a getblocks message on the Dusk wire protocol. It is used to request blocks from another peer.

func (GetBlocks) Copy added in v0.4.0

func (g GetBlocks) Copy() payload.Safe

Copy a GetBlocks message. Implements the payload.Safe interface.

func (*GetBlocks) Decode added in v0.4.0

func (g *GetBlocks) Decode(r *bytes.Buffer) error

Decode a GetBlocks struct from r into g.

func (*GetBlocks) Encode added in v0.4.0

func (g *GetBlocks) Encode(w *bytes.Buffer) error

Encode a GetBlocks struct and write it to w.

type GetCandidate added in v0.4.0

type GetCandidate struct {
	Hash []byte
}

GetCandidate is used to request certain candidates from peers.

func (GetCandidate) Copy added in v0.4.0

func (g GetCandidate) Copy() payload.Safe

Copy a GetCandidate message. Implements the payload.Safe interface.

type Inv added in v0.4.0

type Inv struct {
	InvList []InvVect
}

Inv contains a list of Inventory vector.

func (*Inv) AddItem added in v0.4.0

func (inv *Inv) AddItem(t InvType, hash []byte)

AddItem to an Inventory.

func (Inv) Copy added in v0.4.0

func (inv Inv) Copy() payload.Safe

Copy an Inv. Implements the payload.Safe interface.

func (*Inv) Decode added in v0.4.0

func (inv *Inv) Decode(r *bytes.Buffer) error

Decode an Inventory from a buffer.

func (*Inv) Encode added in v0.4.0

func (inv *Inv) Encode(w *bytes.Buffer) error

Encode an Inventory request into a buffer.

type InvType added in v0.4.0

type InvType uint8

InvType is a byte describing the Inventory type.

var (
	// InvTypeMempoolTx is the inventory type for unconfirmed Txs.
	InvTypeMempoolTx InvType = 0
	// InvTypeBlock is the inventory type for confirmed Txs.
	InvTypeBlock InvType = 1
)

type InvVect added in v0.4.0

type InvVect struct {
	Type InvType // Type of data
	Hash []byte  // Hash of the data
}

InvVect represents a request of sort for Inventory data.

func (InvVect) Copy added in v0.4.0

func (i InvVect) Copy() payload.Safe

Copy an InvVect. Implements the payload.Safe interface.

type Message

type Message interface {
	Category() topics.Topic
	Payload() payload.Safe
	Equal(Message) bool
	Id() []byte

	// CachedBinary returns the marshaled form of this Payload as cached during
	// the unmarshaling of incoming messages. In case the message has been
	// created internally and never serialized, this should return an empty buffer.
	CachedBinary() bytes.Buffer

	Metadata() *Metadata
}

Message is the core of the message-oriented architecture of the node. It is particularly important within the consensus, but in practice any component ends up dealing with it. It encapsulates the data exchanged by different nodes as well as internal components. The Message transits inside of the eventbus and is de- serialized through the Gossip procedure.

func Clone added in v0.4.0

func Clone(m Message) (Message, error)

Clone creates a new Message which carries a copy of the payload.

func New

func New(top topics.Topic, p interface{}) Message

New creates a new Message.

func NewWithMetadata added in v0.6.0

func NewWithMetadata(t topics.Topic, payload interface{}, metadata *Metadata) Message

NewWithMetadata creates a new Message with non-nil metadata.

func Unmarshal

func Unmarshal(b *bytes.Buffer, h *Metadata) (Message, error)

Unmarshal mutates the buffer by extracting the topic. It create the Message by setting the topic and unmarshaling the payload into the proper structure It also caches the serialized form within the message.

type Metadata added in v0.6.0

type Metadata struct {
	KadcastHeight byte
	Source        string
	NumNodes      byte
}

Metadata is a struct containing messages metadata.

type NewBlock added in v0.4.4

type NewBlock struct {
	PrevHash   []byte
	Candidate  block.Block
	SignedHash []byte
	// contains filtered or unexported fields
}

NewBlock extends the ScoreProposal with additional fields related to the candidate it pairs up with. The NewBlock is supposed to be immutable once created and it gets forwarded to the other nodes.

func EmptyNewBlock added in v0.4.4

func EmptyNewBlock() NewBlock

EmptyNewBlock is used primarily to initialize the NewBlock, since empty newblocks should not be propagated externally.

func MockNewBlock added in v0.4.4

func MockNewBlock(hdr header.Header, c block.Block) NewBlock

MockNewBlock mocks a NewBlock and returns it.

func NewNewBlock added in v0.4.4

func NewNewBlock(hdr header.Header, prevHash []byte, candidate block.Block) *NewBlock

NewNewBlock creates a new Score from a proposal.

func (NewBlock) Copy added in v0.4.4

func (e NewBlock) Copy() payload.Safe

Copy complies with message.Safe interface. It returns a deep copy of the message safe to publish to multiple subscribers.

func (NewBlock) Equal added in v0.4.4

func (e NewBlock) Equal(s NewBlock) bool

Equal tests if two NewBlock messages are equal.

func (NewBlock) IsEmpty added in v0.4.4

func (e NewBlock) IsEmpty() bool

IsEmpty checks if a NewBlock message is empty.

func (NewBlock) State added in v0.4.4

func (e NewBlock) State() header.Header

State is used to comply to the consensus.Message interface.

func (NewBlock) String added in v0.4.4

func (e NewBlock) String() string

String representation of a NewBlock.

func (NewBlock) VoteHash added in v0.4.4

func (e NewBlock) VoteHash() []byte

VoteHash returns hash of the Candidate block.

func (NewBlock) WithFields added in v0.6.0

func (e NewBlock) WithFields(l *logrus.Entry) *logrus.Entry

WithFields adds a logrus.Entry fields to print all msg fields.

type Reduction

type Reduction struct {
	SignedHash []byte
	// contains filtered or unexported fields
}

Reduction is one of the messages used in the consensus algorithms. As such it encapsulates a header.Header to allow the Coordinator to correctly enforce the sequence of state changes expressed through the algorithm.

func MockCommitteeVoteSet

func MockCommitteeVoteSet(p *user.Provisioners, k []key.Keys, hash []byte, committeeSize int, round uint64, step uint8) []Reduction

MockCommitteeVoteSet mocks a VoteSet.

func MockReduction

func MockReduction(hash []byte, round uint64, step uint8, keys []key.Keys, iterativeIdx ...int) Reduction

MockReduction mocks a Reduction event and returns it. It includes a vararg iterativeIdx to help avoiding duplicates when testing.

func MockVoteSet

func MockVoteSet(hash []byte, round uint64, step uint8, keys []key.Keys, amount int) []Reduction

MockVoteSet mocks a slice of Reduction events for two adjacent steps, and returns it.

func MockVotes

func MockVotes(hash []byte, round uint64, step uint8, keys []key.Keys, amount int) []Reduction

MockVotes mocks a slice of Reduction events and returns it.

func NewReduction

func NewReduction(hdr header.Header) *Reduction

NewReduction returns and empty Reduction event.

func UnmarshalVoteSet

func UnmarshalVoteSet(r *bytes.Buffer) ([]Reduction, error)

UnmarshalVoteSet unmarshals a Reduction slice from a buffer.

func (Reduction) Copy added in v0.4.0

func (r Reduction) Copy() payload.Safe

Copy complies with the Safe interface.

func (Reduction) Equal

func (r Reduction) Equal(msg Message) bool

Equal is used to comply to consensus.Message.

func (Reduction) MarshalJSON added in v0.4.4

func (r Reduction) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Reduction) Sender

func (r Reduction) Sender() []byte

Sender is used to comply to consensus.Message.

func (Reduction) State

func (r Reduction) State() header.Header

State is used to comply to consensus.Message.

func (Reduction) String

func (r Reduction) String() string

type Response added in v0.4.3

type Response struct {
	HashedChallenge []byte
	Port            string
}

Response to a voucher seeder challenge.

func (Response) Copy added in v0.4.3

func (r Response) Copy() payload.Safe

Copy a Response. Implements the payload.Safe interface.

func (*Response) Decode added in v0.4.3

func (r *Response) Decode(b *bytes.Buffer) error

Decode a Response message from a buffer.

func (*Response) Encode added in v0.4.3

func (r *Response) Encode(w *bytes.Buffer) error

Encode a Response object into a buffer.

type SafeBuffer added in v0.4.0

type SafeBuffer struct {
	bytes.Buffer
}

SafeBuffer is a byte.Buffer wrapper that let the Buffer implement Safe.

func (SafeBuffer) Copy added in v0.4.0

func (s SafeBuffer) Copy() payload.Safe

Copy complies with payload.Safe interface. It returns a deep copy of the buffer safe to publish to multiple subscribers.

type Serializable

type Serializable interface {
	SetPayload(payload.Safe)
}

Serializable allows to set a payload.

type SerializableMessage

type SerializableMessage interface {
	Message
	Serializable
}

SerializableMessage is a Serializable and a Message.

type StepVotes

type StepVotes struct {
	BitSet    uint64
	Signature []byte
}

StepVotes represents the aggregated votes for one reduction step. Normally an Agreement event includes two of these structures. They need to be kept separated since the BitSet representation of the Signees does not admit duplicates, whereas the same provisioner may very well be included in the committee for both Reduction steps.

func GenVotes

func GenVotes(hash, seed []byte, round uint64, step uint8, keys []key.Keys, p *user.Provisioners) []*StepVotes

GenVotes randomly generates a slice of StepVotes with the indicated length. Albeit random, the generation is consistent with the rules of Votes.

func NewStepVotes

func NewStepVotes() *StepVotes

NewStepVotes returns a new StepVotes structure for a given round, step and block hash.

func UnmarshalStepVotes

func UnmarshalStepVotes(r *bytes.Buffer) (*StepVotes, error)

UnmarshalStepVotes unmarshals a single StepVote.

func (*StepVotes) Add

func (s *StepVotes) Add(signature []byte) error

Add a vote to the StepVotes struct.

func (*StepVotes) Copy added in v0.4.0

func (s *StepVotes) Copy() *StepVotes

Copy deeply the StepVotes.

func (*StepVotes) Equal

func (s *StepVotes) Equal(other *StepVotes) bool

Equal checks if two StepVotes structs are the same.

func (StepVotes) IsEmpty

func (s StepVotes) IsEmpty() bool

IsEmpty returns whether the StepVotesMsg represents a failed convergence attempt at consensus over a Reduction message.

func (StepVotes) String

func (s StepVotes) String() string

String representation.

type StepVotesMsg

type StepVotesMsg struct {
	header.Header
	StepVotes
	Candidate *block.Block
}

StepVotesMsg is the internal message exchanged by the consensus components (through the signer.SendInternally method). It is not meant for external communications and therefore it does not have a Marshal/Unmarshal methods associated.

func NewStepVotesMsg

func NewStepVotesMsg(round uint64, hash []byte, sender []byte, sv StepVotes, step uint8) StepVotesMsg

NewStepVotesMsg creates a StepVotesMsg. Deprecated.

func (StepVotesMsg) Copy added in v0.4.0

func (s StepVotesMsg) Copy() payload.Safe

Copy deeply the StepVotesMsg.

func (StepVotesMsg) State

func (s StepVotesMsg) State() header.Header

State returns the Header without information about Sender (as this is only for internal communications).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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