diff --git a/beacon_chain/el/deposit_contract.nim b/beacon_chain/el/deposit_contract.nim index 42c739bab..7f92ef769 100644 --- a/beacon_chain/el/deposit_contract.nim +++ b/beacon_chain/el/deposit_contract.nim @@ -14,7 +14,7 @@ import ../networking/network_metadata, web3, web3/confutils_defs, eth/keys, eth/p2p/discoveryv5/random2, stew/[io2, byteutils], - ../spec/eth2_merkleization, + ../spec/[eth2_merkleization, helpers], ../spec/datatypes/base, ../validators/keystore_management @@ -136,16 +136,13 @@ proc sendEth(web3: Web3, to: Eth1Address, valueEth: int): Future[TxHash] = `from`: web3.defaultAccount, gas: Quantity(3000000).some, gasPrice: Quantity(1).some, - value: some(valueEth.u256 * 1000000000000000000.u256), + value: some(valueEth.toWei), to: some(to)) web3.send(tr) type DelayGenerator* = proc(): chronos.Duration {.gcsafe, raises: [].} -proc ethToWei(eth: UInt256): UInt256 = - eth * 1000000000000000000.u256 - proc initWeb3(web3Url, privateKey: string): Future[Web3] {.async.} = result = await newWeb3(web3Url) if privateKey.len != 0: @@ -180,7 +177,7 @@ proc sendDeposits*(deposits: seq[LaunchPadDeposit], SignatureBytes(@(dp.signature.toRaw())), FixedBytes[32](hash_tree_root(dp).data)) - let status = await tx.send(value = 32.u256.ethToWei, gasPrice = gasPrice) + let status = await tx.send(value = 32.toWei, gasPrice = gasPrice) info "Deposit sent", tx = $status diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 425310648..a7780aa3c 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -523,3 +523,9 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader = proc compute_execution_block_hash*(blck: ForkyBeaconBlock): Eth2Digest = rlpHash blockToBlockHeader(blck) + +func toWei*(eth: SomeInteger): UInt256 = + eth.u256 * 1000000000000000000.u256 + +func toWei*(eth: UInt256): UInt256 = + eth * 1000000000000000000.u256 diff --git a/beacon_chain/validators/rewards.nim b/beacon_chain/validators/rewards.nim index eaf200077..2c76a566c 100644 --- a/beacon_chain/validators/rewards.nim +++ b/beacon_chain/validators/rewards.nim @@ -7,7 +7,7 @@ {.push raises: [].} -import ".."/spec/[forks, beaconstate, state_transition_block] +import ".."/spec/[forks, beaconstate, state_transition_block, helpers] type AuxiliaryState = object @@ -56,6 +56,8 @@ template withStateAndMaybeBlindedBlck( const consensusFork {.inject, used.} = ConsensusFork.Deneb template forkyState: untyped {.inject.} = s.denebData template forkyBlck: untyped {.inject.} = b + else: + {.error: "withStateAndMaybeBlindedBlock does not support " & $typeof(b).} func init(t: typedesc[AuxiliaryState], forkedState: ForkedHashedBeaconState): Opt[AuxiliaryState] = @@ -166,9 +168,6 @@ proc collectFromSyncAggregate( if aggregate.sync_committee_bits[i]: proposerOutcome += proposer_reward -proc gweiToWei(eth: Gwei): UInt256 = - eth.u256 * 1000000000000000000.u256 - proc collectBlockRewards*( forkedState: ForkedHashedBeaconState, forkedBlock: RewardingBlock @@ -184,4 +183,4 @@ proc collectBlockRewards*( reward.collectFromAttestations( forkedState, forkedBlock, auxiliaryState, cache) reward.collectFromSyncAggregate(forkedState, forkedBlock, cache) - ok(gweiToWei(reward)) + ok(reward.toWei) diff --git a/ncli/ncli_testnet.nim b/ncli/ncli_testnet.nim index 9f61a8412..5e79fac92 100644 --- a/ncli/ncli_testnet.nim +++ b/ncli/ncli_testnet.nim @@ -15,7 +15,7 @@ import ../beacon_chain/conf, ../beacon_chain/el/el_manager, ../beacon_chain/networking/eth2_network, - ../beacon_chain/spec/eth2_merkleization, + ../beacon_chain/spec/[eth2_merkleization, helpers], ../beacon_chain/spec/datatypes/base, ../beacon_chain/spec/eth2_apis/eth2_rest_serialization, ../beacon_chain/validators/keystore_management, @@ -518,16 +518,13 @@ proc sendEth(web3: Web3, to: Eth1Address, valueEth: int): Future[TxHash] = `from`: web3.defaultAccount, gas: Quantity(3000000).some, gasPrice: Quantity(1).some, - value: some(valueEth.u256 * 1000000000000000000.u256), + value: some(valueEth.toWei), to: some(to)) web3.send(tr) type DelayGenerator = proc(): chronos.Duration {.gcsafe, raises: [].} -func ethToWei(eth: UInt256): UInt256 = - eth * 1000000000000000000.u256 - proc initWeb3(web3Url, privateKey: string): Future[Web3] {.async.} = result = await newWeb3(web3Url) if privateKey.len != 0: @@ -562,7 +559,7 @@ proc sendDeposits(deposits: seq[LaunchPadDeposit], SignatureBytes(@(dp.signature.toRaw())), FixedBytes[32](hash_tree_root(dp).data)) - let status = await tx.send(value = 32.u256.ethToWei, gasPrice = gasPrice) + let status = await tx.send(value = 32.toWei, gasPrice = gasPrice) info "Deposit sent", tx = $status