message

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 MarshalAgreement

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

MarshalAgreement marshals an Agreement event into a buffer.

func MarshalBid

func MarshalBid(r *bytes.Buffer, tx *transactions.Bid) error

MarshalBid into a buffer

func MarshalBlock

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

MarshalBlock marshals a block into a binary buffer

func MarshalCandidate

func MarshalCandidate(b *bytes.Buffer, c Candidate) error

MarshalCandidate encodes a Candidate to a binary form

func MarshalCertificate

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

MarshalCertificate marshals a certificate

func MarshalCoinbase

func MarshalCoinbase(w *bytes.Buffer, c *transactions.Coinbase) error

MarshalCoinbase into a buffer

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 MarshalInput

func MarshalInput(w *bytes.Buffer, i *transactions.Input, encodeSignature bool) error

MarshalInput marshals an Input object into a bytes.Buffer.

func MarshalOutput

func MarshalOutput(w *bytes.Buffer, o *transactions.Output) error

MarshalOutput encode an Output struct and write to w.

func MarshalReduction

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

MarshalReduction a Reduction event into a buffer.

func MarshalScore

func MarshalScore(r *bytes.Buffer, sev Score) error

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

func MarshalStake

func MarshalStake(r *bytes.Buffer, tx *transactions.Stake) error

MarshalStake into a buffer

func MarshalStandard

func MarshalStandard(w *bytes.Buffer, s *transactions.Standard) error

MarshalStandard marshals a standard transaction 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 MarshalTimelock

func MarshalTimelock(r *bytes.Buffer, tx *transactions.Timelock) error

MarshalTimelock marshals a time lock into a buffer

func MarshalTx

func MarshalTx(r *bytes.Buffer, tx transactions.Transaction) error

MarshalTx marshals a tx into a buffer

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 MockCertificate

func MockCertificate(hash []byte, round uint64, keys []key.Keys, p *user.Provisioners) *block.Certificate

MockCertificate mocks a certificate

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 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 UnmarshalBid

func UnmarshalBid(r *bytes.Buffer, tx *transactions.Bid) error

UnmarshalBid tx from a buffer

func UnmarshalBlock

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

UnmarshalBlock unmarshals a block from a binary buffer

func UnmarshalCandidate

func UnmarshalCandidate(b *bytes.Buffer, c *Candidate) error

UnmarshalCandidate consumes a buffer, instantiate and fills the Candidate fields

func UnmarshalCandidateMessage

func UnmarshalCandidateMessage(b *bytes.Buffer, m SerializableMessage) error

UnmarshalCandidateMessage encodes a message.Message (with a Candidate payload) into a buffer

func UnmarshalCertificate

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

UnmarshalCertificate unmarshals a certificate

func UnmarshalCoinbase

func UnmarshalCoinbase(w *bytes.Buffer, c *transactions.Coinbase) error

UnmarshalCoinbase from a buffer

func UnmarshalHeader

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

UnmarshalHeader unmarshal a block header from a binary buffer

func UnmarshalInput

func UnmarshalInput(r *bytes.Buffer, i *transactions.Input) error

UnmarshalInput from a bytes.Buffer.

func UnmarshalLegacyBlock

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

UnmarshalLegacyBlock unmarshals a block from a binary buffer carrying legacy Stake transactions TODO: this should be better handled with a Marshaller object that supports different versions of the protocol

func UnmarshalLegacyStake

func UnmarshalLegacyStake(r *bytes.Buffer, tx *transactions.Stake) error

UnmarshalLegacyStake is Deprecated. It is used solely to allow reutilization and parsing of the legacy Genesis Block

func UnmarshalOutput

func UnmarshalOutput(r *bytes.Buffer, o *transactions.Output) error

UnmarshalOutput decodes an Output object from r into an output struct.

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 serializzation from a buffer

func UnmarshalScore

func UnmarshalScore(r *bytes.Buffer, sev *Score) error

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

func UnmarshalScoreMessage

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

UnmarshalScoreMessage unmarshal a ScoreMessage from a buffer

func UnmarshalStake

func UnmarshalStake(r *bytes.Buffer, tx *transactions.Stake) error

UnmarshalStake from a buffer

func UnmarshalStandard

func UnmarshalStandard(w *bytes.Buffer, s *transactions.Standard) error

UnmarshalStandard tx from a buffer

func UnmarshalTimelock

