This commit is contained in:
pgherveou
2025-10-08 06:28:57 +00:00
parent 765569a8b6
commit 1f84ce6f61
34 changed files with 1093 additions and 503 deletions
+66 -23
View File
@@ -108,7 +108,9 @@ impl GethNode {
let wallet_configuration = AsRef::<WalletConfiguration>::as_ref(&context);
let geth_configuration = AsRef::<GethConfiguration>::as_ref(&context);
let geth_directory = working_directory_configuration.as_path().join(Self::BASE_DIRECTORY);
let geth_directory = working_directory_configuration
.as_path()
.join(Self::BASE_DIRECTORY);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = geth_directory.join(id.to_string());
@@ -196,7 +198,11 @@ impl GethNode {
.read_to_string(&mut stderr)
.context("Failed to read geth --init stderr")?;
if !child.wait().context("Failed waiting for geth --init process to finish")?.success() {
if !child
.wait()
.context("Failed waiting for geth --init process to finish")?
.success()
{
anyhow::bail!("failed to initialize geth node #{:?}: {stderr}", &self.id);
}
@@ -256,7 +262,8 @@ impl GethNode {
Ok(process) => self.handle = Some(process),
Err(err) => {
error!(?err, "Failed to start geth, shutting down gracefully");
self.shutdown().context("Failed to gracefully shutdown after geth start error")?;
self.shutdown()
.context("Failed to gracefully shutdown after geth start error")?;
return Err(err);
}
}
@@ -401,7 +408,10 @@ impl EthereumNode for GethNode {
}
},
)
.instrument(tracing::info_span!("Awaiting transaction receipt", ?transaction_hash))
.instrument(tracing::info_span!(
"Awaiting transaction receipt",
?transaction_hash
))
.await
})
}
@@ -413,8 +423,10 @@ impl EthereumNode for GethNode {
trace_options: GethDebugTracingOptions,
) -> Pin<Box<dyn Future<Output = anyhow::Result<GethTrace>> + '_>> {
Box::pin(async move {
let provider =
self.provider().await.context("Failed to create provider for tracing")?;
let provider = self
.provider()
.await
.context("Failed to create provider for tracing")?;
poll(
Self::TRACE_POLLING_DURATION,
PollingWaitBehavior::Constant(Duration::from_millis(200)),
@@ -422,7 +434,10 @@ impl EthereumNode for GethNode {
let provider = provider.clone();
let trace_options = trace_options.clone();
async move {
match provider.debug_trace_transaction(tx_hash, trace_options).await {
match provider
.debug_trace_transaction(tx_hash, trace_options)
.await
{
Ok(trace) => Ok(ControlFlow::Break(trace)),
Err(error) => {
let error_string = error.to_string();
@@ -502,10 +517,7 @@ impl EthereumNode for GethNode {
Box::pin(async move {
let id = self.id;
let provider = self.provider().await?;
Ok(Arc::new(GethNodeResolver {
id,
provider,
}) as Arc<dyn ResolverApi>)
Ok(Arc::new(GethNodeResolver { id, provider }) as Arc<dyn ResolverApi>)
})
}
@@ -648,7 +660,10 @@ impl ResolverApi for GethNodeResolver {
.context("Failed to get the geth block")?
.context("Failed to get the Geth block, perhaps there are no blocks?")
.and_then(|block| {
block.header.base_fee_per_gas.context("Failed to get the base fee per gas")
block
.header
.base_fee_per_gas
.context("Failed to get the base fee per gas")
})
})
}
@@ -765,7 +780,11 @@ mod tests {
// Arrange
let (context, node) = shared_state();
let account_address = context.wallet_configuration.wallet().default_signer().address();
let account_address = context
.wallet_configuration
.wallet()
.default_signer()
.address();
let transaction = TransactionRequest::default()
.to(account_address)
.value(U256::from(100_000_000_000_000u128));
@@ -788,7 +807,10 @@ mod tests {
// Assert
let version = version.expect("Failed to get the version");
assert!(version.starts_with("geth version"), "expected version string, got: '{version}'");
assert!(
version.starts_with("geth version"),
"expected version string, got: '{version}'"
);
}
#[tokio::test]
@@ -812,8 +834,12 @@ mod tests {
let node = shared_node();
// Act
let gas_limit =
node.resolver().await.unwrap().block_gas_limit(BlockNumberOrTag::Latest).await;
let gas_limit = node
.resolver()
.await
.unwrap()
.block_gas_limit(BlockNumberOrTag::Latest)
.await;
// Assert
let _ = gas_limit.expect("Failed to get the gas limit");
@@ -826,8 +852,12 @@ mod tests {
let node = shared_node();
// Act
let coinbase =
node.resolver().await.unwrap().block_coinbase(BlockNumberOrTag::Latest).await;
let coinbase = node
.resolver()
.await
.unwrap()
.block_coinbase(BlockNumberOrTag::Latest)
.await;
// Assert
let _ = coinbase.expect("Failed to get the coinbase");
@@ -840,8 +870,12 @@ mod tests {
let node = shared_node();
// Act
let block_difficulty =
node.resolver().await.unwrap().block_difficulty(BlockNumberOrTag::Latest).await;
let block_difficulty = node
.resolver()
.await
.unwrap()
.block_difficulty(BlockNumberOrTag::Latest)
.await;
// Assert
let _ = block_difficulty.expect("Failed to get the block difficulty");
@@ -854,7 +888,12 @@ mod tests {
let node = shared_node();
// Act
let block_hash = node.resolver().await.unwrap().block_hash(BlockNumberOrTag::Latest).await;
let block_hash = node
.resolver()
.await
.unwrap()
.block_hash(BlockNumberOrTag::Latest)
.await;
// Assert
let _ = block_hash.expect("Failed to get the block hash");
@@ -867,8 +906,12 @@ mod tests {
let node = shared_node();
// Act
let block_timestamp =
node.resolver().await.unwrap().block_timestamp(BlockNumberOrTag::Latest).await;
let block_timestamp = node
.resolver()
.await
.unwrap()
.block_timestamp(BlockNumberOrTag::Latest)
.await;
// Assert
let _ = block_timestamp.expect("Failed to get the block timestamp");