types

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventDataTypeNewBlock       = byte(0x01)
	EventDataTypeFork           = byte(0x02)
	EventDataTypeTx             = byte(0x03)
	EventDataTypeNewBlockHeader = byte(0x04)

	EventDataTypeRoundState    = byte(0x11)
	EventDataTypeVote          = byte(0x12)
	EventDataTypeSignAggr      = byte(0x13)
	EventDataTypeVote2Proposer = byte(0x14)

	EventDataTypeRequest        = byte(0x21)
	EventDataTypeMessage        = byte(0x22)
	EventDataTypeFinalCommitted = byte(0x23)
)
View Source
const (
	VoteTypePrevote   = byte(0x01)
	VoteTypePrecommit = byte(0x02)
)

Types of votes TODO Make a new type "VoteType"

View Source
const HalfLooseRound = 15
View Source
const LooseRound = 30
View Source
const MaxBlockSize = 22020096 // 21MB TODO make it configurable
View Source
const MaxSignAggrSize = 22020096 // 21MB TODO make it configurable

------------------------ signature aggregation -------------------

Variables

View Source
var (
	PeerStateKey     = "ConsensusReactor.peerState"
	PeerMempoolChKey = "MempoolReactor.peerMempoolCh"
)
View Source
var (
	ErrPartSetUnexpectedIndex = errors.New("Error part set unexpected index")
	ErrPartSetInvalidProof    = errors.New("Error part set invalid proof")
)
View Source
var (
	ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
	ErrInvalidBlockPartHash      = errors.New("Error invalid block part hash")
)
View Source
var (
	ErrVoteUnexpectedStep          = errors.New("Unexpected step")
	ErrVoteInvalidValidatorIndex   = errors.New("Invalid round vote validator index")
	ErrVoteInvalidValidatorAddress = errors.New("Invalid round vote validator address")
	ErrVoteInvalidSignature        = errors.New("Invalid round vote signature")
	ErrVoteInvalidBlockHash        = errors.New("Invalid block hash")
)
View Source
var CONSENSUS_NeatCon string = "neatcon"
View Source
var CONSENSUS_POS string = "pos"
View Source
var CONSENSUS_POW string = "pow"
View Source
var GenDocKey = []byte("GenDocKey")
View Source
var MainnetGenesisJSON string = `` /* 854-byte string literal not displayed */
View Source
var TestnetGenesisJSON string = `` /* 851-byte string literal not displayed */
View Source
var ValidatorCodec = validatorCodec{}

Functions

func AddListenerForEvent

func AddListenerForEvent(evsw EventSwitch, id, event string, cb func(data TMEventData))

func EventStringBlockPart

func EventStringBlockPart() string

func EventStringBond

func EventStringBond() string

Reserved

func EventStringCompleteProposal

func EventStringCompleteProposal() string

func EventStringDupeout

func EventStringDupeout() string

func EventStringFinalCommitted

func EventStringFinalCommitted() string

func EventStringFork

func EventStringFork() string

func EventStringLock

func EventStringLock() string

func EventStringMessage

func EventStringMessage() string

func EventStringNewBlock

func EventStringNewBlock() string

func EventStringNewBlockHeader

func EventStringNewBlockHeader() string

func EventStringNewRound

func EventStringNewRound() string

func EventStringNewRoundStep

func EventStringNewRoundStep() string

func EventStringPolka

func EventStringPolka() string

func EventStringProposal

func EventStringProposal() string

func EventStringProposalBlockParts

func EventStringProposalBlockParts() string

func EventStringRebond

func EventStringRebond() string

func EventStringRelock

func EventStringRelock() string

func EventStringRequest

func EventStringRequest() string

func EventStringSignAggr

func EventStringSignAggr() string

func EventStringTimeoutPropose

func EventStringTimeoutPropose() string

func EventStringTimeoutWait

func EventStringTimeoutWait() string

func EventStringTx

func EventStringTx(tx Tx) string

func EventStringUnbond

func EventStringUnbond() string

func EventStringUnlock

func EventStringUnlock() string

func EventStringVote

func EventStringVote() string

func EventStringVote2Proposer

func EventStringVote2Proposer() string

func FireEventCompleteProposal

func FireEventCompleteProposal(fireable events.Fireable, rs EventDataRoundState)

func FireEventFinalCommitted

func FireEventFinalCommitted(fireable events.Fireable, rs EventDataFinalCommitted)

func FireEventLock

func FireEventLock(fireable events.Fireable, rs EventDataRoundState)

func FireEventMessage

func FireEventMessage(fireable events.Fireable, rs EventDataMessage)

func FireEventNewBlock

func FireEventNewBlock(fireable events.Fireable, block EventDataNewBlock)

func FireEventNewBlockHeader

func FireEventNewBlockHeader(fireable events.Fireable, header EventDataNewBlockHeader)

func FireEventNewRound

func FireEventNewRound(fireable events.Fireable, rs EventDataRoundState)

func FireEventNewRoundStep

func FireEventNewRoundStep(fireable events.Fireable, rs EventDataRoundState)

func FireEventPolka

func FireEventPolka(fireable events.Fireable, rs EventDataRoundState)

func FireEventRelock

func FireEventRelock(fireable events.Fireable, rs EventDataRoundState)

func FireEventRequest

func FireEventRequest(fireable events.Fireable, rs EventDataRequest)

func FireEventSignAggr

func FireEventSignAggr(fireable events.Fireable, sign EventDataSignAggr)

func FireEventTimeoutPropose

func FireEventTimeoutPropose(fireable events.Fireable, rs EventDataRoundState)

func FireEventTimeoutWait

func FireEventTimeoutWait(fireable events.Fireable, rs EventDataRoundState)

func FireEventTx

func FireEventTx(fireable events.Fireable, tx EventDataTx)

func FireEventUnlock

func FireEventUnlock(fireable events.Fireable, rs EventDataRoundState)

func FireEventVote

func FireEventVote(fireable events.Fireable, vote EventDataVote)

