go_hotstuff

package module
v0.0.0-...-ae125c8 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 22 Imported by: 0

README

go-hotstuff

go-hotstuff is a simple implementation of hotstuff consensus protocol.

Run the example

First, run scripts/generate_keys.sh to generate threshold keys, then run scripts/run_server.sh to start four hotstuff servers. There are three kinds of networks you can choose to use, they are basic, chained and event-driven, the default network type is event-driven. There is a simple client where you can find in cmd/hotstuffclient, or you can run scripts/run_client.sh to start it.

TODO

  1. Fix bugs, especially chained hotstuff.
  2. Complete function of syncing blocks.

Reference

M. Yin, D. Malkhi, M. K. Reiter, G. Golan Gueta, and I. Abraham, “HotStuff: BFT Consensus in the Lens of Blockchain,” Mar 2018.

Documentation

Index

Constants

View Source
const (
	PRIVATEKEYFILETYPE = "HOTSTUFF PRIVATE KEY"
	PUBLICKEYFILETYPE  = "HOTSTUFF PUBLIC KEY"
)

Variables

This section is empty.

Functions

func CreateDocumentHash

func CreateDocumentHash(msgBytes []byte, meta *tcrsa.KeyMeta) ([]byte, error)

func CreateFullSignature

func CreateFullSignature(documentHash []byte, partSigs tcrsa.SigShareList, publicKey *tcrsa.KeyMeta) (tcrsa.Signature, error)

func GeneratePrivateKey

func GeneratePrivateKey() (privateKey *ecdsa.PrivateKey, err error)

GeneratePrivateKey 使用ecdsa生成私钥

func GenerateThresholdKeys

func GenerateThresholdKeys(need, all int) (shares tcrsa.KeyShareList, meta *tcrsa.KeyMeta, err error)

GenerateThresholdKeys generate threshold signature keys need: how many signatures we need ,the same as 2f+1 all: how many private keys we need generate, the same as N it may take a bit time to generate keys

func Hash

func Hash(block *pb.Block) []byte

func NewCmdSet

func NewCmdSet() *cmdSetImpl

func ReadPrivateKeyFromFile

func ReadPrivateKeyFromFile(filePath string) (*ecdsa.PrivateKey, error)

ReadPrivateKeyFromFile 从文件中读取私钥

func ReadPublicKeyFromFile

func ReadPublicKeyFromFile(filePath string) (*ecdsa.PublicKey, error)

ReadPublicKeyFromFile 从硬盘中读取公钥

func ReadThresholdPrivateKeyFromFile

func ReadThresholdPrivateKeyFromFile(filePath string) (*tcrsa.KeyShare, error)

func ReadThresholdPublicKeyFromFile

func ReadThresholdPublicKeyFromFile(filePath string) (*tcrsa.KeyMeta, error)

func String

func String(block *pb.Block) string

func TSign

func TSign(documentHash []byte, privateKey *tcrsa.KeyShare, publicKey *tcrsa.KeyMeta) (*tcrsa.SigShare, error)

TSign create the partial signature of replica

func TVerify

func TVerify(publicKey *tcrsa.KeyMeta, signature tcrsa.Signature, msgBytes []byte) (bool, error)

func VerifyPartSig

func VerifyPartSig(partSig *tcrsa.SigShare, documentHash []byte, publicKey *tcrsa.KeyMeta) error

func WritePrivateKeyToFile

func WritePrivateKeyToFile(privateKey *ecdsa.PrivateKey, filePath string) error

WritePrivateKeyToFile 将私钥写入磁盘

func WritePublicKeyToFile

func WritePublicKeyToFile(publicKey *ecdsa.PublicKey, filePath string) error

WritePublicKeyToFile 将公钥写入磁盘

func WriteThresholdPrivateKeyToFile

func WriteThresholdPrivateKeyToFile(privateKey *tcrsa.KeyShare, filePath string) error

func WriteThresholdPublicKeyToFile

func WriteThresholdPublicKeyToFile(publicKey *tcrsa.KeyMeta, filePath string) error

Types

type BlockStorage

type BlockStorage interface {
	Put(block *pb.Block) error
	Get(hash []byte) (*pb.Block, error)
	UpdateState(block *pb.Block) error
	BlockOf(cert *pb.QuorumCert) (*pb.Block, error)
	ParentOf(block *pb.Block) (*pb.Block, error)
	GetLastBlockHash() []byte
	RestoreStatus()
	Close()
}

用于存储和查找区块信息

type BlockStorageImpl

type BlockStorageImpl struct {
	Tip []byte
	// contains filtered or unexported fields
}

func NewBlockStorageImpl

func NewBlockStorageImpl(id string) *BlockStorageImpl

func (*BlockStorageImpl) BlockOf

func (bsi *BlockStorageImpl) BlockOf(cert *pb.QuorumCert) (*pb.Block, error)

func (*BlockStorageImpl) Close

func (bsi *BlockStorageImpl) Close()

func (*BlockStorageImpl) Get

func (bsi *BlockStorageImpl) Get(hash []byte) (*pb.Block, error)

func (*BlockStorageImpl) GetLastBlockHash

func (bsi *BlockStorageImpl) GetLastBlockHash() []byte

func (*BlockStorageImpl) ParentOf

func (bsi *BlockStorageImpl) ParentOf(block *pb.Block) (*pb.Block, error)

func (*BlockStorageImpl) Put

func (bsi *BlockStorageImpl) Put(block *pb.Block) error

func (*BlockStorageImpl) RestoreStatus

func (bsi *BlockStorageImpl) RestoreStatus()

func (*BlockStorageImpl) UpdateState

func (bsi *BlockStorageImpl) UpdateState(block *pb.Block) error

type CmdSet

type CmdSet interface {
	Add(cmds ...string)
	Remove(cmds ...string)
	GetFirst(n int) []string
	IsProposed(cmd string) bool
	MarkProposed(cmds ...string)
	UnMark(cmds ...string)
}

type Timer

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

Wrap golang sdk timer.Timer

func NewTimer

func NewTimer(duration time.Duration) *Timer

NewTimer create a new Timer

func (*Timer) HardStartTimer

func (t *Timer) HardStartTimer()

SoftStartTimer start the timer ,whether it has been started

func (*Timer) Init

func (t *Timer) Init()

Init init time.Timer and stop it

func (*Timer) SoftStartTimer

func (t *Timer) SoftStartTimer()

SoftStartTimer start the timer, if it has not been started

func (*Timer) Stop

func (t *Timer) Stop()

Stop stop timer

func (*Timer) Timeout

func (t *Timer) Timeout() <-chan time.Time

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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