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
3 changes: 3 additions & 0 deletions chain/ethereum/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ impl Into<EthereumBlockWithCalls> for &Block {
effective_gas_price: None,
})
})
// Transaction receipts will be shared along the code, so we put them into an
// Arc here to avoid excessive cloning.
.map(Arc::new)
.collect(),
},
// Comment (437a9f17-67cc-478f-80a3-804fe554b227): This Some() will avoid calls in the triggers_in_block
Expand Down
24 changes: 14 additions & 10 deletions chain/ethereum/src/ethereum_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,9 +1048,10 @@ impl EthereumAdapterTrait for EthereumAdapter {
)
})
.buffered(ENV_VARS.block_ingestor_max_concurrent_json_rpc_calls);
graph::tokio_stream::StreamExt::collect::<Result<Vec<TransactionReceipt>, IngestorError>>(
receipt_stream,
).boxed()
graph::tokio_stream::StreamExt::collect::<
Result<Vec<Arc<TransactionReceipt>>, IngestorError>,
>(receipt_stream)
.boxed()
};

let block_future =
Expand Down Expand Up @@ -1489,7 +1490,9 @@ pub(crate) fn parse_log_triggers(
.logs
.iter()
.filter(move |log| log_filter.matches(log))
.map(move |log| EthereumTrigger::Log(Arc::new(log.clone()), Some(receipt.clone())))
.map(move |log| {
EthereumTrigger::Log(Arc::new(log.clone()), Some(receipt.cheap_clone()))
})
})
.collect()
}
Expand Down Expand Up @@ -1706,7 +1709,7 @@ async fn fetch_transaction_receipts_in_batch_with_retry(
hashes: Vec<H256>,
block_hash: H256,
logger: Logger,
) -> Result<Vec<TransactionReceipt>, IngestorError> {
) -> Result<Vec<Arc<TransactionReceipt>>, IngestorError> {
let retry_log_message = format!(
"batch eth_getTransactionReceipt RPC call for block {:?}",
block_hash
Expand All @@ -1731,7 +1734,7 @@ async fn fetch_transaction_receipts_in_batch(
hashes: Vec<H256>,
block_hash: H256,
logger: Logger,
) -> Result<Vec<TransactionReceipt>, IngestorError> {
) -> Result<Vec<Arc<TransactionReceipt>>, IngestorError> {
let batching_web3 = Web3::new(Batch::new(web3.transport().clone()));
let eth = batching_web3.eth();
let receipt_futures = hashes
Expand All @@ -1750,7 +1753,7 @@ async fn fetch_transaction_receipts_in_batch(

let mut collected = vec![];
for receipt in receipt_futures.into_iter() {
collected.push(receipt.await?)
collected.push(Arc::new(receipt.await?))
}
Ok(collected)
}
Expand All @@ -1761,7 +1764,7 @@ async fn fetch_transaction_receipt_with_retry(
transaction_hash: H256,
block_hash: H256,
logger: Logger,
) -> Result<TransactionReceipt, IngestorError> {
) -> Result<Arc<TransactionReceipt>, IngestorError> {
let logger = logger.cheap_clone();
let retry_log_message = format!(
"eth_getTransactionReceipt RPC call for transaction {:?}",
Expand All @@ -1776,6 +1779,7 @@ async fn fetch_transaction_receipt_with_retry(
.and_then(move |some_receipt| {
resolve_transaction_receipt(some_receipt, transaction_hash, block_hash, logger)
})
.map(Arc::new)
}

fn resolve_transaction_receipt(
Expand Down Expand Up @@ -1897,10 +1901,10 @@ async fn get_transaction_receipts_for_transaction_hashes(
adapter: &EthereumAdapter,
transaction_hashes_by_block: &HashMap<H256, HashSet<H256>>,
logger: Logger,
) -> Result<HashMap<H256, TransactionReceipt>, anyhow::Error> {
) -> Result<HashMap<H256, Arc<TransactionReceipt>>, anyhow::Error> {
use std::collections::hash_map::Entry::Vacant;

let mut receipts_by_hash: HashMap<H256, TransactionReceipt> = HashMap::new();
let mut receipts_by_hash: HashMap<H256, Arc<TransactionReceipt>> = HashMap::new();

// Return early if input set is empty
if transaction_hashes_by_block.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions chain/ethereum/src/runtime/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ where
}

impl<T, B> ToAscObj<AscEthereumEvent_0_0_7<T, B>>
for (EthereumEventData, Option<TransactionReceipt>)
for (EthereumEventData, Option<&TransactionReceipt>)
where
T: AscType + AscIndexId,
B: AscType + AscIndexId,
Expand Down Expand Up @@ -665,7 +665,7 @@ impl ToAscObj<AscEthereumLog> for Log {
}
}

impl ToAscObj<AscEthereumTransactionReceipt> for TransactionReceipt {
impl ToAscObj<AscEthereumTransactionReceipt> for &TransactionReceipt {
fn to_asc_obj<H: AscHeap + ?Sized>(
&self,
heap: &mut H,
Expand Down
6 changes: 3 additions & 3 deletions chain/ethereum/src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum MappingTrigger {
transaction: Arc<Transaction>,
log: Arc<Log>,
params: Vec<LogParam>,
receipt: Option<TransactionReceipt>,
receipt: Option<Arc<TransactionReceipt>>,
},
Call {
block: Arc<LightEthereumBlock>,
Expand Down Expand Up @@ -143,7 +143,7 @@ impl blockchain::MappingTrigger for MappingTrigger {
>,
_,
_,
>(heap, &(ethereum_event_data, receipt), gas)?
>(heap, &(ethereum_event_data, receipt.as_deref()), gas)?
.erase()
} else if api_version >= API_VERSION_0_0_6 {
asc_new::<
Expand Down Expand Up @@ -217,7 +217,7 @@ impl blockchain::MappingTrigger for MappingTrigger {
pub enum EthereumTrigger {
Block(BlockPtr, EthereumBlockTriggerType),
Call(Arc<EthereumCall>),
Log(Arc<Log>, Option<TransactionReceipt>),
Log(Arc<Log>, Option<Arc<TransactionReceipt>>),
}

impl PartialEq for EthereumTrigger {
Expand Down
2 changes: 1 addition & 1 deletion graph/src/components/ethereum/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn evaluate_transaction_status(receipt_status: Option<U64>) -> bool {
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
pub struct EthereumBlock {
pub block: Arc<LightEthereumBlock>,
pub transaction_receipts: Vec<TransactionReceipt>,
pub transaction_receipts: Vec<Arc<TransactionReceipt>>,
}

#[derive(Debug, Default, Clone, PartialEq)]
Expand Down