func FireEventVote2Proposer

func FireEventVote2Proposer(fireable events.Fireable, vote EventDataVote2Proposer)

func HashSignBytes

func HashSignBytes(chainID string, o Signable) []byte

HashSignBytes is a convenience method for getting the hash of the bytes of a signable

func IsVoteTypeValid

func IsVoteTypeValid(type_ byte) bool

func Loose23MajorThreshold

func Loose23MajorThreshold(totalVotingPower *big.Int, round int) *big.Int

max { [(2*LooseRound - round)*totalVotingPower + 3*LooseRound]/(3*LooseRound), totalVotingPower/2 + 1 }

func MakeBlock

func MakeBlock(height uint64, chainID string, commit *Commit,
	block *types.Block, valHash []byte, epochNumber uint64, epochBytes []byte, tx3ProofData []*types.TX3ProofData, partSize int) (*NCBlock, *PartSet)

func SignBytes

func SignBytes(chainID string, o Signable) []byte

SignBytes is a convenience method for getting the bytes to sign of a Signable.

Types

type BlockID

type BlockID struct {
	Hash        []byte        `json:"hash"`
	PartsHeader PartSetHeader `json:"parts"`
}

func (BlockID) Equals

func (blockID BlockID) Equals(other BlockID) bool

func (BlockID) IsZero

func (blockID BlockID) IsZero() bool

func (BlockID) Key

func (blockID BlockID) Key() string

func (BlockID) String

func (blockID BlockID) String() string

func (BlockID) WriteSignBytes

func (blockID BlockID) WriteSignBytes(w io.Writer, n *int, err *error)

type BlockIDApi

type BlockIDApi struct {
	Hash        string           `json:"hash"`
	PartsHeader PartSetHeaderApi `json:"parts"`
}

type CandidateApi

type CandidateApi struct {
	CandidateList []string `json:"candidateList"`
}

type CanonicalJSONBlockID

type CanonicalJSONBlockID struct {
	Hash        []byte                     `json:"hash,omitempty"`
	PartsHeader CanonicalJSONPartSetHeader `json:"parts,omitempty"`
}

func CanonicalBlockID

func CanonicalBlockID(blockID BlockID) CanonicalJSONBlockID

type CanonicalJSONOnceProposal

type CanonicalJSONOnceProposal struct {
	ChainID  string                `json:"chain_id"`
	Proposal CanonicalJSONProposal `json:"proposal"`
}

type CanonicalJSONOnceSignAggr

type CanonicalJSONOnceSignAggr struct {
	ChainID  string                `json:"chain_id"`
	SignAggr CanonicalJSONSignAggr `json:"sign_aggr"`
}

type CanonicalJSONOnceValidatorMsg

type CanonicalJSONOnceValidatorMsg struct {
	ChainID      string                    `json:"chain_id"`
	ValidatorMsg CanonicalJSONValidatorMsg `json:"validator_msg"`
}

----------------------------- author@liaoyd

type CanonicalJSONOnceVote

type CanonicalJSONOnceVote struct {
	ChainID string            `json:"chain_id"`
	Vote    CanonicalJSONVote `json:"vote"`
}

type CanonicalJSONPartSetHeader

type CanonicalJSONPartSetHeader struct {
	Hash  []byte `json:"hash"`
	Total uint64 `json:"total"`
}

func CanonicalPartSetHeader

func CanonicalPartSetHeader(psh PartSetHeader) CanonicalJSONPartSetHeader

type CanonicalJSONProposal

type CanonicalJSONProposal struct {
	BlockPartsHeader CanonicalJSONPartSetHeader `json:"block_parts_header"`
	Height           uint64                     `json:"height"`
	POLBlockID       CanonicalJSONBlockID       `json:"pol_block_id"`
	POLRound         int                        `json:"pol_round"`
	Round            int                        `json:"round"`
	Hash             []byte                     `json:"hash"`
}

func CanonicalProposal

func CanonicalProposal(proposal *Proposal) CanonicalJSONProposal

type CanonicalJSONSignAggr

type CanonicalJSONSignAggr struct {
	Height        uint64               `json:"height"`
	Round         int                  `json:"round"`
	Type          byte                 `json:"type"`
	NumValidators int                  `json:"NumValidators"`
	BlockID       CanonicalJSONBlockID `json:"block_id"`
	Maj23         CanonicalJSONBlockID `json:"maj23"`
	Sum           int64                `json:"sum"`
}

func CanonicalSignAggr

func CanonicalSignAggr(signAggr *SignAggr) CanonicalJSONSignAggr

type CanonicalJSONValidatorMsg

type CanonicalJSONValidatorMsg struct {
	From           string        `json:"from"`
	Epoch          int           `json:"epoch"`
	ValidatorIndex int           `json:"validator_index"`
	Key            string        `json:"key"`
	PubKey         crypto.PubKey `json:"pub_key"`
	Power          uint64        `json:"power"`
	Action         string        `json:"action"`
	Target         string        `json:"target"`
}

type CanonicalJSONVote

type CanonicalJSONVote struct {
	BlockID CanonicalJSONBlockID `json:"block_id"`
	Height  uint64               `json:"height"`
	Round   uint64               `json:"round"`
	Type    byte                 `json:"type"`
}

func CanonicalVote

func CanonicalVote(vote *Vote) CanonicalJSONVote

type Commit

type Commit struct {
	// NOTE: The Precommits are in order of address to preserve the bonded ValidatorSet order.
	// Any peer with a block can gossip precommits by index with a peer without recalculating the
	// active ValidatorSet.
	BlockID BlockID `json:"blockID"`
	Height  uint64  `json:"height"`
	Round   int     `json:"round"`

	// BLS signature aggregation to be added here
	SignAggr crypto.BLSSignature `json:"SignAggr"`
	BitArray *BitArray
	// contains filtered or unexported fields
}

NOTE: Commit is empty for height 1, but never nil.

func (*Commit) Hash

func (commit *Commit) Hash() []byte

