-
Notifications
You must be signed in to change notification settings - Fork 189
fix(rpc): backfill tipset messages from p2p network in a few RPC methods #6421
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
Changes from all commits
b741a6d
991411a
9a78ef9
4705b46
49559db
ff69dc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| 2k | ||
| APIs | ||
| backend | ||
| backfill | ||
| backport | ||
| benchmarking | ||
| blockstore | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ use crate::blocks::RawBlockHeader; | |
| use crate::blocks::{Block, CachingBlockHeader, Tipset, TipsetKey}; | ||
| use crate::chain::index::ResolveNullTipset; | ||
| use crate::chain::{ChainStore, ExportOptions, FilecoinSnapshotVersion, HeadChange}; | ||
| use crate::chain_sync::{get_full_tipset, load_full_tipset}; | ||
| use crate::cid_collections::CidHashSet; | ||
| use crate::ipld::DfsIter; | ||
| use crate::ipld::{CHAIN_EXPORT_STATUS, cancel_export, end_export, start_export}; | ||
|
|
@@ -30,6 +31,7 @@ use crate::shim::executor::Receipt; | |
| use crate::shim::message::Message; | ||
| use crate::utils::db::CborStoreExt as _; | ||
| use crate::utils::io::VoidAsyncWriter; | ||
| use crate::utils::misc::env::is_env_truthy; | ||
| use anyhow::{Context as _, Result}; | ||
| use cid::Cid; | ||
| use fvm_ipld_blockstore::Blockstore; | ||
|
|
@@ -294,7 +296,7 @@ impl RpcMethod<1> for ChainGetParentMessages { | |
| type Ok = Vec<ApiMessage>; | ||
|
|
||
| async fn handle( | ||
| ctx: Ctx<impl Blockstore>, | ||
| ctx: Ctx<impl Blockstore + Send + Sync + 'static>, | ||
| (block_cid,): Self::Params, | ||
| ) -> Result<Self::Ok, ServerError> { | ||
| let store = ctx.store(); | ||
|
|
@@ -305,7 +307,7 @@ impl RpcMethod<1> for ChainGetParentMessages { | |
| Ok(vec![]) | ||
| } else { | ||
| let parent_tipset = Tipset::load_required(store, &block_header.parents)?; | ||
| load_api_messages_from_tipset(store, &parent_tipset) | ||
| load_api_messages_from_tipset(&ctx, parent_tipset.key()).await | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -368,13 +370,13 @@ impl RpcMethod<1> for ChainGetMessagesInTipset { | |
| type Ok = Vec<ApiMessage>; | ||
|
|
||
| async fn handle( | ||
| ctx: Ctx<impl Blockstore>, | ||
| ctx: Ctx<impl Blockstore + Send + Sync + 'static>, | ||
| (ApiTipsetKey(tipset_key),): Self::Params, | ||
| ) -> Result<Self::Ok, ServerError> { | ||
| let tipset = ctx | ||
| .chain_store() | ||
| .load_required_tipset_or_heaviest(&tipset_key)?; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small doubt: Is it possible here that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Messages are periodically garbage collected.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block headers are the spine of the chain that are never garbage collected |
||
| load_api_messages_from_tipset(ctx.store(), &tipset) | ||
| load_api_messages_from_tipset(&ctx, tipset.key()).await | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1314,13 +1316,30 @@ pub(crate) fn chain_notify<DB: Blockstore>( | |
| receiver | ||
| } | ||
|
|
||
| fn load_api_messages_from_tipset( | ||
| store: &impl Blockstore, | ||
| tipset: &Tipset, | ||
| async fn load_api_messages_from_tipset<DB: Blockstore + Send + Sync + 'static>( | ||
| ctx: &crate::rpc::RPCState<DB>, | ||
| tipset_keys: &TipsetKey, | ||
| ) -> Result<Vec<ApiMessage>, ServerError> { | ||
| let full_tipset = tipset | ||
| .fill_from_blockstore(store) | ||
| .context("Failed to load full tipset")?; | ||
| static SHOULD_BACKFILL: LazyLock<bool> = LazyLock::new(|| { | ||
| let enabled = is_env_truthy("FOREST_RPC_BACKFILL_FULL_TIPSET_FROM_NETWORK"); | ||
| if enabled { | ||
| tracing::warn!( | ||
| "Full tipset backfilling from network is enabled via FOREST_RPC_BACKFILL_FULL_TIPSET_FROM_NETWORK, excessive disk and bandwidth usage is expected." | ||
| ); | ||
| } | ||
| enabled | ||
| }); | ||
| let full_tipset = if *SHOULD_BACKFILL { | ||
|
LesnyRumcajs marked this conversation as resolved.
|
||
| get_full_tipset( | ||
| &ctx.sync_network_context, | ||
| ctx.chain_store(), | ||
| None, | ||
| tipset_keys, | ||
| ) | ||
| .await? | ||
| } else { | ||
| load_full_tipset(ctx.chain_store(), tipset_keys)? | ||
| }; | ||
| let blocks = full_tipset.into_blocks(); | ||
| let mut messages = vec![]; | ||
| let mut seen = CidHashSet::default(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let's add some warning that enabling this might lead to excessive disk and bandwidth usage.
Also, let's add a CHANGELOG entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.