-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENG-842: Export topdown events (#871)
- Loading branch information
Showing
17 changed files
with
363 additions
and
247 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2022-2024 Protocol Labs | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use std::path::PathBuf; | ||
|
||
use crate::parse::parse_eth_address; | ||
use clap::{Args, Subcommand}; | ||
use fvm_shared::address::Address; | ||
use ipc_api::subnet_id::SubnetID; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct DebugArgs { | ||
#[command(subcommand)] | ||
pub command: DebugCommands, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum DebugCommands { | ||
/// IPC commands. | ||
Ipc { | ||
#[command(subcommand)] | ||
command: DebugIpcCommands, | ||
}, | ||
} | ||
|
||
#[derive(Subcommand, Debug, Clone)] | ||
pub enum DebugIpcCommands { | ||
/// Fetch topdown events from the parent and export them to JSON. | ||
/// | ||
/// This can be used to construct an upgrade to impute missing events. | ||
ExportTopDownEvents(Box<DebugExportTopDownEventsArgs>), | ||
} | ||
|
||
#[derive(Args, Debug, Clone)] | ||
pub struct DebugExportTopDownEventsArgs { | ||
/// Child subnet for with the events will be fetched | ||
#[arg(long, short)] | ||
pub subnet_id: SubnetID, | ||
|
||
/// Endpoint to the RPC of the child subnet's parent | ||
#[arg(long, short)] | ||
pub parent_endpoint: url::Url, | ||
|
||
/// HTTP basic authentication token. | ||
#[arg(long)] | ||
pub parent_auth_token: Option<String>, | ||
|
||
/// IPC gateway of the parent; 20 byte Ethereum address in 0x prefixed hex format | ||
#[arg(long, value_parser = parse_eth_address)] | ||
pub parent_gateway: Address, | ||
|
||
/// IPC registry of the parent; 20 byte Ethereum address in 0x prefixed hex format | ||
#[arg(long, value_parser = parse_eth_address)] | ||
pub parent_registry: Address, | ||
|
||
/// The first block to query for events. | ||
#[arg(long)] | ||
pub start_block_height: u64, | ||
|
||
/// The last block to query for events. | ||
#[arg(long)] | ||
pub end_block_height: u64, | ||
|
||
/// Location of the JSON file to write events to. | ||
#[arg(long)] | ||
pub events_file: PathBuf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2022-2024 Protocol Labs | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use anyhow::{anyhow, Context}; | ||
use fendermint_app_options::debug::{ | ||
DebugArgs, DebugCommands, DebugExportTopDownEventsArgs, DebugIpcCommands, | ||
}; | ||
use fendermint_vm_topdown::proxy::IPCProviderProxy; | ||
use ipc_provider::{ | ||
config::subnet::{EVMSubnet, SubnetConfig}, | ||
IpcProvider, | ||
}; | ||
|
||
use crate::cmd; | ||
|
||
cmd! { | ||
DebugArgs(self) { | ||
match &self.command { | ||
DebugCommands::Ipc { command } => command.exec(()).await, | ||
} | ||
} | ||
} | ||
|
||
cmd! { | ||
DebugIpcCommands(self) { | ||
match self { | ||
DebugIpcCommands::ExportTopDownEvents(args) => | ||
export_topdown_events(args).await | ||
} | ||
} | ||
} | ||
|
||
async fn export_topdown_events(args: &DebugExportTopDownEventsArgs) -> anyhow::Result<()> { | ||
// Configuration for the child subnet on the parent network, | ||
// based on how it's done in `run.rs` and the `genesis ipc from-parent` command. | ||
let parent_provider = IpcProvider::new_with_subnet( | ||
None, | ||
ipc_provider::config::Subnet { | ||
id: args | ||
.subnet_id | ||
.parent() | ||
.ok_or_else(|| anyhow!("subnet is not a child"))?, | ||
config: SubnetConfig::Fevm(EVMSubnet { | ||
provider_http: args.parent_endpoint.clone(), | ||
provider_timeout: None, | ||
auth_token: args.parent_auth_token.clone(), | ||
registry_addr: args.parent_registry, | ||
gateway_addr: args.parent_gateway, | ||
}), | ||
}, | ||
)?; | ||
|
||
let parent_proxy = IPCProviderProxy::new(parent_provider, args.subnet_id.clone()) | ||
.context("failed to create provider proxy")?; | ||
|
||
let events = fendermint_vm_topdown::sync::fetch_topdown_events( | ||
&parent_proxy, | ||
args.start_block_height, | ||
args.end_block_height, | ||
) | ||
.await | ||
.context("failed to fetch topdown events")?; | ||
|
||
let json = serde_json::to_string_pretty(&events)?; | ||
std::fs::write(&args.events_file, json)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.