Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pallet-revive] Add eth_get_logs #7506

Merged
merged 45 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7a46af1
Fixes
pgherveou Feb 5, 2025
b527fc7
nit
pgherveou Feb 5, 2025
8ed5113
rm log
pgherveou Feb 5, 2025
e23b270
fix
pgherveou Feb 5, 2025
571aaaa
Update from pgherveou running command 'prdoc --audience runtime_dev -…
github-actions[bot] Feb 5, 2025
e692fdd
get rid of extra traits
pgherveou Feb 5, 2025
8f1e5e1
fix
pgherveou Feb 5, 2025
3eb3fec
update example api
pgherveou Feb 5, 2025
22421a2
Fix rpc
pgherveou Feb 5, 2025
cff3c5d
Update from pgherveou running command 'prdoc --audience runtime_dev -…
github-actions[bot] Feb 5, 2025
af848d5
Add assert
pgherveou Feb 5, 2025
462f643
wip
pgherveou Feb 6, 2025
60e21bf
fix
pgherveou Feb 6, 2025
08c21b5
rm eth-indexer
pgherveou Feb 6, 2025
9fa7698
fix
pgherveou Feb 6, 2025
af72b25
rm helper method
pgherveou Feb 6, 2025
cb54a9d
Update from pgherveou running command 'prdoc --audience runtime_dev -…
github-actions[bot] Feb 6, 2025
5e647f4
enable old block indexing
pgherveou Feb 6, 2025
d074f35
run migration in receipt_provider
pgherveou Feb 6, 2025
e4a4482
fix clippy, cleanup db
pgherveou Feb 6, 2025
289e3fd
fix tests
pgherveou Feb 6, 2025
a5a20d0
add skeleton
pgherveou Feb 6, 2025
7b2b40e
Merge branch 'master' into pg/fix-eth-fee-rpc
pgherveou Feb 6, 2025
8171f3e
fix
pgherveou Feb 6, 2025
3f11f2e
fixes
pgherveou Feb 7, 2025
bfb37f2
fix metadata
pgherveou Feb 7, 2025
729ce37
Merge branch 'pg/fix-eth-fee-rpc' into pg/fix-rpc-dead-lock
pgherveou Feb 7, 2025
646966d
Fixes
pgherveou Feb 7, 2025
1110ff7
Merge branch 'pg/fix-rpc-dead-lock' into pg/add-eth-get-logs
pgherveou Feb 7, 2025
bcdd5d5
fixes
pgherveou Feb 7, 2025
7598103
fix index
pgherveou Feb 7, 2025
00dca85
fix interface
pgherveou Feb 7, 2025
276cdd8
fix tests
pgherveou Feb 7, 2025
1f324a5
Merge branch 'master' into pg/fix-rpc-dead-lock
pgherveou Feb 7, 2025
3248fb9
fix some js files
pgherveou Feb 7, 2025
7e9ba43
Merge branch 'pg/fix-rpc-dead-lock' into pg/add-eth-get-logs
pgherveou Feb 7, 2025
39a6f6e
add js test
pgherveou Feb 7, 2025
d6477ca
Update from pgherveou running command 'prdoc --audience runtime_dev -…
github-actions[bot] Feb 7, 2025
12f3e7a
index by hash
pgherveou Feb 7, 2025
60f0641
make clippy happy
pgherveou Feb 7, 2025
8728b28
Update substrate/frame/revive/rpc/src/block_info_provider.rs
pgherveou Feb 7, 2025
0c29859
Merge branch 'master' into pg/add-eth-get-logs
pgherveou Feb 7, 2025
c6349ec
Update prdoc/pr_7506.prdoc
pgherveou Feb 10, 2025
47d66e1
fix misc debugging log
pgherveou Feb 10, 2025
5824496
fix js stuff
pgherveou Feb 10, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions prdoc/pr_7506.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: '[pallet-revive] Add eth_get_logs'
doc:
- audience: Runtime Dev
description: "Add support for eth_get_logs rpc method\r\n"
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
crates:
- name: pallet-revive-eth-rpc
bump: minor
- name: pallet-revive
bump: minor

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

1 change: 1 addition & 0 deletions substrate/frame/revive/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ tokio = { workspace = true, features = ["full"] }

[dev-dependencies]
env_logger = { workspace = true }
pretty_assertions = { workspace = true }
static_init = { workspace = true }
substrate-cli-test-utils = { workspace = true }
subxt-signer = { workspace = true, features = ["unstable-eth"] }
37 changes: 37 additions & 0 deletions substrate/frame/revive/rpc/examples/js/src/geth-diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,42 @@ for (const env of envs) {
],
})
})

test('logs', async () => {
let address = await getEventExampleAddr()
let { request } = await env.serverWallet.simulateContract({
address,
abi: EventExampleAbi,
functionName: 'triggerEvent',
})

let hash = await env.serverWallet.writeContract(request)
let receipt = await env.serverWallet.waitForTransactionReceipt({ hash })
const logs = await env.serverWallet.getLogs({
address,
blockHash: receipt.blockHash,
})
expect(logs).toHaveLength(1)
expect(logs[0]).toMatchObject({
address,
data: '0x00000000000000000000000000000000000000000000000000000000000030390000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000b48656c6c6f20776f726c64000000000000000000000000000000000000000000',
transactionHash: hash,
})

expect(
decodeEventLog({
abi: EventExampleAbi,
data: logs[0].data,
topics: logs[0].topics,
})
).toEqual({
eventName: 'ExampleEvent',
args: {
sender: env.serverWallet.account.address,
value: 12345n,
message: 'Hello world',
},
})
})
})
}
28 changes: 28 additions & 0 deletions substrate/frame/revive/rpc/migrations/0002_create_log_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE IF NOT EXISTS logs (
block_hash BLOB NOT NULL,
transaction_index INTEGER NOT NULL,
log_index INTEGER NOT NULL,
address BLOB NOT NULL,
block_number INTEGER NOT NULL,
transaction_hash BLOB NOT NULL,
topic_0 BLOB,
topic_1 BLOB,
topic_2 BLOB,
topic_3 BLOB,
data BLOB,
PRIMARY KEY (block_hash, transaction_index, log_index)
);