func (*Commit) NumCommits

func (commit *Commit) NumCommits() int

func (*Commit) Size

func (commit *Commit) Size() int

func (*Commit) StringIndented

func (commit *Commit) StringIndented(indent string) string

func (*Commit) Type

func (commit *Commit) Type() byte

func (*Commit) ValidateBasic

func (commit *Commit) ValidateBasic() error

type CommitApi

type CommitApi struct {
	BlockID BlockIDApi     `json:"blockID"`
	Height  hexutil.Uint64 `json:"height"`
	Round   int            `json:"round"`

	// BLS signature aggregation to be added here
	SignAggr crypto.BLSSignature `json:"signAggr"`
	BitArray *BitArray           `json:"bitArray"`
}

type ConsensusAggr

type ConsensusAggr struct {
	PublicKeys []string         `json:"publicKey"`
	Addresses  []common.Address `json:"address"`
}

type DefaultSigner

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

Implements Signer

func NewDefaultSigner

func NewDefaultSigner(priv crypto.PrivKey) *DefaultSigner

func (*DefaultSigner) Sign

func (ds *DefaultSigner) Sign(msg []byte) crypto.Signature

Implements Signer

type EpochApi

type EpochApi struct {
	Number         hexutil.Uint64    `json:"number"`
	RewardPerBlock *hexutil.Big      `json:"rewardPerBlock"`
	StartBlock     hexutil.Uint64    `json:"startBlock"`
	EndBlock       hexutil.Uint64    `json:"endBlock"`
	StartTime      time.Time         `json:"startTime"`
	EndTime        time.Time         `json:"endEime"`
	Validators     []*EpochValidator `json:"validators"`
}

type EpochApiForConsole

type EpochApiForConsole struct {
	Number         hexutil.Uint64              `json:"number"`
	RewardPerBlock *hexutil.Big                `json:"rewardPerBlock"`
	StartBlock     hexutil.Uint64              `json:"startBlock"`
	EndBlock       hexutil.Uint64              `json:"endBlock"`
	StartTime      time.Time                   `json:"startTime"`
	EndTime        time.Time                   `json:"endTime"`
	Validators     []*EpochValidatorForConsole `json:"validators"`
}

For console

type EpochValidator

type EpochValidator struct {
	Address        common.Address `json:"address"`
	PubKey         string         `json:"publicKey"`
	Amount         *hexutil.Big   `json:"votingPower"`
	RemainingEpoch hexutil.Uint64 `json:"remainEpoch"`
}

type EpochValidatorForConsole

type EpochValidatorForConsole struct {
	Address        string         `json:"address"`
	PubKey         string         `json:"publicKey"`
	Amount         *hexutil.Big   `json:"votingPower"`
	RemainingEpoch hexutil.Uint64 `json:"remainEpoch"`
}

For console

type EpochValidatorVoteApi

type EpochValidatorVoteApi struct {
	EpochValidator
	Salt     string      `json:"salt"`
	VoteHash common.Hash `json:"voteHash"` // VoteHash = Keccak256(Epoch Number + PubKey + Amount + Salt)
	TxHash   common.Hash `json:"txHash"`
}

type EpochValidatorVoteApiForConsole

type EpochValidatorVoteApiForConsole struct {
	EpochValidatorForConsole
	Salt     string      `json:"salt"`
	VoteHash common.Hash `json:"voteHash"` // VoteHash = Keccak256(Epoch Number + PubKey + Amount + Salt)
	TxHash   common.Hash `json:"txHash"`
}

type EpochVotesApi

type EpochVotesApi struct {
	EpochNumber hexutil.Uint64           `json:"voteForEpoch"`
	StartBlock  hexutil.Uint64           `json:"startBlock"`
	EndBlock    hexutil.Uint64           `json:"endBlock"`
	Votes       []*EpochValidatorVoteApi `json:"votes"`
}

type EpochVotesApiForConsole

type EpochVotesApiForConsole struct {
	EpochNumber hexutil.Uint64                     `json:"voteForEpoch"`
	StartBlock  hexutil.Uint64                     `json:"startBlock"`
	EndBlock    hexutil.Uint64                     `json:"endBlock"`
	Votes       []*EpochValidatorVoteApiForConsole `json:"votes"`
}

type ErrVoteConflictingVotes

type ErrVoteConflictingVotes struct {
	VoteA *Vote
	VoteB *Vote
}

func (*ErrVoteConflictingVotes) Error

func (err *ErrVoteConflictingVotes) Error() string

type EventCache

type EventCache interface {
	Fireable
	Flush()
}

func NewEventCache

func NewEventCache(evsw EventSwitch) EventCache

type EventDataFinalCommitted

type EventDataFinalCommitted struct {
	BlockNumber uint64
}

FinalCommittedEvent is posted when a proposal is committed

func (EventDataFinalCommitted) AssertIsTMEventData

func (_ EventDataFinalCommitted) AssertIsTMEventData()

type EventDataMessage

type EventDataMessage struct {
	Payload []byte `json:"payload"`
}

EventDataMessage is posted for Istanbul engine communication

func (EventDataMessage) AssertIsTMEventData

func (_ EventDataMessage) AssertIsTMEventData()

type EventDataNewBlock

type EventDataNewBlock struct {
	Block *NCBlock `json:"block"`
}

func (EventDataNewBlock) AssertIsTMEventData

func (_ EventDataNewBlock) AssertIsTMEventData()

type EventDataNewBlockHeader

type EventDataNewBlockHeader struct {
	Height int `json:"height"`
}

light weight event for benchmarking

func (EventDataNewBlockHeader) AssertIsTMEventData

func (_ EventDataNewBlockHeader) AssertIsTMEventData()

type EventDataRequest

type EventDataRequest struct {
	Proposal *neatTypes.Block `json:"proposal"`
}

EventDataRequest is posted to propose a proposal

func (EventDataRequest) AssertIsTMEventData

func (_ EventDataRequest) AssertIsTMEventData()

