broadcast

package
v0.0.0-...-782863c Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package broadcast implements the network broadcast and consensus within a shard.

Index

Constants

This section is empty.

Variables

View Source
var OP_name = map[int32]string{
	0: "UNKNOWN",
	1: "ACK_BROADCAST",
	2: "BROADCAST",
	3: "GET_BLOCKS",
	4: "GET_ROUNDS",
	5: "LIST_BLOCKS",
}
View Source
var OP_value = map[string]int32{
	"UNKNOWN":       0,
	"ACK_BROADCAST": 1,
	"BROADCAST":     2,
	"GET_BLOCKS":    3,
	"GET_ROUNDS":    4,
	"LIST_BLOCKS":   5,
}

Functions

func Replay

func Replay(dir string, nodeID uint64, g *blockmania.Graph, start uint64, batch int) error

Replay loads all blocks from the given start point and replays them onto the graph in the given batch size.

Types

type AckBroadcast

type AckBroadcast struct {
	Last                 uint64   `protobuf:"varint,1,opt,name=last,proto3" json:"last,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*AckBroadcast) Descriptor

func (*AckBroadcast) Descriptor() ([]byte, []int)

func (*AckBroadcast) GetLast

func (m *AckBroadcast) GetLast() uint64

func (*AckBroadcast) ProtoMessage

func (*AckBroadcast) ProtoMessage()

func (*AckBroadcast) Reset

func (m *AckBroadcast) Reset()

func (*AckBroadcast) String

func (m *AckBroadcast) String() string

func (*AckBroadcast) XXX_DiscardUnknown

func (m *AckBroadcast) XXX_DiscardUnknown()

func (*AckBroadcast) XXX_Marshal

func (m *AckBroadcast) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*AckBroadcast) XXX_Merge

func (dst *AckBroadcast) XXX_Merge(src proto.Message)

func (*AckBroadcast) XXX_Size

func (m *AckBroadcast) XXX_Size() int

func (*AckBroadcast) XXX_Unmarshal

func (m *AckBroadcast) XXX_Unmarshal(b []byte) error

type Block

type Block struct {
	Node                 uint64        `protobuf:"varint,1,opt,name=node,proto3" json:"node,omitempty"`
	Previous             *SignedData   `protobuf:"bytes,2,opt,name=previous" json:"previous,omitempty"`
	References           []*SignedData `protobuf:"bytes,3,rep,name=references" json:"references,omitempty"`
	Round                uint64        `protobuf:"varint,4,opt,name=round,proto3" json:"round,omitempty"`
	Transactions         *Transactions `protobuf:"bytes,5,opt,name=transactions" json:"transactions,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

func (*Block) Descriptor

func (*Block) Descriptor() ([]byte, []int)

func (*Block) GetNode

func (m *Block) GetNode() uint64

func (*Block) GetPrevious

func (m *Block) GetPrevious() *SignedData

func (*Block) GetReferences

func (m *Block) GetReferences() []*SignedData

func (*Block) GetRound

func (m *Block) GetRound() uint64

func (*Block) GetTransactions

func (m *Block) GetTransactions() *Transactions

func (*Block) Iter

func (b *Block) Iter() *TxIterator

Iter returns a iterator for the block's transactions.

func (*Block) ProtoMessage

func (*Block) ProtoMessage()

func (*Block) Reset

func (m *Block) Reset()

func (*Block) String

func (m *Block) String() string

func (*Block) XXX_DiscardUnknown

func (m *Block) XXX_DiscardUnknown()

func (*Block) XXX_Marshal

func (m *Block) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Block) XXX_Merge

func (dst *Block) XXX_Merge(src proto.Message)

func (*Block) XXX_Size

func (m *Block) XXX_Size() int

func (*Block) XXX_Unmarshal

func (m *Block) XXX_Unmarshal(b []byte) error

type BlockReference

type BlockReference struct {
	Hash                 []byte   `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
	Node                 uint64   `protobuf:"varint,2,opt,name=node,proto3" json:"node,omitempty"`
	Round                uint64   `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*BlockReference) Descriptor

func (*BlockReference) Descriptor() ([]byte, []int)

func (*BlockReference) GetHash

func (m *BlockReference) GetHash() []byte

func (*BlockReference) GetNode

func (m *BlockReference) GetNode() uint64

func (*BlockReference) GetRound

func (m *BlockReference) GetRound() uint64

func (*BlockReference) ProtoMessage

func (*BlockReference) ProtoMessage()

func (*BlockReference) Reset

func (m *BlockReference) Reset()

func (*BlockReference) Size

func (b *BlockReference) Size() int

Size returns the rough size of a BlockReference in bytes.

func (*BlockReference) String

func (m *BlockReference) String() string

func (*BlockReference) XXX_DiscardUnknown

