core

package
v0.0.0-...-3d668b6 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	MainnetChainID = "mainnet"

	MainnetGenesisBlockHash = "0xd8836c6cf3c3ccea0b015b4ed0f9efb0ffe6254db793a515843c9d0f68cbab65"

	GenesisBlockHeight = uint64(0)
)
View Source
const (
	SVStart = iota
	SVEnd
)
View Source
const (
	StakeForValidator     uint8 = 0
	StakeForGuardian      uint8 = 1
	StakeForEliteEdgeNode uint8 = 2

	ReturnLockingPeriod uint64 = 28800      // number of blocks, approximately 2 days with 6 second block time
	InvalidReturnHeight uint64 = ^uint64(0) // max uint64
)
View Source
const BlockTrioStoreKeyPrefix = "prooftrio_"
View Source
const (
	// MaxNumRegularTxsPerBlock represents the max number of regular transaction can be inclulded in one block
	MaxNumRegularTxsPerBlock int = 512
)
View Source
const SnapshotHeaderMagic = "ThetaToDaMoon"

Variables

View Source
var (
	EmptyRootHash    = CalculateRootHash([]common.Bytes{})
	SuicidedCodeHash = common.HexToHash("deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead")
)
View Source
var (
	MinEliteEdgeNodeStakeDeposit *big.Int
	MaxEliteEdgeNodeStakeDeposit *big.Int
)
View Source
var (
	MinGuardianStakeDeposit *big.Int

	MinGuardianStakeDeposit1000 *big.Int
)
View Source
var (
	MinValidatorStakeDeposit     *big.Int
	MinValidatorStakeDeposit200K *big.Int
)
View Source
var Bloom9 = bloom9
View Source
var DefaultSigner *crypto.PrivateKey
View Source
var (
	// ErrValidatorNotFound for ID is not found in validator set.
	ErrValidatorNotFound = errors.New("ValidatorNotFound")
)
View Source
var HardcodeBlockHashes = map[uint64]string{}

HardcodeBlockHashes maps block heights to hardcode block hashes

View Source
var TestBlocks map[string]*Block = make(map[string]*Block)
View Source
var TestBlocksLock = &sync.Mutex{}
View Source
var (
	Zero *big.Int
)

Functions

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func Bytestoi

func Bytestoi(arr []byte) uint64

func CalculateRootHash

func CalculateRootHash(items []common.Bytes) common.Hash

func Itobytes

func Itobytes(val uint64) []byte

func ReadRecord

func ReadRecord(file *os.File, obj interface{}) (uint64, error)

func ResetTestBlocks

func ResetTestBlocks()

func WriteLastCheckpoint

func WriteLastCheckpoint(writer *bufio.Writer, lastCheckpoint *LastCheckpoint) error

func WriteMetadata

func WriteMetadata(writer *bufio.Writer, metadata *SnapshotMetadata) error

func WriteRecord

func WriteRecord(writer *bufio.Writer, k, v common.Bytes) error

func WriteSnapshotHeader

func WriteSnapshotHeader(writer *bufio.Writer, snapshotHeader *SnapshotHeader) error

Types

type AggregatedEENVotes

type AggregatedEENVotes struct {
	Block      common.Hash      // Hash of the block.
	Multiplies []uint32         // Multiplies of each signer.
	Addresses  []common.Address // Addresses of each signer
	Signature  *bls.Signature   // Aggregated signature.
}

AggregatedEENVotes represents the aggregated elite edge node votes on a block.

func NewAggregatedEENVotes

func NewAggregatedEENVotes(block common.Hash) *AggregatedEENVotes

func (*AggregatedEENVotes) Abs

func (a *AggregatedEENVotes) Abs() int

Abs returns the number of voted elite edge nodes in the vote

func (*AggregatedEENVotes) Copy

Copy clones the aggregated votes

func (*AggregatedEENVotes) Merge

Merge creates a new aggregation that combines two vote sets. Returns nil, nil if input vote is a subset of current vote.

func (*AggregatedEENVotes) Pick

Pick selects better vote from two votes.

func (*AggregatedEENVotes) String

func (a *AggregatedEENVotes) String() string

func (*AggregatedEENVotes) Validate

Validate performs basic validation of the voteset.

type AggregatedVotes

type AggregatedVotes struct {
	Block      common.Hash    // Hash of the block.
	Gcp        common.Hash    // Hash of guardian candidate pool.
	Multiplies []uint32       // Multiplies of each signer.
	Signature  *bls.Signature // Aggregated signiature.
}

