core

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: GPL-3.0 Imports: 22 Imported by: 1

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 = "0x2693b94e3a2ae55626c0d9cbcf1af2f631ba3b4af7a21a03ea9750bacf974041"

	GenesisBlockHeight = uint64(0)
)

* MAINNET *

View Source
const (
	SVStart = iota
	SVEnd
)
View Source
const (
	StakeForValidator uint8 = 0
	StakeForSentry    uint8 = 1

	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 = 256
	MaxNumRegularTxsPerBlock int = 512
)
View Source
const SnapshotHeaderMagic = "DneroNetwork"

Variables

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

	MinSentryStakeDeposit1000 *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 (
	MinValidatorStakeDeposit *big.Int
)
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 AggregatedVotes

type AggregatedVotes struct {
	Block      common.Hash    // Hash of the block.
	Gcp        common.Hash    // Hash of sentry 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 *SentryCandidatePool) *AggregatedVotes

func (*AggregatedVotes) Abs

func (a *AggregatedVotes) Abs() int

Abs returns the number of voted sentrys 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
	SentryVotes *AggregatedVotes `rlp:"nil"` // Added in DneroV1.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 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 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) (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)
	GetSentryCandidatePool(blockHash common.Hash) (*SentryCandidatePool, 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 Sentry added in v1.0.0

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

func (*Sentry) String added in v1.0.0

func (g *Sentry) String() string

type SentryCandidatePool added in v1.0.0

type SentryCandidatePool struct {
	SortedSentrys []*Sentry // Sentrys sorted by holder address.
}

func NewSentryCandidatePool added in v1.0.0

func NewSentryCandidatePool() *SentryCandidatePool

NewSentryCandidatePool creates a new instance of SentryCandidatePool.

func (*SentryCandidatePool) Add added in v1.0.0

func (gcp *SentryCandidatePool) Add(g *Sentry) bool

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

func (*SentryCandidatePool) Contains added in v1.0.0

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

Contains checks if given address is in the pool.

func (*SentryCandidatePool) DepositStake added in v1.0.0

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

func (*SentryCandidatePool) Hash added in v1.0.0

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

Hash calculates the hash of gcp.

func (*SentryCandidatePool) Index added in v1.0.0

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

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

func (*SentryCandidatePool) Len added in v1.0.0

func (gcp *SentryCandidatePool) Len() int

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

func (*SentryCandidatePool) Less added in v1.0.0

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

func (*SentryCandidatePool) PubKeys added in v1.0.0

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

PubKeys exports sentrys' public keys.

func (*SentryCandidatePool) Remove added in v1.0.0

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

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

func (*SentryCandidatePool) ReturnStakes added in v1.0.0

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

func (*SentryCandidatePool) Swap added in v1.0.0

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

func (*SentryCandidatePool) WithStake added in v1.0.0

func (gcp *SentryCandidatePool) WithStake() *SentryCandidatePool

WithStake returns a new pool with withdrawn sentrys filtered out.

func (*SentryCandidatePool) WithdrawStake added in v1.0.0

func (gcp *SentryCandidatePool) WithdrawStake(source common.Address, holder common.Address, currentHeight uint64) 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 {
	Source       common.Address
	Amount       *big.Int
	Withdrawn    bool
	ReturnHeight uint64
}

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 (*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) (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