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

feat(rpc) Implement Filecoin.EthGetLogs #4780

Merged
merged 113 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 111 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
28d17c4
Add EthGetLogs method (wip)
elmattic Sep 19, 2024
35c4c50
Construct filter result from events
elmattic Sep 19, 2024
e7a093e
Merge branch 'main' into elmattic/eth-get-logs
elmattic Sep 19, 2024
94a1f2b
Retrieve events root
elmattic Sep 20, 2024
945bef8
Merge branch 'main' into elmattic/eth-get-logs
elmattic Sep 20, 2024
6493489
Merge branch 'main' into elmattic/eth-get-logs
elmattic Sep 25, 2024
4b8250d
Add events persistence (wip)
elmattic Sep 25, 2024
bb257d0
Add storage of events
elmattic Sep 26, 2024
19a8978
Refactor config
elmattic Sep 26, 2024
cf95443
Add optional storage of events
elmattic Sep 27, 2024
e36a251
Merge branch 'main' into elmattic/eth-get-logs
elmattic Sep 30, 2024
6341d26
Shim the StampedEvent type
elmattic Sep 30, 2024
cce60e2
Add storing of events for FVM3
elmattic Sep 30, 2024
f52dcdd
Appease clippy
elmattic Sep 30, 2024
ca29d13
Appease clippy
elmattic Sep 30, 2024
5f954b0
Fix get of events
elmattic Sep 30, 2024
36d3a84
Add rpc test
elmattic Sep 30, 2024
24c82f1
Add event filtering (wip)
elmattic Oct 1, 2024
903ed94
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 1, 2024
ad5fa58
Add topics
elmattic Oct 1, 2024
a49370c
Add event index
elmattic Oct 1, 2024
25aaa79
Fix emitter addr
elmattic Oct 1, 2024
e682a66
Cleanup
elmattic Oct 1, 2024
551932e
Fix emitter address filtering when address key is null
elmattic Oct 1, 2024
aefb09d
Refactor
elmattic Oct 2, 2024
ddaafca
Add filtering of topics
elmattic Oct 2, 2024
cedfb0e
Add rpc test
elmattic Oct 2, 2024
aa72a1c
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 2, 2024
d056ffe
Appease clippy
elmattic Oct 2, 2024
ecff37e
Drop events with mis-sized topics
elmattic Oct 2, 2024
150f022
Appease clippy
elmattic Oct 2, 2024
5bba011
Don't try to test filters
elmattic Oct 3, 2024
6c9fbed
Log codec and flags
elmattic Oct 4, 2024
f7eb55c
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 4, 2024
f8ed74d
Add some context
elmattic Oct 4, 2024
f6ae3b5
Store events in the tipset cache
elmattic Oct 4, 2024
4550608
Appease clippy
elmattic Oct 4, 2024
d66133e
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 4, 2024
9e95edb
Add more logs
elmattic Oct 4, 2024
aaef778
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 4, 2024
5d6394d
Filter events when address is unresolved
elmattic Oct 4, 2024
a1f5e2f
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 7, 2024
54ac09f
Refactor
elmattic Oct 7, 2024
71ec51b
Refactor
elmattic Oct 7, 2024
6a0afdb
Remove imports
elmattic Oct 7, 2024
050c700
Pass store events
elmattic Oct 7, 2024
60ba129
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 7, 2024
3e297be
Fix build of tests
elmattic Oct 7, 2024
27c4d17
Add EthGetLogs to the filter lists
elmattic Oct 7, 2024
1c011b9
Remove commented-out dbg macro
elmattic Oct 7, 2024
185f0e9
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 8, 2024
4ae2174
Refactor tuples to struct
elmattic Oct 8, 2024
43be64c
Move events to an option
elmattic Oct 8, 2024
2879a63
Clean up
elmattic Oct 8, 2024
e8f8804
Refactor events
elmattic Oct 8, 2024
5403ed7
Refactor function to use return an option
elmattic Oct 8, 2024
5b63a01
Shim ActorEvent
elmattic Oct 8, 2024
775fee9
Add more shims and use them
elmattic Oct 8, 2024
40f07ec
Remove use import
elmattic Oct 8, 2024
137ada1
Refactor Entry shim to avoid cloning
elmattic Oct 8, 2024
831ec49
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 9, 2024
f8ccf29
Refactor ParsedFilter to use an enum internally
elmattic Oct 9, 2024
c779233
Appease clippy
elmattic Oct 9, 2024
8d04950
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 11, 2024
d27d655
Bail out if messages and events differ in length
elmattic Oct 11, 2024
342fde7
Move bool to an enum
elmattic Oct 11, 2024
f1b155a
Refactor to same name
elmattic Oct 11, 2024
a6595ad
Appease clippy
elmattic Oct 11, 2024
3bd91f0
Kick except out of the party
elmattic Oct 11, 2024
727790d
Rename Int64 and Uint64 with an Eth prefix
elmattic Oct 11, 2024
5d9da4a
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 11, 2024
a7febdc
Add unit test for eth_tx_hash_from_signed_message
elmattic Oct 14, 2024
9e26de1
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 14, 2024
2ccd40b
Add unit test for eth_tx_hash_from_message_cid
elmattic Oct 14, 2024
7eafa8b
Test None case
elmattic Oct 14, 2024
967dae1
Fix warning message
elmattic Oct 14, 2024
7668578
Use more idiomatic pattern
elmattic Oct 14, 2024
752baac
Appease clippy
elmattic Oct 14, 2024
8456410
Refactor
elmattic Oct 14, 2024
c3e8fd6
Add test for do_match fn and avoid unnecessary cloning
elmattic Oct 14, 2024
52ca26e
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 15, 2024
1fcab14
Add entry
elmattic Oct 15, 2024
2f88b0c
Add topic entries
elmattic Oct 15, 2024
b30e19f
Add more asserts
elmattic Oct 16, 2024
8a83522
Add more asserts
elmattic Oct 16, 2024
c7750a2
Rework EthHashList
elmattic Oct 16, 2024
ada0248
Rework topic matching logic
elmattic Oct 16, 2024
3c910e9
Split tests
elmattic Oct 16, 2024
7ee6605
Add assert for wildcard case
elmattic Oct 16, 2024
e7711ea
Cover all cases
elmattic Oct 16, 2024
606f83a
Add one more assert
elmattic Oct 16, 2024
eac03f1
Add one more assert with mis-sized topic
elmattic Oct 16, 2024
7af6d5d
Appease clippy
elmattic Oct 16, 2024
d084627
Use a matching topic0 instead
elmattic Oct 17, 2024
8088983
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 17, 2024
262cfe9
Remove internal function
elmattic Oct 17, 2024
e84c0e5
Uncomment-out and fix code
elmattic Oct 17, 2024
295c32f
Add unit test for eth_log_from_event
elmattic Oct 17, 2024
c6a9c0f
Add more cases to test
elmattic Oct 17, 2024
9421647
Cover more cases
elmattic Oct 17, 2024
351977d
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 21, 2024
7fb2c49
Remove get_events
elmattic Oct 21, 2024
46c9164
Add documentation on public items
elmattic Oct 21, 2024
cc5e1b3
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 21, 2024
5d10395
Add separated event cache
elmattic Oct 22, 2024
0e90a74
Add separate event cache size
elmattic Oct 22, 2024
6fa9293
Appease clippy
elmattic Oct 22, 2024
582dbda
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 22, 2024
7ff7cb3
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 23, 2024
7edb48d
Add comment
elmattic Oct 23, 2024
34e8312
Merge branch 'main' into elmattic/eth-get-logs
elmattic Oct 23, 2024
e6f9300
Remove --enable-event-caching cli flag
elmattic Oct 23, 2024
79ec7da
Rename enum to VMEvent
elmattic Oct 23, 2024
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
2 changes: 2 additions & 0 deletions scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
!Filecoin.StateReplay
# TODO(elmattic): https://github.com/ChainSafe/forest/issues/4759
!Filecoin.EthGetTransactionReceipt
# TODO(elmattic): https://github.com/ChainSafe/forest/issues/4851
!Filecoin.EthGetLogs
2 changes: 2 additions & 0 deletions scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
!Filecoin.ChainSetHead
# TODO(elmattic): https://github.com/ChainSafe/forest/issues/4759
!Filecoin.EthGetTransactionReceipt
# TODO(elmattic): https://github.com/ChainSafe/forest/issues/4851
!Filecoin.EthGetLogs
9 changes: 5 additions & 4 deletions src/chain/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::sync::Arc;