type EventDataRoundState

type EventDataRoundState struct {
	Height uint64 `json:"height"`
	Round  int    `json:"round"`
	Step   string `json:"step"`

	// private, not exposed to websockets
	RoundState interface{} `json:"-"`
}

NOTE: This goes into the replay WAL

func (EventDataRoundState) AssertIsTMEventData

func (_ EventDataRoundState) AssertIsTMEventData()

type EventDataSignAggr

type EventDataSignAggr struct {
	SignAggr *SignAggr
}

func (EventDataSignAggr) AssertIsTMEventData

func (_ EventDataSignAggr) AssertIsTMEventData()

type EventDataTx

type EventDataTx struct {
	Height int    `json:"height"`
	Tx     Tx     `json:"tx"`
	Data   []byte `json:"data"`
	Log    string `json:"log"`
	Error  string `json:"error"` // this is redundant information for now
}

All txs fire EventDataTx

func (EventDataTx) AssertIsTMEventData

func (_ EventDataTx) AssertIsTMEventData()

type EventDataVote

type EventDataVote struct {
	Vote *Vote
}

func (EventDataVote) AssertIsTMEventData

func (_ EventDataVote) AssertIsTMEventData()

type EventDataVote2Proposer

type EventDataVote2Proposer struct {
	Vote        *Vote
	ProposerKey string
}

func (EventDataVote2Proposer) AssertIsTMEventData

func (_ EventDataVote2Proposer) AssertIsTMEventData()

type EventSwitch

type EventSwitch interface {
	events.EventSwitch
}

func NewEventSwitch

func NewEventSwitch() EventSwitch

type Eventable

type Eventable interface {
	SetEventSwitch(EventSwitch)
}

type Fireable

type Fireable interface {
	events.Fireable
}

type ForbiddenApi

type ForbiddenApi struct {
	ForbiddenList []string `json:"forbiddenList"`
}

type GenesisDoc

type GenesisDoc struct {
	ChainID      string          `json:"chain_id"`
	Consensus    string          `json:"consensus"` //should be 'pos' or 'pow'
	GenesisTime  time.Time       `json:"genesis_time"`
	RewardScheme RewardSchemeDoc `json:"reward_scheme"`
	CurrentEpoch OneEpochDoc     `json:"current_epoch"`
}

func GenesisDocFromJSON

func GenesisDocFromJSON(jsonBlob []byte) (genDoc *GenesisDoc, err error)

读取 genesisdocjson,并做转换

func (*GenesisDoc) SaveAs

func (genDoc *GenesisDoc) SaveAs(file string) error

Utility method for saving GenensisDoc as JSON file.

func (genDoc *GenesisDoc) SaveAs(file string) error {
	genDocBytes, err := json.MarshalIndent(genDoc, "", "\t")
	if err != nil {
		fmt.Println(err)
	}

	return WriteFile(file, genDocBytes, 0644)
}

写入文件使用

type GenesisDocWrite

type GenesisDocWrite struct {
	ChainID      string           `json:"chain_id"`
	Consensus    string           `json:"consensus"` //should be 'pos' or 'pow'
	GenesisTime  time.Time        `json:"genesis_time"`
	RewardScheme RewardSchemeDoc  `json:"reward_scheme"`
	CurrentEpoch OneEpochDocWrite `json:"current_epoch"`
}

写入文件使用

type GenesisValidator

type GenesisValidator struct {
	EthAccount     common.Address `json:"address"`
	PubKey         crypto.PubKey  `json:"pub_key"`
	Amount         *big.Int       `json:"amount"`
	Name           string         `json:"name"`
	RemainingEpoch uint64         `json:"epoch"`
}

func (GenesisValidator) MarshalJSON

func (gv GenesisValidator) MarshalJSON() ([]byte, error)

func (*GenesisValidator) UnmarshalJSON

func (gv *GenesisValidator) UnmarshalJSON(input []byte) error

type GenesisValidatorWrite

type GenesisValidatorWrite struct {
	EthAccount     string        `json:"address"`
	PubKey         crypto.PubKey `json:"pub_key"`
	Amount         *big.Int      `json:"amount"`
	Name           string        `json:"name"`
	RemainingEpoch uint64        `json:"epoch"`
}

写入文件使用

func (GenesisValidatorWrite) MarshalJSON

func (gv GenesisValidatorWrite) MarshalJSON() ([]byte, error)

写入文件中间转换

func (*GenesisValidatorWrite) UnmarshalJSON

func (gv *GenesisValidatorWrite) UnmarshalJSON(input []byte) error

写入文件中间转换

type IntermediateBlockResult

type IntermediateBlockResult struct {
	Block *types.Block
	// followed by block execute result
	State    *state.StateDB
	Receipts types.Receipts
	Ops      *types.PendingOps
}

IntermediateBlockResult represents intermediate block execute result.

type NCBlock

type NCBlock struct {
	Block              *types.Block             `json:"block"`
	NTCExtra           *NeatConExtra            `json:"ntcexdata"`
	TX3ProofData       []*types.TX3ProofData    `json:"tx3proofdata"`
	IntermediateResult *IntermediateBlockResult `json:"-"`
}

func (*NCBlock) FillSeenCommitHash

func (b *NCBlock) FillSeenCommitHash()

func (*NCBlock) FromBytes

func (b *NCBlock) FromBytes(reader io.Reader) (*NCBlock, error)

func (*NCBlock) Hash

func (b *NCBlock) Hash() []byte

Computes and returns the block hash. If the block is incomplete, block hash is nil for safety.

func (*NCBlock) HashesTo

func (b *NCBlock) HashesTo(hash []byte) bool

Convenience. A nil block never hashes to anything. Nothing hashes to a nil hash.

func (*NCBlock) MakePartSet

func (b *NCBlock) MakePartSet(partSize int) *PartSet

func (*NCBlock) String

func (b *NCBlock) String() string

func (*NCBlock) StringIndented

func (b *NCBlock) StringIndented(indent string) string