AggregatedVotes represents votes on a block.

func NewAggregateVotes

func NewAggregateVotes(block common.Hash, gcp *GuardianCandidatePool) *AggregatedVotes

func (*AggregatedVotes) Abs

func (a *AggregatedVotes) Abs() int

Abs returns the number of voted guardians in the vote

func (*AggregatedVotes) Copy

func (a *AggregatedVotes) Copy() *AggregatedVotes

Copy clones the aggregated votes

func (*AggregatedVotes) Merge

Merge creates a new aggregation that combines two vote sets. Returns nil, nil if input vote is a subset of current vote.

func (*AggregatedVotes) Pick

Pick selects better vote from two votes.

func (*AggregatedVotes) Sign

func (a *AggregatedVotes) Sign(key *bls.SecretKey, signerIdx int) bool

Sign adds signer's signature. Returns false if signer has already signed.

func (*AggregatedVotes) String

func (a *AggregatedVotes) String() string

func (*AggregatedVotes) Validate

Validate verifies the voteset.

type BackupBlock

type BackupBlock struct {
	Block *ExtendedBlock
	Votes *VoteSet `rlp:"nil"`
}

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

func CreateTestBlock(name string, parent string) *Block

CreateTestBlock creates a block for testing.

func GetTestBlock

func GetTestBlock(name string) *Block

func NewBlock

func NewBlock() *Block

NewBlock creates a new Block.

func (*Block) AddTxs

func (b *Block) AddTxs(txs []common.Bytes)

AddTxs adds transactions to the block and update transaction root hash.

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (*Block) EncodeRLP

func (b *Block) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*Block) String

func (b *Block) String() string

func (*Block) Validate

func (b *Block) Validate(chainID string) result.Result

Validate checks the block is legitimate.

type BlockHeader

type BlockHeader struct {
	ChainID            string
	Epoch              uint64
	Height             uint64
	Parent             common.Hash
	HCC                CommitCertificate
	GuardianVotes      *AggregatedVotes    `rlp:"nil"` // Added in Theta2.0 fork.
	EliteEdgeNodeVotes *AggregatedEENVotes `rlp:"nil"` // Added in Theta3.0 fork.
	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) DecodeRLP

func (h *BlockHeader) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (*BlockHeader) EncodeRLP

func (h *BlockHeader) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*BlockHeader) Hash

func (h *BlockHeader) Hash() common.Hash

Hash of header.

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.

func (*BlockHeader) Validate

func (h *BlockHeader) Validate(chainID string) result.Result

Validate checks the header is legitimate.

type BlockStatus

type BlockStatus byte
const (
	BlockStatusPending BlockStatus = BlockStatus(iota)
	BlockStatusValid
	BlockStatusInvalid
	BlockStatusCommitted
	BlockStatusDirectlyFinalized
	BlockStatusIndirectlyFinalized
	BlockStatusTrusted
	BlockStatusDisposed
)

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

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func (*Bloom) Add

func (b *Bloom) Add(d *big.Int)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(test *big.Int) bool

func (Bloom) TestBytes

func (b Bloom) TestBytes(test []byte) bool

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

type ByID

type ByID []Validator

ByID implements sort.Interface for ValidatorSet based on ID.

func (ByID) Len

func (b ByID) Len() int

func (ByID) Less

func (b ByID) Less(i, j int) bool

func (ByID) Swap

func (b ByID) Swap(i, j int)

type CommitCertificate

type CommitCertificate struct {
	Votes     *VoteSet `rlp:"nil"`
	BlockHash common.Hash
}

CommitCertificate represents a commit made a majority of validators.

func (CommitCertificate) Copy

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 EENBlsSigMsg

type EENBlsSigMsg struct {
	Block common.Hash
}

type EENVote

type EENVote struct {
	Block     common.Hash    // Hash of the block.
	Height    uint64         // Height of the block, just for reference
	Address   common.Address // Address of the edge node.
	Signature *bls.Signature // Aggregated signiature.
	Timestamp *big.Int       // Unix timestamp when the EENVote was created, just for reference
}

EENVote represents the vote for a block from an elite edge node.

func NewEENVote

func NewEENVote(block common.Hash, blockHeight uint64, eenAddr common.Address, signature *bls.Signature) *EENVote

func (*EENVote) String

func (e *EENVote) String() string

func (*EENVote) Validate

func (e *EENVote) Validate(eenBLSPubkey *bls.PublicKey) result.Result