func (m *BlockReference) XXX_DiscardUnknown()

func (*BlockReference) XXX_Marshal

func (m *BlockReference) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BlockReference) XXX_Merge

func (dst *BlockReference) XXX_Merge(src proto.Message)

func (*BlockReference) XXX_Size

func (m *BlockReference) XXX_Size() int

func (*BlockReference) XXX_Unmarshal

func (m *BlockReference) XXX_Unmarshal(b []byte) error

type Broadcaster

type Broadcaster interface {
	AddTransaction(txdata []byte, fee uint64) error
	Register(cb Callback)
}

type Callback

type Callback func(round uint64, blocks []*SignedData)

Callback defines the delivery callback registered with the broadcast service. The callback should call Acknowledge at some point so as to mark the delivery of the round as successful.

type Config

type Config struct {
	Broadcast     *config.Broadcast
	Connections   *config.Connections
	Directory     string
	Key           signature.KeyPair
	Keys          map[uint64]signature.PublicKey
	MaxPayload    int
	NetConsensus  *config.NetConsensus
	NodeConsensus *config.NodeConsensus
	NodeID        uint64
	Peers         []uint64
}

Config for the broadcast service.

type GetBlocks

type GetBlocks struct {
	Blocks               []*BlockReference `protobuf:"bytes,1,rep,name=blocks" json:"blocks,omitempty"`
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func (*GetBlocks) Descriptor

func (*GetBlocks) Descriptor() ([]byte, []int)

func (*GetBlocks) GetBlocks

func (m *GetBlocks) GetBlocks() []*BlockReference

func (*GetBlocks) ProtoMessage

func (*GetBlocks) ProtoMessage()

func (*GetBlocks) Reset

func (m *GetBlocks) Reset()

func (*GetBlocks) String

func (m *GetBlocks) String() string

func (*GetBlocks) XXX_DiscardUnknown

func (m *GetBlocks) XXX_DiscardUnknown()

func (*GetBlocks) XXX_Marshal

func (m *GetBlocks) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetBlocks) XXX_Merge

func (dst *GetBlocks) XXX_Merge(src proto.Message)

func (*GetBlocks) XXX_Size

func (m *GetBlocks) XXX_Size() int

func (*GetBlocks) XXX_Unmarshal

func (m *GetBlocks) XXX_Unmarshal(b []byte) error

type GetRounds

type GetRounds struct {
	Rounds               []uint64 `protobuf:"varint,1,rep,packed,name=rounds" json:"rounds,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GetRounds) Descriptor

func (*GetRounds) Descriptor() ([]byte, []int)

func (*GetRounds) GetRounds

func (m *GetRounds) GetRounds() []uint64

func (*GetRounds) ProtoMessage

func (*GetRounds) ProtoMessage()

func (*GetRounds) Reset

func (m *GetRounds) Reset()

func (*GetRounds) String

func (m *GetRounds) String() string

func (*GetRounds) XXX_DiscardUnknown

func (m *GetRounds) XXX_DiscardUnknown()

func (*GetRounds) XXX_Marshal

func (m *GetRounds) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetRounds) XXX_Merge

func (dst *GetRounds) XXX_Merge(src proto.Message)

func (*GetRounds) XXX_Size

func (m *GetRounds) XXX_Size() int

func (*GetRounds) XXX_Unmarshal

func (m *GetRounds) XXX_Unmarshal(b []byte) error

type ListBlocks

type ListBlocks struct {
	Blocks               []*SignedData `protobuf:"bytes,1,rep,name=blocks" json:"blocks,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

func (*ListBlocks) Descriptor

func (*ListBlocks) Descriptor() ([]byte, []int)

func (*ListBlocks) GetBlocks

func (m *ListBlocks) GetBlocks() []*SignedData

func (*ListBlocks) ProtoMessage

func (*ListBlocks) ProtoMessage()

func (*ListBlocks) Reset

func (m *ListBlocks) Reset()

func (*ListBlocks) String

func (m *ListBlocks) String() string

func (*ListBlocks) XXX_DiscardUnknown

func (m *ListBlocks) XXX_DiscardUnknown()

func (*ListBlocks) XXX_Marshal

func (m *ListBlocks) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ListBlocks) XXX_Merge

func (dst *ListBlocks) XXX_Merge(src proto.Message)

func (*ListBlocks) XXX_Size

func (m *ListBlocks) XXX_Size() int

func (*ListBlocks) XXX_Unmarshal

func (m *ListBlocks) XXX_Unmarshal(b []byte) error

type OP

type OP int32
const (
	OP_UNKNOWN       OP = 0
	OP_ACK_BROADCAST OP = 1
	OP_BROADCAST     OP = 2
	OP_GET_BLOCKS    OP = 3
	OP_GET_ROUNDS    OP = 4
	OP_LIST_BLOCKS   OP = 5
)