func (*NCBlock) StringShort

func (b *NCBlock) StringShort() string

func (*NCBlock) ToBytes

func (b *NCBlock) ToBytes() []byte

func (*NCBlock) ValidateBasic

func (b *NCBlock) ValidateBasic(ncExtra *NeatConExtra) error

Basic validation that doesn't involve state data.

type NeatConExtra

type NeatConExtra struct {
	ChainID         string    `json:"chain_id"`
	Height          uint64    `json:"height"`
	Time            time.Time `json:"time"`
	NeedToSave      bool      `json:"need_to_save"`
	NeedToBroadcast bool      `json:"need_to_broadcast"`
	EpochNumber     uint64    `json:"epoch_number"`
	SeenCommitHash  []byte    `json:"last_commit_hash"` // commit from validators from the last block
	ValidatorsHash  []byte    `json:"validators_hash"`  // validators for the current block
	SeenCommit      *Commit   `json:"seen_commit"`
	EpochBytes      []byte    `json:"epoch_bytes"`
}

func DecodeExtraData

func DecodeExtraData(extra string) (ncExtra *NeatConExtra, err error)

func ExtractNeatConExtra

func ExtractNeatConExtra(h *neatTypes.Header) (*NeatConExtra, error)

ExtractNeatConExtra extracts all values of the NeatConExtra from the header. It returns an error if the length of the given extra-data is less than 32 bytes or the extra-data can not be decoded.

func (*NeatConExtra) Copy

func (te *NeatConExtra) Copy() *NeatConExtra

be careful, here not deep copy because just reference to SeenCommit

func (*NeatConExtra) Hash

func (te *NeatConExtra) Hash() []byte

NOTE: hash is nil if required fields are missing.

func (*NeatConExtra) String

func (te *NeatConExtra) String() string

type NeatConExtraApi

type NeatConExtraApi struct {
	ChainID         string         `json:"chainId"`
	Height          hexutil.Uint64 `json:"height"`
	Time            time.Time      `json:"time"`
	NeedToSave      bool           `json:"needToSave"`
	NeedToBroadcast bool           `json:"needToBroadcast"`
	EpochNumber     hexutil.Uint64 `json:"epochNumber"`
	SeenCommitHash  string         `json:"lastCommitHash"` // commit from validators from the last block
	ValidatorsHash  string         `json:"validatorsHash"` // validators for the current block
	SeenCommit      *CommitApi     `json:"seenCommit"`
	EpochBytes      []byte         `json:"epochBytes"`
}

type OneEpochDoc

type OneEpochDoc struct {
	Number         uint64             `json:"number"`
	RewardPerBlock *big.Int           `json:"reward_per_block"`
	StartBlock     uint64             `json:"start_block"`
	EndBlock       uint64             `json:"end_block"`
	Status         int                `json:"status"`
	Validators     []GenesisValidator `json:"validators"`
}

func (OneEpochDoc) MarshalJSON

func (ep OneEpochDoc) MarshalJSON() ([]byte, error)

func (*OneEpochDoc) UnmarshalJSON

func (ep *OneEpochDoc) UnmarshalJSON(input []byte) error

type OneEpochDocWrite

type OneEpochDocWrite struct {
	Number         uint64                  `json:"number"`
	RewardPerBlock *big.Int                `json:"reward_per_block"`
	StartBlock     uint64                  `json:"start_block"`
	EndBlock       uint64                  `json:"end_block"`
	Status         int                     `json:"status"`
	Validators     []GenesisValidatorWrite `json:"validators"`
}

写入文件使用

func (OneEpochDocWrite) MarshalJSON

func (ep OneEpochDocWrite) MarshalJSON() ([]byte, error)

写入文件中间转换

func (*OneEpochDocWrite) UnmarshalJSON

func (ep *OneEpochDocWrite) UnmarshalJSON(input []byte) error

写入文件中间转换

type Part

type Part struct {
	Index int                `json:"index"`
	Bytes []byte             `json:"bytes"`
	Proof merkle.SimpleProof `json:"proof"`
	// contains filtered or unexported fields
}

func (*Part) Hash

func (part *Part) Hash() []byte

func (*Part) String

func (part *Part) String() string

func (*Part) StringIndented

func (part *Part) StringIndented(indent string) string

type PartSet

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

func NewPartSetFromData

func NewPartSetFromData(data []byte, partSize int) *PartSet

Returns an immutable, full PartSet from the data bytes. The data bytes are split into "partSize" chunks, and merkle tree computed.

func NewPartSetFromHeader

func NewPartSetFromHeader(header PartSetHeader) *PartSet

Returns an empty PartSet ready to be populated.

func (*PartSet) AddPart

func (ps *PartSet) AddPart(part *Part, verify bool) (bool, error)

func (*PartSet) BitArray

func (ps *PartSet) BitArray() *BitArray

func (*PartSet) Count

func (ps *PartSet) Count() int

func (*PartSet) GetPart

func (ps *PartSet) GetPart(index int) *Part

func (*PartSet) GetReader

func (ps *PartSet) GetReader() io.Reader

func (*PartSet) HasHeader

func (ps *PartSet) HasHeader(header PartSetHeader) bool

func (*PartSet) Hash

func (ps *PartSet) Hash() []byte

func (*PartSet) HashesTo

func (ps *PartSet) HashesTo(hash []byte) bool

func (*PartSet) Header

func (ps *PartSet) Header() PartSetHeader

func (*PartSet) IsComplete

func (ps *PartSet) IsComplete() bool

func (*PartSet) StringShort

func (ps *PartSet) StringShort() string

func (*PartSet) Total

func (ps *PartSet) Total() int

type PartSetHeader

type PartSetHeader struct {
	Total uint64 `json:"total"`
	Hash  []byte `json:"hash"`
}

func (PartSetHeader) Equals

func (psh PartSetHeader) Equals(other PartSetHeader) bool

func (PartSetHeader) IsZero

func (psh PartSetHeader) IsZero() bool

