From 3f37caa0da2b8e617d07b9ad66cb7cc8152b110a Mon Sep 17 00:00:00 2001 From: Miran Date: Tue, 8 Oct 2024 03:54:02 +0200 Subject: [PATCH] fix deprecated warnings (#6606) --- beacon_chain/el/deposit_contract.nim | 2 +- beacon_chain/el/engine_api_conversions.nim | 20 +++++++++---------- beacon_chain/el/eth1_chain.nim | 2 +- beacon_chain/networking/network_metadata.nim | 2 +- .../eth2_apis/eth2_rest_serialization.nim | 18 ++++++++--------- beacon_chain/spec/helpers.nim | 8 ++++---- beacon_chain/spec/presets.nim | 8 ++++---- research/fakeee.nim | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/beacon_chain/el/deposit_contract.nim b/beacon_chain/el/deposit_contract.nim index 1dcdfccef..6aa87a3c1 100644 --- a/beacon_chain/el/deposit_contract.nim +++ b/beacon_chain/el/deposit_contract.nim @@ -12,7 +12,7 @@ import chronos, chronicles, confutils, stint, json_serialization, ../filepath, ../networking/network_metadata, - web3, web3/confutils_defs, eth/keys, eth/p2p/discoveryv5/random2, + web3, web3/confutils_defs, eth/common/keys, eth/p2p/discoveryv5/random2, stew/[io2, byteutils], ../spec/eth2_merkleization, ../spec/datatypes/base, diff --git a/beacon_chain/el/engine_api_conversions.nim b/beacon_chain/el/engine_api_conversions.nim index 6c1032c0b..f6972ec8c 100644 --- a/beacon_chain/el/engine_api_conversions.nim +++ b/beacon_chain/el/engine_api_conversions.nim @@ -56,7 +56,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV1): gas_limit: rpcExecutionPayload.gasLimit.uint64, gas_used: rpcExecutionPayload.gasUsed.uint64, timestamp: rpcExecutionPayload.timestamp.uint64, - extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.bytes), + extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.data), base_fee_per_gas: rpcExecutionPayload.baseFeePerGas, block_hash: rpcExecutionPayload.blockHash.asEth2Digest, transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init( @@ -88,7 +88,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV1OrV2|ExecutionPaylo gas_limit: rpcExecutionPayload.gasLimit.uint64, gas_used: rpcExecutionPayload.gasUsed.uint64, timestamp: rpcExecutionPayload.timestamp.uint64, - extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.bytes), + extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.data), base_fee_per_gas: rpcExecutionPayload.baseFeePerGas, block_hash: rpcExecutionPayload.blockHash.asEth2Digest, transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init( @@ -119,7 +119,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV3): gas_limit: rpcExecutionPayload.gasLimit.uint64, gas_used: rpcExecutionPayload.gasUsed.uint64, timestamp: rpcExecutionPayload.timestamp.uint64, - extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.bytes), + extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.data), base_fee_per_gas: rpcExecutionPayload.baseFeePerGas, block_hash: rpcExecutionPayload.blockHash.asEth2Digest, transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init( @@ -141,12 +141,12 @@ func asConsensusType*(payload: engine_api.GetPayloadV3Response): blobsBundle: deneb.BlobsBundle( commitments: KzgCommitments.init( payload.blobsBundle.commitments.mapIt( - kzg_abi.KzgCommitment(bytes: it.bytes))), + kzg_abi.KzgCommitment(bytes: it.data))), proofs: KzgProofs.init( payload.blobsBundle.proofs.mapIt( - kzg_abi.KzgProof(bytes: it.bytes))), + kzg_abi.KzgProof(bytes: it.data))), blobs: Blobs.init( - payload.blobsBundle.blobs.mapIt(it.bytes)))) + payload.blobsBundle.blobs.mapIt(it.data)))) func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4): electra.ExecutionPayload = @@ -189,7 +189,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4): gas_used: rpcExecutionPayload.gasUsed.uint64, timestamp: rpcExecutionPayload.timestamp.uint64, extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init( - rpcExecutionPayload.extraData.bytes), + rpcExecutionPayload.extraData.data), base_fee_per_gas: rpcExecutionPayload.baseFeePerGas, block_hash: rpcExecutionPayload.blockHash.asEth2Digest, transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init( @@ -211,12 +211,12 @@ func asConsensusType*(payload: engine_api.GetPayloadV4Response): blobsBundle: deneb.BlobsBundle( commitments: KzgCommitments.init( payload.blobsBundle.commitments.mapIt( - kzg_abi.KzgCommitment(bytes: it.bytes))), + kzg_abi.KzgCommitment(bytes: it.data))), proofs: KzgProofs.init( payload.blobsBundle.proofs.mapIt( - kzg_abi.KzgProof(bytes: it.bytes))), + kzg_abi.KzgProof(bytes: it.data))), blobs: Blobs.init( - payload.blobsBundle.blobs.mapIt(it.bytes)))) + payload.blobsBundle.blobs.mapIt(it.data)))) func asEngineExecutionPayload*(blockBody: bellatrix.BeaconBlockBody): ExecutionPayloadV1 = diff --git a/beacon_chain/el/eth1_chain.nim b/beacon_chain/el/eth1_chain.nim index 7b05c92ab..6d9b668b1 100644 --- a/beacon_chain/el/eth1_chain.nim +++ b/beacon_chain/el/eth1_chain.nim @@ -36,7 +36,7 @@ template toGaugeValue*(x: Quantity | BlockNumber): int64 = toGaugeValue(distinctBase x) type - Eth1BlockNumber* = BlockNumber + Eth1BlockNumber* = Quantity Eth1BlockTimestamp* = uint64 Eth1BlockObj* = object diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index b6aa6c6f0..86649b018 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -43,7 +43,7 @@ const incbinEnabled* = sizeof(pointer) == 8 type - Eth1BlockHash* = web3types.BlockHash + Eth1BlockHash* = web3types.Hash32 Eth1Network* = enum mainnet diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index eacc1fcde..38dd3f8eb 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -25,8 +25,8 @@ export json_serialization, net, sets, rest_types, slashing_protection_common, jsonSerializationResults, rest_keymanager_types -from web3/primitives import BlockHash, BlockNumber -export primitives.BlockHash, primitives.BlockNumber +from web3/primitives import Hash32, Quantity +export primitives.Hash32, primitives.Quantity func decodeMediaType*( contentType: Opt[ContentTypeData]): Result[MediaType, string] = @@ -995,14 +995,14 @@ proc readValue*(reader: var JsonReader[RestJson], value: var uint8) {. else: reader.raiseUnexpectedValue($res.error() & ": " & svalue) -## BlockNumber +## BlockNumber/Quantity proc writeValue*( - w: var JsonWriter[RestJson], value: BlockNumber) {.raises: [IOError].} = + w: var JsonWriter[RestJson], value: Quantity) {.raises: [IOError].} = w.writeValue(distinctBase(value)) proc readValue*( reader: var JsonReader[RestJson], - value: var BlockNumber) {.raises: [IOError, SerializationError].} = + value: var Quantity) {.raises: [IOError, SerializationError].} = reader.readValue(distinctBase(value)) ## RestNumeric @@ -1272,17 +1272,17 @@ proc writeValue*( writer: var JsonWriter[RestJson], value: BitArray) {.raises: [IOError].} = writeValue(writer, hexOriginal(value.bytes)) -## BlockHash -proc readValue*(reader: var JsonReader[RestJson], value: var BlockHash) {. +## BlockHash/Hash32 +proc readValue*(reader: var JsonReader[RestJson], value: var Hash32) {. raises: [IOError, SerializationError].} = try: hexToByteArray(reader.readValue(string), distinctBase(value)) except ValueError: raiseUnexpectedValue(reader, - "BlockHash value should be a valid hex string") + "Hash32 value should be a valid hex string") proc writeValue*( - writer: var JsonWriter[RestJson], value: BlockHash) {.raises: [IOError].} = + writer: var JsonWriter[RestJson], value: Hash32) {.raises: [IOError].} = writeValue(writer, hexOriginal(distinctBase(value))) ## Eth2Digest diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 5748fef97..f33e86148 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -35,14 +35,14 @@ func toGwei*(eth: Ether): Gwei = distinctBase(eth) * ETH_TO_GWEI type - ExecutionHash256* = eth_types.Hash256 + ExecutionHash256* = eth_types.Hash32 ExecutionTransaction* = eth_types.Transaction ExecutionReceipt* = eth_types.Receipt ExecutionWithdrawal* = eth_types.Withdrawal ExecutionDepositRequest* = eth_types.DepositRequest ExecutionWithdrawalRequest* = eth_types.WithdrawalRequest ExecutionConsolidationRequest* = eth_types.ConsolidationRequest - ExecutionBlockHeader* = eth_types.BlockHeader + ExecutionBlockHeader* = eth_types.Header FinalityCheckpoints* = object justified*: Checkpoint @@ -592,7 +592,7 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader = stateRoot : payload.state_root.to(Root), transactionsRoot : txRoot, receiptsRoot : payload.receipts_root.to(Root), - logsBloom : BloomFilter payload.logs_bloom.data.to(Bloom), + logsBloom : Bloom payload.logs_bloom.data.to(Bloom), difficulty : default(DifficultyInt), number : payload.block_number, gasLimit : payload.gas_limit, @@ -600,7 +600,7 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader = timestamp : EthTime(payload.timestamp), extraData : payload.extra_data.asSeq, mixHash : Bytes32 payload.prev_randao.data, # EIP-4399 `mixHash` -> `prevRandao` - nonce : default(BlockNonce), + nonce : default(Bytes8), baseFeePerGas : Opt.some payload.base_fee_per_gas, withdrawalsRoot : withdrawalsRoot, blobGasUsed : blobGasUsed, # EIP-4844 diff --git a/beacon_chain/spec/presets.nim b/beacon_chain/spec/presets.nim index 7b5dfa35e..364d7cfcd 100644 --- a/beacon_chain/spec/presets.nim +++ b/beacon_chain/spec/presets.nim @@ -42,7 +42,7 @@ type # Transition TERMINAL_TOTAL_DIFFICULTY*: UInt256 - TERMINAL_BLOCK_HASH*: BlockHash + TERMINAL_BLOCK_HASH*: Hash32 TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH*: Epoch # Not actively used, but part of the spec # Genesis @@ -164,7 +164,7 @@ when const_preset == "mainnet": TERMINAL_TOTAL_DIFFICULTY: u256"115792089237316195423570985008687907853269984665640564039457584007913129638912", # By default, don't use these params - TERMINAL_BLOCK_HASH: BlockHash.fromHex( + TERMINAL_BLOCK_HASH: Hash32.fromHex( "0x0000000000000000000000000000000000000000000000000000000000000000"), # Genesis @@ -643,8 +643,8 @@ template parse(T: type string, input: string): T = template parse(T: type Eth1Address, input: string): T = Eth1Address.fromHex(input) -template parse(T: type BlockHash, input: string): T = - BlockHash.fromHex(input) +template parse(T: type Hash32, input: string): T = + Hash32.fromHex(input) template parse(T: type UInt256, input: string): T = parse(input, UInt256, 10) diff --git a/research/fakeee.nim b/research/fakeee.nim index c88ecc02a..ab2cddab3 100644 --- a/research/fakeee.nim +++ b/research/fakeee.nim @@ -81,7 +81,7 @@ proc setupEngineAPI*(server: RpcServer) = info "eth_getBlockByNumber", quantityTag, fullTransactions return if quantityTag == "latest": - JrpcConv.encode(BlockObject(number: 1000.BlockNumber)).JsonString + JrpcConv.encode(BlockObject(number: 1000.Quantity)).JsonString else: "{}".JsonString @@ -89,7 +89,7 @@ proc setupEngineAPI*(server: RpcServer) = data: string, fullTransactions: bool) -> BlockObject: info "eth_getBlockByHash", data = toHex(data), fullTransactions - return BlockObject(number: 1000.BlockNumber) + return BlockObject(number: 1000.Quantity) server.rpc("eth_chainId") do() -> Quantity: info "eth_chainId"