bump `nim-web3` to `80c7aa6de2a26c57fa1f06ad47f3ac6058e6545b` (#6088)

- Add writeValue for BlockNumber
- make `BlockNumber` `distinct`
This commit is contained in:
Etan Kissling 2024-03-19 14:21:47 +01:00 committed by GitHub
parent 595d110b37
commit 1dd2c939ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 19 deletions

View File

@ -356,9 +356,6 @@ func isSynced*(m: ELManager): bool =
template eth1ChainBlocks*(m: ELManager): Deque[Eth1Block] = template eth1ChainBlocks*(m: ELManager): Deque[Eth1Block] =
m.eth1Chain.blocks m.eth1Chain.blocks
template toGaugeValue(x: Quantity): int64 =
toGaugeValue(distinctBase x)
# TODO: Add cfg validation # TODO: Add cfg validation
# MIN_GENESIS_ACTIVE_VALIDATOR_COUNT should be larger than SLOTS_PER_EPOCH # MIN_GENESIS_ACTIVE_VALIDATOR_COUNT should be larger than SLOTS_PER_EPOCH
# doAssert SECONDS_PER_ETH1_BLOCK * cfg.ETH1_FOLLOW_DISTANCE < GENESIS_DELAY, # doAssert SECONDS_PER_ETH1_BLOCK * cfg.ETH1_FOLLOW_DISTANCE < GENESIS_DELAY,
@ -1514,10 +1511,10 @@ func earliestBlockOfInterest(
(2 * m.cfg.ETH1_FOLLOW_DISTANCE) + (2 * m.cfg.ETH1_FOLLOW_DISTANCE) +
votedBlocksSafetyMargin votedBlocksSafetyMargin
if latestEth1BlockNumber > blocksOfInterestRange: if latestEth1BlockNumber > blocksOfInterestRange.Eth1BlockNumber:
latestEth1BlockNumber - blocksOfInterestRange latestEth1BlockNumber - blocksOfInterestRange
else: else:
0 0.Eth1BlockNumber
proc syncBlockRange(m: ELManager, proc syncBlockRange(m: ELManager,
connection: ELConnection, connection: ELConnection,
@ -1744,13 +1741,13 @@ proc syncEth1Chain(m: ELManager, connection: ELConnection) {.async.} =
except CatchableError as err: except CatchableError as err:
warn "Failed to obtain the latest block from the EL", err = err.msg warn "Failed to obtain the latest block from the EL", err = err.msg
raise err raise err
latestBlockNumber = Eth1BlockNumber(latestBlock.number) latestBlockNumber = latestBlock.number
m.syncTargetBlock = some( m.syncTargetBlock = some(
if Eth1BlockNumber(latestBlock.number) > m.cfg.ETH1_FOLLOW_DISTANCE: if latestBlock.number > m.cfg.ETH1_FOLLOW_DISTANCE.Eth1BlockNumber:
Eth1BlockNumber(latestBlock.number) - m.cfg.ETH1_FOLLOW_DISTANCE latestBlock.number - m.cfg.ETH1_FOLLOW_DISTANCE
else: else:
Eth1BlockNumber(0)) 0.Eth1BlockNumber)
if m.syncTargetBlock.get <= eth1SyncedTo: if m.syncTargetBlock.get <= eth1SyncedTo:
# The chain reorged to a lower height. # The chain reorged to a lower height.
# It's relatively safe to ignore that. # It's relatively safe to ignore that.
@ -1766,7 +1763,7 @@ proc syncEth1Chain(m: ELManager, connection: ELConnection) {.async.} =
depositContract, depositContract,
eth1SyncedTo + 1, eth1SyncedTo + 1,
m.syncTargetBlock.get, m.syncTargetBlock.get,
m.earliestBlockOfInterest(Eth1BlockNumber latestBlock.number)) m.earliestBlockOfInterest(latestBlock.number))
eth1SyncedTo = m.syncTargetBlock.get eth1SyncedTo = m.syncTargetBlock.get
eth1_synced_head.set eth1SyncedTo.toGaugeValue eth1_synced_head.set eth1SyncedTo.toGaugeValue
@ -1858,4 +1855,4 @@ proc testWeb3Provider*(web3Url: Uri,
ns = web3.contractSender(DepositContract, depositContractAddress) ns = web3.contractSender(DepositContract, depositContractAddress)
discard request "Deposit root": discard request "Deposit root":
ns.get_deposit_root.call(blockNumber = latestBlock.number.uint64) ns.get_deposit_root.call(blockNumber = latestBlock.number)

View File

@ -13,7 +13,7 @@ import
../beacon_chain_db, ../beacon_chain_db,
../spec/[deposit_snapshots, digest, eth2_merkleization, forks, network], ../spec/[deposit_snapshots, digest, eth2_merkleization, forks, network],
../spec/datatypes/base, ../spec/datatypes/base,
web3/[primitives, eth_api_types], web3/[conversions, eth_api_types],
./merkle_minimal ./merkle_minimal
export beacon_chain_db, deques, digest, base, forks export beacon_chain_db, deques, digest, base, forks
@ -30,8 +30,11 @@ declarePublicGauge eth1_finalized_deposits,
declareGauge eth1_chain_len, declareGauge eth1_chain_len,
"The length of the in-memory chain of Eth1 blocks" "The length of the in-memory chain of Eth1 blocks"
template toGaugeValue*(x: Quantity | BlockNumber): int64 =
toGaugeValue(distinctBase x)
type type
Eth1BlockNumber* = uint64 Eth1BlockNumber* = BlockNumber
Eth1BlockTimestamp* = uint64 Eth1BlockTimestamp* = uint64
Eth1BlockObj* = object Eth1BlockObj* = object
@ -169,7 +172,7 @@ proc pruneOldBlocks(chain: var Eth1Chain, depositIndex: uint64) =
chain.db.putDepositContractSnapshot DepositContractSnapshot( chain.db.putDepositContractSnapshot DepositContractSnapshot(
eth1Block: lastBlock.hash, eth1Block: lastBlock.hash,
depositContractState: chain.finalizedDepositsMerkleizer.toDepositContractState, depositContractState: chain.finalizedDepositsMerkleizer.toDepositContractState,
blockHeight: lastBlock.number) blockHeight: distinctBase(lastBlock.number))
eth1_finalized_head.set lastBlock.number.toGaugeValue eth1_finalized_head.set lastBlock.number.toGaugeValue
eth1_finalized_deposits.set lastBlock.depositCount.toGaugeValue eth1_finalized_deposits.set lastBlock.depositCount.toGaugeValue

View File

@ -29,8 +29,8 @@ export
json_serialization, net, sets, rest_types, slashing_protection_common, json_serialization, net, sets, rest_types, slashing_protection_common,
jsonSerializationResults, rest_keymanager_types jsonSerializationResults, rest_keymanager_types
from web3/primitives import BlockHash from web3/primitives import BlockHash, BlockNumber
export primitives.BlockHash export primitives.BlockHash, primitives.BlockNumber
func decodeMediaType*( func decodeMediaType*(
contentType: Opt[ContentTypeData]): Result[MediaType, string] = contentType: Opt[ContentTypeData]): Result[MediaType, string] =
@ -959,6 +959,16 @@ proc readValue*(reader: var JsonReader[RestJson], value: var uint8) {.
else: else:
reader.raiseUnexpectedValue($res.error() & ": " & svalue) reader.raiseUnexpectedValue($res.error() & ": " & svalue)
## BlockNumber
proc writeValue*(
w: var JsonWriter[RestJson], value: BlockNumber) {.raises: [IOError].} =
w.writeValue(distinctBase(value))
proc readValue*(
reader: var JsonReader[RestJson],
value: var BlockNumber) {.raises: [IOError, SerializationError].} =
reader.readValue(distinctBase(value))
## RestNumeric ## RestNumeric
proc writeValue*(w: var JsonWriter[RestJson], proc writeValue*(w: var JsonWriter[RestJson],
value: RestNumeric) {.raises: [IOError].} = value: RestNumeric) {.raises: [IOError].} =

View File

@ -81,7 +81,7 @@ proc setupEngineAPI*(server: RpcServer) =
info "eth_getBlockByNumber", quantityTag, fullTransactions info "eth_getBlockByNumber", quantityTag, fullTransactions
return if quantityTag == "latest": return if quantityTag == "latest":
JrpcConv.encode(BlockObject(number: 1000.Quantity)).JsonString JrpcConv.encode(BlockObject(number: 1000.BlockNumber)).JsonString
else: else:
"{}".JsonString "{}".JsonString
@ -89,7 +89,7 @@ proc setupEngineAPI*(server: RpcServer) =
data: string, fullTransactions: bool) -> BlockObject: data: string, fullTransactions: bool) -> BlockObject:
info "eth_getBlockByHash", data = toHex(data), fullTransactions info "eth_getBlockByHash", data = toHex(data), fullTransactions
return BlockObject(number: 1000.Quantity) return BlockObject(number: 1000.BlockNumber)
server.rpc("eth_chainId") do() -> Quantity: server.rpc("eth_chainId") do() -> Quantity:
info "eth_chainId" info "eth_chainId"

2
vendor/nim-web3 vendored

@ -1 +1 @@
Subproject commit 747001250a27278e0f0f1706fe1dec88ad3ede8d Subproject commit 80c7aa6de2a26c57fa1f06ad47f3ac6058e6545b