meter

package
v1.2.0-fix10 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Edison                     = iota + 1
	EdisonSysContractStartNum  = 4900000 //around 11/18/2020
	TestnetSysContractStartNum = 100000
	EdisonMainnetStartNum      = 0
	EdisonTestnetStartNum      = 0

	//chainID
	MainnetChainID = 82 // 0x52 for mainnet
	TestnetChainID = 83 // 0x53 for testnet
)

Fork Release Version Edision: The initial Basic Release. Features include

View Source
const (
	Tesla                = iota + 2
	TeslaMainnetStartNum = 9470000 // Tesla hard fork around 03/22/2021 08:00-09:00 (Beijing Time)
	TeslaTestnetStartNum = 0       //

	// Tesla 1.1 Hardfork
	// includes feature updates:
	// 1)bucket update issue fix, bound balance before update bucket
	// 2) allow update for forever bucket
	// 2) correct wrong buckets in Tesla 1.0 due to bucket update issue
	// 3) account lock fix, allow transfer only if (amount + lockedMTRG) < (balance + boundbalance), fix includes native transfer and system contract ERC20 transfer
	// 4)update (total votes / self vote) limit from 10x to 100x
	Tesla1_1MainnetStartNum = 9680000

	TeslaFork2_MainnetStartNum = 10382000 // around 4/16/2021 11:00 AM (Beijing)
	TeslaFork2_TestnetStartNum = 682000   // around 4/16/2021 11:00 AM (Beijing)

	// Tesla 1.3 Hardfork
	// includes feature updates:
	// 1) evm upgrade from v1.18.10 to v1.18.14
	// 2) istanbul porting from vechain
	// 3) aggregate autobid
	// 4) fix the contract address issue: if caller is external, use tx nonce + clauseIndex
	//    otherwise, caller is internal, use global counter as entropy
	// 5) fix the empty chainid issue
	TeslaFork3_MainnetAuctionDefectStartNum = 14811495
	TeslaFork3_MainnetStartNum              = 14875500 // around 8/24/2021 10:00 AM (Beijing)
	TeslaFork3_TestnetStartNum              = 4220000  //  4220000

	// Tesla 1.4 Hardfork
	// includes feature updates:
	// 1) contract address schema update, after tesla fork4, contract created by external account should use
	// meter-specific address scheme for created contract: keccak256(txID, clauseIndex, counter)
	// 2) fixed the sync failure at 10963576 (negative total stake balance for stakeholder, should snap to 0 once negative)
	// 3) fixed the sync failure at 13931713 (use caller for contract address creation, should use origin)
	TeslaFork4_TestnetStartNum = 4932000
	TeslaFork4_MainnetStartNum = 15138000 // around 9/1/2021 9:30 AM (Beijing)
)

Tesla: The staking/auction release, Features include:

View Source
const (
	// --------------------- Epoch --------------------------
	MTR  = byte(0)
	MTRG = byte(1)
	// minimum height for committee relay.
	NPowBlockPerEpoch    = 60   // epoch time (normaly 1 pow block takes 1 minutes)
	MaxNPowBlockPerEpoch = 3000 // if too many pow blocks need to be packed in kblock, truncate to the last 3000 pow blocks
	NEpochPerDay         = 24 * 60 / NPowBlockPerEpoch
	KBlockEpoch          = 14603 // wrong LastKBlockHeight

	// ------------------- Miner Reward ---------------------
	MaxNClausePerRewardTx = 200 // pack reward tx with maxinum 200 clauses

	// --------------- Validator Reward ---------------------
	NDays   = 10 // smooth with n days, the (last n days's total received MTR) * 1/n will be used as the validator reward for current day
	NDaysV2 = 1  // hard fork from 10 to 1

	// ------------------ Auction ---------------------------
	NEpochPerAuction       = 24 // every n Epoch move to next auction
	NAuctionPerDay         = 24 * 60 / NPowBlockPerEpoch / NEpochPerAuction
	MaxNClausePerAutobidTx = 1000

	// auction release mtrg (new version)
	AuctionReleaseBase      = 40000000 // total base of 400M MTRG
	AuctionReleaseInflation = 5e16     // yoy 5%, in unit of wei (aka. 1e18)

	//  ------------------ Basics ----------------------------
	BlockInterval             uint64 = 10           // time interval between two consecutive blocks.
	BaseTxGas                 uint64 = params.TxGas // 21000
	TxGas                     uint64 = 5000
	ClauseGas                 uint64 = params.TxGas - TxGas
	ClauseGasContractCreation uint64 = params.TxGasContractCreation - TxGas

	// InitialGasLimit was 10 *1000 *100, only accommodates 476 Txs, block size 61k, so change to 200M
	MinGasLimit          uint64 = 1000 * 1000
	InitialGasLimit      uint64 = 200 * 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.

	MaxBlockProposers uint64 = 101

	TolerableBlockPackingTime = 100 * time.Millisecond // the indicator to adjust target block gas limit

	MaxBackTrackingBlockNumber = 65535
)

