thor

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: LGPL-3.0 Imports: 16 Imported by: 28

Documentation

Index

Constants

View Source
const (
	TxGas                     uint64 = 5000
	ClauseGas                 uint64 = params.TxGas - TxGas
	ClauseGasContractCreation uint64 = params.TxGasContractCreation - TxGas

	MinGasLimit          uint64 = 1000 * 1000
	InitialGasLimit      uint64 = 10 * 1000 * 1000 // InitialGasLimit gas limit value int genesis block.
	GasLimitBoundDivisor uint64 = 1024             // from ethereum
	GetBalanceGas        uint64 = 400              // EIP158 gas table
	SloadGas             uint64 = 200              // EIP158 gas table
	SstoreSetGas         uint64 = params.SstoreSetGas
	SstoreResetGas       uint64 = params.SstoreResetGas

	MaxTxWorkDelay            uint32 = 30                     // (unit: block) if tx delay exceeds this value, no energy can be exchanged.
	TolerableBlockPackingTime        = 500 * time.Millisecond // the indicator to adjust target block gas limit
	MaxStateHistory                  = 65535                  // max guaranteed state history allowed to be accessed in EVM, presented in block number

	GasTargetPercentage      = 75                 // percentage of the block gas limit to determine the gas target
	InitialBaseFee           = 10_000_000_000_000 // 10^13 wei, 0.00001 VTHO
	BaseFeeChangeDenominator = 8                  // determines the percentage change in the base fee per block based on network utilization

	MaxPosScore = 10000 // max total score after PoS fork
)
NOTE: any changes to gas limit or block interval may affect how the txIndex and blockNumber are stored in logdb/sequence.go:
 - an increase in gas limit may require more bits for txIndex;
 - if block frequency is increased, blockNumber will increment faster, potentially exhausting the allocated bits sooner than expected.

Constants of block chain.

View Source
const (
	// AddressLength length of address in bytes.
	AddressLength = common.AddressLength
)

Variables

View Source
var (
	KeyExecutorAddress           = BytesToBytes32([]byte("executor"))
	KeyRewardRatio               = BytesToBytes32([]byte("reward-ratio"))
	KeyValidatorRewardPercentage = BytesToBytes32([]byte("validator-reward-percentage"))
	KeyLegacyTxBaseGasPrice      = BytesToBytes32([]byte("base-gas-price")) // the legacy tx default gas price
	KeyProposerEndorsement       = BytesToBytes32([]byte("proposer-endorsement"))
	KeyMaxBlockProposers         = BytesToBytes32([]byte("max-block-proposers"))
	KeyCurveFactor               = BytesToBytes32([]byte("curve-factor")) // curve factor to define VTHO issuance after PoS
	KeyDelegatorContractAddress  = BytesToBytes32([]byte("delegator-contract-address"))
	// staker switches to control the pause of staker and stargate, last bit pauses the delegator contract, second-to-last bit pauses  the staker contract
	KeyStakerSwitches = BytesToBytes32([]byte("staker-switches"))

	InitialMaxBlockProposers         uint64 = 101
	InitialRewardRatio                      = big.NewInt(3e17) // 30%
	InitialValidatorRewardPercentage        = 30               // 30%
	InitialBaseGasPrice                     = big.NewInt(1e15)
	InitialProposerEndorsement              = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(25000000))
	InitialCurveFactor                      = big.NewInt(76800)

	EnergyGrowthRate      = big.NewInt(5000000000) // WEI THOR per token(VET) per second. about 0.000432 THOR per token per day.
	NumberOfBlocksPerYear = big.NewInt(8640 * 365) // number of blocks per year, non leap (365 days)
)

Keys of governance params.

View Source
var NoFork = ForkConfig{
	VIP191:    math.MaxUint32,
	ETH_CONST: math.MaxUint32,
	BLOCKLIST: math.MaxUint32,
	ETH_IST:   math.MaxUint32,
	VIP214:    math.MaxUint32,
	FINALITY:  math.MaxUint32,
	GALACTICA: math.MaxUint32,
	HAYABUSA:  math.MaxUint32,
}

NoFork a special config without any forks.

View Source
var SoloFork = ForkConfig{
	VIP191:    0,
	ETH_CONST: 0,
	BLOCKLIST: 0,
	ETH_IST:   0,
	VIP214:    0,
	FINALITY:  0,

	GALACTICA: 1,
	HAYABUSA:  1,
}

SoloFork is used to define the solo fork config.

Functions

func BlockInterval

func BlockInterval() uint64

default value is 10 seconds

func CooldownPeriod added in v2.4.0

func CooldownPeriod() uint32

default value is 1 day

func EpochLength added in v2.4.0

func EpochLength() uint32

default value is 180 blocks, 30 minutes

func EvictionCheckInterval added in v2.4.0

func EvictionCheckInterval() uint32

default value is 3 days

func HayabusaTP added in v2.4.0

func HayabusaTP() uint32

