Only one place to declare gwei (#1802)
* Only one place to declare gwei * Fix weiAmount overflow
This commit is contained in:
parent
20885f4ca5
commit
12f494e669
|
@ -1,12 +1,13 @@
|
|||
import
|
||||
std/[tables, math],
|
||||
std/[tables],
|
||||
eth/keys,
|
||||
stew/endians2,
|
||||
nimcrypto/sha2,
|
||||
chronicles,
|
||||
./engine_client,
|
||||
../../../nimbus/transaction,
|
||||
../../../nimbus/common
|
||||
../../../nimbus/common,
|
||||
../../../nimbus/utils/utils
|
||||
|
||||
type
|
||||
BaseTx* = object of RootObj
|
||||
|
@ -77,9 +78,6 @@ proc new*(_: type TxSender, params: NetworkParams): TxSender =
|
|||
result.createAccounts()
|
||||
result.fillBalance(params)
|
||||
|
||||
func gwei(n: int64): GasInt {.compileTime.} =
|
||||
GasInt(n * (10 ^ 9))
|
||||
|
||||
proc getTxType(tc: BaseTx, nonce: uint64): TxType =
|
||||
if tc.txType.isNone:
|
||||
if nonce mod 2 == 0:
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import
|
||||
std/[tables, sets, strutils, math],
|
||||
std/[tables, sets, strutils],
|
||||
eth/common/eth_types,
|
||||
json_rpc/[rpcclient],
|
||||
stew/[byteutils, results],
|
||||
../engine_client
|
||||
../engine_client,
|
||||
../../../nimbus/utils/utils
|
||||
|
||||
type
|
||||
Withdrawals* = ref object
|
||||
|
@ -25,10 +26,6 @@ proc get*(wh: WDHistory, blockNumber: uint64): Result[seq[Withdrawal], string] =
|
|||
return err("withdrawal not found in block " & $blockNumber)
|
||||
ok(wds.list)
|
||||
|
||||
# Helper types to convert gwei into wei more easily
|
||||
func weiAmount(w: Withdrawal): UInt256 =
|
||||
w.amount.u256 * (10 ^ 9).u256
|
||||
|
||||
# Gets an account expected value for a given block, taking into account all
|
||||
# withdrawals that credited the account.
|
||||
func getExpectedAccountBalance*(wh: WDHistory, account: EthAddress, blockNumber: uint64): UInt256 =
|
||||
|
|
|
@ -17,6 +17,7 @@ import
|
|||
../../../nimbus/common,
|
||||
../../../nimbus/config,
|
||||
../../../nimbus/rpc,
|
||||
../../../nimbus/utils/utils,
|
||||
../../../nimbus/core/[chain, tx_pool, sealer],
|
||||
../../../tests/test_helpers,
|
||||
./vault
|
||||
|
@ -33,7 +34,7 @@ type
|
|||
|
||||
const
|
||||
initPath = "hive_integration" / "nodocker" / "rpc" / "init"
|
||||
gasPrice* = 30000000000 # 30 Gwei or 30 * pow(10, 9)
|
||||
gasPrice* = 30.gwei
|
||||
chainID* = ChainID(7)
|
||||
|
||||
proc manageAccounts(ctx: EthContext, conf: NimbusConf) =
|
||||
|
|
|
@ -87,7 +87,7 @@ proc procBlkPreamble(vmState: BaseVMState;
|
|||
raise ValidationError.newException("Post-Shanghai block body must have withdrawals")
|
||||
|
||||
for withdrawal in body.withdrawals.get:
|
||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.amount.gwei)
|
||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
|
||||
else:
|
||||
if header.withdrawalsRoot.isSome:
|
||||
raise ValidationError.newException("Pre-Shanghai block header must not have withdrawalsRoot")
|
||||
|
|
|
@ -226,7 +226,7 @@ proc vmExecCommit(pst: TxPackerStateRef)
|
|||
# EIP-4895
|
||||
if xp.chain.nextFork >= FkShanghai:
|
||||
for withdrawal in xp.chain.withdrawals:
|
||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.amount.gwei)
|
||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
|
||||
|
||||
# EIP-3675: no reward for miner in POA/POS
|
||||
if vmState.com.consensus == ConsensusType.POW:
|
||||
|
|
|
@ -119,5 +119,9 @@ proc decompose*(rlpBytes: openArray[byte],
|
|||
var rlp = rlpFromBytes(rlpBytes)
|
||||
rlp.decompose(header, body)
|
||||
|
||||
func gwei*(n: uint64): UInt256 =
|
||||
n.u256 * (10 ^ 9).u256
|
||||
func gwei*(n: uint64): GasInt =
|
||||
GasInt(n * (10'u64 ^ 9'u64))
|
||||
|
||||
# Helper types to convert gwei into wei more easily
|
||||
func weiAmount*(w: Withdrawal): UInt256 =
|
||||
w.amount.u256 * (10'u64 ^ 9'u64).u256
|
||||
|
|
|
@ -24,6 +24,7 @@ import
|
|||
../hive_integration/nodocker/consensus/consensus_sim,
|
||||
../hive_integration/nodocker/graphql/graphql_sim,
|
||||
../hive_integration/nodocker/engine/engine_sim,
|
||||
../hive_integration/nodocker/pyspec/pyspec_sim,
|
||||
../tools/t8n/t8n,
|
||||
../tools/t8n/t8n_test,
|
||||
../tools/evmstate/evmstate,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import
|
||||
std/[math, tables, times, os],
|
||||
std/[tables, times, os],
|
||||
eth/[keys],
|
||||
stew/[byteutils, results], unittest2,
|
||||
../nimbus/db/state_db,
|
||||
|
@ -11,6 +11,7 @@ import
|
|||
../nimbus/core/casper,
|
||||
../nimbus/core/executor,
|
||||
../nimbus/common/common,
|
||||
../nimbus/utils/utils,
|
||||
../nimbus/[vm_state, vm_types],
|
||||
./test_txpool/helpers,
|
||||
./macro_assembler
|
||||
|
@ -49,9 +50,6 @@ proc privKey(keyHex: string): PrivateKey =
|
|||
|
||||
kRes.get()
|
||||
|
||||
func gwei(n: uint64): GasInt {.compileTime.} =
|
||||
GasInt(n * (10'u64 ^ 9'u64))
|
||||
|
||||
proc makeTx*(t: var TestEnv, recipient: EthAddress, amount: UInt256, payload: openArray[byte] = []): Transaction =
|
||||
const
|
||||
gasLimit = 75000.GasInt
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[json, strutils, times, tables, os, math, streams],
|
||||
std/[json, strutils, times, tables, os, streams],
|
||||
eth/[rlp, trie, eip1559],
|
||||
stint, stew/results,
|
||||
"."/[config, types, helpers],
|
||||
|
@ -192,9 +192,6 @@ proc closeTrace(vmState: BaseVMstate) =
|
|||
if tracer.isNil.not:
|
||||
tracer.close()
|
||||
|
||||
func gwei(n: uint64): UInt256 =
|
||||
n.u256 * (10 ^ 9).u256
|
||||
|
||||
proc exec(ctx: var TransContext,
|
||||
vmState: BaseVMState,
|
||||
stateReward: Option[UInt256],
|
||||
|
@ -284,7 +281,7 @@ proc exec(ctx: var TransContext,
|
|||
|
||||
if ctx.env.withdrawals.isSome:
|
||||
for withdrawal in ctx.env.withdrawals.get:
|
||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.amount.gwei)
|
||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
|
||||
|
||||
let miner = ctx.env.currentCoinbase
|
||||
let fork = vmState.com.toEVMFork
|
||||
|
|
Loading…
Reference in New Issue