meter

package
v1.2.0-fork8-fix1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OP_ADDLOCK    = uint32(1)
	OP_REMOVELOCK = uint32(2)
	OP_TRANSFER   = uint32(3)
	OP_GOVERNING  = uint32(100)
)
View Source
const (
	OP_START = uint32(1)
	OP_STOP  = uint32(2)
	OP_BID   = uint32(3)

	USER_BID = uint32(0)
	AUTO_BID = uint32(1)
)
View Source
const (
	MainnetChainID = 82 // 0x52 for mainnet
	TestnetChainID = 83 // 0x53 for testnet
)

chainID

View Source
const (
	EdisonMainnetStartNum             = 0
	EdisonTestnetStartNum             = 0
	EdisonSysContract_MainnetStartNum = 4900000 //around 11/18/2020
	EdisonSysContract_TestnetStartNum = 100000
)

Edision: The initial Basic Release. Features include

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

)

Tesla: The staking/auction release, Features include:

View Source
const (
	TeslaFork1_MainnetStartNum = 9680000
	TeslaFork1_TestnetStartNum = 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

View Source
const (
	TeslaFork2_MainnetStartNum = 10382000 // around 4/16/2021 11:00 AM (Beijing)
	TeslaFork2_TestnetStartNum = 682000   // around 4/16/2021 11:00 AM (Beijing)
)
View Source
const (
	TeslaFork3_MainnetAuctionDefectStartNum = 14811495
	TeslaFork3_MainnetStartNum              = 14875500 // around 8/24/2021 10:00 AM (Beijing)
	TeslaFork3_TestnetStartNum              = 4220000  //  4220000
)

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
View Source
const (
	TeslaFork4_MainnetStartNum = 15138000 // around 9/1/2021 9:30 AM (Beijing)
	TeslaFork4_TestnetStartNum = 4932000
)

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)

View Source
const (
	TeslaFork5_MainnetStartNum = 25650000 // around 7/4/2022 9:30 AM (PDT)
	TeslaFork5_TestnetStartNum = 4932000  // same as fork4
)

Tesla 1.5 Hardfork (Not Yet) includes feature updates: 1) fix the governing for matured unbound buckets to avoid duplicate handling 2) fix wrong boundbalance on account 0x08ebea6584b3d9bf6fbcacf1a1507d00a61d95b7 on mainnet 3) more to come

View Source
const (
	TeslaFork6_MainnetStartNum = 33023000 // around 1/31/2023 9:30 AM (PDT)
	TeslaFork6_TestnetStartNum = 25836347 //
)

fork6 includes feature: 1) huge performance boost: 1.1) merge autobid into governV2 txs to minimize tx execution overhead 1.2) upgrade ethereum dependency to 1.10.20 that include rlp enhancement, 30% faster encoding/decoding 1.3) trie optimization, 20-30% faster trie node access, this is really helpful for large tries 1.4) removes unncessary auctionTxs/dists in auction summary list, except for the very last auction. It takes effect on the first tx after fork6, and auction close will keep it that way. 2) pacemaker restart after 5 consecutive timeouts to bound max timeout, enable overriting for pre-commited block 3) staking updates: 3.1) staking correction on the first tx after fork6, takes care of candidates/buckets mismatch 3.2) correct calculation for bucket sub 3.3) disallow candidate update with same name/ip/pubkey 3.4) injail information will fill `createTime` with jailed block number 4) native call return gas updated from 1562 to 1264 5) create a new http net client every time error occurs so peer won't be blocked by `Failed to send message` 6) code structure & test 6.1) fix all the test cases that ships with binary 6.2) code refactory for maintanability, and prepare for liquid staking 6.3) log optimization for readability

View Source
const (
	TeslaFork7_MainnetStartNum = 33274000 // around 2/7/2023 9:30 AM (PDT)
	TeslaFork7_TestnetStartNum = 25836347 // same as fork6
)

deprecate the usage of `timestamp` and `nonce` in StakingBody and AuctionBody input `timestamp` will be ignored, and set to block timestamp input `nonce` will be ignored, and set to clause index