use crate::blocks::{CachingBlockHeader, Tipset, TipsetKey, TxMeta};
use crate::fil_cns;
use crate::interpreter::BlockMessages;
use crate::interpreter::VMTrace;
use crate::interpreter::{BlockMessages, EventCache, VMTrace};
use crate::libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
use crate::message::{ChainMessage, Message as MessageTrait, SignedMessage};
use crate::networks::{ChainConfig, Height};
Expand All @@ -16,6 +15,7 @@ use crate::shim::{
address::Address, econ::TokenAmount, executor::Receipt, message::Message,
state_tree::StateTree, version::NetworkVersion,
};
use crate::state_manager::StateOutput;
use crate::utils::db::{BlockstoreExt, CborStoreExt};
use ahash::{HashMap, HashMapExt, HashSet};
use anyhow::Context;
Expand Down Expand Up @@ -340,7 +340,7 @@ where
// state-root without caching.
let genesis_timestamp = heaviest_tipset.genesis(&chain_index.db)?.timestamp;
let beacon = Arc::new(chain_config.get_beacon_schedule(genesis_timestamp));
let (state, _) = crate::state_manager::apply_block_messages(
let StateOutput { state_root, .. } = crate::state_manager::apply_block_messages(
genesis_timestamp,
Arc::clone(&chain_index),
Arc::clone(&chain_config),
Expand All @@ -353,9 +353,10 @@ where
Arc::clone(&heaviest_tipset),
crate::state_manager::NO_CALLBACK,
VMTrace::NotTraced,
EventCache::NotCached,
)
.map_err(|e| Error::Other(e.to_string()))?;
return Ok((heaviest_tipset, state));
return Ok((heaviest_tipset, state_root));
}

