utils

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InmemorySnapshots      = 128 // Number of recent vote snapshots to keep in memory
	BlockSignersCacheLimit = 9000
	M2ByteLength           = 4
)
View Source
const (
	PeriodicJobPeriod = 60
	PoolHygieneRound  = 10
)

Variables

View Source
var (
	EpochLength = uint64(900) // Default number of blocks after which to checkpoint and reset the pending votes

	ExtraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
	ExtraSeal   = 65 // Fixed number of extra-data suffix bytes reserved for signer seal

	NonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer
	NonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer.

	UncleHash      = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
	InmemoryEpochs = 5 * EpochLength          // Number of mapping from block to epoch switch infos to keep in memory
)

XDPoS delegated-proof-of-stake protocol constants.

View Source
var (
	// errUnknownBlock is returned when the list of signers is requested for a block
	// that is not part of the local blockchain.
	ErrUnknownBlock = errors.New("unknown block")

	// errInvalidCheckpointBeneficiary is returned if a checkpoint/epoch transition
	// block has a beneficiary set to non-zeroes.
	ErrInvalidCheckpointBeneficiary = errors.New("beneficiary in checkpoint block non-zero")

	// errInvalidVote is returned if a nonce value is something else that the two
	// allowed constants of 0x00..0 or 0xff..f.
	ErrInvalidVote = errors.New("vote nonce not 0x00..0 or 0xff..f")

	// errInvalidCheckpointVote is returned if a checkpoint/epoch transition block
	// has a vote nonce set to non-zeroes.
	ErrInvalidCheckpointVote = errors.New("vote nonce in checkpoint block non-zero")

	// errMissingVanity is returned if a block's extra-data section is shorter than
	// 32 bytes, which is required to store the signer vanity.
	ErrMissingVanity = errors.New("extra-data 32 byte vanity prefix missing")

	// errMissingSignature is returned if a block's extra-data section doesn't seem
	// to contain a 65 byte secp256k1 signature.
	ErrMissingSignature = errors.New("extra-data 65 byte suffix signature missing")

	// errExtraSigners is returned if non-checkpoint block contain signer data in
	// their extra-data fields.
	ErrExtraSigners = errors.New("non-checkpoint block contains extra signer list")

	// errInvalidCheckpointSigners is returned if a checkpoint block contains an
	// invalid list of signers (i.e. non divisible by 20 bytes, or not the correct
	// ones).
	ErrInvalidCheckpointSigners = errors.New("invalid signer list on checkpoint block")

	ErrInvalidCheckpointPenalties = errors.New("invalid penalty list on checkpoint block")

	ErrValidatorsNotLegit = errors.New("validators does not match what's stored in snapshot minus its penalty")
	ErrPenaltiesNotLegit  = errors.New("penalties does not match")

	// errInvalidMixDigest is returned if a block's mix digest is non-zero.
	ErrInvalidMixDigest = errors.New("non-zero mix digest")

	// errInvalidUncleHash is returned if a block contains an non-empty uncle list.
	ErrInvalidUncleHash = errors.New("non empty uncle hash")

	// errInvalidDifficulty is returned if the difficulty of a block is not either
	// of 1 or 2, or if the value does not match the turn of the signer.
	ErrInvalidDifficulty = errors.New("invalid difficulty")

	// ErrInvalidTimestamp is returned if the timestamp of a block is lower than
	// the previous block's timestamp + the minimum block period.
	ErrInvalidTimestamp = errors.New("invalid timestamp")

	// errInvalidVotingChain is returned if an authorization list is attempted to
	// be modified via out-of-range or non-contiguous headers.
	ErrInvalidVotingChain = errors.New("invalid voting chain")

	ErrInvalidHeaderOrder = errors.New("invalid header order")
	ErrInvalidChild       = errors.New("invalid header child")

	// errUnauthorized is returned if a header is signed by a non-authorized entity.
	ErrUnauthorized = errors.New("unauthorized")

	ErrFailedDoubleValidation = errors.New("wrong pair of creator-validator in double validation")

	// errWaitTransactions is returned if an empty block is attempted to be sealed
	// on an instant chain (0 second period). It's important to refuse these as the
	// block reward is zero, so an empty block just bloats the chain... fast.
	ErrWaitTransactions = errors.New("waiting for transactions")

	ErrInvalidCheckpointValidators = errors.New("invalid validators list on checkpoint block")

	ErrEmptyEpochSwitchValidators = errors.New("empty validators list on epoch switch block")

	ErrInvalidV2Extra                = errors.New("Invalid v2 extra in the block")
	ErrInvalidQC                     = errors.New("Invalid QC content")
	ErrInvalidQCSignatures           = errors.New("Invalid QC Signatures")
	ErrInvalidTC                     = errors.New("Invalid TC content")
	ErrInvalidTCSignatures           = errors.New("Invalid TC Signatures")
	ErrEmptyBlockInfoHash            = errors.New("BlockInfo hash is empty")
	ErrInvalidFieldInNonEpochSwitch  = errors.New("Invalid field exist in a non-epoch swtich block")
	ErrValidatorNotWithinMasternodes = errors.New("Validator address is not in the master node list")
	ErrCoinbaseAndValidatorMismatch  = errors.New("Validator and coinbase address in header does not match")
	ErrNotItsTurn                    = errors.New("Not validator's turn to mine this block")

	ErrRoundInvalid = errors.New("Invalid Round, it shall be bigger than QC round")

	ErrAlreadyMined = errors.New("Already mined")
)

Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.