View Source
const (
	TeslaFork8_MainnetStartNum = 34975000 // around 3/17/2023 9:30 AM (PDT)
	// TeslaFork8_TestnetStartNum = 27323000 // around 2/18/2023 4:00 PM (PDT)
	TeslaFork8_TestnetStartNum = 27902500 // around 2/26/2023 12:00 PM (PDT)
)

fork8 includes features:

  1. LiquidStaking native support with two parts 1.1) upgraded meter tracker interface with `native_bucket` operations 1.2) auto loaded `ScriptEngine` system contract that provides accessible methods
  2. recalculate MTR/MTRG total add sub, providing a correct total supply for system contract
  3. future minted MTR/MTRG will update global meter tracker
  4. enable validator to change ip/pubkey/name separately
  5. self vote ratio check will only check (total value of buckets voted to candidate) / (candidate bucket value) < 100
  6. fix two race conditions: 6.1) commited kblock handled and pacemaker started, but right before OnBeat, synced KBlock kicks in and reset the pacemaker in this case, the proposalMap panics due to nil pointer 6.2) commited kblock handled, but pacemaker not started yet, a NewView with HigherQC arrives and scheduled an OnBeat with very high round in this case, the OnBeat will invalidate all future rounds
  7. added API 7.1) GET /buckets/ownedby/{owner} to read buckets owned by a specific user 7.1) GET /debug/rawstorage/{address}/{key} to read raw storage on state 7.2) GET /debug/supply to read MTR/MTRG tracker 7.3) GET /trace/{txhash}/{clauseIndex} to provide unified trace that includes scriptengine tx 7.4) GET /rerun/{txhash}/{clauseIndex} rerun tx and get the result
View Source
const (
	JailCriteria = 2000 // 100 times of missing proposer (roughly 2 epoch of misconducting, when 1 epoch = 1 hour)

	DoubleSignPts      = 2000
	MissingLeaderPts   = 1000
	MissingProposerPts = 20
	MissingVoterPts    = 2

	PhaseOutEpochCount    = 4 // half points after 12 epoch (half a day)
	PhaseOutDoubleSignPts = DoubleSignPts / 2
	PhaseOutLeaderPts     = MissingLeaderPts / 2
	PhaseOutProposerPts   = MissingProposerPts / 2
	PhaseOutVoterPts      = MissingVoterPts / 2
	WipeOutEpochCount     = PhaseOutEpochCount * 2 // does not count if longer than 2*PhaseOutEpochOut

	NObservationEpochs = 8 // Only the last 8 epochs are used to calculate violation count

	MaxMissingProposerPerEpoch = 3 // if 3 missing proposers or more infractions in one epoch, violation is raised
	MaxMissingLeaderPerEpoch   = 2
	MaxDoubleSignPerEpoch      = 1

	JailCriteria_MissingProposerViolation = 2 // only 2 times of missing-proposer-epoch violation is allowed,
	JailCriteria_MissingLeaderViolation   = 2
	JailCriteria_DoubleSignViolation      = 1
)
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 (
	MIN_CANDIDATE_UPDATE_INTV = uint64(3600 * 24) // 1 day
	TESLA1_0_SELF_VOTE_RATIO  = 10                // max candidate total votes / self votes ratio < 10x in Tesla 1.0
	TESLA1_1_SELF_VOTE_RATIO  = 100               // max candidate total votes / self votes ratio < 100x in Tesla 1.1
)
View Source
const (
	BUCKET_ADD_OPT = 0
	BUCKET_SUB_OPT = 1
)

bucket update options

View Source
const (
	ONE_DAY_LOCK      = uint32(0)
	ONE_DAY_LOCK_RATE = uint8(0)
	ONE_DAY_LOCK_TIME = uint64(60 * 60 * 24)

	ONE_WEEK_LOCK      = uint32(1)
	ONE_WEEK_LOCK_RATE = uint8(5) // 5 percent
	ONE_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 7)

	TWO_WEEK_LOCK      = uint32(2)
	TWO_WEEK_LOCK_RATE = uint8(6) // %6
	TWO_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 14)

	THREE_WEEK_LOCK      = uint32(3)
	THREE_WEEK_LOCK_RATE = uint8(7)
	THREE_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 21)

	FOUR_WEEK_LOCK      = uint32(4)
	FOUR_WEEK_LOCK_RATE = uint8(8)
	FOUR_WEEK_LOCK_TIME = uint64(60 * 60 * 24 * 28)

	// for candidate bucket ONLY
	FOREVER_LOCK      = uint32(1000)
	FOREVER_LOCK_RATE = ONE_WEEK_LOCK_RATE
	FOREVER_LOCK_TIME = uint64(0)
)

