types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// --------------------- Epoch --------------------------
	MTR  = byte(0)
	MTRG = byte(1)

	//  ------------------ Basics ----------------------------
	BlockInterval uint64 = 10          // time interval between two consecutive blocks.
	BaseTxGas     uint64 = ParamsTxGas // 21000
	TxGas         uint64 = 5000

	// InitialGasLimit was 10 *1000 *100, only accommodates 476 Txs, block size 61k, so change to 200M
	SloadGas       uint64 = 200 // EIP158 gas table
	SstoreSetGas   uint64 = ParamsSstoreSetGas
	SstoreResetGas uint64 = ParamsSstoreResetGas

	NBlockDelayToEnableValidatorSet = 4
)

Constants of block chain.

View Source
const (
	MaximumExtraDataSize        uint64 = 32    // Maximum size extra data may be after Genesis.
	ExpByteGas                  uint64 = 10    // Times ceil(log256(exponent)) for the EXP instruction.
	ParamsSloadGas              uint64 = 50    // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added.
	CallValueTransferGas        uint64 = 9000  // Paid for CALL when the value transfer is non-zero.
	CallNewAccountGas           uint64 = 25000 // Paid for CALL when the destination address didn't exist prior.
	ParamsTxGas                 uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.
	ParamsTxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions.
	TxDataZeroGas               uint64 = 4     // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions.
	QuadCoeffDiv                uint64 = 512   // Divisor for the quadratic particle of the memory cost equation.
	LogDataGas                  uint64 = 8     // Per byte in a LOG* operation's data.
	CallStipend                 uint64 = 2300  // Free gas given at beginning of call.

	Sha3Gas     uint64 = 30 // Once per SHA3 operation.
	Sha3WordGas uint64 = 4  // Once per word of the SHA3 operation's data.

	ParamsSstoreSetGas   uint64 = 20000 // Once per SLOAD operation.
	ParamsSstoreResetGas uint64 = 5000  // Once per SSTORE operation if the zeroness changes from zero.
	SstoreClearGas       uint64 = 5000  // Once per SSTORE operation if the zeroness doesn't change.
	SstoreRefundGas      uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero.

	InitCodeWordGas uint64 = 2 // Once per word of the init code when creating a contract.

	NetSstoreNoopGas  uint64 = 200   // Once per SSTORE operation if the value doesn't change.
	NetSstoreInitGas  uint64 = 20000 // Once per SSTORE operation from clean zero.
	NetSstoreCleanGas uint64 = 5000  // Once per SSTORE operation from clean non-zero.
	NetSstoreDirtyGas uint64 = 200   // Once per SSTORE operation from dirty.

	NetSstoreClearRefund      uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot
	NetSstoreResetRefund      uint64 = 4800  // Once per SSTORE operation for resetting to the original non-zero value
	NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value

	WarmStorageReadCostEIP2929 = uint64(100) // WARM_STORAGE_READ_COST

	JumpdestGas             uint64 = 1     // Once per JUMPDEST operation.
	EpochDuration           uint64 = 30000 // Duration between proof-of-work epochs.
	CallGas                 uint64 = 40    // Once per CALL operation & message call transaction.
	CreateDataGas           uint64 = 200   //
	CallCreateDepth         uint64 = 1024  // Maximum depth of call/create stack.
	ExpGas                  uint64 = 10    // Once per EXP instruction
	LogGas                  uint64 = 375   // Per LOG* operation.
	CopyGas                 uint64 = 3     //
	StackLimit              uint64 = 1024  // Maximum size of VM stack allowed.
	TierStepGas             uint64 = 0     // Once per operation, for a selection of them.
	LogTopicGas             uint64 = 375   // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas.
	CreateGas               uint64 = 32000 // Once per CREATE operation & contract-creation transaction.
	Create2Gas              uint64 = 32000 // Once per CREATE2 operation
	SuicideRefundGas        uint64 = 24000 // Refunded following a suicide operation.
	MemoryGas               uint64 = 3     // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL.
	TxDataNonZeroGas        uint64 = 68    // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions.
	TxDataNonZeroGasEIP2028 uint64 = 16    // Per byte of non zero data attached to a transaction after EIP 2028 (part in Istanbul)

	MaxCodeSize     = 24576           // Maximum bytecode to permit for a contract
	MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions

	Keccak256Gas     uint64 = 30 // Once per KECCAK256 operation.
	Keccak256WordGas uint64 = 6  // Once per word of the KECCAK256 operation's data.

	EcrecoverGas            uint64 = 3000   // Elliptic curve sender recovery gas price
	Sha256BaseGas           uint64 = 60     // Base price for a SHA256 operation
	Sha256PerWordGas        uint64 = 12     // Per-word price for a SHA256 operation
	Ripemd160BaseGas        uint64 = 600    // Base price for a RIPEMD160 operation
	Ripemd160PerWordGas     uint64 = 120    // Per-word price for a RIPEMD160 operation
	IdentityBaseGas         uint64 = 15     // Base price for a data copy operation
	IdentityPerWordGas      uint64 = 3      // Per-work price for a data copy operation
	ModExpQuadCoeffDiv      uint64 = 20     // Divisor for the quadratic particle of the big int modular exponentiation
	Bn256AddGas             uint64 = 500    // Gas needed for an elliptic curve addition
	Bn256ScalarMulGas       uint64 = 40000  // Gas needed for an elliptic curve scalar multiplication
	Bn256PairingBaseGas     uint64 = 100000 // Base price for an elliptic curve pairing check
	Bn256PairingPerPointGas uint64 = 80000  // Per-point price for an elliptic curve pairing check
)
View Source
const (
	// MaxTotalVotingPower - the maximum allowed total voting power.
	// It needs to be sufficiently small to, in all cases:
	// 1. prevent clipping in incrementProposerPriority()
	// 2. let (diff+diffMax-1) not overflow in IncrementProposerPriority()
	// (Proof of 1 is tricky, left to the reader).
	// It could be higher, but this is sufficiently large for our purposes,
	// and leaves room for defensive purposes.
	MaxTotalVotingPower = int64(math.MaxInt64) / 8

	// PriorityWindowSizeFactor - is a constant that when multiplied with the
	// total voting power gives the maximum allowed distance between validator
	// priorities.
	PriorityWindowSizeFactor = 2
)
View Source
const (
	// MaxChainIDLen is a maximum length of the chain ID.
	MaxChainIDLen = 50
)