Functions

func CompareSignersLists

func CompareSignersLists(list1 []common.Address, list2 []common.Address) bool

compare 2 signers lists return true if they are same elements, otherwise return false

func DecodeBytesExtraFields

func DecodeBytesExtraFields(b []byte, val interface{}) error

Decode extra fields for consensus version >= 2 (XDPoS 2.0 and future versions)

func ExtractValidatorsFromBytes

func ExtractValidatorsFromBytes(byteValidators []byte) []int64

Extract validators from byte array.

func Hop

func Hop(len, pre, cur int) int

func Position

func Position(list []common.Address, x common.Address) int

Types

type ErrIncomingMessageRoundNotEqualCurrentRound

type ErrIncomingMessageRoundNotEqualCurrentRound struct {
	Type          string
	IncomingRound types.Round
	CurrentRound  types.Round
}

func (*ErrIncomingMessageRoundNotEqualCurrentRound) Error

type ErrIncomingMessageRoundTooFarFromCurrentRound

type ErrIncomingMessageRoundTooFarFromCurrentRound struct {
	Type          string
	IncomingRound types.Round
	CurrentRound  types.Round
}

func (*ErrIncomingMessageRoundTooFarFromCurrentRound) Error

type LendingService

type LendingService interface {
	GetLendingStateRoot(block *types.Block, author common.Address) (common.Hash, error)
	GetLendingState(block *types.Block, author common.Address) (*lendingstate.LendingStateDB, error)
	HasLendingState(block *types.Block, author common.Address) bool
	GetStateCache() lendingstate.Database
	GetTriegc() *prque.Prque
	ApplyOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, lendingStateDB *lendingstate.LendingStateDB, tradingStateDb *tradingstate.TradingStateDB, lendingOrderBook common.Hash, order *lendingstate.LendingItem) ([]*lendingstate.LendingTrade, []*lendingstate.LendingItem, error)
	GetCollateralPrices(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, collateralToken common.Address, lendingToken common.Address) (*big.Int, *big.Int, error)
	GetMediumTradePriceBeforeEpoch(chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, baseToken common.Address, quoteToken common.Address) (*big.Int, error)
	ProcessLiquidationData(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingState *tradingstate.TradingStateDB, lendingState *lendingstate.LendingStateDB) (updatedTrades map[common.Hash]*lendingstate.LendingTrade, liquidatedTrades, autoRepayTrades, autoTopUpTrades, autoRecallTrades []*lendingstate.LendingTrade, err error)
	SyncDataToSDKNode(chain consensus.ChainContext, state *state.StateDB, block *types.Block, takerOrderInTx *lendingstate.LendingItem, txHash common.Hash, txMatchTime time.Time, trades []*lendingstate.LendingTrade, rejectedOrders []*lendingstate.LendingItem, dirtyOrderCount *uint64) error
	UpdateLiquidatedTrade(blockTime uint64, result lendingstate.FinalizedResult, trades map[common.Hash]*lendingstate.LendingTrade) error
	RollbackLendingData(txhash common.Hash) error
}

