cleisthenes

package module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

README

Cleisthenes License Language Coverage Status Build Status

Cleisthenes is HBBFT(Honey Badger Byzantine Fault Tolerance) consensus library adaptable to any application.

Documentation

More detail of each component is documented here

  • HoneyBadgerBFT Overview [KO / EN]
  • Reliable Broadcast (RBC) [KO / EN]
  • Byzantine Binary Agreement (BBA) [KO / EN]
  • Threshold Encryption (TE) [KO / EN]

Architecture

Logical View

HoneyBadger (HB) receives transaction from Application and queuing them into its own buffer, HB also manages consensus epoch which helps to distinguish every consensus. Everytime new epoch starts, HB creates batch with its own transactions, then sends it to the ACS to consensus this batch and other nodes' batch.

Asynchronous Common Set (ACS) is main API of Honey Badger BFT where agreement takes place. ACS uses RBC and BBA to consensus its own node batch as well as other nodes' batch who joined to same network.

Reliable Broadcast (RBC) distribute single node's batch to the rest of the nodes in the network. The result of RBC is set of batches of all nodes in the network. RBC guarantees that every node gets the same output, event if the sender or other nodes try to sending different information to different nodes.

Byzantine Binary Agreement (BBA) determines whether or not a batch is included in the set of batches, based on a composite of votes from all nodes in the network. BBA is completed once more than 2/3 of the participating nodes agree on whether to include the batch in the set of batches.

Module View

Contribution

Contribution Guide CONTRIBUTION

CLA Hub

To get started, sign the Contributor License Agreement.

Documentation

Index

Constants

View Source
const (
	DefaultDialTimeout = 3 * time.Second
)

Variables

View Source
var ErrUndefinedRequestType = errors.New("unexpected request type")

Functions

This section is empty.

Types

type AbstractTx

type AbstractTx map[string]interface{}

type Address

type Address struct {
	Ip   string
	Port uint16
}

func ToAddress

func ToAddress(addrStr string) (Address, error)

func (Address) String

func (a Address) String() string

type Batch

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

TODO: should be removed, after ACS merged TODO: ACS should use BatchMessage instead

func (*Batch) TxList

func (batch *Batch) TxList() []Transaction

TxList is a function returns the transaction list on batch

type BatchChannel

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

func NewBatchChannel

func NewBatchChannel(size int) *BatchChannel

func (*BatchChannel) Receive

func (c *BatchChannel) Receive() <-chan BatchMessage

func (*BatchChannel) Send

func (c *BatchChannel) Send(msg BatchMessage)

type BatchMessage

type BatchMessage struct {
	Epoch Epoch
	Batch map[Member][]byte
}

Batch is result of ACS set of contributions of at least n-f number of nodes. BatchMessage is used between ACS component and Honeybadger component.

After ACS done its own task for its epoch send BatchMessage to Honeybadger, then Honeybadger decrypt batch message.

type BatchReceiver

type BatchReceiver interface {
	Receive() <-chan BatchMessage
}

type BatchSender

type BatchSender interface {
	Send(msg BatchMessage)
}

type Binary

type Binary = bool
const (
	One  Binary = true
	Zero        = false
)

type BinaryChannel

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

func NewBinaryChannel

func NewBinaryChannel(size int) *BinaryChannel

func (*BinaryChannel) Receive

func (c *BinaryChannel) Receive() <-chan BinaryMessage

func (*BinaryChannel) Send

func (c *BinaryChannel) Send(msg BinaryMessage)

type BinaryMessage

type BinaryMessage struct {
	Member Member
	Binary Binary
}

type BinaryReceiver

type BinaryReceiver interface {
	Receive() <-chan BinaryMessage
}

type BinarySender

type BinarySender interface {
	Send(msg BinaryMessage)
}

type BinaryState

type BinaryState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBinaryState

func NewBinaryState() *BinaryState

func (*BinaryState) Set

func (b *BinaryState) Set(bin Binary)

func (*BinaryState) Undefined

func (b *BinaryState) Undefined() bool

func (*BinaryState) Value

func (b *BinaryState) Value() Binary

type Broadcaster

type Broadcaster interface {
	// ShareMessage is a function that broadcast Single message to all nodes
	ShareMessage(msg pb.Message)

	// DistributeMessage is a function that broadcast multiple different messages one by one to all nodes
	DistributeMessage(msgList []pb.Message)
}

type CStreamWrapper

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

client side stream wrapper

func (*CStreamWrapper) Close

func (csw *CStreamWrapper) Close()

func (*CStreamWrapper) GetStream

func (csw *CStreamWrapper) GetStream() Stream

func (*CStreamWrapper) Recv

func (csw *CStreamWrapper) Recv() (*pb.Message, error)

func (*CStreamWrapper) Send

