Documentation ¶
Index ¶
- Constants
- Variables
- func BloomLookup(bin Bloom, topic bytesBacked) bool
- func Bytestoi(arr []byte) uint64
- func Itobytes(val uint64) []byte
- func ReadRecord(file *os.File, obj interface{}) error
- func ResetTestBlocks()
- func WriteMetadata(writer *bufio.Writer, metadata *SnapshotMetadata) error
- func WriteRecord(writer *bufio.Writer, k, v common.Bytes) error
- type BackupBlock
- type Block
- type BlockHeader
- func (h *BlockHeader) CalculateHash() common.Hash
- func (h *BlockHeader) Hash() common.Hash
- func (h *BlockHeader) SetSignature(sig *crypto.Signature)
- func (h *BlockHeader) SignBytes() common.Bytes
- func (h *BlockHeader) String() string
- func (h *BlockHeader) UpdateHash() common.Hash
- func (h *BlockHeader) Validate(chainID string) result.Result
- type BlockStatus
- func (bs BlockStatus) IsCommitted() bool
- func (bs BlockStatus) IsDirectlyFinalized() bool
- func (bs BlockStatus) IsFinalized() bool
- func (bs BlockStatus) IsIndirectlyFinalized() bool
- func (bs BlockStatus) IsInvalid() bool
- func (bs BlockStatus) IsPending() bool
- func (bs BlockStatus) IsTrusted() bool
- func (bs BlockStatus) IsValid() bool
- type Bloom
- func (b *Bloom) Add(d *big.Int)
- func (b Bloom) Big() *big.Int
- func (b Bloom) Bytes() []byte
- func (b Bloom) MarshalText() ([]byte, error)
- func (b *Bloom) SetBytes(d []byte)
- func (b Bloom) Test(test *big.Int) bool
- func (b Bloom) TestBytes(test []byte) bool
- func (b *Bloom) UnmarshalText(input []byte) error
- type ByID
- type CommitCertificate
- type ConsensusEngine
- type ExtendedBlock
- type ExtendedBlockInnerJSON
- type Ledger
- type Proposal
- type SnapshotBlockTrio
- type SnapshotFirstBlock
- type SnapshotMetadata
- type SnapshotSecondBlock
- type SnapshotThirdBlock
- type SnapshotTrieRecord
- type Stake
- type StakeHolder
- type StakeJSON
- type TxInfo
- type VCPProof
- func (vp *VCPProof) DecodeRLP(stream *rlp.Stream) error
- func (vp VCPProof) EncodeRLP(w io.Writer) error
- func (vp *VCPProof) Get(key []byte) (value []byte, err error)
- func (vp VCPProof) GetKvs() []*proofKV
- func (vp *VCPProof) Has(key []byte) (bool, error)
- func (vp *VCPProof) Put(key []byte, value []byte) error
- type Validator
- type ValidatorCandidatePool
- func (vcp *ValidatorCandidatePool) DepositStake(source common.Address, holder common.Address, amount *big.Int) (err error)
- func (vcp *ValidatorCandidatePool) GetTopStakeHolders(maxNumStakeHolders int) []*StakeHolder
- func (vcp *ValidatorCandidatePool) ReturnStakes(currentHeight uint64) []*Stake
- func (vcp *ValidatorCandidatePool) WithdrawStake(source common.Address, holder common.Address, currentHeight uint64) error
- type ValidatorManager
- type ValidatorSet
- func (s *ValidatorSet) AddValidator(validator Validator)
- func (s *ValidatorSet) Copy() *ValidatorSet
- func (s *ValidatorSet) Equals(t *ValidatorSet) bool
- func (s *ValidatorSet) GetValidator(id common.Address) (Validator, error)
- func (s *ValidatorSet) HasMajority(votes *VoteSet) bool
- func (s *ValidatorSet) HasMajorityVotes(votes []Vote) bool
- func (s *ValidatorSet) SetValidators(validators []Validator)
- func (s *ValidatorSet) Size() int
- func (s *ValidatorSet) String() string
- func (s *ValidatorSet) TotalStake() *big.Int
- func (s *ValidatorSet) Validators() []Validator
- type ViewSelector
- type Vote
- type VoteByID
- type VoteSet
- func (s *VoteSet) AddVote(vote Vote)
- func (s *VoteSet) Copy() *VoteSet
- func (s *VoteSet) DecodeRLP(stream *rlp.Stream) error
- func (s *VoteSet) EncodeRLP(w io.Writer) error
- func (s *VoteSet) FilterByValidators(validators *ValidatorSet) *VoteSet
- func (s *VoteSet) IsEmpty() bool
- func (s *VoteSet) MarshalJSON() ([]byte, error)
- func (s *VoteSet) Merge(another *VoteSet) *VoteSet
- func (s *VoteSet) Size() int
- func (s *VoteSet) String() string
- func (s *VoteSet) UniqueVoter() *VoteSet
- func (s *VoteSet) UniqueVoterAndBlock() *VoteSet
- func (s *VoteSet) UnmarshalJSON(b []byte) error
- func (s *VoteSet) Validate() result.Result
- func (s *VoteSet) Votes() []Vote
Constants ¶
const ( // BloomByteLength represents the number of bytes used in a header log bloom. BloomByteLength = 256 // BloomBitLength represents the number of bits used in a header log bloom. BloomBitLength = 8 * BloomByteLength )
const ( MainnetChainID = "mainnet" MainnetGenesisBlockHash = "0xd8836c6cf3c3ccea0b015b4ed0f9efb0ffe6254db793a515843c9d0f68cbab65" GenesisBlockHeight = uint64(0) )
const ( SVStart = iota SVEnd )
const ( StakeForValidator uint8 = 0 StakeForGuardian uint8 = 1 ReturnLockingPeriod uint64 = 28800 // number of blocks, approximately 2 days with 6 second block time InvalidReturnHeight uint64 = ^uint64(0) // max uint64 )
const BlockTrioStoreKeyPrefix = "prooftrio_"
const ( // MaxNumRegularTxsPerBlock represents the max number of regular transaction can be inclulded in one block MaxNumRegularTxsPerBlock int = 8192 )
Variables ¶
var Bloom9 = bloom9
var DefaultSigner *crypto.PrivateKey
var (
EmptyRootHash = calculateRootHash([]common.Bytes{})
)
var ( // ErrValidatorNotFound for ID is not found in validator set. ErrValidatorNotFound = errors.New("ValidatorNotFound") )
var (
MinValidatorStakeDeposit *big.Int
)
var TestBlocksLock = &sync.Mutex{}
var (
Zero *big.Int
)
Functions ¶
func BloomLookup ¶
func ReadRecord ¶
func ResetTestBlocks ¶
func ResetTestBlocks()
func WriteMetadata ¶
func WriteMetadata(writer *bufio.Writer, metadata *SnapshotMetadata) error
Types ¶
type BackupBlock ¶
type BackupBlock struct { Block *ExtendedBlock Votes *VoteSet `rlp:"nil"` Next *BackupBlock }
func (*BackupBlock) String ¶
func (b *BackupBlock) String() string
type Block ¶
type Block struct { *BlockHeader Txs []common.Bytes `json:"transactions"` }
Block represents a block in chain.
func CreateTestBlock ¶
CreateTestBlock creates a block for testing.
func GetTestBlock ¶
type BlockHeader ¶
type BlockHeader struct { ChainID string Epoch uint64 Height uint64 Parent common.Hash HCC CommitCertificate TxHash common.Hash ReceiptHash common.Hash `json:"-"` Bloom Bloom `json:"-"` StateHash common.Hash Timestamp *big.Int Proposer common.Address Signature *crypto.Signature // contains filtered or unexported fields }
BlockHeader contains the essential information of a block.
func (*BlockHeader) CalculateHash ¶
func (h *BlockHeader) CalculateHash() common.Hash
func (*BlockHeader) SetSignature ¶
func (h *BlockHeader) SetSignature(sig *crypto.Signature)
SetSignature sets given signature in header.
func (*BlockHeader) SignBytes ¶
func (h *BlockHeader) SignBytes() common.Bytes
SignBytes returns raw bytes to be signed.
func (*BlockHeader) String ¶
func (h *BlockHeader) String() string
func (*BlockHeader) UpdateHash ¶
func (h *BlockHeader) UpdateHash() common.Hash
UpdateHash recalculate hash of header.
type BlockStatus ¶
type BlockStatus byte
const ( BlockStatusPending BlockStatus = BlockStatus(iota) BlockStatusValid BlockStatusInvalid BlockStatusCommitted BlockStatusDirectlyFinalized BlockStatusIndirectlyFinalized BlockStatusTrusted )
Block status transitions:
+-------+ +-------+ +-------------------+ |Pending+---+------>Invalid| +----->IndirectlyFinalized| +-------+ | +-------+ | +-------------------+
| | | +-----+ +---------+ | +-----------------+ +------>Valid+-------->Committed+---+----->DirectlyFinalized| +-----+ +---------+ +-----------------+
func (BlockStatus) IsCommitted ¶
func (bs BlockStatus) IsCommitted() bool
func (BlockStatus) IsDirectlyFinalized ¶
func (bs BlockStatus) IsDirectlyFinalized() bool
func (BlockStatus) IsFinalized ¶
func (bs BlockStatus) IsFinalized() bool
func (BlockStatus) IsIndirectlyFinalized ¶
func (bs BlockStatus) IsIndirectlyFinalized() bool
func (BlockStatus) IsInvalid ¶
func (bs BlockStatus) IsInvalid() bool
func (BlockStatus) IsPending ¶
func (bs BlockStatus) IsPending() bool
func (BlockStatus) IsTrusted ¶
func (bs BlockStatus) IsTrusted() bool
func (BlockStatus) IsValid ¶
func (bs BlockStatus) IsValid() bool
IsValid returns whether block has been validated.
type Bloom ¶
type Bloom [BloomByteLength]byte
Bloom represents a 2048 bit bloom filter.
func BytesToBloom ¶
BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.
func (Bloom) MarshalText ¶
MarshalText encodes b as a hex string with 0x prefix.
func (*Bloom) SetBytes ¶
SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.
func (*Bloom) UnmarshalText ¶
UnmarshalText b as a hex string with 0x prefix.
type CommitCertificate ¶
CommitCertificate represents a commit made a majority of validators.
func (CommitCertificate) Copy ¶
func (cc CommitCertificate) Copy() CommitCertificate
Copy creates a copy of this commit certificate.
func (CommitCertificate) IsValid ¶
func (cc CommitCertificate) IsValid(validators *ValidatorSet) bool
IsValid checks if a CommitCertificate is valid.
func (CommitCertificate) String ¶
func (cc CommitCertificate) String() string
type ConsensusEngine ¶
type ConsensusEngine interface { ID() string PrivateKey() *crypto.PrivateKey GetTip(includePendingBlockingLeaf bool) *ExtendedBlock GetEpoch() uint64 GetLedger() Ledger AddMessage(msg interface{}) FinalizedBlocks() chan *Block GetLastFinalizedBlock() *ExtendedBlock }
ConsensusEngine is the interface of a consensus engine.
type ExtendedBlock ¶
type ExtendedBlock struct { *Block Children []common.Hash `json:"children"` Status BlockStatus `json:"status"` HasValidatorUpdate bool }
ExtendedBlock is wrapper over Block, containing extra information related to the block.
func (*ExtendedBlock) MarshalJSON ¶
func (eb *ExtendedBlock) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler
func (*ExtendedBlock) ShortString ¶
func (eb *ExtendedBlock) ShortString() string
ShortString returns a short string describing the block.
func (*ExtendedBlock) String ¶
func (eb *ExtendedBlock) String() string
type ExtendedBlockInnerJSON ¶
type ExtendedBlockInnerJSON ExtendedBlock
type Ledger ¶
type Ledger interface { GetCurrentBlock() *Block ScreenTxUnsafe(rawTx common.Bytes) result.Result ScreenTx(rawTx common.Bytes) (priority *TxInfo, res result.Result) ProposeBlockTxs(block *Block) (stateRootHash common.Hash, blockRawTxs []common.Bytes, res result.Result) ApplyBlockTxs(block *Block) result.Result ResetState(height uint64, rootHash common.Hash) result.Result FinalizeState(height uint64, rootHash common.Hash) result.Result GetFinalizedValidatorCandidatePool(blockHash common.Hash, isNext bool) (*ValidatorCandidatePool, error) PruneState(endHeight uint64) error }
Ledger defines the interface of the ledger
type Proposal ¶
type Proposal struct { Block *Block `rlp:"nil"` ProposerID common.Address Votes *VoteSet `rlp:"nil"` }
Proposal represents a proposal of a new block.
type SnapshotBlockTrio ¶
type SnapshotBlockTrio struct { First SnapshotFirstBlock Second SnapshotSecondBlock Third SnapshotThirdBlock }
type SnapshotFirstBlock ¶
type SnapshotFirstBlock struct { Header BlockHeader Proof VCPProof }
type SnapshotMetadata ¶
type SnapshotMetadata struct { ProofTrios []SnapshotBlockTrio TailTrio SnapshotBlockTrio }
type SnapshotSecondBlock ¶
type SnapshotSecondBlock struct {
Header BlockHeader
}
type SnapshotThirdBlock ¶
type SnapshotThirdBlock struct { Header BlockHeader VoteSet *VoteSet }
type SnapshotTrieRecord ¶
type StakeHolder ¶
func (*StakeHolder) String ¶
func (sh *StakeHolder) String() string
func (*StakeHolder) TotalStake ¶
func (sh *StakeHolder) TotalStake() *big.Int
type StakeJSON ¶
type StakeJSON struct { Source common.Address `json:"source"` Amount *common.JSONBig `json:"amount"` Withdrawn bool `json:"withdrawn"` ReturnHeight *common.JSONBig `json:"return_height"` }
func NewStakeJSON ¶
type VCPProof ¶
type VCPProof struct {
// contains filtered or unexported fields
}
type Validator ¶
Validator contains the public information of a validator.
func NewValidator ¶
NewValidator creates a new validator instance.
type ValidatorCandidatePool ¶
type ValidatorCandidatePool struct {
SortedCandidates []*StakeHolder
}
func (*ValidatorCandidatePool) DepositStake ¶
func (*ValidatorCandidatePool) GetTopStakeHolders ¶
func (vcp *ValidatorCandidatePool) GetTopStakeHolders(maxNumStakeHolders int) []*StakeHolder
func (*ValidatorCandidatePool) ReturnStakes ¶
func (vcp *ValidatorCandidatePool) ReturnStakes(currentHeight uint64) []*Stake
func (*ValidatorCandidatePool) WithdrawStake ¶
type ValidatorManager ¶
type ValidatorManager interface { SetConsensusEngine(consensus ConsensusEngine) GetProposer(blockHash common.Hash, epoch uint64) Validator GetNextProposer(blockHash common.Hash, epoch uint64) Validator GetValidatorSet(blockHash common.Hash) *ValidatorSet GetNextValidatorSet(blockHash common.Hash) *ValidatorSet }
ValidatorManager is the component for managing validator related logic for consensus engine.
type ValidatorSet ¶
type ValidatorSet struct {
// contains filtered or unexported fields
}
ValidatorSet represents a set of validators.
func NewValidatorSet ¶
func NewValidatorSet() *ValidatorSet
NewValidatorSet returns a new instance of ValidatorSet.
func (*ValidatorSet) AddValidator ¶
func (s *ValidatorSet) AddValidator(validator Validator)
AddValidator adds a validator to the validator set.
func (*ValidatorSet) Copy ¶
func (s *ValidatorSet) Copy() *ValidatorSet
Copy creates a copy of this validator set.
func (*ValidatorSet) Equals ¶
func (s *ValidatorSet) Equals(t *ValidatorSet) bool
Equals checks whether the validator set is the same as another validator set
func (*ValidatorSet) GetValidator ¶
func (s *ValidatorSet) GetValidator(id common.Address) (Validator, error)
GetValidator returns a validator if a matching ID is found.
func (*ValidatorSet) HasMajority ¶
func (s *ValidatorSet) HasMajority(votes *VoteSet) bool
HasMajority checks whether a vote set has reach majority.
func (*ValidatorSet) HasMajorityVotes ¶
func (s *ValidatorSet) HasMajorityVotes(votes []Vote) bool
HasMajorityVotes checks whether a vote set has reach majority.
func (*ValidatorSet) SetValidators ¶
func (s *ValidatorSet) SetValidators(validators []Validator)
SetValidators sets validators
func (*ValidatorSet) Size ¶
func (s *ValidatorSet) Size() int
Size returns the number of the validators in the validator set.
func (*ValidatorSet) String ¶
func (s *ValidatorSet) String() string
String represents the string representation of the validator set
func (*ValidatorSet) TotalStake ¶
func (s *ValidatorSet) TotalStake() *big.Int
TotalStake returns the total stake of the validators in the set.
func (*ValidatorSet) Validators ¶
func (s *ValidatorSet) Validators() []Validator
Validators returns a slice of validators.
type ViewSelector ¶
type ViewSelector int
const ( DeliveredView ViewSelector = 1 CheckedView ViewSelector = 2 ScreenedView ViewSelector = 3 )
type Vote ¶
type Vote struct { Block common.Hash // Hash of the tip as seen by the voter. Height uint64 // Height of the tip Epoch uint64 // Voter's current epoch. It doesn't need to equal the epoch in the block above. ID common.Address // Voter's address. Signature *crypto.Signature }
Vote represents a vote on a block by a validaor.
func (*Vote) SetSignature ¶
SetSignature sets given signature in vote.
func (*Vote) Sign ¶
func (v *Vote) Sign(priv *crypto.PrivateKey)
Sign signs the vote using given private key.
type VoteByID ¶
type VoteByID []Vote
VoteByID implements sort.Interface for []Vote based on Voter's ID.
type VoteSet ¶
type VoteSet struct {
// contains filtered or unexported fields
}
VoteSet represents a set of votes on a proposal.
func (*VoteSet) FilterByValidators ¶ added in v1.0.1
func (s *VoteSet) FilterByValidators(validators *ValidatorSet) *VoteSet
FilterByValidators removes votes from non-validators.
func (*VoteSet) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (*VoteSet) UniqueVoter ¶
UniqueVoter consolidate vote set by removing votes from the same voter in older epoches.
func (*VoteSet) UniqueVoterAndBlock ¶
UniqueVoterAndBlock consolidate vote set by removing votes from the same voter to same block in older epoches.
func (*VoteSet) UnmarshalJSON ¶
UnmarshalJSON implements json.Marshaler