type Masternode

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

type MissedRoundInfo added in v1.6.0

type MissedRoundInfo struct {
	Round            types.Round
	Miner            common.Address
	CurrentBlockHash common.Hash
	CurrentBlockNum  *big.Int
	ParentBlockHash  common.Hash
	ParentBlockNum   *big.Int
}

type Pool

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

func NewPool

func NewPool() *Pool

func (*Pool) Add

func (p *Pool) Add(obj PoolObj) (int, map[common.Hash]PoolObj)

return true if it has reached threshold

func (*Pool) Clear

func (p *Pool) Clear()

func (*Pool) ClearByPoolKey

func (p *Pool) ClearByPoolKey(poolKey string)

Given the pool key, clean its content

func (*Pool) ClearPoolKeyByObj

func (p *Pool) ClearPoolKeyByObj(obj PoolObj)

Given the pool object, clear all object under the same pool key

func (*Pool) Get

func (p *Pool) Get() map[string]map[common.Hash]PoolObj

func (*Pool) GetObjsByKey

func (p *Pool) GetObjsByKey(poolKey string) []PoolObj

func (*Pool) PoolObjKeysList

func (p *Pool) PoolObjKeysList() []string

func (*Pool) Size

func (p *Pool) Size(obj PoolObj) int

type PoolObj

type PoolObj interface {
	Hash() common.Hash
	PoolKey() string
	GetSigner() common.Address
}

type PublicApiMissedRoundsMetadata added in v1.6.0

type PublicApiMissedRoundsMetadata struct {
	EpochRound       types.Round
	EpochBlockNumber *big.Int
	MissedRounds     []MissedRoundInfo
}

type PublicApiSnapshot

type PublicApiSnapshot struct {
	Number  uint64                          `json:"number"`  // Block number where the snapshot was created
	Hash    common.Hash                     `json:"hash"`    // Block hash where the snapshot was created
	Signers map[common.Address]struct{}     `json:"signers"` // Set of authorized signers at this moment
	Recents map[uint64]common.Address       `json:"recents"` // Set of recent signers for spam protections
	Votes   []*clique.Vote                  `json:"votes"`   // List of votes cast in chronological order
	Tally   map[common.Address]clique.Tally `json:"tally"`   // Current vote tally to avoid recalculating
}

type TradingService

type TradingService interface {
	GetTradingStateRoot(block *types.Block, author common.Address) (common.Hash, error)
	GetTradingState(block *types.Block, author common.Address) (*tradingstate.TradingStateDB, error)
	GetEmptyTradingState() (*tradingstate.TradingStateDB, error)
	HasTradingState(block *types.Block, author common.Address) bool
	GetStateCache() tradingstate.Database
	GetTriegc() *prque.Prque
	ApplyOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, XDCXstatedb *tradingstate.TradingStateDB, orderBook common.Hash, order *tradingstate.OrderItem) ([]map[string]string, []*tradingstate.OrderItem, error)
	UpdateMediumPriceBeforeEpoch(epochNumber uint64, tradingStateDB *tradingstate.TradingStateDB, statedb *state.StateDB) error
	IsSDKNode() bool
	SyncDataToSDKNode(takerOrder *tradingstate.OrderItem, txHash common.Hash, txMatchTime time.Time, statedb *state.StateDB, trades []map[string]string, rejectedOrders []*tradingstate.OrderItem, dirtyOrderCount *uint64) error
	RollbackReorgTxMatch(txhash common.Hash) error
	GetTokenDecimal(chain consensus.ChainContext, statedb *state.StateDB, tokenAddr common.Address) (*big.Int, error)
}

Jump to

Keyboard shortcuts

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