bound lock options

View Source
const (
	COMMISSION_RATE_MAX     = uint64(100 * 1e07) // 100%
	COMMISSION_RATE_MIN     = uint64(1 * 1e07)   // 1%
	COMMISSION_RATE_DEFAULT = uint64(10 * 1e07)  // 10%
)

================================= commission rate 1% presents 1e07, unit is shannon (1e09)

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

Variables

View Source
var (
	DevAccounts = `` /* 429-byte string literal not displayed */

	MTRAddSubAccounts = `` /* 1031-byte string literal not displayed */

	MTRGAddSubAccounts = `` /* 54437-byte string literal not displayed */

)
View Source
var (
	//0x6163636f756e742d6c6f636b2d61646472657373
	AccountLockModuleAddr = BytesToAddress([]byte("account-lock-address"))
	ProfileListKey        = Blake2b([]byte("account-lock-profile-list-key"))

	// 0x74696f6e2d6163636f756e742d61646472657373
	AuctionModuleAddr     = BytesToAddress([]byte("auction-account-address"))
	AuctionSummaryListKey = Blake2b([]byte("summary-list-key"))
	AuctionCBKey          = Blake2b([]byte("auction-active-cb-key"))

	// 0x616B696e672D6D6F64756c652d61646472657373
	StakingModuleAddr      = BytesToAddress([]byte("staking-module-address"))
	DelegateListKey        = Blake2b([]byte("delegate-list-key"))
	CandidateListKey       = Blake2b([]byte("candidate-list-key"))
	StakeHolderListKey     = Blake2b([]byte("stake-holder-list-key"))
	BucketListKey          = Blake2b([]byte("global-bucket-list-key"))
	DelegateStatListKey    = Blake2b([]byte("delegate-statistics-list-key"))
	StatisticsEpochKey     = Blake2b([]byte("delegate-statistics-epoch-key"))
	InJailListKey          = Blake2b([]byte("delegate-injail-list-key"))
	ValidatorRewardListKey = Blake2b([]byte("validator-reward-list-key"))
)

