pbft

package
v0.0.0-...-1414968 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TunablesConfigEnv is an env var to fetch tunables .yaml conf
	TunablesConfigEnv = "TRUE_TUNABLES_CONF"
	// GeneralConfigEnv is an env var to fetch logistics .ini conf
	GeneralConfigEnv = "TRUE_GENERAL_CONF"
	// PeerNetworkEnv is an env var to fetch hosts file contaning peer address list
	PeerNetworkEnv = "TRUE_NETWORK_CONF"
	// SimulatedEnv apprises the project of products env vs an alternate reality
	SimulatedEnv = "TRUE_SIMULATION"
)
View Source
const (
	TypeRequest = iota
)

const ServerPort = 40162 const BufferSize = 4096 * 32

Variables

This section is empty.

Functions

func CheckConfigErr

func CheckConfigErr(err error)

CheckConfigErr first prints config specific error messages (TODO: add context param for message), then redirects to project wide CheckErr()

func FromGOB64

func FromGOB64(str string) []byte

FromGOB64 is a base64 decoder

func GetCWD

func GetCWD() string

GetCWD provides the current work dir's absolute filepath, where CWD is the one where truechain-engine binary shots were was fired from.

func GetDefaultGenesisBlock

func GetDefaultGenesisBlock() *pb.PbftBlock

GetDefaultGenesisBlock returns a default genesis block

func GetHash

func GetHash(plaintext string) string

GetHash generates sha512 hash for a string

func LoadLogisticsCfg

func LoadLogisticsCfg() (*ini.File, error)

LoadLogisticsCfg loads the .cfg file

func NewPbftBlock

func NewPbftBlock(header *pb.PbftBlockHeader, txns []*pb.Transaction) *pb.PbftBlock

NewPbftBlock creates and returns a new block

func NewPbftBlockHeader

func NewPbftBlockHeader(n, gasLimit, gasUsed int64, parentHash, txnsHash []byte) *pb.PbftBlockHeader

NewPbftBlockHeader creates and returns a new block header

func RegisterPbftGrpcListener

func RegisterPbftGrpcListener(grpcPort int, sv *Server)

RegisterPbftGrpcListener listens to client for new transaction requests on grpcPort

func ToGOB64

func ToGOB64(m []byte) string

ToGOB64 is a go binary encoder

func VerifySender

func VerifySender(tx *pb.Transaction, n int) ([]byte, bool)

VerifySender verifies transaction sender by matching public key obtained from transaction signature with expected public key TODO This should match sender addresses later

func WriteNewKeys

func WriteNewKeys(kcount int, kdir string)

WriteNewKeys generates kcount # of ECDSA public-private key pairs and writes them into a folder kdir.

Types

type ActiveItem

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

ActiveItem keeps track of currently active request and msg digest

type ApplyMsg

type ApplyMsg struct {
	Index   int
	Content interface{}
}

ApplyMsg keeps track of messages and their indices. It's used by both the server and client. Consider it as kind of like the common Z environment variable.

type BftCommittee

type BftCommittee struct {
	Blocksize      int `yaml:"block_size"` // Blocksize specifies the number of transactions per block
	BlockFrequency int `yaml:"block_frequency"`
	Lambda         int `yaml:"lambda"`
	WaitTimeout    int `yaml:"wait_timeout"`
	Tbft           int `yaml:"tbft"`
	Th             int `yaml:"th"`
	ActualDelta    int `yaml:"actual_delta"`
	Delta          int `yaml:"delta"`
	Alpha          int `yaml:"alpha"`
	Csize          int `yaml:"csize"`
}

BftCommittee config initiates assumption values from whitepaper May or maynot change during runtime

type Config

type Config struct {
	Tunables
	Logistics
	Network
}

Config - configuration for pbft.Config Note: struct fields must be public in order for unmarshal to correctly populate the data.

func GetPbftConfig

func GetPbftConfig() *Config

GetPbftConfig returns the basic PBFT configuration used for simulation

func (*Config) GenerateKeysToFile

func (cfg *Config) GenerateKeysToFile()

GenerateKeysToFile generates ECDSA public-private keypairs to a folder

func (*Config) GetIPConfigs

func (cfg *Config) GetIPConfigs()

GetIPConfigs loads all the IPs from the ~/hosts files

func (*Config) LoadTunablesConfig

func (cfg *Config) LoadTunablesConfig() error

LoadTunablesConfig loads the .yaml file

func (*Config) MakeTransportations

func (cfg *Config) MakeTransportations(index int) []*rpc.Client

MakeTransportations is a placeholder. All network related functions should be defined here. TODO: implement send/receive messages with RPC

func (*Config) ValidateConfig

func (cfg *Config) ValidateConfig(cfgData *ini.File) error

ValidateConfig checks for aberrance and loads struct Config{} with tunables and logistics vars

type DailyBFTNode

