Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Feb 7, 2025
1 parent 729ce37 commit 646966d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 41 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Useful commands:
--
-- Set DATABASE_URL environment variable.
-- export DATABASE_URL=sqlite:///$HOME/tx_hashes.db
-- export DATABASE_URL=sqlite:///$HOME/eth_rpc.db
--
-- Create DB:
-- cargo sqlx database create
Expand All @@ -17,4 +17,6 @@ CREATE TABLE IF NOT EXISTS transaction_hashes (
block_hash BLOB NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_block_hash ON transaction_hashes (block_hash);
CREATE INDEX IF NOT EXISTS idx_block_hash ON transaction_hashes (
block_hash
);
8 changes: 4 additions & 4 deletions substrate/frame/revive/rpc/src/receipt_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl ReceiptExtractor {
address: event.contract,
topics: event.topics,
data: Some(event.data.into()),
block_number: Some(block_number),
block_number,
transaction_hash,
transaction_index: Some(transaction_index.into()),
block_hash: Some(block_hash),
log_index: Some(event_details.index().into()),
transaction_index: transaction_index.into(),
block_hash,
log_index: event_details.index().into(),
..Default::default()
})
})
Expand Down
14 changes: 8 additions & 6 deletions substrate/frame/revive/rpc/src/receipt_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ pub trait ReceiptProvider: Send + Sync {
async fn insert(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]);

/// Similar to `insert`, but intended for archiving receipts from historical blocks.
/// Cache providers may use the default no-operation implementation.
async fn archive(&self, _block_hash: &H256, _receipts: &[(TransactionSigned, ReceiptInfo)]) {}
async fn archive(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]);

/// Deletes receipts associated with the specified block hash.
/// Archive providers can use the default no-operation implementation.
async fn remove(&self, _block_hash: &H256) {}
async fn remove(&self, block_hash: &H256);

/// Get the receipt for the given block hash and transaction index.
async fn receipt_by_block_hash_and_index(
Expand All @@ -57,13 +55,17 @@ pub trait ReceiptProvider: Send + Sync {
}

#[async_trait]
impl<Main: ReceiptProvider, Fallback: ReceiptProvider> ReceiptProvider for (Main, Fallback) {
impl<Cache: ReceiptProvider, Archive: ReceiptProvider> ReceiptProvider for (Cache, Archive) {
async fn insert(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]) {
join!(self.0.insert(block_hash, receipts), self.1.insert(block_hash, receipts));
}

async fn archive(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]) {
self.1.insert(block_hash, receipts).await;
}

async fn remove(&self, block_hash: &H256) {
join!(self.0.remove(block_hash), self.1.remove(block_hash));
self.0.remove(block_hash).await;
}

async fn receipt_by_block_hash_and_index(
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/revive/rpc/src/receipt_provider/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ impl CacheReceiptProvider {

#[async_trait]
impl ReceiptProvider for CacheReceiptProvider {
async fn archive(&self, _block_hash: &H256, _receipts: &[(TransactionSigned, ReceiptInfo)]) {}

async fn insert(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]) {
let mut cache = self.cache.write().await;
cache.insert(block_hash, receipts);
Expand Down
13 changes: 4 additions & 9 deletions substrate/frame/revive/rpc/src/receipt_provider/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl DBReceiptProvider {

#[async_trait]
impl ReceiptProvider for DBReceiptProvider {
async fn remove(&self, _block_hash: &H256) {}

async fn archive(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]) {
self.insert(block_hash, receipts).await;
}
Expand All @@ -80,12 +82,8 @@ impl ReceiptProvider for DBReceiptProvider {

let result = query!(
r#"
INSERT INTO transaction_hashes (transaction_hash, block_hash, transaction_index)
INSERT OR REPLACE INTO transaction_hashes (transaction_hash, block_hash, transaction_index)
VALUES ($1, $2, $3)
ON CONFLICT(transaction_hash) DO UPDATE SET
block_hash = EXCLUDED.block_hash,
transaction_index = EXCLUDED.transaction_index
"#,
transaction_hash,
block_hash,
Expand All @@ -95,10 +93,7 @@ impl ReceiptProvider for DBReceiptProvider {
.await;

if let Err(err) = result {
log::error!(
"Error inserting transaction for block hash {block_hash:?}: {:?}",
err
);
log::error!("Error inserting transaction for block hash {block_hash:?}: {err:?}");
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions substrate/frame/revive/src/evm/api/rpc_types_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,17 @@ pub struct Log {
/// address
pub address: Address,
/// block hash
#[serde(rename = "blockHash", skip_serializing_if = "Option::is_none")]
pub block_hash: Option<H256>,
#[serde(rename = "blockHash")]
pub block_hash: H256,
/// block number
#[serde(rename = "blockNumber", skip_serializing_if = "Option::is_none")]
pub block_number: Option<U256>,
#[serde(rename = "blockNumber")]
pub block_number: U256,
/// data
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Bytes>,
/// log index
#[serde(rename = "logIndex", skip_serializing_if = "Option::is_none")]
pub log_index: Option<U256>,
#[serde(rename = "logIndex")]
pub log_index: U256,
/// removed
#[serde(skip_serializing_if = "Option::is_none")]
pub removed: Option<bool>,
Expand All @@ -398,8 +398,8 @@ pub struct Log {
#[serde(rename = "transactionHash")]
pub transaction_hash: H256,
/// transaction index
#[serde(rename = "transactionIndex", skip_serializing_if = "Option::is_none")]
pub transaction_index: Option<U256>,
#[serde(rename = "transactionIndex")]
pub transaction_index: U256,
}

/// Syncing progress
Expand Down

0 comments on commit 646966d

Please sign in to comment.