func (csw *CStreamWrapper) Send(message *pb.Message) error

type CipherText

type CipherText []byte

type Coin

type Coin Binary

type CoinGenerator

type CoinGenerator interface {
	Coin(uint64) Coin
}

type ConnHandler

type ConnHandler func(conn Connection)

type ConnId

type ConnId = string

type Connection

type Connection interface {
	Send(msg pb.Message, successCallBack func(interface{}), errCallBack func(error))
	Ip() Address
	Id() ConnId
	Close()
	Start() error
	Handle(handler Handler)
}

func NewConnection

func NewConnection(ip Address, id ConnId, streamWrapper StreamWrapper) (Connection, error)

type ConnectionPool

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

func NewConnectionPool

func NewConnectionPool() *ConnectionPool

func (*ConnectionPool) Add

func (p *ConnectionPool) Add(addr Address, conn Connection)

func (*ConnectionPool) DistributeMessage

func (p *ConnectionPool) DistributeMessage(msgList []pb.Message)

func (*ConnectionPool) GetAll

func (p *ConnectionPool) GetAll() []Connection

func (*ConnectionPool) Remove

func (p *ConnectionPool) Remove(addr Address)

func (*ConnectionPool) ShareMessage

func (p *ConnectionPool) ShareMessage(msg pb.Message)

type Contribution

type Contribution struct {
	TxList []Transaction
}

type DataChannel

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

func NewDataChannel

func NewDataChannel(size int) *DataChannel

func (*DataChannel) Receive

func (c *DataChannel) Receive() <-chan DataMessage

func (*DataChannel) Send

func (c *DataChannel) Send(msg DataMessage)

type DataMessage

type DataMessage struct {
	Member Member
	Data   []byte
}

type DataReceiver

type DataReceiver interface {
	Receive() <-chan DataMessage
}

type DataSender

type DataSender interface {
	Send(msg DataMessage)
}

type DecryptionShare

type DecryptionShare [96]byte

type DefaultTxQueueManager

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

func NewDefaultTxQueueManager

func NewDefaultTxQueueManager(
	txQueue TxQueue,
	hb HoneyBadger,
	contributionSize int,
	batchSize int,

	tryInterval time.Duration,

	txVerifier TxValidator,
) *DefaultTxQueueManager

func (*DefaultTxQueueManager) AddTransaction

func (m *DefaultTxQueueManager) AddTransaction(tx Transaction) error

func (*DefaultTxQueueManager) Close

func (m *DefaultTxQueueManager) Close()

type DialOpts

type DialOpts struct {
	// Ip is target address which grpc client is going to dial
	Addr Address

	// Duration for which to block while established a new connection
	Timeout time.Duration
}

type Epoch

type Epoch uint64

type ErrHandler

type ErrHandler func(err error)

type GrpcClient

type GrpcClient struct{}

func NewClient

func NewClient() *GrpcClient

func (GrpcClient) Dial

func (c GrpcClient) Dial(opts DialOpts) (Connection, error)

type GrpcConnection

type GrpcConnection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*GrpcConnection) Close

func (conn *GrpcConnection) Close()

func (*GrpcConnection) Handle

func (conn *GrpcConnection) Handle(handler Handler)

func (*GrpcConnection) Id

func (conn *GrpcConnection) Id() ConnId

func (*GrpcConnection) Ip

func (conn *GrpcConnection) Ip() Address

func (*GrpcConnection) Send

func (conn *GrpcConnection) Send(msg pb.Message, successCallBack func(interface{}), errCallBack func(error))

func (*GrpcConnection) Start

func (conn *GrpcConnection) Start() error

type GrpcServer

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

func NewServer

func NewServer(addr Address) *GrpcServer

func (*GrpcServer) Listen

func (s *GrpcServer) Listen()

func (GrpcServer) MessageStream

func (s GrpcServer) MessageStream(streamServer pb.StreamService_MessageStreamServer) error

MessageStream handle request to connection from remote peer. First, configure ip of remote peer, then based on that info create connection after that handler of server process handles that connection.

func (*GrpcServer) OnConn

func (s *GrpcServer) OnConn(handler ConnHandler)

func (*GrpcServer) OnErr

func (s *GrpcServer) OnErr(handler ErrHandler)

func (*GrpcServer) Stop

func (s *GrpcServer) Stop()

type Handler

type Handler interface {
	ServeRequest(msg Message)
}

request handler

type HoneyBadger

type HoneyBadger interface {
	HandleContribution(contribution Contribution)
	HandleMessage(msg *pb.Message) error
	OnConsensus() bool
}

type MemCacheTracer

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

func NewMemCacheTracer

func NewMemCacheTracer() *MemCacheTracer

func (*MemCacheTracer) Log

func (t *MemCacheTracer) Log(keyvals ...string)