Variables

View Source
var (
	// Keys
	KeyExecutorAddress = BytesToBytes32([]byte("executor"))

	ZeroAddress = common.HexToAddress("0x0000000000000000000000000000000000000000")
)

Keys of governance params.

View Source
var (
	DifficultyBoundDivisor = big.NewInt(2048)   // The bound divisor of the difficulty, used in the update calculations.
	GenesisDifficulty      = big.NewInt(131072) // Difficulty of the Genesis block.
	MinimumDifficulty      = big.NewInt(131072) // The minimum that the difficulty may ever be.
	DurationLimit          = big.NewInt(13)     // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not.
)
View Source
var ErrProposerNotInVals = errors.New("proposer not in validator set")

ErrProposerNotInVals is returned if the proposer is not in the validator set.

View Source
var ErrTotalVotingPowerOverflow = fmt.Errorf("total voting power of resulting valset exceeds max %d",
	MaxTotalVotingPower)

ErrTotalVotingPowerOverflow is returned if the total voting power of the resulting validator set exceeds MaxTotalVotingPower.

View Source
var NoFork = ForkConfig{
	FixTransferLog: math.MaxUint32,
}

NoFork a special config without any forks.

View Source
var Size []uint64

Functions

func Addr2IP

func Addr2IP(addr net.Addr) string

func MakeName

func MakeName(name, version string) string

MakeName creates a node name that follows the ethereum convention for such names. It adds the operation system name and Go runtime version the name.

func PrettyStorage

func PrettyStorage(storage uint64) string

func Sizeof

func Sizeof(i interface{}) (size uint64)

Sizeof Function Will Find Approximate Size of Object in Bytes

Types

type BLSPrivKey

type BLSPrivKey []byte

func NewBlsPrivKey

func NewBlsPrivKey() BLSPrivKey

func (BLSPrivKey) Bytes

func (k BLSPrivKey) Bytes() []byte

func (BLSPrivKey) Equals

func (k BLSPrivKey) Equals(other cmtcrypto.PrivKey) bool

func (BLSPrivKey) PubKey

func (k BLSPrivKey) PubKey() cmtcrypto.PubKey