let next_ts = chain_index
Expand Down
2 changes: 2 additions & 0 deletions src/cli_shared/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct Client {
pub load_actors: bool,
/// `TTL` to set for Ethereum `Hash` to `Cid` entries or `None` to never reclaim them.
pub eth_mapping_ttl: Option<u32>,
pub enable_event_caching: bool,
}

impl Default for Client {
Expand Down Expand Up @@ -93,6 +94,7 @@ impl Default for Client {
),
load_actors: true,
eth_mapping_ttl: None,
enable_event_caching: true,
}
}
}
4 changes: 4 additions & 0 deletions src/cli_shared/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ impl Config {
pub fn db_config(&self) -> &DbConfig {
&self.parity_db
}

pub fn chain(&self) -> &NetworkChain {
&self.chain
}
}

#[cfg(test)]
Expand Down
6 changes: 6 additions & 0 deletions src/cli_shared/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ pub struct CliOpts {
/// Skip loading actors from the actors bundle.
#[arg(long)]
pub skip_load_actors: bool,
/// Cache events in the tipset state cache (default: true)
#[arg(long)]
pub enable_event_caching: Option<bool>,
}

impl CliOpts {
Expand Down Expand Up @@ -224,6 +227,9 @@ impl CliOpts {
}

cfg.client.load_actors = !self.skip_load_actors;
cfg.client.enable_event_caching = self
.enable_event_caching
.unwrap_or(cfg.client.enable_event_caching);

Ok((cfg, path))
}
Expand Down
10 changes: 5 additions & 5 deletions src/cli_shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use tikv_jemallocator;

