Skip to content

Commit cc13df1

Browse files
authored
chore(rpc): re-optimize endpoints (#6)
* chore(rpc): re-optimize endpoints Seems this was not included when migrating out of the SDK. * chore(repo): clippy / fmt With the new edition/version bump there's a bunch of clippy / fmt changes to do.
1 parent 92628a9 commit cc13df1

File tree

20 files changed

+92
-87
lines changed

20 files changed

+92
-87
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.8.4"
7-
edition = "2021"
8-
rust-version = "1.82"
6+
version = "0.8.2"
7+
edition = "2024"
8+
rust-version = "1.88"
99
authors = ["init4"]
1010
license = "MIT OR Apache-2.0"
1111
homepage = "https://github.com/init4tech/signet-sdk"

crates/blobber/src/block_data.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::{
2-
error::UnrecoverableBlobError, shim::ExtractableChainShim, BlockExtractionError,
3-
BlockExtractorBuilder, ExtractionResult,
2+
BlockExtractionError, BlockExtractorBuilder, ExtractionResult, error::UnrecoverableBlobError,
3+
shim::ExtractableChainShim,
44
};
55
use alloy::{
66
consensus::{Blob, SidecarCoder, SimpleCoder},
77
eips::eip7594::BlobTransactionSidecarVariant,
8-
primitives::{keccak256, TxHash, B256},
8+
primitives::{B256, TxHash, keccak256},
99
};
1010
use init4_bin_base::utils::calc::SlotCalculator;
1111
use reth::{
@@ -334,15 +334,15 @@ mod tests {
334334
BlobTransactionSidecar, SidecarBuilder, SignableTransaction, TxEip2930, TxEnvelope,
335335
},
336336
eips::Encodable2718,
337-
primitives::{bytes, Address, TxKind, U256},
337+
primitives::{Address, TxKind, U256, bytes},
338338
rlp::encode,
339-
signers::{local::PrivateKeySigner, SignerSync},
339+
signers::{SignerSync, local::PrivateKeySigner},
340340
};
341341
use foundry_blob_explorers::TransactionDetails;
342342
use reth::primitives::{Transaction, TransactionSigned};
343343
use reth_transaction_pool::{
344-
test_utils::{testing_pool, MockTransaction},
345344
PoolTransaction, TransactionOrigin,
345+
test_utils::{MockTransaction, testing_pool},
346346
};
347347
use signet_types::constants::SignetSystemConstants;
348348

crates/blobber/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{block_data::BlockExtractor, BlockExtractorConfig};
1+
use crate::{BlockExtractorConfig, block_data::BlockExtractor};
22
use init4_bin_base::utils::calc::SlotCalculator;
33
use reth::transaction_pool::TransactionPool;
44
use url::Url;

crates/db/src/provider.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::{
2+
DataCompat, DbZenithHeader, RuChain, ZenithHeaders,
23
tables::{DbSignetEvent, JournalHashes, SignetEvents},
34
traits::RuWriter,
4-
DataCompat, DbZenithHeader, RuChain, ZenithHeaders,
55
};
66
use alloy::{
77
consensus::{BlockHeader, TxReceipt},
8-
primitives::{map::HashSet, Address, BlockNumber, B256, U256},
8+
primitives::{Address, B256, BlockNumber, U256, map::HashSet},
99
};
1010
use reth::{
1111
primitives::{Account, StaticFileSegment},
@@ -17,13 +17,13 @@ use reth::{
1717
},
1818
};
1919
use reth_db::{
20+
PlainAccountState,
2021
cursor::{DbCursorRO, DbCursorRW},
2122
models::{BlockNumberAddress, StoredBlockBodyIndices},
2223
tables,
2324
transaction::{DbTx, DbTxMut},
24-
PlainAccountState,
2525
};
26-
use reth_prune_types::{PruneMode, MINIMUM_PRUNING_DISTANCE};
26+
use reth_prune_types::{MINIMUM_PRUNING_DISTANCE, PruneMode};
2727
use signet_evm::BlockResult;
2828
use signet_node_types::{NodeTypesDbTrait, SignetNodeTypes};
2929
use signet_types::primitives::RecoveredBlock;

crates/db/src/tables.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use alloy::{
2-
primitives::{bytes::BufMut, Address, BlockNumber, Bytes, B256, U256},
2+
primitives::{Address, B256, BlockNumber, Bytes, U256, bytes::BufMut},
33
rlp::Buf,
44
};
55
use reth_db::{
6+
DatabaseError,
67
table::{Compress, Decompress, DupSort, Table},
7-
tables, DatabaseError,
8+
tables,
89
};
910
use signet_zenith::{
1011
Passage::{Enter, EnterToken},

crates/db/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{DbExtractionResults, DbSignetEvent, RuChain};
2-
use alloy::primitives::{Address, BlockNumber, B256, U256};
2+
use alloy::primitives::{Address, B256, BlockNumber, U256};
33
use itertools::Itertools;
44
use reth::{
55
primitives::Account,

crates/rpc/examples/filler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use alloy::{
33
network::{Ethereum, EthereumWallet, TransactionBuilder},
44
primitives::Bytes,
55
providers::{
6+
Identity, Provider as _, RootProvider, SendableTx,
67
fillers::{
78
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller,
89
WalletFiller,
910
},
10-
Identity, Provider as _, RootProvider, SendableTx,
1111
},
12-
rpc::types::{mev::EthSendBundle, TransactionRequest},
12+
rpc::types::{TransactionRequest, mev::EthSendBundle},
1313
signers::Signer,
1414
};
15-
use eyre::{eyre, Error};
15+
use eyre::{Error, eyre};
1616
use signet_bundle::SignetEthBundle;
1717
use signet_constants::SignetConstants;
1818
use signet_tx_cache::{client::TxCache, types::TxCacheSendBundleResponse};

crates/rpc/examples/order.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use alloy::{
22
consensus::constants::GWEI_TO_WEI,
3-
primitives::{uint, U256},
3+
primitives::{U256, uint},
44
signers::Signer,
55
};
66
use chrono::Utc;
77
use eyre::Error;
8-
use signet_constants::{SignetConstants, NATIVE_TOKEN_ADDRESS};
8+
use signet_constants::{NATIVE_TOKEN_ADDRESS, SignetConstants};
99
use signet_tx_cache::client::TxCache;
1010
use signet_types::UnsignedOrder;
1111
use signet_zenith::RollupOrders::{Input, Order, Output};

crates/rpc/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ajj::{pubsub::ServerShutdown, Router};
1+
use ajj::{Router, pubsub::ServerShutdown};
22
use reth::{args::RpcServerArgs, tasks::TaskExecutor};
33
use std::net::SocketAddr;
44
use tokio::task::JoinHandle;

crates/rpc/src/ctx.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
2+
Pnt,
23
eth::EthError,
34
interest::{ActiveFilter, FilterManager, FilterOutput, SubscriptionManager},
45
receipts::build_signet_receipt,
56
util::BlockRangeInclusiveIter,
6-
Pnt,
77
};
88
use alloy::{
99
consensus::{BlockHeader, Header, Signed, Transaction, TxEnvelope},
@@ -16,21 +16,21 @@ use reth::{
1616
core::primitives::SignerRecoverable,
1717
primitives::{Block, EthPrimitives, Receipt, Recovered, RecoveredBlock, TransactionSigned},
1818
providers::{
19-
providers::{BlockchainProvider, ProviderNodeTypes},
2019
BlockHashReader, BlockIdReader, BlockNumReader, CanonStateSubscriptions, HeaderProvider,
2120
ProviderBlock, ProviderError, ProviderReceipt, ReceiptProvider, StateProviderFactory,
2221
TransactionsProvider,
22+
providers::{BlockchainProvider, ProviderNodeTypes},
2323
},
2424
revm::{database::StateProviderDatabase, primitives::hardfork::SpecId},
2525
rpc::{
2626
eth::{filter::EthFilterError, helpers::types::EthRpcConverter},
2727
server_types::eth::{
28+
EthApiError, EthConfig, EthStateCache, FeeHistoryCache, FeeHistoryEntry,
29+
GasPriceOracle,
2830
fee_history::{
2931
calculate_reward_percentiles_for_block, fee_history_cache_new_blocks_task,
3032
},
31-
logs_utils::{self, append_matching_block_logs, ProviderOrBlock},
32-
EthApiError, EthConfig, EthStateCache, FeeHistoryCache, FeeHistoryEntry,
33-
GasPriceOracle,
33+
logs_utils::{self, ProviderOrBlock, append_matching_block_logs},
3434
},
3535
types::{FilterBlockOption, FilteredParams},
3636
},
@@ -41,12 +41,12 @@ use reth_node_api::{BlockBody, FullNodeComponents};
4141
use reth_rpc_eth_api::{RpcBlock, RpcConvert, RpcReceipt, RpcTransaction};
4242
use signet_evm::EvmNeedsTx;
4343
use signet_tx_cache::client::TxCache;
44-
use signet_types::{constants::SignetSystemConstants, MagicSig};
44+
use signet_types::{MagicSig, constants::SignetSystemConstants};
4545
use std::{marker::PhantomData, sync::Arc};
46-
use tracing::{instrument, trace, Level};
46+
use tracing::{Level, instrument, trace};
4747
use trevm::{
48-
revm::{context::CfgEnv, database::StateBuilder},
4948
Cfg,
49+
revm::{context::CfgEnv, database::StateBuilder},
5050
};
5151

5252
/// Type alias for EVMs using a [`StateProviderBox`] as the `DB` type for
@@ -312,6 +312,20 @@ where
312312
Ok(builder.build())
313313
}
314314

315+
/// Get the [`Header`] for a given block.
316+
pub async fn raw_header(
317+
&self,
318+
t: impl Into<BlockId>,
319+
) -> Result<Option<(B256, Header)>, EthApiError> {
320+
let Some(hash) = self.provider.block_hash_for_id(t.into())? else {
321+
return Ok(None);
322+
};
323+
324+
let header = self.cache.get_header(hash).await.map_err(EthApiError::from)?;
325+
326+
Ok(Some((hash, header)))
327+
}
328+
315329
/// Get the block for a given block, returning the block hash and
316330
/// the block itself.
317331
pub async fn raw_block(
@@ -513,20 +527,18 @@ where
513527
build_signet_receipt(tx, meta, receipt, all_receipts.to_vec()).map(Some)
514528
}
515529

516-
/// Create the [`Block`] object for a specific [`BlockId`].
530+
/// Create the [`Header`] object for a specific [`BlockId`].
517531
pub async fn block_cfg(&self, mut block_id: BlockId) -> Result<Header, EthApiError> {
518532
// If the block is pending, we'll load the latest and
519533
let pending = block_id.is_pending();
520534
if pending {
521535
block_id = BlockId::latest();
522536
}
523537

524-
let Some((_, block)) = self.raw_block(block_id).await? else {
538+
let Some((_, mut header)) = self.raw_header(block_id).await? else {
525539
return Err(EthApiError::HeaderNotFound(block_id));
526540
};
527541

528-
let mut header = block.clone_header();
529-
530542
// Modify the header for pending blocks, to simulate the next block.
531543
if pending {
532544
header.parent_hash = header.hash_slow();

0 commit comments

Comments
 (0)