Script Engine

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_Correction = BytesToBytes32([]byte("Tesla1_1Correction-Flag")) // unset or 0 is not do yet, 1 is done

	KeyEnforceTesla5_Correction = BytesToBytes32([]byte("Tesla5_Correction-Flag")) // unset or 0 is not do yet, 1 is done

	KeyEnforceTesla_Fork6_Correction = BytesToBytes32([]byte("Tesla_Fork6_Correction-Flag")) // unset or 0 is not do yet, 1 is done

	KeyEnforceTesla_Fork8_Correction = BytesToBytes32([]byte("Tesla_Fork8_Correction_Flag")) // unset or 0 is not do yet, 1 is done
	// 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"))

	ScriptEngineSysContractAddr = BytesToAddress([]byte("native-script-engine-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 (
	// bound minimium requirement 100 MTRG
	MIN_BOUND_BALANCE = new(big.Int).Mul(big.NewInt(100), big.NewInt(1e18))

	// delegate minimum requirement 2000 MTRG
	MIN_REQUIRED_BY_DELEGATE *big.Int = new(big.Int).Mul(big.NewInt(int64(2000)), big.NewInt(int64(1e18)))

	// amount to exit from jail 10 MTRGov
	BAIL_FOR_EXIT_JAIL = new(big.Int).Mul(big.NewInt(int64(10)), big.NewInt(int64(1e18)))
)
View Source
var (
	// BlocktChainConfig is the chain parameters to run a node on the main network.
	BlockChainConfig = &ChainConfig{
		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 GetBoundLockOption

func GetBoundLockOption(chose uint32) (opt uint32, rate uint8, locktime uint64)

func GetBoundLocktime

func GetBoundLocktime(opt uint32) (lock uint64)

func GetCommissionRate

func GetCommissionRate(opt uint32) uint64

func GetOpName

func GetOpName(op uint32) string

func InitBlockChainConfig

func InitBlockChainConfig(chainFlag string)

func IsEdison

func IsEdison(blockNum uint32) bool

func IsMainNet

func IsMainNet() bool

func IsStaging

func IsStaging() bool

func IsSysContractEnabled

func IsSysContractEnabled(blockNum uint32) bool

func IsTesla

func IsTesla(blockNum uint32) bool

func IsTeslaFork1

func IsTeslaFork1(blockNum uint32) bool

func IsTeslaFork2

func IsTeslaFork2(blockNum uint32) bool

func IsTeslaFork3

func IsTeslaFork3(blockNum uint32) bool

func IsTeslaFork4

func IsTeslaFork4(blockNum uint32) bool

func IsTeslaFork5

func IsTeslaFork5(blockNum uint32) bool

func IsTeslaFork6

func IsTeslaFork6(blockNum uint32) bool

func IsTeslaFork7

func IsTeslaFork7(blockNum uint32) bool

func IsTeslaFork8

func IsTeslaFork8(blockNum uint32) bool

func IsTestNet

func IsTestNet() bool

func NewBlake2b

func NewBlake2b() hash.Hash

NewBlake2b return blake2b-256 hash.

func PackInfractionToBytes

func PackInfractionToBytes(v *Infraction) ([]byte, error)

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 AuctionCB

type AuctionCB struct {
	AuctionID   Bytes32
	StartHeight uint64
	StartEpoch  uint64
	EndHeight   uint64
	EndEpoch    uint64
	Sequence    uint64
	RlsdMTRG    *big.Int //released mtrg
	RsvdMTRG    *big.Int // reserved mtrg
	RsvdPrice   *big.Int
	CreateTime  uint64

	//changed fields after auction start
	RcvdMTR    *big.Int
	AuctionTxs []*AuctionTx
}

///////////////////////////////////////////////// auctionTx indicates the structure of a auctionTx

func (*AuctionCB) Add

func (cb *AuctionCB) Add(tx *AuctionTx)

func (*AuctionCB) AddAuctionTx

func (cb *AuctionCB) AddAuctionTx(tx *AuctionTx) error

func (*AuctionCB) Count

func (cb *AuctionCB) Count() int

func (*AuctionCB) Exist

func (cb *AuctionCB) Exist(id Bytes32) bool

func (*AuctionCB) Get

func (cb *AuctionCB) Get(id Bytes32) *AuctionTx

func (*AuctionCB) ID

func (cb *AuctionCB) ID() (hash Bytes32)

bucketID auctionTx .. are excluded

func (*AuctionCB) IsActive

func (cb *AuctionCB) IsActive() bool

func (*AuctionCB) Remove

func (cb *AuctionCB) Remove(id Bytes32)

func (*AuctionCB) RemoveAuctionTx

func (cb *AuctionCB) RemoveAuctionTx(tx *AuctionTx) error

Actually Auction do not allow to cancel, so this func should not be called

func (*AuctionCB) ToString

func (cb *AuctionCB) ToString() string

func (*AuctionCB) ToTxList

func (cb *AuctionCB) ToTxList() []*AuctionTx

type AuctionSummary

type AuctionSummary struct {
	AuctionID    Bytes32
	StartHeight  uint64
	StartEpoch   uint64
	EndHeight    uint64
	EndEpoch     uint64
	Sequence     uint64
	RlsdMTRG     *big.Int
	RsvdMTRG     *big.Int
	RsvdPrice    *big.Int
	CreateTime   uint64
	RcvdMTR      *big.Int
	ActualPrice  *big.Int
	LeftoverMTRG *big.Int
	AuctionTxs   []*AuctionTx
	DistMTRG     []*DistMtrg
}

func (*AuctionSummary) ToString

func (a *AuctionSummary) ToString() string

type AuctionSummaryList

type AuctionSummaryList struct {
	Summaries []*AuctionSummary
}

func NewAuctionSummaryList

func NewAuctionSummaryList(summaries []*AuctionSummary) *AuctionSummaryList

func (*AuctionSummaryList) Add

func (a *AuctionSummaryList) Add(summary *AuctionSummary) error

func (*AuctionSummaryList) Count

func (a *AuctionSummaryList) Count() int

func (*AuctionSummaryList) Get

func (*AuctionSummaryList) Last

func (*AuctionSummaryList) Remove

func (a *AuctionSummaryList) Remove(id Bytes32) error

unsupport at this time

func (*AuctionSummaryList) String

func (a *AuctionSummaryList) String() string

func (*AuctionSummaryList) ToList

func (a *AuctionSummaryList) ToList() []AuctionSummary

func (*AuctionSummaryList) ToString

func (a *AuctionSummaryList) ToString() string

type AuctionTx

type AuctionTx struct {
	TxID      Bytes32
	Address   Address
	Amount    *big.Int // total amont wei is unit
	Type      uint32   // USER_BID or AUTO_BID
	Timestamp uint64   //timestamp
	Nonce     uint64   //randomness
}

func NewAuctionTx

func NewAuctionTx(addr Address, amount *big.Int, txtype uint32, time uint64, nonce uint64) *AuctionTx

func (*AuctionTx) ID

func (a *AuctionTx) ID() (hash Bytes32)

func (*AuctionTx) ToString

func (a *AuctionTx) ToString() string

type Bucket

type Bucket struct {
	BucketID   Bytes32
	Owner      Address // stake holder
	Nonce      uint64  // nonce
	CreateTime uint64  // bucket create time

	//non-key fields
	Value     *big.Int // staking unit Wei
	Token     uint8    // token type MTR / MTRG
	Unbounded bool     // this bucket is unbounded, get rid of it after mature
	Candidate Address  // candidate
	Rate      uint8    // bounus rate
	Autobid   uint8    // autobid percentile
	Option    uint32   // option, link with rate
	// deprecated: BonusVotes, will always be 0
	// bonus could be inferred by TotalVotes - Value
	BonusVotes   uint64   // extra votes from staking
	TotalVotes   *big.Int // Value votes + extra votes
	MatureTime   uint64   // time durations, seconds
	CalcLastTime uint64   // last calculate bounus votes timestamp
}

Candidate indicates the structure of a candidate

func NewBucket

func NewBucket(owner Address, cand Address, value *big.Int, token uint8, opt uint32, rate uint8, autobid uint8, create uint64, nonce uint64) *Bucket

func (*Bucket) ID

func (b *Bucket) ID() (hash Bytes32)

bucketID Candidate .. are excluded value and token are excluded since are allowed to change

func (*Bucket) IsForeverLock

func (b *Bucket) IsForeverLock() bool

func (*Bucket) ToString

func (b *Bucket) ToString() string

func (*Bucket) UpdateLockOption

func (b *Bucket) UpdateLockOption(opt uint32, rate uint8)

type BucketList

type BucketList struct {
	Buckets []*Bucket
}

func NewBucketList

func NewBucketList(buckets []*Bucket) *BucketList

func (*BucketList) Add

func (l *BucketList) Add(b *Bucket)

func (*BucketList) Exist

func (l *BucketList) Exist(id Bytes32) bool

func (*BucketList) Get

func (l *BucketList) Get(id Bytes32) *Bucket

func (*BucketList) GetByOwner

func (l *BucketList) GetByOwner(owner Address) []*Bucket

func (*BucketList) Len

func (l *BucketList) Len() int

func (*BucketList) Remove

func (l *BucketList) Remove(id Bytes32)

func (*BucketList) ToList

func (l *BucketList) ToList() []Bucket

func (*BucketList) ToString

func (l *BucketList) ToString() string

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 Candidate

type Candidate struct {
	Addr        Address // the address for staking / reward
	Name        []byte
	Description []byte
	PubKey      []byte // node public key
	IPAddr      []byte // network addr
	Port        uint16
	Commission  uint64    // unit shannon, aka 1e09
	Timestamp   uint64    // last update time
	TotalVotes  *big.Int  // total voting from all buckets
	Buckets     []Bytes32 // all buckets voted for this candidate
}

Candidate indicates the structure of a candidate

func NewCandidate

func NewCandidate(addr Address, name []byte, desc []byte, pubKey []byte, ip []byte, port uint16,
	commission uint64, timeStamp uint64) *Candidate

func (*Candidate) AddBucket

func (c *Candidate) AddBucket(bucket *Bucket)

func (*Candidate) RemoveBucket

func (c *Candidate) RemoveBucket(bucket *Bucket)

func (*Candidate) ToString

func (c *Candidate) ToString() string

type CandidateList

type CandidateList struct {
	Candidates []*Candidate
}

func NewCandidateList

func NewCandidateList(candidates []*Candidate) *CandidateList

func (*CandidateList) Add

func (cl *CandidateList) Add(c *Candidate)

func (*CandidateList) Count

func (cl *CandidateList) Count() int

func (*CandidateList) Exist

func (cl *CandidateList) Exist(addr Address) bool

func (*CandidateList) Get

func (cl *CandidateList) Get(addr Address) *Candidate

func (*CandidateList) Len

func (l *CandidateList) Len() int

func (*CandidateList) Remove

func (cl *CandidateList) Remove(addr Address)

func (*CandidateList) ToList

func (l *CandidateList) ToList() []Candidate

func (*CandidateList) ToString

func (cl *CandidateList) ToString() string

type ChainConfig

type ChainConfig struct {
	ChainFlag   string
	Initialized bool
}

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

func (c *ChainConfig) IsStaging() bool

func (*ChainConfig) IsTestnet

func (c *ChainConfig) IsTestnet() bool

func (*ChainConfig) ToString

func (c *ChainConfig) ToString() string

type Delegate

type Delegate struct {
	Address     Address
	PubKey      []byte //ecdsa.PublicKey
	Name        []byte
	VotingPower *big.Int
	IPAddr      []byte
	Port        uint16
	Commission  uint64 // commission rate. unit shannon, aka, 1e09
	DistList    []*Distributor
}

====

func (*Delegate) ToString

func (d *Delegate) ToString() string

type DelegateList

type DelegateList struct {
	Delegates []*Delegate
}

func NewDelegateList

func NewDelegateList(delegates []*Delegate) *DelegateList

func (*DelegateList) Add

func (l *DelegateList) Add(c *Delegate) error

func (*DelegateList) CleanAll

func (l *DelegateList) CleanAll() error

func (*DelegateList) GetDelegates

func (l *DelegateList) GetDelegates() []*Delegate

func (*DelegateList) Members

func (l *DelegateList) Members() string

func (*DelegateList) SetDelegates

func (l *DelegateList) SetDelegates(delegates []*Delegate)

func (*DelegateList) ToString

func (l *DelegateList) ToString() string

type DelegateStat

type DelegateStat struct {
	Addr        Address // the address for staking / reward
	Name        []byte
	PubKey      []byte // node public key
	TotalPts    uint64 // total points of infraction
	Infractions Infraction
}

Candidate indicates the structure of a candidate

func NewDelegateStat

func NewDelegateStat(addr Address, name []byte, pubKey []byte) *DelegateStat

func (*DelegateStat) CountDoubleSignViolation

func (ds *DelegateStat) CountDoubleSignViolation(epoch uint32) int

func (*DelegateStat) CountMissingLeaderViolation

func (ds *DelegateStat) CountMissingLeaderViolation(epoch uint32) int

func (*DelegateStat) CountMissingProposerViolation

func (ds *DelegateStat) CountMissingProposerViolation(epoch uint32) int

func (*DelegateStat) PhaseOut

func (ds *DelegateStat) PhaseOut(curEpoch uint32)

func (*DelegateStat) ToString

func (ds *DelegateStat) ToString() string

func (*DelegateStat) Update

func (ds *DelegateStat) Update(incr *Infraction)

type DelegateStatList

type DelegateStatList struct {
	Delegates []*DelegateStat
}

func NewDelegateStatList

func NewDelegateStatList(delegates []*DelegateStat) *DelegateStatList

func (*DelegateStatList) Add

func (sl *DelegateStatList) Add(c *DelegateStat)

func (*DelegateStatList) Count

func (sl *DelegateStatList) Count() int

func (*DelegateStatList) Exist

func (sl *DelegateStatList) Exist(addr Address) bool

func (*DelegateStatList) Get

func (sl *DelegateStatList) Get(addr Address) *DelegateStat

func (*DelegateStatList) Remove

func (sl *DelegateStatList) Remove(addr Address)

func (*DelegateStatList) ToList

func (sl *DelegateStatList) ToList() []DelegateStat

func (*DelegateStatList) ToString

func (sl *DelegateStatList) ToString() string

type DistMtrg

type DistMtrg struct {
	Addr   Address
	Amount *big.Int
}

type Distributor

type Distributor struct {
	Address Address
	Autobid uint8  // autobid percentile
	Shares  uint64 // unit shannon, aka, 1e09
}

func NewDistributor

func NewDistributor(addr Address, autobid uint8, shares uint64) *Distributor

func (*Distributor) ToString

func (d *Distributor) ToString() string

type DoubleSigner

type DoubleSigner struct {
	Counter uint32
	Info    []*DoubleSignerInfo
}

type DoubleSignerInfo

type DoubleSignerInfo struct {
	Epoch  uint32
	Height uint32
}

DoubleSigner

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 InJail

type InJail struct {
	Addr        Address // the address for staking / reward
	Name        []byte
	PubKey      []byte // node public key
	TotalPts    uint64 // total points of infraction
	Infractions Infraction
	BailAmount  *big.Int //fine
	JailedTime  uint64
}

Candidate indicates the structure of a candidate

func NewInJail

func NewInJail(addr Address, name []byte, pubKey []byte, pts uint64, inf *Infraction, bail *big.Int, timeStamp uint64) *InJail

func (*InJail) ToString

func (d *InJail) ToString() string

type InJailList

type InJailList struct {
	InJails []*InJail
}

func NewInJailList

func NewInJailList(in []*InJail) *InJailList

func (*InJailList) Add

func (dl *InJailList) Add(c *InJail)

func (*InJailList) Count

func (dl *InJailList) Count() int

func (*InJailList) Exist

func (dl *InJailList) Exist(addr Address) bool

func (*InJailList) Get

func (dl *InJailList) Get(addr Address) *InJail

func (*InJailList) Remove

func (dl *InJailList) Remove(addr Address) error

func (*InJailList) ToList

func (dl *InJailList) ToList() []InJail

func (*InJailList) ToString

func (dl *InJailList) ToString() string

type Infraction

type Infraction struct {
	MissingLeaders   MissingLeader
	MissingProposers MissingProposer
	MissingVoters    MissingVoter
	DoubleSigners    DoubleSigner
}

func UnpackBytesToInfraction

func UnpackBytesToInfraction(b []byte) (*Infraction, error)

func (*Infraction) String

func (inf *Infraction) String() string

type MissingLeader

type MissingLeader struct {
	Counter uint32
	Info    []*MissingLeaderInfo
}

type MissingLeaderInfo

type MissingLeaderInfo struct {
	Epoch uint32
	Round uint32
}

MissingLeader

type MissingProposer

type MissingProposer struct {
	Counter uint32
	Info    []*MissingProposerInfo
}

func (MissingProposer) String

func (m MissingProposer) String() string

type MissingProposerInfo

type MissingProposerInfo struct {
	Epoch  uint32
	Height uint32
}

MissingProposer

type MissingVoter

type MissingVoter struct {
	Counter uint32
	Info    []*MissingVoterInfo
}

type MissingVoterInfo

type MissingVoterInfo struct {
	Epoch  uint32
	Height uint32
}

MissingVoter

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 Profile

type Profile struct {
	Addr           Address
	Memo           []byte
	LockEpoch      uint32
	ReleaseEpoch   uint32
	MeterAmount    *big.Int
	MeterGovAmount *big.Int
}

Profile indicates the structure of a Profile

func NewProfile

func NewProfile(addr Address, memo []byte, lock uint32, release uint32, mtr *big.Int, mtrg *big.Int) *Profile

func (*Profile) ToString

func (c *Profile) ToString() string

type ProfileList

type ProfileList struct {
	Profiles []*Profile
}

func NewProfileList

func NewProfileList(Profiles []*Profile) *ProfileList

func (*ProfileList) Add

func (cl *ProfileList) Add(c *Profile)

func (*ProfileList) Count

func (cl *ProfileList) Count() int

func (*ProfileList) Exist

func (cl *ProfileList) Exist(addr Address) bool

func (*ProfileList) Get

func (cl *ProfileList) Get(addr Address) *Profile

func (*ProfileList) Remove

func (cl *ProfileList) Remove(addr Address)

func (*ProfileList) ToList

func (l *ProfileList) ToList() []Profile

func (*ProfileList) ToString

func (cl *ProfileList) ToString() string

type RewardInfo

type RewardInfo struct {
	Address Address
	Amount  *big.Int
}

func (*RewardInfo) String

func (ri *RewardInfo) String() string

func (*RewardInfo) ToString

func (ri *RewardInfo) ToString() string

func (*RewardInfo) UniteHash

func (ri *RewardInfo) UniteHash() (hash Bytes32)

type RewardInfoV2

type RewardInfoV2 struct {
	Address       Address
	DistAmount    *big.Int
	AutobidAmount *big.Int
}

func (*RewardInfoV2) String

func (r *RewardInfoV2) String() string

func (*RewardInfoV2) UniteHash

func (r *RewardInfoV2) UniteHash() (hash Bytes32)

type Stakeholder

type Stakeholder struct {
	Holder     Address   // the address for staking / reward
	TotalStake *big.Int  // total voting from all buckets
	Buckets    []Bytes32 // all buckets voted for this Stakeholder
}

Stakeholder indicates the structure of a Stakeholder

func NewStakeholder

func NewStakeholder(holder Address) *Stakeholder

func (*Stakeholder) AddBucket

func (s *Stakeholder) AddBucket(bucket *Bucket)

func (*Stakeholder) RemoveBucket

func (s *Stakeholder) RemoveBucket(bucket *Bucket)

func (*Stakeholder) ToString

func (s *Stakeholder) ToString() string

type StakeholderList

type StakeholderList struct {
	Holders []*Stakeholder
}

func NewStakeholderList

func NewStakeholderList(holders []*Stakeholder) *StakeholderList

func (*StakeholderList) Add

func (l *StakeholderList) Add(s *Stakeholder)

func (*StakeholderList) Exist

func (l *StakeholderList) Exist(addr Address) bool

func (*StakeholderList) Get

func (l *StakeholderList) Get(addr Address) *Stakeholder

func (*StakeholderList) Remove

func (l *StakeholderList) Remove(addr Address)

func (*StakeholderList) ToList

func (l *StakeholderList) ToList() []Stakeholder

func (*StakeholderList) ToString

func (l *StakeholderList) ToString() string

type ValidatorReward

type ValidatorReward struct {
	Epoch       uint32
	BaseReward  *big.Int
	TotalReward *big.Int
	Rewards     []*RewardInfo
}

func (*ValidatorReward) ToString

func (v *ValidatorReward) ToString() string

type ValidatorRewardList

type ValidatorRewardList struct {
	Rewards []*ValidatorReward
}

func NewValidatorRewardList

func NewValidatorRewardList(rewards []*ValidatorReward) *ValidatorRewardList

func (*ValidatorRewardList) Count

func (v *ValidatorRewardList) Count() int

func (*ValidatorRewardList) Get

func (*ValidatorRewardList) GetList

func (v *ValidatorRewardList) GetList() []*ValidatorReward

func (*ValidatorRewardList) Last

func (*ValidatorRewardList) String

func (v *ValidatorRewardList) String() string

func (*ValidatorRewardList) ToList

func (v *ValidatorRewardList) ToList() []*ValidatorReward

func (*ValidatorRewardList) ToString

func (v *ValidatorRewardList) ToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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