byzcoin

package
v0.0.0-...-53feb6c Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2016 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package byzcoin store a novel way of implementing the Bitcoin protocol using CoSi for signing sidechains.

Index

Constants

View Source
const ReadFirstNBlocks = 400

ReadFirstNBlocks specifcy how many blocks in the the BlocksDir it must read (so you only have to copy the first blocks to deterLab)

Variables

This section is empty.

Functions

func GetBlock

func GetBlock(transactions []blkparser.Tx, lastBlock, lastKeyBlock string) (*blockchain.TrBlock, error)

GetBlock returns the next block available from the transaction pool.

func NewSimulation

func NewSimulation(config string) (sda.Simulation, error)

NewSimulation returns a fresh byzcoin simulation out of the toml config

func VerifyBlock

func VerifyBlock(block *blockchain.TrBlock, lastBlock, lastKeyBlock string, done chan bool)

VerifyBlock is a simulation of a real verification block algorithm

Types

type Announce

type Announce struct {
	*cosi.Announcement
	TYPE    RoundType
	Timeout uint64
}

Announce is the struct used during the announcement phase (of both rounds)

type BlockServer

type BlockServer interface {
	AddTransaction(blkparser.Tx)
	Instantiate(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error)
}

BlockServer is a struct where Client can connect and that instantiate ByzCoin protocols when needed.

type BlockSignature

type BlockSignature struct {
	// cosi signature of the commit round.
	Sig *cosi.Signature
	// the block signed.
	Block *blockchain.TrBlock
	// List of peers that did not want to sign.
	Exceptions []cosi.Exception
}

BlockSignature is what a byzcoin protocol outputs. It contains the signature, the block and some possible exceptions.

type ByzCoin

type ByzCoin struct {
	// the node we are represented-in
	*sda.TreeNodeInstance
	// contains filtered or unexported fields
}

ByzCoin is the main struct for running the protocol

func NewByzCoinProtocol

func NewByzCoinProtocol(n *sda.TreeNodeInstance) (*ByzCoin, error)

NewByzCoinProtocol returns a new byzcoin struct

func NewByzCoinRootProtocol

func NewByzCoinRootProtocol(n *sda.TreeNodeInstance, transactions []blkparser.Tx, timeOutMs uint64, failMode uint) (*ByzCoin, error)

NewByzCoinRootProtocol returns a new byzcoin struct with the block to sign that will be sent to all others nodes

func (*ByzCoin) Dispatch

func (bz *ByzCoin) Dispatch() error

Dispatch listen on the different channels

func (*ByzCoin) RegisterOnDone

func (bz *ByzCoin) RegisterOnDone(fn func())

RegisterOnDone registers a callback to call when the byzcoin protocols has really finished (after a view change maybe)

func (*ByzCoin) RegisterOnSignatureDone

func (bz *ByzCoin) RegisterOnSignatureDone(fn func(*BlockSignature))

RegisterOnSignatureDone register a callback to call when the byzcoin protocol reached a signature on the block

func (*ByzCoin) Signature

func (bz *ByzCoin) Signature() *BlockSignature

Signature will generate the final signature, the output of the ByzCoin protocol.

func (*ByzCoin) Start

func (bz *ByzCoin) Start() error

Start will start both rounds "prepare" and "commit" at same time. The "commit" round will wait the end of the "prepare" round during its challenge phase.

type ChallengeCommit

type ChallengeCommit struct {
	TYPE RoundType
	*cosi.Challenge
	// Signature is the basic signature Challenge / response
	Signature *cosi.Signature
	// Exception is the list of peers that did not want to sign. It's needed for
	// verifying the signature. It can not be spoofed otherwise the signature
	// would be wrong.
	Exceptions []cosi.Exception
}

ChallengeCommit is the challenge used by ByzCoin during the "commit" phase. It contains the basic challenge (out of the block we want to sign) + the signature of the "prepare" round. It also contains the exception list coming from the "prepare" phase. This exception list has been collected by the root during the response of the "prepare" phase and broadcast it through the challenge of the "commit". These are needed in order to verify the signature and to see how many peers did not sign. It's not spoofable because otherwise the signature verification will be wrong.

type ChallengePrepare

type ChallengePrepare struct {
	TYPE RoundType
	*cosi.Challenge
	*blockchain.TrBlock
}

ChallengePrepare is the challenge used by ByzCoin during the "prepare" phase. It contains the basic challenge plus the transactions from where the challenge has been generated.

type Client

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

