Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions chain/ethereum/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ use graph::{
blockchain::{
self, Block as BlockchainBlock, BlockPtr, BlockTime, ChainStoreBlock, ChainStoreData,
},
components::ethereum::{AnyBlock, AnyHeader, AnyRpcHeader, AnyRpcTransaction, AnyTxEnvelope},
components::ethereum::{
AnyBlock, AnyHeader, AnyRpcHeader, AnyTransactionReceiptBare, AnyTxEnvelope,
},
prelude::{
alloy::{
self,
consensus::{ReceiptWithBloom, TxEnvelope, TxType},
network::AnyReceiptEnvelope,
primitives::{aliases::B2048, Address, Bloom, Bytes, LogData, B256, U256},
rpc::types::{self as alloy_rpc_types, AccessList, AccessListItem, Transaction},
serde::WithOtherFields,
},
BlockNumber, Error, EthereumBlock, EthereumBlockWithCalls, EthereumCall,
LightEthereumBlock,
Expand Down Expand Up @@ -556,19 +557,12 @@ impl TryInto<AnyBlock> for &Block {

let any_header: AnyRpcHeader = rpc_header.map(AnyHeader::from);

let any_transactions: Vec<AnyRpcTransaction> = transactions
.into_iter()
.map(|tx| AnyRpcTransaction::new(WithOtherFields::new(tx)))
.collect();

let any_block = Block {
Ok(Block {
header: any_header,
transactions: alloy::rpc::types::BlockTransactions::Full(any_transactions),
transactions: alloy::rpc::types::BlockTransactions::Full(transactions),
uncles,
withdrawals: None,
};

Ok(AnyBlock::new(WithOtherFields::new(any_block)))
})
}
}

Expand Down Expand Up @@ -619,7 +613,7 @@ impl TryInto<EthereumBlockWithCalls> for &Block {
fn transaction_trace_to_alloy_txn_reciept(
t: &TransactionTrace,
block: &Block,
) -> Result<Option<alloy::network::AnyTransactionReceipt>, Error> {
) -> Result<Option<AnyTransactionReceiptBare>, Error> {
use alloy::consensus::{Eip658Value, Receipt};
let r = t.receipt.as_ref();

Expand Down Expand Up @@ -719,7 +713,7 @@ fn transaction_trace_to_alloy_txn_reciept(
inner: any_envelope,
};

Ok(Some(WithOtherFields::new(receipt)))
Ok(Some(receipt))
}

impl BlockHeader {
Expand Down Expand Up @@ -1014,7 +1008,7 @@ mod test {

let receipt = receipt_opt.unwrap();

assert_eq!(receipt.inner.inner.r#type, 126);
assert_eq!(receipt.inner.r#type, 126);
assert_eq!(receipt.gas_used, 21000);
assert_eq!(receipt.transaction_index, Some(0));
}
Expand Down
11 changes: 4 additions & 7 deletions chain/ethereum/src/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ fn create_dummy_transaction(
transaction_index: Option<u64>,
transaction_hash: Option<B256>,
) -> Result<AnyTransaction, anyhow::Error> {
use alloy::serde::WithOtherFields;
use graph::components::ethereum::AnyTxEnvelope;
use graph::prelude::alloy::{
consensus::transaction::Recovered, consensus::Signed, primitives::Signature,
Expand All @@ -465,15 +464,13 @@ fn create_dummy_transaction(

let recovered = Recovered::new_unchecked(any_envelope, Address::ZERO);

let inner_tx = Transaction {
Ok(Transaction {
inner: recovered,
block_hash: Some(block_hash),
block_number: Some(block_number),
transaction_index,
effective_gas_price: None,
};

Ok(AnyTransaction::new(WithOtherFields::new(inner_tx)))
})
}

impl DataSource {
Expand Down Expand Up @@ -812,7 +809,7 @@ impl DataSource {
let logging_extras = Arc::new(o! {
"signature" => event_handler.event.to_string(),
"address" => format!("{}", &log.address()),
"transaction" => format!("{}", &transaction.inner.tx_hash()),
"transaction" => format!("{}", &transaction.tx_hash()),
});
let handler = event_handler.handler.clone();
let calls = DeclaredCall::from_log_trigger_with_event(
Expand Down Expand Up @@ -921,7 +918,7 @@ impl DataSource {
let logging_extras = Arc::new(o! {
"function" => handler.function.to_string(),
"to" => format!("{}", &call.to),
"transaction" => format!("{}", &transaction.inner.tx_hash()),
"transaction" => format!("{}", &transaction.tx_hash()),
});
Ok(Some(TriggerWithHandler::<Chain>::new_with_logging_extras(
MappingTrigger::Call {
Expand Down
71 changes: 34 additions & 37 deletions chain/ethereum/src/ethereum_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use graph::futures03::{
use graph::prelude::{
alloy::{
self,
network::{AnyNetwork, TransactionResponse},
network::TransactionResponse,
primitives::{Address, B256},
providers::{
ext::TraceApi,
Expand Down Expand Up @@ -86,8 +86,8 @@ type AlloyProvider = FillProvider<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
RootProvider<AnyNetwork>,
AnyNetwork,
RootProvider<AnyNetworkBare>,
AnyNetworkBare,
>;

#[derive(Clone)]
Expand Down Expand Up @@ -167,22 +167,22 @@ impl EthereumAdapter {
) -> Self {
let alloy = match &transport {
Transport::RPC(client) => Arc::new(
alloy::providers::ProviderBuilder::<_, _, AnyNetwork>::default()
.network::<AnyNetwork>()
alloy::providers::ProviderBuilder::<_, _, AnyNetworkBare>::default()
.network::<AnyNetworkBare>()
.with_recommended_fillers()
.connect_client(client.clone()),
),
Transport::IPC(ipc_connect) => Arc::new(
alloy::providers::ProviderBuilder::<_, _, AnyNetwork>::default()
.network::<AnyNetwork>()
alloy::providers::ProviderBuilder::<_, _, AnyNetworkBare>::default()
.network::<AnyNetworkBare>()
.with_recommended_fillers()
.connect_ipc(ipc_connect.clone())
.await
.expect("Failed to connect to Ethereum IPC"),
),
Transport::WS(ws_connect) => Arc::new(
alloy::providers::ProviderBuilder::<_, _, AnyNetwork>::default()
.network::<AnyNetwork>()
alloy::providers::ProviderBuilder::<_, _, AnyNetworkBare>::default()
.network::<AnyNetworkBare>()
.with_recommended_fillers()
.connect_ws(ws_connect.clone())
.await
Expand Down Expand Up @@ -2062,7 +2062,7 @@ pub(crate) fn parse_block_triggers(
async fn fetch_receipt_from_ethereum_client(
eth: &EthereumAdapter,
transaction_hash: B256,
) -> anyhow::Result<alloy::network::AnyTransactionReceipt> {
) -> anyhow::Result<AnyTransactionReceiptBare> {
match eth.alloy.get_transaction_receipt(transaction_hash).await {
Ok(Some(receipt)) => Ok(receipt),
Ok(None) => bail!("Could not find transaction receipt"),
Expand Down Expand Up @@ -2215,7 +2215,7 @@ async fn fetch_transaction_receipts_in_batch_with_retry(
hashes: Vec<B256>,
block_hash: B256,
logger: ProviderLogger,
) -> Result<Vec<Arc<alloy::network::AnyTransactionReceipt>>, IngestorError> {
) -> Result<Vec<Arc<AnyTransactionReceiptBare>>, IngestorError> {
let retry_log_message = format!(
"batch eth_getTransactionReceipt RPC call for block {:?}",
block_hash
Expand All @@ -2241,7 +2241,7 @@ async fn fetch_transaction_receipts_in_batch(
hashes: Vec<B256>,
block_hash: B256,
logger: ProviderLogger,
) -> Result<Vec<Arc<alloy::network::AnyTransactionReceipt>>, IngestorError> {
) -> Result<Vec<Arc<AnyTransactionReceiptBare>>, IngestorError> {
// Use the batch method to get all receipts at once
let receipts = batch_get_transaction_receipts(alloy, hashes.clone())
.await
Expand Down Expand Up @@ -2270,17 +2270,16 @@ async fn fetch_transaction_receipts_in_batch(
async fn batch_get_transaction_receipts(
provider: Arc<AlloyProvider>,
tx_hashes: Vec<B256>,
) -> Result<Vec<Option<alloy::network::AnyTransactionReceipt>>, Box<dyn std::error::Error>> {
) -> Result<Vec<Option<AnyTransactionReceiptBare>>, Box<dyn std::error::Error>> {
let mut batch = alloy::rpc::client::BatchRequest::new(provider.client());
let mut receipt_futures = Vec::new();

// Add all receipt requests to batch
for tx_hash in &tx_hashes {
let receipt_future = batch
.add_call::<(B256,), Option<alloy::network::AnyTransactionReceipt>>(
"eth_getTransactionReceipt",
&(*tx_hash,),
)?;
let receipt_future = batch.add_call::<(B256,), Option<AnyTransactionReceiptBare>>(
"eth_getTransactionReceipt",
&(*tx_hash,),
)?;
receipt_futures.push(receipt_future);
}

Expand Down Expand Up @@ -2332,7 +2331,7 @@ async fn fetch_receipts_with_retry(
block_hash: B256,
logger: ProviderLogger,
supports_block_receipts: bool,
) -> Result<Vec<Arc<alloy::network::AnyTransactionReceipt>>, IngestorError> {
) -> Result<Vec<Arc<AnyTransactionReceiptBare>>, IngestorError> {
if supports_block_receipts {
return fetch_block_receipts_with_retry(alloy, hashes, block_hash, logger).await;
}
Expand All @@ -2345,7 +2344,7 @@ async fn fetch_individual_receipts_with_retry(
hashes: Vec<B256>,
block_hash: B256,
logger: ProviderLogger,
) -> Result<Vec<Arc<alloy::network::AnyTransactionReceipt>>, IngestorError> {
) -> Result<Vec<Arc<AnyTransactionReceiptBare>>, IngestorError> {
if ENV_VARS.fetch_receipts_in_batches {
return fetch_transaction_receipts_in_batch_with_retry(alloy, hashes, block_hash, logger)
.await;
Expand All @@ -2364,9 +2363,9 @@ async fn fetch_individual_receipts_with_retry(
})
.buffered(ENV_VARS.block_ingestor_max_concurrent_json_rpc_calls);

tokio_stream::StreamExt::collect::<
Result<Vec<Arc<alloy::network::AnyTransactionReceipt>>, IngestorError>,
>(receipt_stream)
tokio_stream::StreamExt::collect::<Result<Vec<Arc<AnyTransactionReceiptBare>>, IngestorError>>(
receipt_stream,
)
.await
}

Expand All @@ -2376,7 +2375,7 @@ async fn fetch_block_receipts_with_retry(
hashes: Vec<B256>,
block_hash: B256,
logger: ProviderLogger,
) -> Result<Vec<Arc<alloy::network::AnyTransactionReceipt>>, IngestorError> {
) -> Result<Vec<Arc<AnyTransactionReceiptBare>>, IngestorError> {
use graph::prelude::alloy::rpc::types::BlockId;
let retry_log_message = format!("eth_getBlockReceipts RPC call for block {:?}", block_hash);

Expand Down Expand Up @@ -2420,7 +2419,7 @@ async fn fetch_transaction_receipt_with_retry(
transaction_hash: B256,
block_hash: B256,
logger: ProviderLogger,
) -> Result<Arc<alloy::network::AnyTransactionReceipt>, IngestorError> {
) -> Result<Arc<AnyTransactionReceiptBare>, IngestorError> {
let retry_log_message = format!(
"eth_getTransactionReceipt RPC call for transaction {:?}",
transaction_hash
Expand All @@ -2443,11 +2442,11 @@ async fn fetch_transaction_receipt_with_retry(
}

fn resolve_transaction_receipt(
transaction_receipt: Option<alloy::network::AnyTransactionReceipt>,
transaction_receipt: Option<AnyTransactionReceiptBare>,
transaction_hash: B256,
block_hash: B256,
logger: ProviderLogger,
) -> Result<alloy::network::AnyTransactionReceipt, IngestorError> {
) -> Result<AnyTransactionReceiptBare, IngestorError> {
match transaction_receipt {
// A receipt might be missing because the block was uncled, and the transaction never
// made it back into the main chain.
Expand Down Expand Up @@ -2580,11 +2579,10 @@ async fn get_transaction_receipts_for_transaction_hashes(
transaction_hashes_by_block: &HashMap<B256, HashSet<B256>>,
subgraph_metrics: Arc<SubgraphEthRpcMetrics>,
logger: ProviderLogger,
) -> Result<HashMap<B256, Arc<alloy::network::AnyTransactionReceipt>>, anyhow::Error> {
) -> Result<HashMap<B256, Arc<AnyTransactionReceiptBare>>, anyhow::Error> {
use std::collections::hash_map::Entry::Vacant;

let mut receipts_by_hash: HashMap<B256, Arc<alloy::network::AnyTransactionReceipt>> =
HashMap::new();
let mut receipts_by_hash: HashMap<B256, Arc<AnyTransactionReceiptBare>> = HashMap::new();

// Return early if input set is empty
if transaction_hashes_by_block.is_empty() {
Expand Down Expand Up @@ -2665,8 +2663,7 @@ mod tests {
EthereumBlockWithCalls,
};
use graph::blockchain::BlockPtr;
use graph::components::ethereum::AnyBlock;
use graph::prelude::alloy::network::AnyNetwork;
use graph::components::ethereum::AnyNetworkBare;
use graph::prelude::alloy::primitives::{Address, Bytes, B256};
use graph::prelude::alloy::providers::mock::Asserter;
use graph::prelude::alloy::providers::ProviderBuilder;
Expand All @@ -2682,7 +2679,7 @@ mod tests {

let block = EthereumBlockWithCalls {
ethereum_block: EthereumBlock {
block: Arc::new(LightEthereumBlock::new(AnyBlock::from(block))),
block: Arc::new(LightEthereumBlock::new(block)),
..Default::default()
},
calls: Some(vec![EthereumCall {
Expand Down Expand Up @@ -2743,8 +2740,8 @@ mod tests {
let json_value: Value = serde_json::from_str(json_response).unwrap();

let asserter = Asserter::new();
let provider = ProviderBuilder::<_, _, AnyNetwork>::default()
.network::<AnyNetwork>()
let provider = ProviderBuilder::<_, _, AnyNetworkBare>::default()
.network::<AnyNetworkBare>()
.with_recommended_fillers()
.connect_mocked_client(asserter.clone());

Expand Down Expand Up @@ -2827,7 +2824,7 @@ mod tests {
#[allow(unreachable_code)]
let block = EthereumBlockWithCalls {
ethereum_block: EthereumBlock {
block: Arc::new(LightEthereumBlock::new(AnyBlock::from(block))),
block: Arc::new(LightEthereumBlock::new(block)),
..Default::default()
},
calls: Some(vec![EthereumCall {
Expand Down Expand Up @@ -2858,7 +2855,7 @@ mod tests {
#[allow(unreachable_code)]
let block = EthereumBlockWithCalls {
ethereum_block: EthereumBlock {
block: Arc::new(LightEthereumBlock::new(AnyBlock::from(block))),
block: Arc::new(LightEthereumBlock::new(block)),
..Default::default()
},
calls: Some(vec![EthereumCall {
Expand Down
8 changes: 2 additions & 6 deletions chain/ethereum/src/runtime/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use graph::prelude::alloy;
use graph::prelude::alloy::consensus::TxReceipt;
use graph::prelude::alloy::network::ReceiptResponse;
use graph::prelude::alloy::rpc::types::{Log, TransactionReceipt};
use graph::prelude::alloy::serde::WithOtherFields;
use graph::{
prelude::BigInt,
runtime::{
Expand Down Expand Up @@ -587,10 +586,7 @@ where

#[async_trait]
impl<'a, T, B, Inner> ToAscObj<AscEthereumEvent_0_0_7<T, B>>
for (
EthereumEventData<'a>,
Option<&WithOtherFields<TransactionReceipt<Inner>>>,
)
for (EthereumEventData<'a>, Option<&TransactionReceipt<Inner>>)
where
T: AscType + AscIndexId + Send,
B: AscType + AscIndexId + Send,
Expand All @@ -615,7 +611,7 @@ where
params,
} = event_data.to_asc_obj(heap, gas).await?;
let receipt = if let Some(receipt_data) = optional_receipt {
asc_new(heap, &receipt_data.inner(), gas).await?
asc_new(heap, receipt_data, gas).await?
} else {
AscPtr::null()
};
Expand Down
2 changes: 1 addition & 1 deletion chain/ethereum/src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use graph::abi;
use graph::blockchain::MappingTriggerTrait;
use graph::blockchain::TriggerData;
use graph::components::ethereum::AnyTransaction;
use graph::components::ethereum::AnyTransactionReceiptBare as AlloyTransactionReceipt;
use graph::data::subgraph::API_VERSION_0_0_2;
use graph::data::subgraph::API_VERSION_0_0_6;
use graph::data::subgraph::API_VERSION_0_0_7;
use graph::data_source::common::DeclaredCall;
use graph::prelude::alloy::consensus::Transaction as TransactionTrait;
use graph::prelude::alloy::network::AnyTransactionReceipt as AlloyTransactionReceipt;
use graph::prelude::alloy::network::TransactionResponse;
use graph::prelude::alloy::primitives::{Address, B256, U256};
use graph::prelude::alloy::rpc::types::Log;
Expand Down
8 changes: 5 additions & 3 deletions graph/src/components/ethereum/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod network;
mod types;

pub use self::network::AnyNetworkBare;
pub use self::types::{
AnyBlock, AnyTransaction, EthereumBlock, EthereumBlockWithCalls, EthereumCall,
LightEthereumBlock, LightEthereumBlockExt,
AnyBlock, AnyTransaction, AnyTransactionReceiptBare, EthereumBlock, EthereumBlockWithCalls,
EthereumCall, LightEthereumBlock, LightEthereumBlockExt,
};

// Re-export Alloy network types for convenience
pub use alloy::network::{AnyHeader, AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction, AnyTxEnvelope};
pub use alloy::network::{AnyHeader, AnyRpcHeader, AnyTxEnvelope};
Loading