This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cryptoAtwill
committed
Oct 17, 2023
1 parent
249675c
commit e9d0c6b
Showing
5 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
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,79 @@ | ||
// Copyright 2022-2023 Protocol Labs | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::commands::get_subnet_config; | ||
use crate::{CommandLineHandler, GlobalArguments}; | ||
use anyhow::anyhow; | ||
use async_trait::async_trait; | ||
use clap::Args; | ||
use fvm_shared::address::Address; | ||
use ipc_identity::EvmKeyStore; | ||
use ipc_provider::checkpoint::BottomUpCheckpointManager; | ||
use ipc_provider::new_evm_keystore_from_path; | ||
use ipc_sdk::subnet_id::SubnetID; | ||
use std::str::FromStr; | ||
use std::sync::{Arc, RwLock}; | ||
use std::time::Duration; | ||
|
||
const DEFAULT_CHECKPOINT_INTERVAL: u64 = 15; | ||
|
||
/// The command to run the bottom up relayer in the background. | ||
pub(crate) struct BottomUpRelayer; | ||
|
||
#[async_trait] | ||
impl CommandLineHandler for BottomUpRelayer { | ||
type Arguments = BottomUpRelayerArgs; | ||
|
||
async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> { | ||
log::debug!("start bottom up relayer with args: {:?}", arguments); | ||
|
||
let config_path = global.config_path(); | ||
|
||
let mut keystore = new_evm_keystore_from_path(&config_path)?; | ||
let validator = match (arguments.validator.as_ref(), keystore.get_default()?) { | ||
(Some(validator), _) => Address::from_str(validator)?, | ||
(None, Some(addr)) => { | ||
log::info!("using default address: {addr:?}"); | ||
Address::try_from(addr)? | ||
} | ||
_ => { | ||
return Err(anyhow!("no validator address provided")); | ||
} | ||
}; | ||
|
||
let subnet = SubnetID::from_str(&arguments.subnet)?; | ||
let parent = subnet | ||
.parent() | ||
.ok_or_else(|| anyhow!("root does not have parent"))?; | ||
|
||
let child = get_subnet_config(&config_path, &subnet)?; | ||
let parent = get_subnet_config(&config_path, &parent)?; | ||
|
||
let manager = BottomUpCheckpointManager::new_evm_manager( | ||
parent.clone(), | ||
child.clone(), | ||
Arc::new(RwLock::new(keystore)), | ||
) | ||
.await?; | ||
|
||
let interval = Duration::from_secs( | ||
arguments | ||
.checkpoint_interval_sec | ||
.unwrap_or(DEFAULT_CHECKPOINT_INTERVAL), | ||
); | ||
manager.run(validator, interval).await; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
#[command(about = "Start the bottom up relayer")] | ||
pub(crate) struct BottomUpRelayerArgs { | ||
#[arg(long, short, help = "The subnet id of the checkpointing subnet")] | ||
pub subnet: String, | ||
#[arg(long, short, help = "The number of seconds to submit checkpoint")] | ||
pub checkpoint_interval_sec: Option<u64>, | ||
#[arg(long, short, help = "The hex encoded address of the validator")] | ||
pub validator: Option<String>, | ||
} |
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