func (PartSetHeader) String

func (psh PartSetHeader) String() string

func (PartSetHeader) WriteSignBytes

func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int, err *error)

type PartSetHeaderApi

type PartSetHeaderApi struct {
	Total hexutil.Uint64 `json:"total"`
	Hash  string         `json:"hash"`
}

type PartSetReader

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

func NewPartSetReader

func NewPartSetReader(parts []*Part) *PartSetReader

func (*PartSetReader) Read

func (psr *PartSetReader) Read(p []byte) (n int, err error)

type PrivV

type PrivV struct {
	Address string         `json:"address"`
	PubKey  crypto.PubKey  `json:"consensus_pub_key"`
	PrivKey crypto.PrivKey `json:"consensus_priv_key"`

	Signer `json:"-"`
	// contains filtered or unexported fields
}

修改 privalidator 的地址类型为string

type PrivValidator

type PrivValidator struct {
	// NeatChain Account Address
	Address common.Address `json:"address"`
	// NeatChain Consensus Public Key, in BLS format
	PubKey crypto.PubKey `json:"consensus_pub_key"`
	// NeatChain Consensus Private Key, in BLS format
	// PrivKey should be empty if a Signer other than the default is being used.
	PrivKey crypto.PrivKey `json:"consensus_priv_key"`

	Signer `json:"-"`
	// contains filtered or unexported fields
}

func GenPrivValidatorKey

func GenPrivValidatorKey(address common.Address) *PrivValidator

func LoadPrivValidator

func LoadPrivValidator(filePath string) *PrivValidator

修改加载文件的方法,兼容string 的地址类型

func (*PrivValidator) GetAddress

func (pv *PrivValidator) GetAddress() []byte

func (*PrivValidator) GetPubKey

func (pv *PrivValidator) GetPubKey() crypto.PubKey

func (*PrivValidator) Save

func (pv *PrivValidator) Save()

func (*PrivValidator) SetFile

func (pv *PrivValidator) SetFile(filePath string)

func (*PrivValidator) SignProposal

func (pv *PrivValidator) SignProposal(chainID string, proposal *Proposal) error

func (*PrivValidator) SignVote

func (pv *PrivValidator) SignVote(chainID string, vote *Vote) error

func (*PrivValidator) String

func (pv *PrivValidator) String() string

type PrivValidatorsByAddress

type PrivValidatorsByAddress []*PrivValidator

func (PrivValidatorsByAddress) Len

func (pvs PrivValidatorsByAddress) Len() int

func (PrivValidatorsByAddress) Less

func (pvs PrivValidatorsByAddress) Less(i, j int) bool

func (PrivValidatorsByAddress) Swap

func (pvs PrivValidatorsByAddress) Swap(i, j int)

type Proposal

type Proposal struct {
	NodeID           string           `json:"node_id"`
	Height           uint64           `json:"height"`
	Round            int              `json:"round"`
	Hash             []byte           `json:"hash"`
	BlockPartsHeader PartSetHeader    `json:"block_parts_header"`
	POLRound         int              `json:"pol_round"`    // -1 if null.
	POLBlockID       BlockID          `json:"pol_block_id"` // zero if null.
	ProposerNetAddr  string           `json:"proposer_net_addr"`
	ProposerPeerKey  string           `json:"proposer_peer_key"`
	Signature        crypto.Signature `json:"signature"`
}

func NewProposal

func NewProposal(height uint64, round int, hash []byte, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID, peerKey string) *Proposal

polRound: -1 if no polRound.

func (*Proposal) BlockHash

func (p *Proposal) BlockHash() []byte

func (*Proposal) BlockHeaderHash

func (p *Proposal) BlockHeaderHash() []byte

func (*Proposal) String

func (p *Proposal) String() string

func (*Proposal) WriteSignBytes

func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type RefundValidatorAmount

type RefundValidatorAmount struct {
	Address common.Address
	Amount  *big.Int // Amount will be nil when Voteout is true
	Voteout bool     // Voteout means refund all the amount (self deposit + delegate)
}

type RewardSchemeDoc

type RewardSchemeDoc struct {
	TotalReward        *big.Int `json:"total_reward"`
	RewardFirstYear    *big.Int `json:"reward_first_year"`
	EpochNumberPerYear uint64   `json:"epoch_no_per_year"`
	TotalYear          uint64   `json:"total_year"`
}

func (RewardSchemeDoc) MarshalJSON

func (rs RewardSchemeDoc) MarshalJSON() ([]byte, error)

func (*RewardSchemeDoc) UnmarshalJSON

func (rs *RewardSchemeDoc) UnmarshalJSON(input []byte) error

type SignAggr

type SignAggr struct {
	ChainID       string
	Height        uint64    `json:"height"`
	Round         int       `json:"round"`
	Type          byte      `json:"type"`
	NumValidators int       `json:"numValidators"`
	BlockID       BlockID   `json:"blockid"`
	Maj23         BlockID   `json:"maj23"`
	BitArray      *BitArray `json:"bitarray"`
	Sum           int64     `json:"sum"`

	// BLS signature aggregation to be added here
	SignatureAggr crypto.BLSSignature `json:"SignatureAggr"`
	SignBytes     []byte              `json:"sign_bytes"`
}

func MakeSignAggr

func MakeSignAggr(height uint64, round int, mtype byte, numValidators int, blockID BlockID, chainID string, bitArray *BitArray, signAggr crypto.BLSSignature) *SignAggr

func (*SignAggr) HasAll

func (sa *SignAggr) HasAll(valSet *ValidatorSet) bool

func (*SignAggr) HasTwoThirdsMajority

func (sa *SignAggr) HasTwoThirdsMajority(valSet *ValidatorSet) bool

func (*SignAggr) IsCommit

func (sa *SignAggr) IsCommit() bool

func (*SignAggr) MakeCommit

func (sa *SignAggr) MakeCommit() *Commit

func (*SignAggr) SetBitArray

func (sa *SignAggr) SetBitArray(newBitArray *BitArray)