default value is 14 days

func HighStakingPeriod added in v2.4.0

func HighStakingPeriod() uint32

default value is 30 days

func IsOriginBlocked

func IsOriginBlocked(origin Address) bool

IsOriginBlocked returns true if the address is in the blocklist

func LoadCorrectReceiptsRoots

func LoadCorrectReceiptsRoots() map[string]string

LoadCorrectReceiptsRoots load a map from block ID to correct receipts root.

func LockConfig added in v2.4.0

func LockConfig()

LockConfig locks the config, preventing any further changes. Required for mainnet and testnet.

func LowStakingPeriod added in v2.4.0

func LowStakingPeriod() uint32

default value is 7 days

func MediumStakingPeriod added in v2.4.0

func MediumStakingPeriod() uint32

default value is 15 days

func MockBlocklist

func MockBlocklist(list []string)

MockBlocklist mock the blocklist

func NewBlake2b

func NewBlake2b() hash.Hash

NewBlake2b return blake2b-256 hash.

func SeederInterval

func SeederInterval() uint32

default value is 8640 blocks, 1 day

func SetConfig added in v2.4.0

func SetConfig(cfg Config)

SetConfig sets the config. If the config is not set, the default values will be used. If the config is locked, will panic.

func ValidatorEvictionThreshold added in v2.4.0

func ValidatorEvictionThreshold() uint32

default value is 7 days

Types

type Address

type Address common.Address

Address address of account.

func BytesToAddress

func BytesToAddress(b []byte) Address

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

func CreateContractAddress

func CreateContractAddress(txID Bytes32, clauseIndex uint32, creationCount uint32) Address

CreateContractAddress to generate contract address according to tx id, clause index and contract creation count.

func MustParseAddress

func MustParseAddress(s string) Address

MustParseAddress convert string presented address into Address type, panic on error.

func ParseAddress

func ParseAddress(s string) (Address, error)

ParseAddress convert string presented address into Address type.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns byte slice form of address.

func (Address) Hex added in v2.4.0

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) IsZero

func (a Address) IsZero() bool

IsZero returns if address is all zero bytes.

func (*Address) MarshalJSON

func (a *Address) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Address) String

func (a Address) String() string

String implements the stringer interface

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Bytes32

type Bytes32 [32]byte

Bytes32 array of 32 bytes.

func Blake2b

func Blake2b(data ...[]byte) Bytes32

Blake2b computes blake2b-256 checksum for given data.

func Blake2bFn

func Blake2bFn(fn func(w io.Writer)) (h Bytes32)

Blake2bFn computes blake2b-256 checksum for the provided writer.

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 Keccak256

func Keccak256(data ...[]byte) (h Bytes32)

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

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

UnmarshalJSON implements json.Unmarshaler.

type Config added in v2.4.0

type Config struct {
	BlockInterval              uint64 `json:"blockInterval"`              // time interval between two consecutive blocks.
	EpochLength                uint32 `json:"epochLength"`                // number of blocks per epoch, also the number of blocks between two checkpoints.
	SeederInterval             uint32 `json:"seederInterval"`             // blocks between two scheduler seeder epochs.
	ValidatorEvictionThreshold uint32 `json:"validatorEvictionThreshold"` // the number of blocks after which offline validator will be evicted from the leader group (7 days)
	EvictionCheckInterval      uint32 `json:"evictionCheckInterval"`      // blocks between two eviction function executions

	// staker parameters
	LowStakingPeriod    uint32  `json:"lowStakingPeriod"`
	MediumStakingPeriod uint32  `json:"mediumStakingPeriod"`
	HighStakingPeriod   uint32  `json:"highStakingPeriod"`
	CooldownPeriod      uint32  `json:"cooldownPeriod"`
	HayabusaTP          *uint32 `json:"hayabusaTP"`
}

type ForkConfig

type ForkConfig struct {
	VIP191    uint32
	ETH_CONST uint32
	BLOCKLIST uint32
	ETH_IST   uint32
	VIP214    uint32
	FINALITY  uint32
	HAYABUSA  uint32 // Start of the Hayabusa Transition Period - PoA is still active until the transition period is over and 2/3 of the MBP have entered the PoS queue
	GALACTICA uint32
}

nolint: revive ForkConfig config for a fork.

func GetForkConfig

func GetForkConfig(genesisID Bytes32) *ForkConfig

GetForkConfig get fork config for the given genesis ID. Only works for the well-known networks.Custom network will get nil.

func (*ForkConfig) String

func (fc *ForkConfig) String() string

type StorageSize added in v2.1.2

type StorageSize uint64

StorageSize describes storage size in bytes.

func (StorageSize) String added in v2.1.2

func (ss StorageSize) String() string

func (*StorageSize) Write added in v2.1.2

func (ss *StorageSize) Write(b []byte) (int, error)

Write implements io.Writer, so it can be passed into function that accepts io.Writer to count written bytes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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