func (BLSPrivKey) Sign

func (k BLSPrivKey) Sign(msg []byte) ([]byte, error)

func (BLSPrivKey) Type

func (k BLSPrivKey) Type() string

type BLSPubKey

type BLSPubKey []byte

crypto.PubKey

type PubKey interface {
	Address() Address
	Bytes() []byte
	VerifySignature(msg []byte, sig []byte) bool
	Equals(other PubKey) bool
	Type() string
}

func (BLSPubKey) Address

func (k BLSPubKey) Address() cmttypes.Address

func (BLSPubKey) Bytes

func (k BLSPubKey) Bytes() []byte

func (BLSPubKey) Equals

func (k BLSPubKey) Equals(other cmtcrypto.PubKey) bool

func (BLSPubKey) Type

func (k BLSPubKey) Type() string

func (BLSPubKey) VerifySignature

func (k BLSPubKey) VerifySignature(msg []byte, sig []byte) bool

type BlsMaster

type BlsMaster struct {
	PrivKey bls.SecretKey //my private key
	PubKey  bls.PublicKey //my public key

}

func NewBlsMaster

func NewBlsMaster(privKey bls.SecretKey, pubKey bls.PublicKey) *BlsMaster

func NewBlsMasterWithRandKey

func NewBlsMasterWithRandKey() *BlsMaster

func NewBlsMasterWithSecretBytes

func NewBlsMasterWithSecretBytes(secretBytes []byte) *BlsMaster

func (*BlsMaster) Destroy

func (bm *BlsMaster) Destroy() bool

BLS is implemented by C, memeory need to be freed. Signatures also need to be freed but Not here!!!

func (*BlsMaster) GetAddress

func (bm *BlsMaster) GetAddress() common.Address

func (*BlsMaster) GetPublicKey

func (bm *BlsMaster) GetPublicKey() bls.PublicKey

func (*BlsMaster) Print

func (bm *BlsMaster) Print()

func (*BlsMaster) SignHash

func (bm *BlsMaster) SignHash(hash [32]byte) []byte

func (*BlsMaster) SignMessage

func (bm *BlsMaster) SignMessage(msg []byte) bls.Signature

sign the part of msg

func (*BlsMaster) ValidateKeyPair

func (bm *BlsMaster) ValidateKeyPair() bool

func (*BlsMaster) VerifySignature

func (bm *BlsMaster) VerifySignature(signature, msgHash, blsPK []byte) (bool, error)

type Bytes32

type Bytes32 [32]byte

Bytes32 array of 32 bytes.

func BytesToBytes32

func BytesToBytes32(b []byte) Bytes32

BytesToBytes32 converts bytes slice into Bytes32. If b is larger than Bytes32 legnth, b will be cropped (from the left). If b is smaller than Bytes32 length, b will be extended (from the left).

func MustParseBytes32

func MustParseBytes32(s string) Bytes32

MustParseBytes32 convert string presented into Bytes32 type, panic on error.

func ParseBytes32

func ParseBytes32(s string) (Bytes32, error)

ParseBytes32 convert string presented into Bytes32 type

func (Bytes32) AbbrevString

func (b Bytes32) AbbrevString() string

AbbrevString returns abbrev string presentation.

func (Bytes32) Bytes

func (b Bytes32) Bytes() []byte

Bytes returns byte slice form of Bytes32.

func (Bytes32) Equal

func (b Bytes32) Equal(a Bytes32) bool

func (Bytes32) IsZero

func (b Bytes32) IsZero() bool

IsZero returns if Bytes32 has all zero bytes.

func (*Bytes32) MarshalJSON

func (b *Bytes32) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Bytes32) String

func (b Bytes32) String() string

String implements stringer

func (Bytes32) ToBlockShortID

func (b Bytes32) ToBlockShortID() string

Number extract block number from block id.

func (*Bytes32) UnmarshalJSON