func (*SignAggr) SetMaj23

func (sa *SignAggr) SetMaj23(blockID BlockID)

func (*SignAggr) SignAggr

func (sa *SignAggr) SignAggr() crypto.BLSSignature

func (*SignAggr) SignAggrVerify

func (sa *SignAggr) SignAggrVerify(msg []byte, valSet *ValidatorSet) bool

func (*SignAggr) SignRound

func (sa *SignAggr) SignRound() int

func (*SignAggr) Size

func (sa *SignAggr) Size() int

func (*SignAggr) String

func (va *SignAggr) String() string

func (*SignAggr) StringIndented

func (va *SignAggr) StringIndented(indent string) string

func (*SignAggr) StringShort

func (va *SignAggr) StringShort() string

func (*SignAggr) TwoThirdsMajority

func (sa *SignAggr) TwoThirdsMajority() (blockID BlockID, ok bool)

Returns either a blockhash (or nil) that received +2/3 majority. If there exists no such majority, returns (nil, PartSetHeader{}, false).

func (*SignAggr) WriteSignBytes

func (sa *SignAggr) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type Signable

type Signable interface {
	WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
}

Signable is an interface for all signable things. It typically removes signatures before serializing.

type Signer

type Signer interface {
	Sign(msg []byte) crypto.Signature
}

This is used to sign votes. It is the caller's duty to verify the msg before calling Sign, eg. to avoid double signing. Currently, the only callers are SignVote and SignProposal

type SwitchEpochOp

type SwitchEpochOp struct {
	ChainId       string
	NewValidators *ValidatorSet
}

SwitchEpoch op

func (*SwitchEpochOp) Conflict

func (op *SwitchEpochOp) Conflict(op1 neatTypes.PendingOp) bool

func (*SwitchEpochOp) String

func (op *SwitchEpochOp) String() string

type TMEventData

type TMEventData interface {
	events.EventData
	AssertIsTMEventData()
}

implements events.EventData

type Tx

type Tx []byte

func (Tx) Hash

func (tx Tx) Hash() []byte

NOTE: this is the hash of the go-wire encoded Tx. Tx has no types at this level, so just length-prefixed. Alternatively, it may make sense to add types here and let []byte be type 0x1 so we can have versioned txs if need be in the future.

type TxProof

type TxProof struct {
	Index, Total int
	RootHash     []byte
	Data         Tx
	Proof        merkle.SimpleProof
}

func (TxProof) LeafHash

func (tp TxProof) LeafHash() []byte

func (TxProof) Validate

func (tp TxProof) Validate(dataHash []byte) error

Validate returns nil if it matches the dataHash, and is internally consistent otherwise, returns a sensible error

type Txs

type Txs []Tx

func (Txs) Hash

func (txs Txs) Hash() []byte

func (Txs) Index

func (txs Txs) Index(tx Tx) int

Index returns the index of this transaction in the list, or -1 if not found

func (Txs) IndexByHash

func (txs Txs) IndexByHash(hash []byte) int

Index returns the index of this transaction hash in the list, or -1 if not found

func (Txs) Proof

func (txs Txs) Proof(i int) TxProof

Proof returns a simple merkle proof for this node.

Panics if i < 0 or i >= len(txs)

TODO: optimize this!

type Validator

type Validator struct {
	Address        []byte        `json:"address"`
	PubKey         crypto.PubKey `json:"pub_key"`
	VotingPower    *big.Int      `json:"voting_power"`
	RemainingEpoch uint64        `json:"remain_epoch"`
}

Volatile state for each Validator TODO: make non-volatile identity

func NewValidator

func NewValidator(address []byte, pubKey crypto.PubKey, votingPower *big.Int) *Validator

func (*Validator) Copy

func (v *Validator) Copy() *Validator

Creates a new copy of the validator so we can mutate accum. Panics if the validator is nil.

func (*Validator) Equals

func (v *Validator) Equals(other *Validator) bool

func (*Validator) Hash

func (v *Validator) Hash() []byte

func (*Validator) String

func (v *Validator) String() string

type ValidatorSet

type ValidatorSet struct {
	// NOTE: persisted via reflect, must be exported.
	Validators []*Validator `json:"validators"`
	// contains filtered or unexported fields
}

ValidatorSet represent a set of *Validator at a given height. The validators can be fetched by address or index. The index is in order of .Address, so the indices are fixed for all rounds of a given blockchain height. On the other hand, the .AccumPower of each validator and the designated .GetProposer() of a set changes every round, upon calling .IncrementAccum(). NOTE: Not goroutine-safe. NOTE: All get/set to validators should copy the value for safety. TODO: consider validator Accum overflow TODO: move valset into an iavl tree where key is 'blockbonded|pubkey'

func NewValidatorSet

func NewValidatorSet(vals []*Validator) *ValidatorSet

func (*ValidatorSet) Add

func (valSet *ValidatorSet) Add(val *Validator) (added bool)

func (*ValidatorSet) AggrPubKey

func (valSet *ValidatorSet) AggrPubKey(bitMap *cmn.BitArray) crypto.PubKey

func (*ValidatorSet) Copy

func (valSet *ValidatorSet) Copy() *ValidatorSet

func (*ValidatorSet) Equals

func (valSet *ValidatorSet) Equals(other *ValidatorSet) bool

func (*ValidatorSet) GetAggrPubKeyAndAddress

func (valSet *ValidatorSet) GetAggrPubKeyAndAddress(bitMap *cmn.BitArray) (*ConsensusAggr, error)

func (*ValidatorSet) GetByAddress

func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator)

func (*ValidatorSet) GetByIndex

func (valSet *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator)

func (*ValidatorSet) HasAddress

func (valSet *ValidatorSet) HasAddress(address []byte) bool

HasAddress returns true if address given is in the validator set, false - otherwise.

func (*ValidatorSet) Hash

func (valSet *ValidatorSet) Hash() []byte

func (*ValidatorSet) Iterate