type DailyBFTNode interface {
	ProxyProcessPrePrepare(arg ProxyProcessPrePrepareArg, reply *ProxyProcessPrePrepareReply) error
	ProxyProcessPrepare(arg ProxyProcessPrepareArg, reply *ProxyProcessPrepareReply) error
	ProxyProcessCommit(arg ProxyProcessCommitArg, reply *ProxyProcessCommitReply) error
	ProxyProcessViewChange(arg ProxyProcessViewChangeArg, reply *ProxyProcessViewChangeReply) error
	ProxyProcessNewView(arg ProxyProcessNewViewArg, reply *ProxyProcessNewViewReply) error
	ProxyProcessCheckpoint(arg ProxyProcessCheckpointArg, reply *ProxyProcessCheckpointReply) error

	NewClientRequest(req Request, clientID int)
	// contains filtered or unexported methods
}

DailyBFTNode - an interface supposed to expose fastchain / committee consensus to an orchestration mechanism See - https://github.com/truechain/truechain-consensus-core/issues/26

type DigType

type DigType string

DigType is the message digest type

type General

type General struct {
	MaxFail         int `yaml:"max_fail"`
	BasePort        int `yaml:"rpc_base_port"`
	OutputThreshold int `yaml:"output_threshold"`
	MaxLogSize      int `yaml:"max_log_size"`
	GrpcBasePort    int `yaml:"grpc_base_port"`
	RequestTimeout  int `yaml:"request_timeout"`
}

General defines generic tunables

type Log

type Log struct {
}

Log - Final daily LOG that is signed by the BFT committee member

type Logistics

type Logistics struct {
	LedgerLoc string
	LD        string
	ServerLog string
	ClientLog string
	KD        string // key directory where pub/priva ECDSA keys are stored
}

Logistics contains paths corresponding to following env vars: TRUE_CONF_DIR='/etc/truechain/' - contains hosts, tunables and logistics configurables TRUE_LOG_DIR='/var/log/truechain' - contains all things ledger and logs TRUE_LIB_DIR='/var/lib/truechain' - contains keys and all things db

type MsgSignature

type MsgSignature struct {
	R *big.Int
	S *big.Int
}

MsgSignature contains the EC coordinates

type MsgType

type MsgType string

MsgType contains the message of the request as part of RequestInner

type Network

type Network struct {
	N         int      // number of nodes to be launchedt
	IPList    []string // stores list of IP addresses belonging to BFT nodes
	Ports     []int    // stores list of Ports belonging to BFT nodes
	GrpcPorts []int    // stores list of ports serving grpc requests
	NumQuest  int      // NumQuest is the number of requests sent from client
	NumKeys   int      // NumKeys is the count of IP addresses (BFT nodes) participating
	HostsFile string   // contains network addresses for server/client/peers
}

Network - generic struct used by each node to interact with connection pool details

type Node

type Node struct {
	ListenReady chan bool
	SetupReady  chan bool

	EcdsaKey *ecdsa.PrivateKey

	ID int
	N  int

	Primary int

	KeyDict map[int]keyItem
	// contains filtered or unexported fields
}

Node contains base properties of a Node

func Make

func Make(cfg *Config, me int, port int, view int) *Node

Make registers all node config objects,

func (*Node) ProxyProcessCheckpoint

func (nd *Node) ProxyProcessCheckpoint(arg ProxyProcessCheckpointArg, reply *ProxyProcessCheckpointReply) error

ProxyProcessCheckpoint processes checkpoint for PBFT ledger

func (*Node) ProxyProcessCommit

func (nd *Node) ProxyProcessCommit(arg ProxyProcessCommitArg, reply *ProxyProcessCommitReply) error

ProxyProcessCommit trigger Commit phase of PBFT

func (*Node) ProxyProcessNewView

func (nd *Node) ProxyProcessNewView(arg ProxyProcessNewViewArg, reply *ProxyProcessNewViewReply) error

ProxyProcessNewView triggers and frames a new view from current request

func (*Node) ProxyProcessPrePrepare

func (nd *Node) ProxyProcessPrePrepare(arg ProxyProcessPrePrepareArg, reply *ProxyProcessPrePrepareReply) error

ProxyProcessPrePrepare trigger Pre-Prepare request

func (*Node) ProxyProcessPrepare

func (nd *Node) ProxyProcessPrepare(arg ProxyProcessPrepareArg, reply *ProxyProcessPrepareReply) error

ProxyProcessPrepare trigger Prepare phase of PBFT

func (*Node) ProxyProcessViewChange

func (nd *Node) ProxyProcessViewChange(arg ProxyProcessViewChangeArg, reply *ProxyProcessViewChangeReply) error

ProxyProcessViewChange trigger view change process request

func (*Node) VerifyBlockTxs

func (nd *Node) VerifyBlockTxs(blk *pb.PbftBlock) bool

VerifyBlockTxs verifies transactions in a block by checking sender and account nonce

type ProxyProcessCheckpointArg

type ProxyProcessCheckpointArg struct {
	Req      Request
	ClientID int
}

