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 network-jumpstart command to entropy-test-cli #1004

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ At the moment this project **does not** adhere to
- Set inital signers ([#971](https://github.com/entropyxyz/entropy-core/pull/971))
- Add parent key threshold dynamically ([#974](https://github.com/entropyxyz/entropy-core/pull/974))
- TSS attestation endpoint ([#1001](https://github.com/entropyxyz/entropy-core/pull/1001))
- Add `network-jumpstart` command to `entropy-test-cli` ([#1004](https://github.com/entropyxyz/entropy-core/pull/1004))

### Changed
- Fix TSS `AccountId` keys in chainspec ([#993](https://github.com/entropyxyz/entropy-core/pull/993))
Expand Down
28 changes: 28 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,31 @@ pub async fn change_threshold_accounts(
.ok_or(anyhow!("Error with transaction"))?;
Ok(result_event)
}

/// Trigger a network wide distributed key generation (DKG) event.
///
/// Fails if the network has already been jumpstarted.
pub async fn jumpstart_network(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
signer: sr25519::Pair,
) -> Result<(), ClientError> {
// In this case we don't care too much about the result because we're more interested in the
// `FinishedNetworkJumpStart` event, which happens later on.
let jump_start_request = entropy::tx().registry().jump_start_network();
let _result =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says in the doccomment that this fails if the network has already been jumpstarted. I can't see where that would happen. Isn't there also a case where the network is not yet ready to be jumpstarted because of too few validators? Or do we just manually decide when its ready by running this command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so what would happen is when we submit the jump_start_network() extrinsic we'd get back one of those errors instead of a success event (StartedNetworkJumpStart), and then we'd bail out of this function

submit_transaction_with_pair(api, rpc, &signer, &jump_start_request, None).await?;

let mut blocks_sub = api.blocks().subscribe_finalized().await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i didn't know about this, this is so much nicer that polling with a timer.


while let Some(block) = blocks_sub.next().await {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the jump start DKG fails? Im guessing we just wont get confirmations and this will hang forever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah right now it would just sit waiting for the event 😅

let block = block?;
let events = block.events().await?;

if events.has::<entropy::registry::events::FinishedNetworkJumpStart>()? {
break;
}
}

Ok(())
}
29 changes: 27 additions & 2 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use entropy_client::{
},
client::{
change_endpoint, change_threshold_accounts, get_accounts, get_api, get_programs, get_rpc,
register, sign, store_program, update_programs, VERIFYING_KEY_LENGTH,
jumpstart_network, register, sign, store_program, update_programs, VERIFYING_KEY_LENGTH,
},
};
use sp_core::{sr25519, Hasher, Pair};
Expand Down Expand Up @@ -76,7 +76,7 @@ enum CliCommand {
/// A name or mnemonic from which to derive a program modification keypair.
/// This is used to send the register extrinsic so it must be funded
/// If giving a name it must be preceded with "//", eg: "--mnemonic-option //Alice"
/// If giving a mnemonic it must be enclosed in quotes, eg: "--mnemonic-option "alarm mutual concert...""
/// If giving a mnemonic it must be enclosed in quotes, eg: "--mnemonic-option "alarm mutual concert...""
#[arg(short, long)]
mnemonic_option: Option<String>,
},
Expand Down Expand Up @@ -143,6 +143,17 @@ enum CliCommand {
},
/// Display a list of registered Entropy accounts
Status,
/// Triggers the network wide distributed key generation process.
///
/// A fully jumpstarted network is required for the on-chain registration flow to work
/// correctly.
///
/// Note: Any account may trigger the jumpstart process.
JumpstartNetwork {
/// The mnemonic for the signer which will trigger the jumpstart process.
#[arg(short, long)]
mnemonic_option: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR but i still think its insane that this isn't a positional argument

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't think it should be positional 😉 But we do need to refactor the CLI UX at some point, it's not as consistent or friendly as it can be

},
}

pub async fn run_command(
Expand Down Expand Up @@ -392,6 +403,20 @@ pub async fn run_command(

Ok("Threshold accounts changed".to_string())
},
CliCommand::JumpstartNetwork { mnemonic_option } => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
passed_mnemonic.unwrap_or("//Alice".to_string())
};

let signer = <sr25519::Pair as Pair>::from_string(&mnemonic, None)?;
println!("Account being used for jumpstart: {}", signer.public());

jumpstart_network(&api, &rpc, signer).await?;

Ok("Succesfully jumpstarted network.".to_string())
},
}
}

Expand Down
Loading