Client is a client simulation. At the moment we do not measure the communication between client and server. Hence, we do not even open a real network connection

func NewClient

func NewClient(s BlockServer) *Client

NewClient returns a fresh new client out of a blockserver

func (*Client) StartClientSimulation

func (c *Client) StartClientSimulation(blocksDir string, numTxs int) error

StartClientSimulation can be called from outside (from an simulation implementation) to simulate a client. Parameters: blocksDir is the directory where to find the transaction blocks (.dat files) numTxs is the number of transactions the client will create

type Commitment

type Commitment struct {
	TYPE RoundType
	*cosi.Commitment
}

Commitment is the commitment packets that is sent for both rounds

type Response

type Response struct {
	*cosi.Response
	Exceptions []cosi.Exception
	TYPE       RoundType
}

Response is the struct used by ByzCoin during the response. It contains the response + the basic exception list.

type RoundType

type RoundType int32

RoundType is a type to know if we are in the "prepare" round or the "commit" round

const (
	// RoundPrepare is the first round (prepare)
	RoundPrepare RoundType = iota
	// RoundCommit is the final round (Commit)
	RoundCommit
)

type Server

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

Server is the long-term control service that listens for transactions and dispatch them to a new ByzCoin for each new signing that we want to do. It creates the ByzCoin protocols and run them. only used by the root since only the root participates to the creation of the block.

func NewByzCoinServer

func NewByzCoinServer(blockSize int, timeOutMs uint64, fail uint) *Server

NewByzCoinServer returns a new fresh ByzCoinServer. It must be given the blockSize in order to efficiently give the transactions to the ByzCoin instances.

func (*Server) AddTransaction

func (s *Server) AddTransaction(tr blkparser.Tx)

AddTransaction add a new transactions to the list of transactions to commit

func (*Server) BlockSignaturesChan

func (s *Server) BlockSignaturesChan() <-chan BlockSignature

BlockSignaturesChan returns a channel that is given each new block signature as soon as they are arrive (Wether correct or not).

func (*Server) Instantiate

func (s *Server) Instantiate(node *sda.TreeNodeInstance) (sda.ProtocolInstance, error)

Instantiate takes blockSize transactions and create the byzcoin instances.

func (*Server) ListenClientTransactions

func (s *Server) ListenClientTransactions()

ListenClientTransactions will bind to a port a listen for incoming connection from clients. These client will be able to pass the transactions to the server.

func (*Server) WaitEnoughBlocks

func (s *Server) WaitEnoughBlocks() []blkparser.Tx

WaitEnoughBlocks is called to wait on the server until it has enough transactions to make a block

type Simulation

type Simulation struct {
	// sda fields:
	sda.SimulationBFTree
	// your simulation specific fields:
	SimulationConfig
}

Simulation implements da.Simulation interface

func (*Simulation) Run

func (e *Simulation) Run(sdaConf *sda.SimulationConfig) error

Run implements sda.Simulation interface

func (*Simulation) Setup

func (e *Simulation) Setup(dir string, hosts []string) (*sda.SimulationConfig, error)

Setup implements sda.Simulation interface. It checks on the availability of the block-file and downloads it if missing. Then the block-file will be copied to the simulation-directory

type SimulationConfig

type SimulationConfig struct {
	// Blocksize is the number of transactions in one block:
	Blocksize int
	// timeout the leader after TimeoutMs milliseconds
	TimeoutMs uint64
	// Fail:
	// 0  do not fail
	// 1 fail by doing nothing
	// 2 fail by sending wrong blocks
	Fail uint
}

SimulationConfig is the config used by the simulation for byzcoin

Directories

Path Synopsis
Bitcoin-blockchain specific functions.
Bitcoin-blockchain specific functions.
blkparser
Basically adapation from the file at https://github.com/tsileo/blkparser Copy/paste from the file at https://github.com/tsileo/blkparser Basically adapation from the file at https://github.com/tsileo/blkparser Package blkparser basically is an adaptation from a file at https://github.com/tsileo/blkparser
Basically adapation from the file at https://github.com/tsileo/blkparser Copy/paste from the file at https://github.com/tsileo/blkparser Basically adapation from the file at https://github.com/tsileo/blkparser Package blkparser basically is an adaptation from a file at https://github.com/tsileo/blkparser
Package pbft is the Practical Byzantine Fault Tolerance algorithm with some simplifications.
Package pbft is the Practical Byzantine Fault Tolerance algorithm with some simplifications.

Jump to

Keyboard shortcuts

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