Constants of block chain.

View Source
const (
	//This ceof is based s9 ant miner, 1.323Kw 13.5T hashrate coef 11691855416.9 unit 1e18
	//python -c "print 2**32 * 1.323 /120/13.5/1000/1000/1000/1000/10/30 * 1e18"
	POW_DEFAULT_REWARD_COEF_S9 = int64(11691855417)
	//efficiency w/hash  python -c "print 1.323/13.5" = 0.098
	POW_S9_EFFECIENCY = 0.098
	//M10 spec 1500W, 25TH
	//python -c "print 2**32 * 1.5 /120/25/1000/1000/1000/1000/10/30 * 1e18"
	POW_DEFAULT_REWARD_COEF_M10 = int64(7158278826)
	POW_M10_EFFECIENCY          = 0.060

	// mainnet effeciency set as 0.053
	//python -c "print 2**32 * 0.053 /120/1000/1000/1000/1000/10/30 * 1e18"
	POW_DEFAULT_REWARD_COEF_MAIN = int64(6323146297)
	POW_M10_EFFECIENCY_MAIN      = 0.053
)

powpool coef

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

Variables

View Source
var (
	SysContractStartNum uint32 = EdisonSysContractStartNum
	EdisonStartNum      uint32 = EdisonSysContractStartNum
	TeslaStartNum       uint32 = TeslaMainnetStartNum

	TeslaFork2StartNum uint32 = TeslaFork2_MainnetStartNum
	TeslaFork3StartNum uint32 = TeslaFork3_MainnetStartNum
	TeslaFork4StartNum uint32 = TeslaFork4_MainnetStartNum

	// Genesis hashes to enforce below configs on.
	GenesisHash = MustParseBytes32("0x00000000733c970e6a7d68c7db54e3705eee865a97a07bf7e695c63b238f5e52")
)

start block number support sys-contract