func (b *Bytes32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ChecksummedGenesisDoc

type ChecksummedGenesisDoc struct {
	GenesisDoc     *GenesisDoc
	Sha256Checksum []byte
}

ChecksummedGenesisDoc combines a GenesisDoc together with its SHA256 checksum.

type ForkConfig

type ForkConfig struct {
	FixTransferLog uint32
}

ForkConfig config for a fork.

func GetForkConfig

func GetForkConfig(genesisID Bytes32) ForkConfig

GetForkConfig get fork config for given genesis ID.

func (ForkConfig) String

func (fc ForkConfig) String() string

type GenesisDoc

type GenesisDoc struct {
	GenesisTime     time.Time                 `json:"genesis_time"`
	ChainID         string                    `json:"chain_id"`
	InitialHeight   int64                     `json:"initial_height"`
	ConsensusParams *cmttypes.ConsensusParams `json:"consensus_params,omitempty"`
	Validators      []GenesisValidator        `json:"validators,omitempty"`
	AppHash         cmtbytes.HexBytes         `json:"app_hash"`
	AppState        json.RawMessage           `json:"app_state,omitempty"`
}

GenesisDoc defines the initial conditions for a CometBFT blockchain, in particular its validator set.

func GenesisDocFromFile

func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error)

GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc.

func GenesisDocFromJSON

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

GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.

func (*GenesisDoc) SaveAs

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

SaveAs is a utility method for saving GenensisDoc as a JSON file.

func (*GenesisDoc) ValidateAndComplete

func (genDoc *GenesisDoc) ValidateAndComplete() error

ValidateAndComplete checks that all necessary fields are present and fills in defaults for optional fields left empty.

func (*GenesisDoc) ValidatorsHash

func (genDoc *GenesisDoc) ValidatorsHash() []byte

ValidatorsHash returns the hash of the validator set contained in the GenesisDoc.

type GenesisDocLoader

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

func NewGenesisDocLoader

func NewGenesisDocLoader(baseDir string) *GenesisDocLoader

func (*GenesisDocLoader) Load

func (k *GenesisDocLoader) Load() (*GenesisDoc, error)

type GenesisDocProvider

type GenesisDocProvider func() (ChecksummedGenesisDoc, error)

GenesisDocProvider returns a GenesisDoc together with its SHA256 checksum. It allows the GenesisDoc to be pulled from sources other than the filesystem, for instance from a distributed key-value store cluster.

func DefaultGenesisDocProviderFunc

func DefaultGenesisDocProviderFunc(config *cfg.Config) GenesisDocProvider

DefaultGenesisDocProviderFunc returns a GenesisDocProvider that loads the GenesisDoc from the config.GenesisFile() on the filesystem.

type GenesisValidator

type GenesisValidator struct {
	Address cmttypes.Address `json:"address"`
	PubKey  crypto.PubKey    `json:"pub_key"`
	Power   int64            `json:"power"`
	Name    string           `json:"name"`
	IP      string           `json:"ip"`   // added by us
	Port    uint32           `json:"port"` // added by us
}

GenesisValidator is an initial validator.

type KeyLoader

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

func NewKeyLoader

func NewKeyLoader(baseDir string) *KeyLoader

func (*KeyLoader) Load

func (k *KeyLoader) Load() (*BlsMaster, error)

type KeysContent

type KeysContent struct {
	Secret string `json:"secret"`
	Pubkey string `json:"pubkey"`
}

type MemStore

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

func NewMemStore

func NewMemStore() *MemStore

func (*MemStore) Get

func (s *MemStore) Get(key string) []byte

func (*MemStore) Keys

func (s *MemStore) Keys() []string

func (*MemStore) Put

func (s *MemStore) Put(k, v []byte) error

type NetAddress

type NetAddress struct {
	IP   net.IP `json:"ip"`
	Port uint32 `json:"port"`
	// contains filtered or unexported fields
}

NetAddress defines information about a peer on the network including its ID, IP address, and port.

func NewNetAddress

func NewNetAddress(addr net.Addr) *NetAddress

NewNetAddress returns a new NetAddress using the provided TCP address. When testing, other net.Addr (except TCP) will result in using 0.0.0.0:0. When normal run, other net.Addr (except TCP) will panic. TODO: socks proxies?

func NewNetAddressFromNetIP

func NewNetAddressFromNetIP(ip netip.Addr, port uint32) *NetAddress

NewNetAddressIPPort returns a new NetAddress using the provided IP and port number.

func (*NetAddress) Dial

func (na *NetAddress) Dial() (net.Conn, error)

Dial calls net.Dial on the address.

func (*NetAddress) DialString

func (na *NetAddress) DialString() string