func (OP) EnumDescriptor

func (OP) EnumDescriptor() ([]byte, []int)

func (OP) String

func (x OP) String() string

type Service

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

Service implements the broadcast and consensus system.

TODO(tav): pad/re-order to minimise false sharing.

func New

func New(ctx context.Context, cfg *Config, top *network.Topology) (*Service, error)

New returns a fully instantiated broadcaster service.

func (*Service) Acknowledge

func (s *Service) Acknowledge(round uint64)

Acknowledge should be called by BroadcastEnd in the registered Callback to mark a particular round as being fully delivered. If not, all unacknowledged rounds will be replayed when the node restarts.

func (*Service) AddTransaction

func (s *Service) AddTransaction(txdata []byte, fee uint64) error

AddTransaction adds the given transaction data onto a queue to be added to the current block.

func (*Service) Handle

func (s *Service) Handle(peerID uint64, msg *service.Message) (*service.Message, error)

Handle implements the service Handler interface for handling messages received over a connection.

func (*Service) Name

func (s *Service) Name() string

Name specifies the name of the service for use in debugging service handlers.

func (*Service) Register

func (s *Service) Register(cb Callback)

Register saves the given callback to be called when transactions have reached consensus. It'll also trigger the replaying of any unacknowledged rounds.

type SignedData

type SignedData struct {
	Data                 []byte   `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	Signature            []byte   `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

The data of a SignedData may either be an encoded Block or BlockReference.

func (*SignedData) Block

func (s *SignedData) Block() (*Block, error)

Block returns the decoded Block struct assuming the SignedData is of a Block.

func (*SignedData) Descriptor

func (*SignedData) Descriptor() ([]byte, []int)

func (*SignedData) Digest

func (s *SignedData) Digest() []byte

Digest returns the hash of the underlying data.

func (*SignedData) GetData

func (m *SignedData) GetData() []byte

func (*SignedData) GetSignature

func (m *SignedData) GetSignature() []byte

func (*SignedData) ProtoMessage

func (*SignedData) ProtoMessage()

func (*SignedData) Reset

func (m *SignedData) Reset()

func (*SignedData) Size

func (s *SignedData) Size() int

Size returns the rough size of the SignedData in bytes.

func (*SignedData) String

func (m *SignedData) String() string

func (*SignedData) XXX_DiscardUnknown

func (m *SignedData) XXX_DiscardUnknown()

func (*SignedData) XXX_Marshal

func (m *SignedData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SignedData) XXX_Merge

func (dst *SignedData) XXX_Merge(src proto.Message)

func (*SignedData) XXX_Size

func (m *SignedData) XXX_Size() int

func (*SignedData) XXX_Unmarshal

func (m *SignedData) XXX_Unmarshal(b []byte) error

type TransactionData

type TransactionData struct {
	Data []byte
	Fee  uint64
}

TransactionData represents the transaction's combined data and fee.

type TransactionList

type TransactionList []TransactionData

TransactionList wraps a slice of TransactionData for the purposes of sorting.

func (TransactionList) Sort

func (t TransactionList) Sort()

Sort orders the TransactionList in descending order of the transaction fee and then hash if the fees are equal.

type Transactions

type Transactions struct {
	Count                uint64   `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"`
	Data                 []byte   `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Transactions) Descriptor

func (*Transactions) Descriptor() ([]byte, []int)

func (*Transactions) GetCount

func (m *Transactions) GetCount() uint64

func (*Transactions) GetData

func (m *Transactions) GetData() []byte

func (*Transactions) ProtoMessage

func (*Transactions) ProtoMessage()

func (*Transactions) Reset

func (m *Transactions) Reset()

func (*Transactions) String

func (m *Transactions) String() string

func (*Transactions) XXX_DiscardUnknown

func (m *Transactions) XXX_DiscardUnknown()

func (*Transactions) XXX_Marshal

func (m *Transactions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Transactions) XXX_Merge

func (dst *Transactions) XXX_Merge(src proto.Message)

func (*Transactions) XXX_Size

func (m *Transactions) XXX_Size() int

func (*Transactions) XXX_Unmarshal

func (m *Transactions) XXX_Unmarshal(b []byte) error

type TxIterator

type TxIterator struct {
	TxData []byte
	TxFee  uint64
	// contains filtered or unexported fields
}

TxIterator provides support for iterating over a Block's transactions.

func (*TxIterator) Next

func (t *TxIterator) Next()

Next moves the iterator forward. The TxData and TxFee values of the iterator are only valid until the next call to Next().

func (*TxIterator) Valid

func (t *TxIterator) Valid() bool

Valid returns whether the iterator is still valid and has more elements to iterate over.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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