Validate verifies the vote.

type EliteEdgeNode

type EliteEdgeNode struct {
	*StakeHolder
	Pubkey *bls.PublicKey `json:"-"`
}

func NewEliteEdgeNode

func NewEliteEdgeNode(stakeHolder *StakeHolder, pubkey *bls.PublicKey) *EliteEdgeNode

func (*EliteEdgeNode) DepositStake

func (een *EliteEdgeNode) DepositStake(source common.Address, amount *big.Int) error

func (*EliteEdgeNode) ReturnStake

func (een *EliteEdgeNode) ReturnStake(source common.Address, currentHeight uint64) (*Stake, error)

func (*EliteEdgeNode) String

func (een *EliteEdgeNode) String() string

func (*EliteEdgeNode) WithdrawStake

func (een *EliteEdgeNode) WithdrawStake(source common.Address, currentHeight uint64) (*Stake, error)

type EliteEdgeNodePool

type EliteEdgeNodePool interface {
	Contains(eenAddr common.Address) bool
	GetPubKeys(eenAddrs []common.Address) []*bls.PublicKey
	Get(eenAddr common.Address) *EliteEdgeNode
	Upsert(een *EliteEdgeNode)
	GetAll(withstake bool) []*EliteEdgeNode
	DepositStake(source common.Address, holder common.Address, amount *big.Int, pubkey *bls.PublicKey, blockHeight uint64) (err error)
	WithdrawStake(source common.Address, holder common.Address, currentHeight uint64) (*Stake, error)
	RandomRewardWeight(block common.Hash, eenAddr common.Address) int
}

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) DecodeRLP

func (eb *ExtendedBlock) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (*ExtendedBlock) EncodeRLP

func (eb *ExtendedBlock) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*ExtendedBlock) Hash

func (eb *ExtendedBlock) Hash() common.Hash

Hash of header.

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 Guardian

type Guardian struct {
	*StakeHolder
	Pubkey *bls.PublicKey `json:"-"`
}

func (*Guardian) String

func (g *Guardian) String() string

type GuardianCandidatePool

type GuardianCandidatePool struct {
	SortedGuardians []*Guardian // Guardians sorted by holder address.
}

func NewGuardianCandidatePool

func NewGuardianCandidatePool() *GuardianCandidatePool

NewGuardianCandidatePool creates a new instance of GuardianCandidatePool.

func (*GuardianCandidatePool) Add

func (gcp *GuardianCandidatePool) Add(g *Guardian) bool

Add inserts guardian into the pool; returns false if guardian is already added.

func (*GuardianCandidatePool) Contains

func (gcp *GuardianCandidatePool) Contains(g common.Address) bool

Contains checks if given address is in the pool.

func (*GuardianCandidatePool) DepositStake

func (gcp *GuardianCandidatePool) DepositStake(source common.Address, holder common.Address, amount *big.Int, pubkey *bls.PublicKey, blockHeight uint64) (err error)

func (*GuardianCandidatePool) GetWithHolderAddress

func (gcp *GuardianCandidatePool) GetWithHolderAddress(addr common.Address) *Guardian

GetWithHolderAddress returns the guardian node correspond to the stake holder in the pool. Returns nil if not found.

func (*GuardianCandidatePool) Hash

func (gcp *GuardianCandidatePool) Hash() common.Hash

Hash calculates the hash of gcp.

func (*GuardianCandidatePool) Index

func (gcp *GuardianCandidatePool) Index(pubkey *bls.PublicKey) int

Index returns index of a public key in the pool. Returns -1 if not found.

func (*GuardianCandidatePool) Len

func (gcp *GuardianCandidatePool) Len() int

Implements sort.Interface for Guardians based on the Address field.

func (*GuardianCandidatePool) Less

func (gcp *GuardianCandidatePool) Less(i, j int) bool

func (*GuardianCandidatePool) PubKeys

func (gcp *GuardianCandidatePool) PubKeys() []*bls.PublicKey

PubKeys exports guardians' public keys.

func (*GuardianCandidatePool) Remove

func (gcp *GuardianCandidatePool) Remove(g common.Address) bool

Remove removes a guardian from the pool; returns false if guardian is not found.

func (*GuardianCandidatePool) ReturnStakes

func (gcp *GuardianCandidatePool) ReturnStakes(currentHeight uint64) []*Stake

func (*GuardianCandidatePool) Swap

func (gcp *GuardianCandidatePool) Swap(i, j int)