func (*NetAddress) DialTimeout

func (na *NetAddress) DialTimeout(timeout time.Duration) (net.Conn, error)

DialTimeout calls net.DialTimeout on the address.

func (*NetAddress) Equals

func (na *NetAddress) Equals(other interface{}) bool

Equals reports whether na and other are the same addresses, including their ID, IP, and Port.

func (*NetAddress) Local

func (na *NetAddress) Local() bool

Local returns true if it is a local address.

func (*NetAddress) RFC1918

func (na *NetAddress) RFC1918() bool

func (*NetAddress) RFC3849

func (na *NetAddress) RFC3849() bool

func (*NetAddress) RFC3927

func (na *NetAddress) RFC3927() bool

func (*NetAddress) RFC3964

func (na *NetAddress) RFC3964() bool

func (*NetAddress) RFC4193

func (na *NetAddress) RFC4193() bool

func (*NetAddress) RFC4380

func (na *NetAddress) RFC4380() bool

func (*NetAddress) RFC4843

func (na *NetAddress) RFC4843() bool

func (*NetAddress) RFC4862

func (na *NetAddress) RFC4862() bool

func (*NetAddress) RFC6052

func (na *NetAddress) RFC6052() bool

func (*NetAddress) RFC6145

func (na *NetAddress) RFC6145() bool

func (*NetAddress) ReachabilityTo

func (na *NetAddress) ReachabilityTo(o *NetAddress) int

ReachabilityTo checks whenever o can be reached from na.

func (*NetAddress) Routable

func (na *NetAddress) Routable() bool

Routable returns true if the address is routable.

func (*NetAddress) Same

func (na *NetAddress) Same(other interface{}) bool

Same returns true is na has the same non-empty ID or DialString as other.

func (*NetAddress) String

func (na *NetAddress) String() string

String representation: <IP>:<PORT>

func (*NetAddress) Valid

func (na *NetAddress) Valid() bool

For IPv4 these are either a 0 or all bits set address. For IPv6 a zero address or one that matches the RFC3849 documentation address format.

type NodeKey

type NodeKey struct {
	Bytes []byte `json:"priv_key"` // our priv key
}

NodeKey is the persistent peer key. It contains the nodes private key for authentication.

func LoadNodeKey

func LoadNodeKey(filePath string) (*NodeKey, error)

LoadNodeKey loads NodeKey located in filePath.

func LoadOrGenNodeKey

func LoadOrGenNodeKey(filePath string) (*NodeKey, error)

LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If the file does not exist, it generates and saves a new NodeKey.

func (*NodeKey) PrivateKey

func (nodeKey *NodeKey) PrivateKey() *ecdsa.PrivateKey

func (*NodeKey) PubKey

func (nodeKey *NodeKey) PubKey() ecdsa.PublicKey

PubKey returns the peer's PubKey.

func (*NodeKey) SaveAs

func (nodeKey *NodeKey) SaveAs(filePath string) error

SaveAs persists the NodeKey to filePath.

type PrettyDuration

type PrettyDuration time.Duration

PrettyDuration is a pretty printed version of a time.Duration value that cuts the unnecessary precision off from the formatted textual representation.

func (PrettyDuration) String

func (d PrettyDuration) String() string

String implements the Stringer interface, allowing pretty printing of duration values rounded to three decimals.

type TimeoutCert

type TimeoutCert struct {
	Epoch    uint64
	Round    uint32
	BitArray *cmn.BitArray
	MsgHash  [32]byte
	AggSig   []byte
}

definition for TimeoutCert

func (*TimeoutCert) DecodeRLP

func (tc *TimeoutCert) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*TimeoutCert) EncodeRLP

func (tc *TimeoutCert) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*TimeoutCert) SigningHash

func (tc *TimeoutCert) SigningHash() (hash Bytes32)

func (*TimeoutCert) String

func (tc *TimeoutCert) String() string

type Transactions

type Transactions []cmttypes.Tx

Transactions a slice of transactions.

func (Transactions) Convert

func (txs Transactions) Convert() [][]byte

func (Transactions) RootHash

func (txs Transactions) RootHash() cmtbytes.HexBytes

RootHash computes merkle root hash of transactions.

type Validator

