hotstuff

package
v0.0.0-...-9fbb145 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgNewView = iota
	MsgPrepare
	MsgVotePrepare
	MsgPreCommit
	MsgVotePreCommit
	MsgCommit
	MsgVoteCommit
	MsgDecide

	// pseudo messages
	MsgStartNewView // for handling new view from app
	MsgTryPropose
	MsgTimer
)
View Source
const (
	PhasePrepare    = iota
	PhaseTryPropose // pseudo phase, used to describe the phase between onNewView and Propose successfully
	PhasePreCommit
	PhaseCommit
	PhaseDecide
	PhaseFinal
)

Variables

View Source
var (
	ErrNewViewFail          = fmt.Errorf("hotstuff new view fail")
	ErrUnhandledMsg         = fmt.Errorf("hotstuff unhandled message")
	ErrViewTimeout          = fmt.Errorf("hotstuff view timeout")
	ErrQCVerification       = fmt.Errorf("hotstuff QC not valid")
	ErrInvalidReplica       = fmt.Errorf("hotstuff replica not valid")
	ErrInvalidQuorumMessage = fmt.Errorf("hotstuff quorum message not valid")
	ErrInsufficientQC       = fmt.Errorf("hotstuff QC insufficient")
	ErrInvalidHighQC        = fmt.Errorf("hotstuff highQC invalid")
	ErrInvalidPrepareQC     = fmt.Errorf("hotstuff prepareQC invalid")
	ErrInvalidPreCommitQC   = fmt.Errorf("hotstuff preCommitQC invalid")
	ErrInvalidCommitQC      = fmt.Errorf("hotstuff commitQC invalid")
	ErrInvalidProposal      = fmt.Errorf("hotstuff proposal invalid")
	ErrInvalidPublicKey     = fmt.Errorf("invalid public key for bls deserialize")
	ErrViewPhaseNotMatch    = fmt.Errorf("hotstuff view phase not match")
	ErrViewOldPhase         = fmt.Errorf("hotstuff old phase ")

	ErrMissingView       = fmt.Errorf("hotstuff view missing")
	ErrInvalidLeaderView = fmt.Errorf("hotstuff invalid leader view")
	ErrExistingView      = fmt.Errorf("hotstuff view existing")
	ErrViewIdNotMatch    = fmt.Errorf("hotstuff view id not match")

	ErrOldState    = fmt.Errorf("hotstuff view state too old")
	ErrFutureState = fmt.Errorf("hotstuff view state of future")
)

Functions

func CalcThreshold

func CalcThreshold(size int) int

func MaskToException

func MaskToException(bMask []byte, groupPublicKey []*bls.PublicKey, beNewVer bool) []*bls.PublicKey

func MaskToExceptionIndexs

func MaskToExceptionIndexs(bMask []byte, cmLen int) []int

func ReadableMsgType

func ReadableMsgType(m uint32) string

func VerifySignature

func VerifySignature(bSign []byte, bMask []byte, data []byte, groupPublicKey []*bls.PublicKey, threshold int) bool

Types

type HotStuffApplication

type HotStuffApplication interface {
	Self() string
	Write(string, *HotstuffMessage) error
	Broadcast(*HotstuffMessage) []error

	GetPublicKey() []*bls.PublicKey

	OnNewView(currentState []byte, extra [][]byte) error
	OnPropose(isKeyBlock bool, state []byte, extra []byte) error
	OnViewDone(kSign *SignedState, tSign *SignedState) error

	CheckView(currentState []byte) error
	Propose() (e error, kState []byte, tState []byte, extra []byte)
	CurrentState() ([]byte, string, uint64)
	GetExtra() []byte // only for new-view procedure
}

type HotstuffMessage

type HotstuffMessage struct {
	Code   uint32
	Number uint64
	ViewId common.Hash
	Id     string
	PubKey []byte

	// The usage of these "DataX" if different per message
	DataA []byte
	DataB []byte
	DataC []byte

	DataD []byte
	DataE []byte
	DataF []byte

	ReceivedAt time.Time
}

type HotstuffProtocolManager

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

func NewHotstuffProtocolManager

func NewHotstuffProtocolManager(a HotStuffApplication, secretKey *bls.SecretKey, publicKey *bls.PublicKey) *HotstuffProtocolManager

func (*HotstuffProtocolManager) DumpView

func (hsm *HotstuffProtocolManager) DumpView(v *View, asLeader bool)

func (*HotstuffProtocolManager) HandleMessage

func (hsm *HotstuffProtocolManager) HandleMessage(msg *HotstuffMessage) error

func (*HotstuffProtocolManager) NewView

func (hsm *HotstuffProtocolManager) NewView() error

for replica

func (*HotstuffProtocolManager) SignHash

func (hsm *HotstuffProtocolManager) SignHash(data []byte) []byte

func (*HotstuffProtocolManager) TryPropose

func (hsm *HotstuffProtocolManager) TryPropose() error

func (*HotstuffProtocolManager) UpdateKeyPair

func (hsm *HotstuffProtocolManager) UpdateKeyPair(sec *bls.SecretKey)

type QC

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

type Quorum

type Quorum struct {
	Index      int // index in the group public keys
	PubKey     *bls.PublicKey
	KSign      bls.Sign
	TSign      bls.Sign
	ValidKSign bool
	ValidTSign bool
}

type SignedState

type SignedState struct {
	State []byte
	Sign  []byte
	Mask  []byte
}

Proposed K or T state with signature and mask, only for OnViewDone() interface

type View

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

Jump to

Keyboard shortcuts

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