/// Gets chain data directory
pub fn chain_path(config: &Config) -> PathBuf {
PathBuf::from(&config.client.data_dir).join(config.chain.to_string())
PathBuf::from(&config.client.data_dir).join(config.chain().to_string())
}

/// Gets car db path
Expand Down Expand Up @@ -57,23 +57,23 @@ mod tests {
let (config_path, config) = read_config(None, None).unwrap();

assert!(config_path.is_none());
assert_eq!(config.chain, NetworkChain::Mainnet);
assert_eq!(config.chain(), &NetworkChain::Mainnet);
}

#[test]
fn read_config_calibnet_override() {
let (config_path, config) = read_config(None, Some(NetworkChain::Calibnet)).unwrap();

assert!(config_path.is_none());
assert_eq!(config.chain, NetworkChain::Calibnet);
assert_eq!(config.chain(), &NetworkChain::Calibnet);
}

#[test]
fn read_config_butterflynet_override() {
let (config_path, config) = read_config(None, Some(NetworkChain::Butterflynet)).unwrap();

assert!(config_path.is_none());
assert_eq!(config.chain, NetworkChain::Butterflynet);
assert_eq!(config.chain(), &NetworkChain::Butterflynet);
}

#[test]
Expand All @@ -86,7 +86,7 @@ mod tests {
let (config_path, config) = read_config(Some(&path), None).unwrap();

assert_eq!(config_path.unwrap(), ConfigPath::Cli(path));
assert_eq!(config.chain, NetworkChain::Mainnet);
assert_eq!(config.chain(), &NetworkChain::Mainnet);
assert_eq!(config, default_config);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
}
check_for_unknown_keys(path.to_path_buf(), &cfg);
} else {
info!("Using default {} config", cfg.chain);
info!("Using default {} config", cfg.chain());
}
if opts.dry_run {
return Ok(());
Expand Down
14 changes: 9 additions & 5 deletions src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(super) async fn start(
config: Config,
shutdown_send: mpsc::Sender<()>,
) -> anyhow::Result<()> {
let chain_config = Arc::new(ChainConfig::from_chain(&config.chain));
let chain_config = Arc::new(ChainConfig::from_chain(config.chain()));
if chain_config.is_testnet() {
CurrentNetwork::set_global(Network::Testnet);
}
Expand Down Expand Up @@ -189,7 +189,7 @@ pub(super) async fn start(
load_all_forest_cars(&db, &forest_car_db_dir)?;

if config.client.load_actors && !opts.stateless {
load_actor_bundles(&db, &config.chain).await?;
load_actor_bundles(&db, config.chain()).await?;
}

let mut services = JoinSet::new();
Expand Down Expand Up @@ -289,14 +289,15 @@ pub(super) async fn start(
Arc::clone(&chain_store),
Arc::clone(&chain_config),
Arc::new(config.sync.clone()),
config.client.enable_event_caching,
)?;

let state_manager = Arc::new(sm);

let network_name = get_network_name_from_genesis(&genesis_header, &state_manager)?;

info!("Using network :: {}", get_actual_chain_name(&network_name));
utils::misc::display_chain_logo(&config.chain);
utils::misc::display_chain_logo(config.chain());
let (tipset_sender, tipset_receiver) = flume::bounded(20);

// if bootstrap peers are not set, set them
Expand Down Expand Up @@ -424,7 +425,10 @@ pub(super) async fn start(
))
.expect("F3 lease manager should not have been initialized before");
let chain_config = chain_config.clone();
let default_f3_root = config.client.data_dir.join(format!("f3/{}", config.chain));
let default_f3_root = config
.client
.data_dir
.join(format!("f3/{}", config.chain()));
let crate::f3::F3Options {
chain_finality,
bootstrap_epoch,
Expand Down Expand Up @@ -553,7 +557,7 @@ async fn set_snapshot_path_if_needed(
}

let vendor = snapshot::TrustedVendor::default();
let chain = &config.chain;
let chain = config.chain();

// What height is our chain at right now, and what network version does that correspond to?
let network_version = chain_config.network_version(epoch);
Expand Down
5 changes: 3 additions & 2 deletions src/db/migration/v0_19_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async fn create_state_manager_and_populate(config: Config, db_name: String) -> a
let forest_car_db_dir = db_root_dir.join(CAR_DB_DIR_NAME);
load_all_forest_cars(&db, &forest_car_db_dir)?;

let chain_config = Arc::new(ChainConfig::from_chain(&config.chain));
let chain_config = Arc::new(ChainConfig::from_chain(config.chain()));

let genesis_header = read_genesis_header(
config.client.genesis_file.as_deref(),
Expand All @@ -173,8 +173,9 @@ async fn create_state_manager_and_populate(config: Config, db_name: String) -> a

let state_manager = StateManager::new(
Arc::clone(&chain_store),
Arc::clone(&chain_config),
chain_config,
Arc::new(config.sync.clone()),
false,
)?;

populate_eth_mappings(&state_manager, &chain_store.heaviest_tipset())?;
Expand Down
32 changes: 29 additions & 3 deletions src/interpreter/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::networks::{ChainConfig, NetworkChain};
use crate::shim::{
address::Address,
econ::TokenAmount,
executor::{ApplyRet, Receipt},
executor::{ApplyRet, Receipt, StampedEvent},
externs::{Rand, RandWrapper},
machine::MultiEngine,
message::{Message, Message_v3},
Expand Down Expand Up @@ -76,6 +76,8 @@ type ForestExecutorV4<DB> = DefaultExecutor_v4<ForestKernelV4<DB>>;

pub type ApplyResult = anyhow::Result<(ApplyRet, Duration)>;

pub type ApplyBlockResult = anyhow::Result<(Vec<Receipt>, Vec<Vec<StampedEvent>>), anyhow::Error>;

/// Comes from <https://github.com/filecoin-project/lotus/blob/v1.23.2/chain/vm/fvm.go#L473>
pub const IMPLICIT_MESSAGE_GAS_LIMIT: i64 = i64::MAX / 2;

Expand Down Expand Up @@ -351,8 +353,10 @@ where
messages: &[BlockMessages],
epoch: ChainEpoch,
mut callback: Option<impl FnMut(MessageCallbackCtx<'_>) -> anyhow::Result<()>>,
) -> Result<Vec<Receipt>, anyhow::Error> {
enable_event_caching: EventCache,
) -> ApplyBlockResult {
let mut receipts = Vec::new();
let mut events = Vec::new();
let mut processed = HashSet::<Cid>::default();

for block in messages.iter() {
Expand Down Expand Up @@ -383,6 +387,10 @@ where
let msg_receipt = ret.msg_receipt();
receipts.push(msg_receipt.clone());

if enable_event_caching.is_cached() {
events.push(ret.events());
}

// Add processed Cid to set of processed messages
processed.insert(cid);
Ok(())
Expand Down Expand Up @@ -428,7 +436,7 @@ where
tracing::error!("End of epoch cron failed to run: {}", e);
}

Ok(receipts)
Ok((receipts, events))
}

/// Applies single message through VM and returns result from execution.
Expand Down Expand Up @@ -590,3 +598,21 @@ impl VMTrace {
matches!(self, VMTrace::Traced)
}
}

/// Caching events will use more memory.
/// This controls whether we should cache or not events when a state transition is performed.
#[derive(Default, Clone, Copy)]
pub enum EventCache {
/// Store event in the tipset state cache
Cached,
/// Do not cache event
#[default]
NotCached,
}

impl EventCache {
/// Should event be kept in cache?
pub fn is_cached(&self) -> bool {
matches!(self, EventCache::Cached)
}
}
Loading
Loading