CREATE INDEX IF NOT EXISTS idx_block_number_address_topics ON logs (
block_number,
address,
topic_0,
topic_1,
topic_2,
topic_3
);

CREATE INDEX IF NOT EXISTS idx_block_hash ON logs (
block_hash
);

9 changes: 9 additions & 0 deletions substrate/frame/revive/rpc/src/block_info_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub trait BlockInfoProvider: Send + Sync {
/// Return the latest ingested block.
async fn latest_block(&self) -> Option<Arc<SubstrateBlock>>;

/// Return the latest block number
async fn latest_block_number(&self) -> Option<SubstrateBlockNumber> {
return self.latest_block().await.map(|block| block.number());
}

/// Get block by block_number.
async fn block_by_number(
&self,
Expand Down Expand Up @@ -225,6 +230,10 @@ pub mod test {
None
}

async fn latest_block_number(&self) -> Option<SubstrateBlockNumber> {
Some(2u32)
}

async fn block_by_number(
&self,
_block_number: SubstrateBlockNumber,
Expand Down
16 changes: 13 additions & 3 deletions substrate/frame/revive/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use crate::{
use jsonrpsee::types::{error::CALL_EXECUTION_FAILED_CODE, ErrorObjectOwned};
use pallet_revive::{
evm::{
extract_revert_message, Block, BlockNumberOrTag, BlockNumberOrTagOrHash,
GenericTransaction, ReceiptInfo, SyncingProgress, SyncingStatus, TransactionSigned, H160,
H256, U256,
extract_revert_message, Block, BlockNumberOrTag, BlockNumberOrTagOrHash, Filter,
GenericTransaction, Log, ReceiptInfo, SyncingProgress, SyncingStatus, TransactionSigned,
H160, H256, U256,
},
EthTransactError, EthTransactInfo,
};
Expand Down Expand Up @@ -132,6 +132,9 @@ pub enum ClientError {
/// The cache is empty.
#[error("cache is empty")]
CacheEmpty,
/// Failed to filter logs.
#[error("Failed to filter logs")]
LogFilterFailed(#[from] anyhow::Error),
}

const REVERT_CODE: i32 = 3;
Expand Down Expand Up @@ -712,4 +715,11 @@ impl Client {
pub fn max_block_weight(&self) -> Weight {
self.max_block_weight
}

/// Get the logs matching the given filter.
pub async fn logs(&self, filter: Option<Filter>) -> Result<Vec<Log>, ClientError> {
let logs =
self.receipt_provider.logs(filter).await.map_err(ClientError::LogFilterFailed)?;
Ok(logs)
}
}
5 changes: 5 additions & 0 deletions substrate/frame/revive/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ impl EthRpcServer for EthRpcServerImpl {
Ok(self.client.receipts_count_per_block(&block.hash).await.map(U256::from))
}

async fn get_logs(&self, filter: Option<Filter>) -> RpcResult<FilterResults> {
let logs = self.client.logs(filter).await?;
Ok(FilterResults::Logs(logs))
}

async fn get_storage_at(
&self,
address: H160,
Expand Down
9 changes: 8 additions & 1 deletion substrate/frame/revive/rpc/src/receipt_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

use jsonrpsee::core::async_trait;
use pallet_revive::evm::{ReceiptInfo, TransactionSigned, H256};
use pallet_revive::evm::{Filter, Log, ReceiptInfo, TransactionSigned, H256};
use tokio::join;

mod cache;
Expand All @@ -34,6 +34,9 @@ pub trait ReceiptProvider: Send + Sync {
/// Similar to `insert`, but intended for archiving receipts from historical blocks.
async fn archive(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]);

/// Get logs that match the given filter.
async fn logs(&self, filter: Option<Filter>) -> anyhow::Result<Vec<Log>>;

/// Deletes receipts associated with the specified block hash.
async fn remove(&self, block_hash: &H256);

Expand Down Expand Up @@ -102,4 +105,8 @@ impl<Cache: ReceiptProvider, Archive: ReceiptProvider> ReceiptProvider for (Cach
}
self.1.signed_tx_by_hash(hash).await
}

async fn logs(&self, filter: Option<Filter>) -> anyhow::Result<Vec<Log>> {
self.1.logs(filter).await
}
}
6 changes: 5 additions & 1 deletion substrate/frame/revive/rpc/src/receipt_provider/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.
use super::ReceiptProvider;
use jsonrpsee::core::async_trait;
use pallet_revive::evm::{ReceiptInfo, TransactionSigned, H256};
use pallet_revive::evm::{Filter, Log, ReceiptInfo, TransactionSigned, H256};
use std::{collections::HashMap, sync::Arc};
use tokio::sync::RwLock;

Expand All @@ -37,6 +37,10 @@ impl CacheReceiptProvider {
impl ReceiptProvider for CacheReceiptProvider {
async fn archive(&self, _block_hash: &H256, _receipts: &[(TransactionSigned, ReceiptInfo)]) {}

async fn logs(&self, _filter: Option<Filter>) -> anyhow::Result<Vec<Log>> {
anyhow::bail!("Not implemented")
}

async fn insert(&self, block_hash: &H256, receipts: &[(TransactionSigned, ReceiptInfo)]) {
let mut cache = self.cache.write().await;
cache.insert(block_hash, receipts);
Expand Down
Loading
Loading