type Validator struct {
	Name        string         `json:"name"`
	Address     common.Address `json:"address"`
	PubKey      bls.PublicKey  `json:"pubkey"`
	IP          netip.Addr     `json:"ip"`
	Port        uint32         `json:"port"`
	VotingPower uint64         `json:"voting_power"`
}

func NewValidator

func NewValidator(address common.Address, hexPubkey string, ip string, port uint32) *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) DecodeRLP

func (v *Validator) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Validator) EncodeRLP

func (v *Validator) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*Validator) Hash

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

func (*Validator) NameAndIP

func (v *Validator) NameAndIP() string

func (*Validator) String

func (v *Validator) String() string

func (*Validator) WithName

func (v *Validator) WithName(name string) *Validator

func (*Validator) WithVotingPower

func (v *Validator) WithVotingPower(vp uint64) *Validator

type ValidatorDef

type ValidatorDef struct {
	Name    string `json:"name"`
	Address string `json:"address"`
	PubKey  string `json:"pubkey"`
	IP      string `json:"ip"`
	Port    uint32 `json:"port"`
}

func (ValidatorDef) String

func (d ValidatorDef) String() string

type ValidatorSet

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

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 .VotingPower, so the indices are fixed for all rounds of a given blockchain height - ie. the validators are sorted by their voting power (descending). Secondary index - .Address (ascending).

On the other hand, the .ProposerPriority of each validator and the designated .GetProposer() of a set changes every round, upon calling .IncrementProposerPriority().

NOTE: Not goroutine-safe. NOTE: All get/set to validators should copy the value for safety.

func LoadValidatorsFromFile

func LoadValidatorsFromFile(network string, dataDir string) *ValidatorSet

func NewValidatorSet

func NewValidatorSet(valz []*Validator) *ValidatorSet

NewValidatorSet initializes a ValidatorSet by copying over the values from `valz`, a list of Validators. If valz is nil or empty, the new ValidatorSet will have an empty list of Validators.

The addresses of validators in `valz` must be unique otherwise the function panics.

Note the validator set size has an implied limit equal to that of the MaxVotesCount - commits by a validator set larger than this will fail validation.

func (*ValidatorSet) Copy

func (vals *ValidatorSet) Copy() *ValidatorSet

Copy each validator into a new ValidatorSet.

func (*ValidatorSet) DeleteByPubkey

func (vals *ValidatorSet) DeleteByPubkey(pubkey bls.PublicKey)

func (*ValidatorSet) GetByIndex

func (vals *ValidatorSet) GetByIndex(index int) (val *Validator)

GetByIndex returns the validator's address and validator itself (copy) by index. It returns nil values if index is less than 0 or greater or equal to len(ValidatorSet.Validators).

func (*ValidatorSet) GetByPubkey

func (vals *ValidatorSet) GetByPubkey(pubkey bls.PublicKey) (val *Validator)

func (*ValidatorSet) HasAddress

func (vals *ValidatorSet) HasAddress(address common.Address) bool

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

func (*ValidatorSet) Hash

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

Hash returns the Merkle root hash build using validators (as leaves) in the set.

See merkle.HashFromByteSlices.

func (*ValidatorSet) Hex

func (vals *ValidatorSet) Hex() string

func (*ValidatorSet) IsNilOrEmpty

func (vals *ValidatorSet) IsNilOrEmpty() bool

IsNilOrEmpty returns true if validator set is nil or empty.

func (ValidatorSet) MarhsalJSON

func (vals ValidatorSet) MarhsalJSON() ([]byte, error)

func (*ValidatorSet) Size

func (vals *ValidatorSet) Size() int

Size returns the length of the validator set.

func (*ValidatorSet) SortWithNonce

func (vals *ValidatorSet) SortWithNonce(nonce uint64) *ValidatorSet

func (*ValidatorSet) String

func (vals *ValidatorSet) String() string

func (*ValidatorSet) UnmarshalJSON

func (vals *ValidatorSet) UnmarshalJSON(b []byte) error

func (*ValidatorSet) Upsert

func (vals *ValidatorSet) Upsert(newV *Validator) *ValidatorSet

type ValidatorSortKey

type ValidatorSortKey struct {
	PubKey  bls.PublicKey
	SortKey []byte
}

Volatile state for each Validator NOTE: The Accum is not included in Validator.Hash(); make sure to update that method if changes are made here

Jump to

Keyboard shortcuts

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