diff --git a/substrate/frame/revive/rpc/.sqlx/query-027a434a38822c2ba4439e8f9f9c1135227c1150f2c5083d1c7c6086b717ada0.json b/substrate/frame/revive/rpc/.sqlx/query-027a434a38822c2ba4439e8f9f9c1135227c1150f2c5083d1c7c6086b717ada0.json deleted file mode 100644 index 016276144901..000000000000 --- a/substrate/frame/revive/rpc/.sqlx/query-027a434a38822c2ba4439e8f9f9c1135227c1150f2c5083d1c7c6086b717ada0.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "db_name": "SQLite", - "query": "\n\t\t\t\tINSERT INTO transaction_hashes (transaction_hash, block_hash, transaction_index)\n\t\t\t\tVALUES ($1, $2, $3)\n\n\t\t\t\tON CONFLICT(transaction_hash) DO UPDATE SET\n\t\t\t\tblock_hash = EXCLUDED.block_hash,\n\t\t\t\ttransaction_index = EXCLUDED.transaction_index\n\t\t\t\t", - "describe": { - "columns": [], - "parameters": { - "Right": 3 - }, - "nullable": [] - }, - "hash": "027a434a38822c2ba4439e8f9f9c1135227c1150f2c5083d1c7c6086b717ada0" -} diff --git a/substrate/frame/revive/rpc/.sqlx/query-de639fe0ac0c3cfdfbbfa07e81a61dae3a284ad4f7979dacb0ccff32cdc39051.json b/substrate/frame/revive/rpc/.sqlx/query-de639fe0ac0c3cfdfbbfa07e81a61dae3a284ad4f7979dacb0ccff32cdc39051.json new file mode 100644 index 000000000000..6df545321395 --- /dev/null +++ b/substrate/frame/revive/rpc/.sqlx/query-de639fe0ac0c3cfdfbbfa07e81a61dae3a284ad4f7979dacb0ccff32cdc39051.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "\n\t\t\t\tINSERT OR REPLACE INTO transaction_hashes (transaction_hash, block_hash, transaction_index)\n\t\t\t\tVALUES ($1, $2, $3)\n\t\t\t\t", + "describe": { + "columns": [], + "parameters": { + "Right": 3 + }, + "nullable": [] + }, + "hash": "de639fe0ac0c3cfdfbbfa07e81a61dae3a284ad4f7979dacb0ccff32cdc39051" +} diff --git a/substrate/frame/revive/rpc/migrations/0001_create_transaction_hashes.sql b/substrate/frame/revive/rpc/migrations/0001_create_transaction_hashes.sql index 26386c7d4d01..8fd6b353faa8 100644 --- a/substrate/frame/revive/rpc/migrations/0001_create_transaction_hashes.sql +++ b/substrate/frame/revive/rpc/migrations/0001_create_transaction_hashes.sql @@ -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 @@ -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 +); diff --git a/substrate/frame/revive/rpc/src/receipt_extractor.rs b/substrate/frame/revive/rpc/src/receipt_extractor.rs index e53f98639671..6338f42ee0cc 100644 --- a/substrate/frame/revive/rpc/src/receipt_extractor.rs +++ b/substrate/frame/revive/rpc/src/receipt_extractor.rs @@ -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() }) }) diff --git a/substrate/frame/revive/rpc/src/receipt_provider.rs b/substrate/frame/revive/rpc/src/receipt_provider.rs index f1d76e6cceb8..bbed54a94b7d 100644 --- a/substrate/frame/revive/rpc/src/receipt_provider.rs +++ b/substrate/frame/revive/rpc/src/receipt_provider.rs @@ -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( @@ -57,13 +55,17 @@ pub trait ReceiptProvider: Send + Sync { } #[async_trait] -impl ReceiptProvider for (Main, Fallback) { +impl 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( diff --git a/substrate/frame/revive/rpc/src/receipt_provider/cache.rs b/substrate/frame/revive/rpc/src/receipt_provider/cache.rs index a4741d18a3b3..765c12f89010 100644 --- a/substrate/frame/revive/rpc/src/receipt_provider/cache.rs +++ b/substrate/frame/revive/rpc/src/receipt_provider/cache.rs @@ -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); diff --git a/substrate/frame/revive/rpc/src/receipt_provider/db.rs b/substrate/frame/revive/rpc/src/receipt_provider/db.rs index 827fadad5b54..42ffe93a9f8b 100644 --- a/substrate/frame/revive/rpc/src/receipt_provider/db.rs +++ b/substrate/frame/revive/rpc/src/receipt_provider/db.rs @@ -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; } @@ -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, @@ -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:?}"); } } } diff --git a/substrate/frame/revive/src/evm/api/rpc_types_gen.rs b/substrate/frame/revive/src/evm/api/rpc_types_gen.rs index 5d31613ca314..e7003ee7c189 100644 --- a/substrate/frame/revive/src/evm/api/rpc_types_gen.rs +++ b/substrate/frame/revive/src/evm/api/rpc_types_gen.rs @@ -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, + #[serde(rename = "blockHash")] + pub block_hash: H256, /// block number - #[serde(rename = "blockNumber", skip_serializing_if = "Option::is_none")] - pub block_number: Option, + #[serde(rename = "blockNumber")] + pub block_number: U256, /// data #[serde(skip_serializing_if = "Option::is_none")] pub data: Option, /// log index - #[serde(rename = "logIndex", skip_serializing_if = "Option::is_none")] - pub log_index: Option, + #[serde(rename = "logIndex")] + pub log_index: U256, /// removed #[serde(skip_serializing_if = "Option::is_none")] pub removed: Option, @@ -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, + #[serde(rename = "transactionIndex")] + pub transaction_index: U256, } /// Syncing progress