func (valSet *ValidatorSet) Iterate(fn func(index int, val *Validator) bool)

func (*ValidatorSet) Remove

func (valSet *ValidatorSet) Remove(address []byte) (val *Validator, removed bool)

func (*ValidatorSet) Size

func (valSet *ValidatorSet) Size() int

func (*ValidatorSet) String

func (valSet *ValidatorSet) String() string

func (*ValidatorSet) StringIndented

func (valSet *ValidatorSet) StringIndented(indent string) string

func (*ValidatorSet) TalliedVotingPower

func (valSet *ValidatorSet) TalliedVotingPower(bitMap *cmn.BitArray) (*big.Int, *big.Int, *big.Int, error)

func (*ValidatorSet) TotalVotingPower

func (valSet *ValidatorSet) TotalVotingPower() *big.Int

func (*ValidatorSet) Update

func (valSet *ValidatorSet) Update(val *Validator) (updated bool)

func (*ValidatorSet) VerifyCommit

func (valSet *ValidatorSet) VerifyCommit(chainID string, height uint64, commit *Commit) error

Verify that +2/3 of the set had signed the given signBytes

func (*ValidatorSet) VerifyCommitAny

func (valSet *ValidatorSet) VerifyCommitAny(chainID string, blockID BlockID, height int, commit *Commit) error

Verify that +2/3 of this set had signed the given signBytes. Unlike VerifyCommit(), this function can verify commits with differeent sets.

type ValidatorStatus

type ValidatorStatus struct {
	IsForbidden bool `json:"isForbidden"`
}

type ValidatorsByAddress

type ValidatorsByAddress []*Validator

func (ValidatorsByAddress) Len

func (vs ValidatorsByAddress) Len() int

func (ValidatorsByAddress) Less

func (vs ValidatorsByAddress) Less(i, j int) bool

func (ValidatorsByAddress) Swap

func (vs ValidatorsByAddress) Swap(i, j int)

type Vote

type Vote struct {
	ValidatorAddress []byte           `json:"validator_address"`
	ValidatorIndex   uint64           `json:"validator_index"`
	Height           uint64           `json:"height"`
	Round            uint64           `json:"round"`
	Type             byte             `json:"type"`
	BlockID          BlockID          `json:"block_id"` // zero if vote is nil.
	Signature        crypto.Signature `json:"signature"`
	SignBytes        []byte           `json:"sign_bytes"`
}

Represents a prevote, precommit, or commit vote from validators for consensus.

func (*Vote) Copy

func (vote *Vote) Copy() *Vote

func (*Vote) DecodeRLP

func (vote *Vote) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the istanbul fields from a RLP stream.

func (*Vote) EncodeRLP

func (vote *Vote) EncodeRLP(w io.Writer) error

EncodeRLP serializes ist into the Ethereum RLP format.

func (*Vote) String

func (vote *Vote) String() string

func (*Vote) WriteSignBytes

func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

type VoteSet

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

func NewVoteSet

func NewVoteSet(chainID string, height uint64, round int, type_ byte, valSet *ValidatorSet) *VoteSet

Constructs a new VoteSet struct used to accumulate votes for given height/round.

func (*VoteSet) AddVote

func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error)

Returns added=true if vote is valid and new. Otherwise returns err=ErrVote[

UnexpectedStep | InvalidIndex | InvalidAddress |
InvalidSignature | InvalidBlockHash | ConflictingVotes ]

Duplicate votes return added=false, err=nil. Conflicting votes return added=*, err=ErrVoteConflictingVotes. NOTE: vote should not be mutated after adding. NOTE: VoteSet must not be nil

func (*VoteSet) BitArray

func (voteSet *VoteSet) BitArray() *BitArray

func (*VoteSet) BitArrayByBlockID

func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID) *BitArray

func (*VoteSet) ChainID

func (voteSet *VoteSet) ChainID() string

func (*VoteSet) GetByAddress

func (voteSet *VoteSet) GetByAddress(address []byte) *Vote

func (*VoteSet) GetByIndex

func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote

NOTE: if validator has conflicting votes, returns "canonical" vote

func (*VoteSet) HasAll

func (voteSet *VoteSet) HasAll() bool

func (*VoteSet) HasTwoThirdsMajority

func (voteSet *VoteSet) HasTwoThirdsMajority() bool

func (*VoteSet) Height

func (voteSet *VoteSet) Height() uint64

func (*VoteSet) IsCommit

func (voteSet *VoteSet) IsCommit() bool

func (*VoteSet) Round

func (voteSet *VoteSet) Round() int

func (*VoteSet) SetPeerMaj23

func (voteSet *VoteSet) SetPeerMaj23(peerID string, blockID BlockID)

If a peer claims that it has 2/3 majority for given blockKey, call this. NOTE: if there are too many peers, or too much peer churn, this can cause memory issues. TODO: implement ability to remove peers too NOTE: VoteSet must not be nil

func (*VoteSet) Size

func (voteSet *VoteSet) Size() int

func (*VoteSet) String

func (voteSet *VoteSet) String() string

func (*VoteSet) StringIndented

func (voteSet *VoteSet) StringIndented(indent string) string

func (*VoteSet) StringShort

func (voteSet *VoteSet) StringShort() string

func (*VoteSet) TwoThirdsMajority

func (voteSet *VoteSet) TwoThirdsMajority() (blockID BlockID, ok bool)

Returns either a blockhash (or nil) that received +2/3 majority. If there exists no such majority, returns (nil, PartSetHeader{}, false).

func (*VoteSet) Type

func (voteSet *VoteSet) Type() byte

func (*VoteSet) Votes

func (voteSet *VoteSet) Votes() []*Vote

type VoteSetReader

type VoteSetReader interface {
	Height() uint64
	Round() int
	Type() byte
	Size() int
	BitArray() *BitArray
	GetByIndex(int) *Vote
	IsCommit() bool
}

Common interface between *consensus.VoteSet and types.Commit

Jump to

Keyboard shortcuts

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