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

Add cli flag for thea foreign chain connector #752

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions clients/thea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ where
pub marker: PhantomData<B>,
/// Defines the chain type our current deployment ( Dev or production )
pub chain_type: ChainType,
/// Foreign Chain URL
pub foreign_chain_url: String,
}

/// Start the Thea gadget.
Expand All @@ -133,6 +135,7 @@ where
is_validator,
marker: _,
chain_type,
foreign_chain_url,
} = ob_params;

let sync_oracle = network.clone();
Expand All @@ -151,7 +154,8 @@ where
},
);

let foreign_connector = get_connector(chain_type, is_validator).await.connector;
let foreign_connector =
get_connector(chain_type, is_validator, foreign_chain_url).await.connector;

let worker_params = worker::WorkerParams {
client,
Expand All @@ -175,7 +179,7 @@ pub struct Connector {
connector: Arc<dyn ForeignConnector>,
}

pub async fn get_connector(chain_type: ChainType, is_validator: bool) -> Connector {
pub async fn get_connector(chain_type: ChainType, is_validator: bool, url: String) -> Connector {
log::info!(target:"thea","Assigning connector based on chain type: {:?}",chain_type);
if !is_validator {
return Connector { connector: Arc::new(NoOpConnector) }
Expand All @@ -184,7 +188,7 @@ pub async fn get_connector(chain_type: ChainType, is_validator: bool) -> Connect
ChainType::Development => Connector { connector: Arc::new(NoOpConnector) },
_ => Connector {
connector: Arc::new(
ParachainClient::connect("ws://127.0.0.1:9902".to_string())
ParachainClient::connect(url)
.await
.expect("Expected to connect to local foreign node"),
),
Expand Down
3 changes: 3 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct Cli {
#[allow(missing_docs)]
#[clap(flatten)]
pub run: RunCmd,
/// Thea expects foreign chain to run in this url
#[arg(short, long, default_value_t = String::from("ws://127.0.0.1:9902"))]
pub foreign_chain_url: String,
}

#[derive(Debug, clap::Subcommand)]
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn run() -> Result<()> {
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
service::new_full(config).map_err(sc_cli::Error::Service)
service::new_full(config, cli.foreign_chain_url).map_err(sc_cli::Error::Service)
})
},
// Some(Subcommand::Inspect(cmd)) => {
Expand Down
13 changes: 10 additions & 3 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub struct NewFullBase {
/// Creates a full service from the configuration.
pub fn new_full_base(
mut config: Configuration,
foreign_chain_url: String,
with_startup_data: impl FnOnce(
&sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
&sc_consensus_babe::BabeLink<Block>,
Expand Down Expand Up @@ -610,6 +611,7 @@ pub fn new_full_base(
marker: Default::default(),
is_validator: role.is_authority(),
chain_type,
foreign_chain_url,
};

// Thea task
Expand All @@ -624,8 +626,12 @@ pub fn new_full_base(
}

/// Builds a new service for a full client.
pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
new_full_base(config, |_, _| ()).map(|NewFullBase { task_manager, .. }| task_manager)
pub fn new_full(
config: Configuration,
foreign_chain_url: String,
) -> Result<TaskManager, ServiceError> {
new_full_base(config, foreign_chain_url, |_, _| ())
.map(|NewFullBase { task_manager, .. }| task_manager)
}

#[cfg(test)]
Expand Down Expand Up @@ -693,6 +699,7 @@ mod tests {
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
new_full_base(
config,
"blah".to_string(),
|block_import: &sc_consensus_babe::BabeBlockImport<Block, _, _>,
babe_link: &sc_consensus_babe::BabeLink<Block>| {
setup_handles = Some((block_import.clone(), babe_link.clone()));
Expand Down Expand Up @@ -868,7 +875,7 @@ mod tests {
crate::chain_spec::tests::integration_test_config_with_two_authorities(),
|config| {
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
new_full_base(config, |_, _| ())?;
new_full_base(config, "blah".to_string(), |_, _| ())?;
Gauthamastro marked this conversation as resolved.
Show resolved Hide resolved
Ok(sc_service_test::TestNetComponents::new(
task_manager,
client,
Expand Down
Loading