Make a call to eth.get_block after establishing an EthereumClient with middlewares to ensure that poa middleware, if needed, works correctly.

v7.4.1-hotfix^2
derekpierre 2024-08-28 20:00:53 -04:00
parent eb7ecc844d
commit 43e0dcb941
No known key found for this signature in database
3 changed files with 12 additions and 11 deletions

View File

@ -13,7 +13,6 @@ from web3.types import TxReceipt, Wei
from nucypher.blockchain.eth.constants import (
AVERAGE_BLOCK_TIME_IN_SECONDS,
POA_CHAINS,
PUBLIC_CHAINS,
)
from nucypher.blockchain.middleware.poa import create_poa_error_redundancy_middleware
@ -94,14 +93,6 @@ class EthereumClient:
self.log.debug("Adding RPC retry middleware to client")
self.add_middleware(RetryRequestMiddleware, name="retry")
# poa middleware
chain_id = self.chain_id
is_poa = chain_id in POA_CHAINS
self.log.info(
f"Blockchain: {self.chain_name} (chain_id={chain_id}, poa={is_poa})"
)
# add POA middleware irrespective of chain
poa_middleware_name = "poa"
self.log.info("Injecting POA middleware at layer 0")

View File

@ -331,6 +331,13 @@ class BlockchainInterface:
# client mutates w3 instance (configures middleware etc.)
self.client = EthereumClient(w3=self.w3)
# log info
latest_block_number = self.client.get_block("latest")["number"]
chain_id = self.client.chain_id
self.log.info(
f"Blockchain: {self.client.chain_name} (chain_id={chain_id}, block_num={latest_block_number})"
)
# web3 instance fully configured; share instance with ATxM and respective strategies
speedup_strategy = ExponentialSpeedupStrategy(
w3=self.w3,

View File

@ -51,9 +51,12 @@ class SyncedMockW3Eth:
chain_id = hex(CHAIN_ID)
block_number = 5
def getBlock(self, blockNumber):
def get_block(self, blockNumber):
return {
'timestamp': datetime.datetime.timestamp(datetime.datetime.now() - datetime.timedelta(seconds=25))
"timestamp": datetime.datetime.timestamp(
datetime.datetime.now() - datetime.timedelta(seconds=25)
),
"number": 123456789,
}