View Source
var (
	// Keys
	KeyExecutorAddress        = BytesToBytes32([]byte("executor"))
	KeyRewardRatio            = BytesToBytes32([]byte("reward-ratio"))
	KeyBaseGasPrice           = BytesToBytes32([]byte("base-gas-price"))
	KeyProposerEndorsement    = BytesToBytes32([]byte("proposer-endorsement"))
	KeyPowPoolCoef            = BytesToBytes32([]byte("powpool-coef"))
	KeyPowPoolCoefFadeDays    = BytesToBytes32([]byte("powpool-coef-fade-days"))
	KeyPowPoolCoefFadeRate    = BytesToBytes32([]byte("powpool-coef-fade-rate"))
	KeyValidatorBenefitRatio  = BytesToBytes32([]byte("validator-benefit-ratio"))
	KeyValidatorBaseReward    = BytesToBytes32([]byte("validator-base-reward"))
	KeyAuctionReservedPrice   = BytesToBytes32([]byte("auction-reserved-price"))
	KeyMinRequiredByDelegate  = BytesToBytes32([]byte("minimium-require-by-delegate"))
	KeyAuctionInitRelease     = BytesToBytes32([]byte("auction-initial-release"))
	KeyBorrowInterestRate     = BytesToBytes32([]byte("borrower-interest-rate"))
	KeyConsensusCommitteeSize = BytesToBytes32([]byte("consensus-committee-size"))
	KeyConsensusDelegateSize  = BytesToBytes32([]byte("consensus-delegate-size"))

	//  mtr-erc20, 0x00000000000000006e61746976652d6d74722d65726332302d61646472657373
	KeyNativeMtrERC20Address = BytesToBytes32([]byte("native-mtr-erc20-address"))
	// mtrg-erc20, 0x000000000000006e61746976652d6d7472672d65726332302d61646472657373
	KeyNativeMtrgERC20Address = BytesToBytes32([]byte("native-mtrg-erc20-address"))

	// 0x00000000000000312d73797374656d2d636f6e74726163742d61646472657373
	KeySystemContractAddress1 = BytesToBytes32([]byte("1-system-contract-address"))
	// 0x00000000000000322d73797374656d2d636f6e74726163742d61646472657373
	KeySystemContractAddress2 = BytesToBytes32([]byte("2-system-contract-address"))
	// 0x00000000000000332d73797374656d2d636f6e74726163742d61646472657373
	KeySystemContractAddress3 = BytesToBytes32([]byte("3-system-contract-address"))
	// 0x00000000000000342d73797374656d2d636f6e74726163742d61646472657373
	KeySystemContractAddress4 = BytesToBytes32([]byte("4-system-contract-address"))

	KeyEnforceTesla1_1Correction = BytesToBytes32([]byte("Tesla1_1Correction-Flag")) // unset or 0 is not do yet, 1 is donw

	// key set transaction fee address
	// 0x6e73616374696f6e2d6665652d62656e65666963696172792d61646472657373
	KeyTransactionFeeAddress = BytesToBytes32([]byte("transaction-fee-beneficiary-address"))

	// Initial values
	InitialRewardRatio         = big.NewInt(3e17) // 30%
	InitialBaseGasPrice        = big.NewInt(5e11) // each tx gas is about 0.01 meter
	InitialProposerEndorsement = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(25000000))

	InitialPowPoolCoef           = big.NewInt(POW_DEFAULT_REWARD_COEF_MAIN)                           // coef start with Main
	InitialPowPoolCoefFadeDays   = new(big.Int).Mul(big.NewInt(550), big.NewInt(1e18))                // fade day initial is 550 days
	InitialPowPoolCoefFadeRate   = new(big.Int).Mul(big.NewInt(5), big.NewInt(1e17))                  // fade rate initial with 0.5
	InitialValidatorBenefitRatio = big.NewInt(4e17)                                                   //40% percent of total auciton gain
	InitialValidatorBaseReward   = new(big.Int).Mul(big.NewInt(25), big.NewInt(1e16))                 // base reward for each validator 0.25
	InitialAuctionReservedPrice  = big.NewInt(5e17)                                                   // 1 MTRG settle with 0.5 MTR
	InitialMinRequiredByDelegate = new(big.Int).Mul(big.NewInt(int64(300)), big.NewInt(int64(1e18)))  // minimium require for delegate is 300 mtrg
	InitialAuctionInitRelease    = new(big.Int).Mul(big.NewInt(int64(1000)), big.NewInt(int64(1e18))) // auction reward initial release, is 1000

	// TBA
	InitialBorrowInterestRate     = big.NewInt(1e17)                                                  // bowrrower interest rate, initial set as 10%
	InitialConsensusCommitteeSize = new(big.Int).Mul(big.NewInt(int64(50)), big.NewInt(int64(1e18)))  // consensus committee size, is set to 50
	InitialConsensusDelegateSize  = new(big.Int).Mul(big.NewInt(int64(100)), big.NewInt(int64(1e18))) // consensus delegate size, is set to 100

	// This account takes 40% of auction gain to distribute to validators in consensus
	// 0x61746f722d62656e656669742d61646472657373
	ValidatorBenefitAddr = BytesToAddress([]byte("validator-benefit-address"))

	AuctionLeftOverAccount = MustParseAddress("0xe852f654dfaee0e2b60842657379a56e1cafa292")

	ZeroAddress = MustParseAddress("0x0000000000000000000000000000000000000000")
	//////////////////////////////
	// The Following Accounts are defined for DFL Community
	InitialExecutorAccount = MustParseAddress("0xdbb11b66f1d62bdeb5f47018d85e2401d7e3dc2e")
	InitialDFLTeamAccount1 = MustParseAddress("0x2fa2d56e312c47709537acb198446205736022aa")
	InitialDFLTeamAccount2 = MustParseAddress("0x08ebea6584b3d9bf6fbcacf1a1507d00a61d95b7")
	InitialDFLTeamAccount3 = MustParseAddress("0x045df1ef32d6db371f1857bb60551ef2e43abb1e")
	InitialDFLTeamAccount4 = MustParseAddress("0xde4f71f45ae821614e9dd1256fef06780b775216")
	InitialDFLTeamAccount5 = MustParseAddress("0xab22ab75f8c42b6969c5d226f39aeb7be35bf24b")
	InitialDFLTeamAccount6 = MustParseAddress("0x63723217e860bc409e29b46eec70101cd03d8242")
	InitialDFLTeamAccount7 = MustParseAddress("0x0374f5867ab2effd2277c895e7d1088b10ec9452")
	InitialDFLTeamAccount8 = MustParseAddress("0x5308b6f26f21238963d0ea0b391eafa9be53c78e")

	TeslaValidatorBenefitRatio = big.NewInt(1e18)

	NewViewPeersLimit = 8
)

