Skip to content

Commit

Permalink
Listen to all the chains in the wallet (linera-io#1058)
Browse files Browse the repository at this point in the history
* add UserChain::make_other

* listen to all chains in the Wallet
  • Loading branch information
ma2bd authored Oct 31, 2023
1 parent 97aa2d7 commit 96ea105
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion linera-service/src/chain_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
where
C: ClientContext<P> + Send + 'static,
{
let chain_ids = context.wallet_state().own_chain_ids();
let chain_ids = context.wallet_state().chain_ids();
let context = Arc::new(Mutex::new(context));
for chain_id in chain_ids {
Self::run_with_chain_id(
Expand Down
11 changes: 11 additions & 0 deletions linera-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ impl UserChain {
next_block_height: BlockHeight::ZERO,
}
}

/// Creates an entry for a chain that we don't own.
pub fn make_other(description: ChainDescription, timestamp: Timestamp) -> Self {
Self {
chain_id: description.into(),
key_pair: None,
block_hash: None,
timestamp,
next_block_height: BlockHeight::ZERO,
}
}
}

/// A wrapper around `InnerWalletState` which owns a [`FileLock`] to prevent
Expand Down
12 changes: 3 additions & 9 deletions linera-service/src/linera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ enum WalletCommand {
#[structopt(long = "genesis")]
genesis_config_path: PathBuf,

// Other chains to follow.
/// Other chains to follow.
#[structopt(long)]
with_other_chains: Vec<ChainId>,

Expand Down Expand Up @@ -2052,24 +2052,18 @@ async fn main() -> Result<(), anyhow::Error> {
testing_prng_seed,
} => {
let genesis_config = GenesisConfig::read(genesis_config_path)?;
let mut rng = Box::<dyn CryptoRng>::from(*testing_prng_seed);
let chains = with_other_chains
.iter()
.filter_map(|chain_id| {
let (description, _, _, timestamp) = genesis_config
.chains
.iter()
.find(|(desc, _, _, _)| ChainId::from(*desc) == *chain_id)?;
Some(UserChain::make_initial(&mut rng, *description, *timestamp))
Some(UserChain::make_other(*description, *timestamp))
})
.collect();
let new_prng_seed = if testing_prng_seed.is_some() {
Some(rng.gen())
} else {
None
};
let mut context =
ClientContext::create(&options, genesis_config, new_prng_seed, chains)?;
ClientContext::create(&options, genesis_config, *testing_prng_seed, chains)?;
context.save_wallet();
options.initialize_storage().await?;
Ok(())
Expand Down

0 comments on commit 96ea105

Please sign in to comment.