func (*GuardianCandidatePool) WithStake

func (gcp *GuardianCandidatePool) WithStake() *GuardianCandidatePool

WithStake returns a new pool with withdrawn guardians filtered out.

func (*GuardianCandidatePool) WithdrawStake

func (gcp *GuardianCandidatePool) WithdrawStake(source common.Address, holder common.Address, currentHeight uint64) error

type HardcodeBlockHash

type HardcodeBlockHash struct {
	Height    uint64
	BlockHash common.Hash
}

type LastCheckpoint

type LastCheckpoint struct {
	CheckpointHeader    *BlockHeader
	IntermediateHeaders []*BlockHeader
}

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, shouldIncludeValidatorUpdateTxs bool) (stateRootHash common.Hash, blockRawTxs []common.Bytes, res result.Result)
	ApplyBlockTxs(block *Block) result.Result
	ApplyBlockTxsForChainCorrection(block *Block) (common.Hash, result.Result)
	//ResetState(height uint64, rootHash common.Hash) result.Result
	ResetState(block *Block) result.Result
	FinalizeState(height uint64, rootHash common.Hash) result.Result
	GetFinalizedValidatorCandidatePool(blockHash common.Hash, isNext bool) (*ValidatorCandidatePool, error)
	GetGuardianCandidatePool(blockHash common.Hash) (*GuardianCandidatePool, error)
	GetEliteEdgeNodePoolOfLastCheckpoint(blockHash common.Hash) (EliteEdgeNodePool, 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.

func (Proposal) String

func (p Proposal) String() string

type RewardDistribution

type RewardDistribution struct {
	StakeHolder     common.Address // the stake delegate, i.e. a guardian node or an elite edge node address
	Beneficiary     common.Address // the beneficiary to split the reward
	SplitBasisPoint uint           // An integer between 0 and 10000, representing the fraction of the reward the beneficiary should get (in terms of 1/10000), https://en.wikipedia.org/wiki/Basis_point
}

func NewRewardDistribution

func NewRewardDistribution(stakeHolder common.Address, beneficiary common.Address, splitBasisPoint uint) (*RewardDistribution, error)

type SnapshotBlockTrio

type SnapshotBlockTrio struct {
	First  SnapshotFirstBlock
	Second SnapshotSecondBlock
	Third  SnapshotThirdBlock
}

type SnapshotFirstBlock

type SnapshotFirstBlock struct {
	Header *BlockHeader
	Proof  VCPProof
}

type SnapshotHeader

type SnapshotHeader struct {
	Magic   string
	Version uint
}

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 SnapshotTrieRecord struct {
	K common.Bytes // key
	V common.Bytes // value
}

type Stake

type Stake struct {
	Holder       common.Address `rlp:"-"` // Keep reference to holder in memory to process split
	Source       common.Address
	Amount       *big.Int
	Withdrawn    bool
	ReturnHeight uint64
}

func NewStake

func NewStake(source common.Address, amount *big.Int) *Stake

func (Stake) MarshalJSON

func (s Stake) MarshalJSON() ([]byte, error)

func (*Stake) String

func (s *Stake) String() string

func (*Stake) UnmarshalJSON

func (s *Stake) UnmarshalJSON(data []byte) error

type StakeHolder

type StakeHolder struct {
	Holder common.Address
	Stakes []*Stake
}

TODO: Should rename StakeHolder to StakeDelegate

func NewStakeHolder

func NewStakeHolder(holder common.Address, stakes []*Stake) *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

func NewStakeJSON(stake Stake) StakeJSON

func (StakeJSON) Stake

func (s StakeJSON) Stake() Stake

type TxInfo

type TxInfo struct {
	EffectiveGasPrice *big.Int
	Address           common.Address
	Sequence          uint64
}

TxInfo encapsulates information used by mempool to sorting.

type VCPProof

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

func (*VCPProof) DecodeRLP

func (vp *VCPProof) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (VCPProof) EncodeRLP

func (vp VCPProof) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*VCPProof) Get

func (vp *VCPProof) Get(key []byte) (value []byte, err error)

func (VCPProof) GetKvs

func (vp VCPProof) GetKvs() []*proofKV

func (*VCPProof) Has

func (vp *VCPProof) Has(key []byte) (bool, error)

func (*VCPProof) Put

func (vp *VCPProof) Put(key []byte, value []byte) error

type Validator

type Validator struct {
	Address common.Address
	Stake   *big.Int
}

Validator contains the public information of a validator.

func NewValidator