func UnmarshalTimelock(r *bytes.Buffer, tx *transactions.Timelock) error

UnmarshalTimelock tx from a buffer

func UnmarshalTx

func UnmarshalTx(r *bytes.Buffer) (transactions.Transaction, error)

UnmarshalTx unmarshals a tx from a buffer

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 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) 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(signedVotes []byte)

SetSignature set a signature to the Agreement

func (Agreement) SignedVotes

func (a Agreement) SignedVotes() []byte

SignedVotes 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 Candidate

type Candidate struct {
	*block.Block
	*block.Certificate
}

Candidate is the composition of block and certificates

func MakeCandidate

func MakeCandidate(blk *block.Block, cert *block.Certificate) Candidate

MakeCandidate creates a Candidate from a block and a certificate. It is meant for actual creation of the Candidate, rather than struct-decoding of a transmitted one

func NewCandidate

func NewCandidate() *Candidate

NewCandidate is used for instantiating a new Candidate

func (Candidate) Equal

func (c Candidate) Equal(m Message) bool

Equal is needed by the message.Message interface

func (Candidate) Sender

func (c Candidate) Sender() []byte

Sender is empty (as the BG sends the Candidate in all confidentiality)

func (Candidate) State

func (c Candidate) State() header.Header

State is for complying to the consensus.Message interface. In the case of Candidate, the Step does not make sense (since we have one block per round) and the Sender is anonymous in nature

func (Candidate) String

func (c Candidate) String() string

String representation of the Candidate

type Message

type Message interface {
	//fmt.Stringer
	Category() topics.Topic
	Payload() interface{}
	Equal(Message) bool
	Id() []byte
}

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 New

func New(t topics.Topic, payload interface{}) Message

New creates a new Message

func Unmarshal

func Unmarshal(b *bytes.Buffer) (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 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) Equal

func (r Reduction) Equal(msg Message) bool

Equal is used to comply to consensus.Message

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 Score

type Score struct {
	ScoreProposal
	PrevHash []byte
	VoteHash []byte
}

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

func EmptyScore

func EmptyScore() Score

EmptyScore is used primarily to initialize the Score, since empty scores should not be propagated externally

func MockScore

func MockScore(hdr header.Header, hash []byte) Score

MockScore mocks a Score and returns it.

func NewScore

func NewScore(proposal ScoreProposal, pubkey, prevHash, voteHash []byte) *Score

NewScore creates a new Score from a proposal

func (Score) Equal

func (e Score) Equal(s Score) bool

Equal tests if two Scores are equal

func (Score) String

func (e Score) String() string

String representation of a Score

type ScoreProposal

type ScoreProposal struct {
	Score         []byte
	Proof         []byte
	Z             []byte
	BidListSubset []byte
	Seed          []byte
	// contains filtered or unexported fields
}

ScoreProposal is an internal packet created by the node. the Score Message with the fields consistent with the Blind Bid data structure

func EmptyScoreProposal

func EmptyScoreProposal(hdr header.Header) ScoreProposal

EmptyScoreProposal is used to initialize a ScoreProposal. It is used primarily by the internal Score generator

func MockScoreProposal

func MockScoreProposal(hdr header.Header) ScoreProposal

MockScoreProposal mocks a ScoreProposal up

func NewScoreProposal

func NewScoreProposal(hdr header.Header, seed []byte, proof zkproof.ZkProof) ScoreProposal

NewScoreProposal creates a new ScoreProposa

func (ScoreProposal) IsEmpty

func (e ScoreProposal) IsEmpty() bool

IsEmpty tests a ScoreProposal for emptyness

func (ScoreProposal) Sender

func (e ScoreProposal) Sender() []byte

Sender of a Score event is the anonymous Z

func (ScoreProposal) State

func (e ScoreProposal) State() header.Header

State is used to comply to the consensus.Message interface

func (ScoreProposal) String

func (e ScoreProposal) String() string

String representation of the ScoreProposal

type Serializable

type Serializable interface {
	SetPayload(interface{})
}

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 {
	Apk       *bls.Apk
	BitSet    uint64
	Signature *bls.Signature
	Step      uint8
}

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 []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, sender []byte, step uint8) error

Add a vote to the StepVotes struct.

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 {
	StepVotes
	// contains filtered or unexported fields
}

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) StepVotesMsg

NewStepVotesMsg creates a 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)

Jump to

Keyboard shortcuts

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