ProxyProcessCheckpointArg holds checkPoint args for PBFT checkpoints

type ProxyProcessCheckpointReply

type ProxyProcessCheckpointReply struct {
}

ProxyProcessCheckpointReply ack for PBFT checkpoint

type ProxyProcessCommitArg

type ProxyProcessCommitArg struct {
	Req Request
}

ProxyProcessCommitArg holds Commit Phase declarative args

type ProxyProcessCommitReply

type ProxyProcessCommitReply struct {
}

ProxyProcessCommitReply reply ack for PBFT commit phase

type ProxyProcessNewViewArg

type ProxyProcessNewViewArg struct {
	Req      Request
	ClientID int
}

ProxyProcessNewViewArg holds new view arg for client request

type ProxyProcessNewViewReply

type ProxyProcessNewViewReply struct {
}

ProxyProcessNewViewReply reply ack for new view request

type ProxyProcessPrePrepareArg

type ProxyProcessPrePrepareArg struct {
	Req      Request
	ClientID int
}

ProxyProcessPrePrepareArg holds context for committee, maps Request to client

type ProxyProcessPrePrepareReply

type ProxyProcessPrePrepareReply struct {
}

ProxyProcessPrePrepareReply is a stub atm, an ack of reply

type ProxyProcessPrepareArg

type ProxyProcessPrepareArg struct {
	Req      Request
	ClientID int
}

ProxyProcessPrepareArg holds client-request context for Prepare phase of PBFT

type ProxyProcessPrepareReply

type ProxyProcessPrepareReply struct {
}

ProxyProcessPrepareReply is a stub atm, an ack of reply to trigger Prepare

type ProxyProcessViewChangeArg

type ProxyProcessViewChangeArg struct {
	Req  Request
	From int
}

ProxyProcessViewChangeArg holds view change context from previous request

type ProxyProcessViewChangeReply

type ProxyProcessViewChangeReply struct {
}

ProxyProcessViewChangeReply holds view change reply context

type Request

type Request struct {
	Inner RequestInner
	Dig   DigType
	Sig   MsgSignature
}

Request is the object juggled between the nodes

func (*Request) AddSig

func (req *Request) AddSig(privKey *ecdsa.PrivateKey)

AddSig signs message with private key of node

type RequestInner

type RequestInner struct {
	ID        int
	Seq       int
	View      int
	Reqtype   int //or int?
	Msg       MsgType
	Block     *pb.PbftBlock
	Timestamp int64
}

RequestInner represents the core structure of a request Reqtype maps to following iota'ed constants ( typePrePrepare, typePrepare, typeCommit, typeInit,

typeRequest, typeViewChange, typeNewView, typeCheckpoint )

type Server

type Server struct {
	IP   string
	Port int
	Nd   *Node
	Cfg  *Config
	// contains filtered or unexported fields
}

Server defines the base properties of a pbft node server

func BuildServer

func BuildServer(cfg *Config, me int) *Server

BuildServer initiates the Server resource properties and listens to client's message requests as well as interacts with the channel

func (*Server) Start

func (sv *Server) Start()

Start - Initial server logic goes here

type Slowchain

type Slowchain struct {
	Csize int `yaml:"csize"` // Snailchain's chainsize
}

Slowchain defines attiributes specific to slowchain. Note: Csize is just a placeholder and has no use.

type Testbed

type Testbed struct {
	Total            int  `yaml:"total"`
	ClientID         int  `yaml:"client_id"`
	InitServerID     int  `yaml:"server_id_init"`
	ThreadingEnabled bool `yaml:"threading_enabled"`
	MaxRetries       int  `yaml:"max_retries"`
	MaxRequests      int  `yaml:"max_requests"`
	BatchSize        int  `yaml:"batch_size"`
}

Testbed configuration params are a stimulus for simulation

type Tunables

type Tunables struct {
	// struct tags, to add metadata to a struct's fields
	// testbed config
	Testbed      `yaml:"testbed"`
	Slowchain    `yaml:"slowchain"`
	General      `yaml:"general"`
	BftCommittee `yaml:"bft_committee"`
}

Tunables is grouped under the struct Config, cocoon params for the server

func DefaultTunables

func DefaultTunables() *Tunables

DefaultTunables contains default values for Tunables, in case, config file wasn't found

type TxPool

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

TxPool defines the transaction pool

func (*TxPool) Add

func (tp *TxPool) Add(tx *pb.Transaction, sender []byte)

Add adds a new transaction from sender account to the transaction pool

func (*TxPool) Get

func (tp *TxPool) Get(txHash common.Hash) *pb.Transaction

Get returns a transaction if it is contained in the pool and nil otherwise.

func (*TxPool) GetTxCount

func (tp *TxPool) GetTxCount() int

GetTxCount returns the number of transactions currently in the transaction pool

func (*TxPool) Remove

func (tp *TxPool) Remove(txHash common.Hash)

Remove removes a transaction from the transaction pool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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