func NewValidator(addressStr string, stake *big.Int) Validator

NewValidator creates a new validator instance.

func (Validator) Equals

func (v Validator) Equals(x Validator) bool

Equals checks whether the validator is the same as another validator

func (Validator) ID

func (v Validator) ID() common.Address

ID returns the ID of the validator, which is the string representation of its address.

func (Validator) String

func (v Validator) String() string

String represents the string representation of the validator

type ValidatorCandidatePool

type ValidatorCandidatePool struct {
	SortedCandidates []*StakeHolder
}

func (*ValidatorCandidatePool) DepositStake

func (vcp *ValidatorCandidatePool) DepositStake(source common.Address, holder common.Address, amount *big.Int, blockHeight uint64) (err error)

func (*ValidatorCandidatePool) FindStakeDelegate

func (vcp *ValidatorCandidatePool) FindStakeDelegate(delegateAddr common.Address) *StakeHolder

func (*ValidatorCandidatePool) GetTopStakeHolders

func (vcp *ValidatorCandidatePool) GetTopStakeHolders(maxNumStakeHolders int) []*StakeHolder

func (*ValidatorCandidatePool) ReturnStakes

func (vcp *ValidatorCandidatePool) ReturnStakes(currentHeight uint64) []*Stake

func (*ValidatorCandidatePool) WithdrawStake

func (vcp *ValidatorCandidatePool) WithdrawStake(source common.Address, holder common.Address, currentHeight uint64) error

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) Hash

func (v Vote) Hash() common.Hash

Hash calculates vote's hash.

func (*Vote) SetSignature

func (v *Vote) SetSignature(sig *crypto.Signature)

SetSignature sets given signature in vote.

func (*Vote) Sign

func (v *Vote) Sign(priv *crypto.PrivateKey)

Sign signs the vote using given private key.

func (Vote) SignBytes

func (v Vote) SignBytes() common.Bytes

SignBytes returns raw bytes to be signed.

func (Vote) String

func (v Vote) String() string

func (Vote) Validate

func (v Vote) Validate() result.Result

Validate checks the vote is legitimate.

type VoteByID

type VoteByID []Vote

VoteByID implements sort.Interface for []Vote based on Voter's ID.

func (VoteByID) Len

func (a VoteByID) Len() int

func (VoteByID) Less

func (a VoteByID) Less(i, j int) bool

func (VoteByID) Swap

func (a VoteByID) Swap(i, j int)

type VoteSet

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

VoteSet represents a set of votes on a proposal.

func NewVoteSet

func NewVoteSet() *VoteSet

NewVoteSet creates an instance of VoteSet.

func (*VoteSet) AddVote

func (s *VoteSet) AddVote(vote Vote)

AddVote adds a vote to vote set. Duplicate votes are ignored.

func (*VoteSet) Copy

func (s *VoteSet) Copy() *VoteSet

Copy creates a copy of this vote set.

func (*VoteSet) DecodeRLP

func (s *VoteSet) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (*VoteSet) EncodeRLP

func (s *VoteSet) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*VoteSet) FilterByValidators

func (s *VoteSet) FilterByValidators(validators *ValidatorSet) *VoteSet

FilterByValidators removes votes from non-validators.

func (*VoteSet) IsEmpty

func (s *VoteSet) IsEmpty() bool

IsEmpty returns wether the vote set is empty.

func (*VoteSet) MarshalJSON

func (s *VoteSet) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*VoteSet) Merge

func (s *VoteSet) Merge(another *VoteSet) *VoteSet

Merge combines two vote sets.

func (*VoteSet) Size

func (s *VoteSet) Size() int

Size returns the number of votes in the vote set.

func (*VoteSet) String

func (s *VoteSet) String() string

func (*VoteSet) UniqueVoter

func (s *VoteSet) UniqueVoter() *VoteSet

UniqueVoter consolidate vote set by removing votes from the same voter in older epoches.

func (*VoteSet) UniqueVoterAndBlock

func (s *VoteSet) UniqueVoterAndBlock() *VoteSet

UniqueVoterAndBlock consolidate vote set by removing votes from the same voter to same block in older epoches.

func (*VoteSet) UnmarshalJSON

func (s *VoteSet) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Marshaler

func (*VoteSet) Validate

func (s *VoteSet) Validate() result.Result

Validate checks the vote set is legitimate.

func (*VoteSet) Votes

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

Votes return a slice of votes in the vote set.

Jump to

Keyboard shortcuts

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