Keys of governance params.

View Source
var (
	// BlocktChainConfig is the chain parameters to run a node on the main network.
	BlockChainConfig = &ChainConfig{
		ChainGenesisID: GenesisHash,
		ChainFlag:      "",
		Initialized:    false,
	}
)
View Source
var NoFork = ForkConfig{
	FixTransferLog: math.MaxUint32,
}

NoFork a special config without any forks.

Functions

func EthCreateContractAddress

func EthCreateContractAddress(b common.Address, nonce uint32) common.Address

to compatible with ethereum contract creation count.

func EthCreateContractAddress2

func EthCreateContractAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address

CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.

func InitBlockChainConfig

func InitBlockChainConfig(genesisID Bytes32, chainFlag string)

func IsMainChainEdison

func IsMainChainEdison(blockNum uint32) bool

func IsMainChainTesla

func IsMainChainTesla(blockNum uint32) bool

func IsMainChainTeslaFork2

func IsMainChainTeslaFork2(blockNum uint32) bool

func IsMainChainTeslaFork3

func IsMainChainTeslaFork3(blockNum uint32) bool

func IsMainChainTeslaFork4

func IsMainChainTeslaFork4(blockNum uint32) bool

func IsMainNet

func IsMainNet() bool

func IsTestChainTesla

func IsTestChainTesla(blockNum uint32) bool

func IsTestChainTeslaFork2

func IsTestChainTeslaFork2(blockNum uint32) bool

func IsTestChainTeslaFork3

func IsTestChainTeslaFork3(blockNum uint32) bool

func IsTestChainTeslaFork4

func IsTestChainTeslaFork4(blockNum uint32) bool

func IsTestNet

func IsTestNet() bool

func NewBlake2b

func NewBlake2b() hash.Hash

NewBlake2b return blake2b-256 hash.

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) 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) (b32 Bytes32)

Blake2b computes blake2b-256 checksum for given data.

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

type ChainConfig struct {
	ChainGenesisID Bytes32 // set while init
	ChainFlag      string
	Initialized    bool
}

func (*ChainConfig) IsEdison

func (p *ChainConfig) IsEdison(blockNum uint32) bool

TBD: There would be more rules when 2nd fork is there.

func (*ChainConfig) IsInitialized

func (c *ChainConfig) IsInitialized() bool

func (*ChainConfig) IsMainnet

func (c *ChainConfig) IsMainnet() bool

chain flag right now ONLY 3: "main"/"test"/"warringstakes"

func (*ChainConfig) IsTesla

func (p *ChainConfig) IsTesla(blockNum uint32) bool

func (*ChainConfig) IsTeslaFork2

func (p *ChainConfig) IsTeslaFork2(blockNum uint32) bool

func (*ChainConfig) IsTeslaFork3

func (p *ChainConfig) IsTeslaFork3(blockNum uint32) bool

func (*ChainConfig) IsTeslaFork4

func (p *ChainConfig) IsTeslaFork4(blockNum uint32) bool

func (*ChainConfig) IsTestnet

func (c *ChainConfig) IsTestnet() bool

func (*ChainConfig) ToString

func (c *ChainConfig) ToString() string

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

Jump to

Keyboard shortcuts

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