func (*MemCacheTracer) Trace

func (t *MemCacheTracer) Trace()

type MemTxQueue

type MemTxQueue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

memQueue defines transaction FIFO memQueue

func NewTxQueue

func NewTxQueue() *MemTxQueue

func (*MemTxQueue) Len

func (q *MemTxQueue) Len() int

len returns size of memQueue

func (*MemTxQueue) Poll

func (q *MemTxQueue) Poll() (Transaction, error)

Poll returns first element of memQueue, and erase it.

func (*MemTxQueue) Push

func (q *MemTxQueue) Push(tx Transaction)

Push adds transaction to memQueue.

type Member

type Member struct {
	Address Address
}

Member contains Node information who participate in the network

func NewMember

func NewMember(host string, port uint16) *Member

func NewMemberWithAddress

func NewMemberWithAddress(addr Address) *Member

type MemberMap

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

MemberMap manages members information

func NewMemberMap

func NewMemberMap() *MemberMap

func (*MemberMap) Add

func (m *MemberMap) Add(member *Member)

func (*MemberMap) Del

func (m *MemberMap) Del(addr Address)

func (*MemberMap) Member

func (m *MemberMap) Member(addr Address) (Member, bool)

func (*MemberMap) Members

func (m *MemberMap) Members() []Member

AllMembers returns current members into array format

type Message

type Message struct {
	*pb.Message
	Conn Connection
}

message used with other nodes

type MessageEndpoint

type MessageEndpoint interface {
	HandleMessage(*pb.Message) error
}

type PublicKey

type PublicKey []byte

type Request

type Request interface {
	Recv()
}

type RequestRepository

type RequestRepository interface {
	Save(addr Address, req Request) error
	Find(addr Address) (Request, error)
	FindAll() []Request
}

type ResultChannel

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

func NewResultChannel

func NewResultChannel(size int) *ResultChannel

func (*ResultChannel) Receive

func (c *ResultChannel) Receive() <-chan ResultMessage

func (*ResultChannel) Send

func (c *ResultChannel) Send(msg ResultMessage)

type ResultMessage

type ResultMessage struct {
	Epoch Epoch
	Batch []AbstractTx
}

ResultMessage is result of Honeybadger. When Honeybadger receive BatchMessage from ACS, it decrypt BatchMessage and use it to ResultMessage.Batch field.

Honeybadger knows what epoch of ACS done its task. and Honeybadger use that information of epoch and decrypted batch to create ResultMessage then send it back to application

type ResultReceiver

type ResultReceiver interface {
	Receive() <-chan ResultMessage
}

type ResultSender

type ResultSender interface {
	Send(msg ResultMessage)
}

type SStreamWrapper

type SStreamWrapper struct {
	ServerStream pb.StreamService_MessageStreamServer
	// contains filtered or unexported fields
}

server side stream wrapper

func (*SStreamWrapper) Close

func (ssw *SStreamWrapper) Close()

func (*SStreamWrapper) GetStream

func (ssw *SStreamWrapper) GetStream() Stream

func (*SStreamWrapper) Recv

func (ssw *SStreamWrapper) Recv() (*pb.Message, error)

func (*SStreamWrapper) Send

func (ssw *SStreamWrapper) Send(message *pb.Message) error

type SecretKey

type SecretKey [32]byte

type Stream

type Stream interface {
	Send(message *pb.Message) error
	Recv() (*pb.Message, error)
}

type StreamWrapper

type StreamWrapper interface {
	Stream
	Close()
	GetStream() Stream
}

func NewClientStreamWrapper

func NewClientStreamWrapper(conn *grpc.ClientConn) (StreamWrapper, error)

func NewServerStreamWrapper

func NewServerStreamWrapper(serverStream pb.StreamService_MessageStreamServer, cancel context.CancelFunc) StreamWrapper

type Tpke

type Tpke interface {
	Encrypt(msg interface{}) ([]byte, error)
	DecShare(ctBytes []byte) DecryptionShare
	Decrypt(enc []byte) ([]Transaction, error)
	AcceptDecShare(addr Address, decShare DecryptionShare)
	ClearDecShare()
}

type Tracer

type Tracer interface {
	Log(keyvals ...string)
	Trace()
}

type Transaction

type Transaction interface{}

type TxQueue

type TxQueue interface {
	Push(tx Transaction)
	Poll() (Transaction, error)
	Len() int
}

type TxQueueManager

type TxQueueManager interface {
	AddTransaction(tx Transaction) error
}

TxQueueManager manages transaction queue. It receive transaction from client and TxQueueManager have its own policy to propose contribution to honeybadger

type TxValidator

type TxValidator func(Transaction) bool

Directories

Path Synopsis
cmd
example
app
rbc
test
acs
bba
rbc

Jump to

Keyboard shortcuts

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