Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Aug 28, 2024
2 parents ff619ba + d6f734d commit 590ad89
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 831 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ At the moment this project **does not** adhere to
fields, `pallet_staking_extension::initial_signers`, `pallet_parameters::total_signers`, and
`pallet_parameters::threshold`, which are used to set up the initial threshold signing
configuration for the network.
- In [#1030](https://github.com/entropyxyz/entropy-core/pull/1030), the registration flow got
cleaned up. A lot of storage entries, events, and extrinsics were removed from the `Registry`
pallet. The genesis build config was also removed. Additionally, the `new/user/` HTTP endpoint in
the TSS was removed since it was no longer necessary.

### Added
- Jumpstart network ([#918](https://github.com/entropyxyz/entropy-core/pull/918))
Expand All @@ -34,8 +38,9 @@ At the moment this project **does not** adhere to
- Fix TSS `AccountId` keys in chainspec ([#993](https://github.com/entropyxyz/entropy-core/pull/993))

### Removed
- Remove `prune_registration` extrinsic ([#1022](https://github.com/entropyxyz/entropy-core/pull/1022))
- Remove `confirm_registered` extrinsic ([#1025](https://github.com/entropyxyz/entropy-core/pull/1025))
- Remove `prune_registration` extrinsic ([#1022](https://github.com/entropyxyz/entropy-core/pull/1022))
- Remove `confirm_registered` extrinsic ([#1025](https://github.com/entropyxyz/entropy-core/pull/1025))
- Remove old registration flow ([#1030](https://github.com/entropyxyz/entropy-core/pull/1030))

## [0.2.0](https://github.com/entropyxyz/entropy-core/compare/release/v0.1.0...release/v0.2.0) - 2024-07-11

Expand Down
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
95 changes: 11 additions & 84 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::{
EntropyConfig,
},
client::entropy::staking_extension::events::{EndpointChanged, ThresholdAccountChanged},
substrate::{get_registered_details, query_chain, submit_transaction_with_pair},
substrate::{get_registered_details, submit_transaction_with_pair},
user::{get_signers_from_chain, UserSignatureRequest},
Hasher,
};
Expand All @@ -49,7 +49,6 @@ use futures::{future, stream::StreamExt};
use sp_core::{sr25519, Pair};
use subxt::{
backend::legacy::LegacyRpcMethods,
events::EventsClient,
utils::{AccountId32 as SubxtAccountId32, H256},
Config, OnlineClient,
};
Expand All @@ -76,27 +75,15 @@ pub async fn register(
signature_request_keypair: sr25519::Pair,
program_account: SubxtAccountId32,
programs_data: BoundedVec<ProgramInstance>,
on_chain: bool,
) -> Result<([u8; VERIFYING_KEY_LENGTH], RegisteredInfo), ClientError> {
let registration_event = if on_chain {
put_register_request_on_chain(
api,
rpc,
signature_request_keypair.clone(),
program_account,
programs_data,
)
.await?
} else {
put_old_register_request_on_chain(
api,
rpc,
signature_request_keypair.clone(),
program_account,
programs_data,
)
.await?
};
let registration_event = put_register_request_on_chain(
api,
rpc,
signature_request_keypair.clone(),
program_account,
programs_data,
)
.await?;

let verifying_key = registration_event.1 .0;
let registered_info = get_registered_details(api, rpc, verifying_key.clone()).await?;
Expand Down Expand Up @@ -126,10 +113,7 @@ pub async fn sign(
) -> Result<RecoverableSignature, ClientError> {
let message_hash = Hasher::keccak(&message);

let registered_info =
get_registered_details(api, rpc, signature_verifying_key.to_vec()).await?;
let with_parent_key = registered_info.derivation_path.is_some();
let validators_info = get_signers_from_chain(api, rpc, with_parent_key).await?;
let validators_info = get_signers_from_chain(api, rpc).await?;

tracing::debug!("Validators info {:?}", validators_info);
let block_number = rpc.chain_get_header(None).await?.ok_or(ClientError::BlockNumber)?.number;
Expand Down Expand Up @@ -332,7 +316,7 @@ pub async fn put_register_request_on_chain(
) -> Result<entropy::registry::events::AccountRegistered, ClientError> {
tracing::debug!("Registering an account using on-chain flow.");

let registering_tx = entropy::tx().registry().register_on_chain(deployer, program_instances);
let registering_tx = entropy::tx().registry().register(deployer, program_instances);
let registered_events =
submit_transaction_with_pair(api, rpc, &signature_request_keypair, &registering_tx, None)
.await?;
Expand All @@ -348,63 +332,6 @@ pub async fn put_register_request_on_chain(
registered_event
}

/// Submits a transaction registering an account on-chain using the old off-chain flow.
#[tracing::instrument(
skip_all,
fields(
user_account = ?signature_request_keypair.public(),
)
)]
pub async fn put_old_register_request_on_chain(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
signature_request_keypair: sr25519::Pair,
deployer: SubxtAccountId32,
program_instances: BoundedVec<ProgramInstance>,
) -> Result<entropy::registry::events::AccountRegistered, ClientError> {
tracing::debug!("Registering an account using old off-chain flow.");

let registering_tx = entropy::tx().registry().register(deployer, program_instances);
submit_transaction_with_pair(api, rpc, &signature_request_keypair, &registering_tx, None)
.await?;

let account_id: SubxtAccountId32 = signature_request_keypair.public().into();

for _ in 0..50 {
let block_hash = rpc.chain_get_block_hash(None).await?;
let events =
EventsClient::new(api.clone()).at(block_hash.ok_or(ClientError::BlockHash)?).await?;
let registered_event = events.find::<entropy::registry::events::AccountRegistered>();
for event in registered_event.flatten() {
// check if the event belongs to this user
if event.0 == account_id {
return Ok(event);
}
}
std::thread::sleep(std::time::Duration::from_millis(1000));
}

Err(ClientError::RegistrationTimeout)
}

/// Check that the verfiying key from a new signature matches that in the from the
/// on-chain registration info for a given account
pub async fn check_verifying_key(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
verifying_key: VerifyingKey,
) -> Result<(), ClientError> {
let verifying_key_serialized = verifying_key.to_encoded_point(true).as_bytes().to_vec();

// Get the verifying key associated with this account, if it exist return ok
let registered_query =
entropy::storage().registry().registered(BoundedVec(verifying_key_serialized));
let query_registered_status = query_chain(api, rpc, registered_query, None).await;
query_registered_status?.ok_or(ClientError::NotRegistered)?;

Ok(())
}

/// Changes the endpoint of a validator
pub async fn change_endpoint(
api: &OnlineClient<EntropyConfig>,
Expand Down
22 changes: 4 additions & 18 deletions crates/client/src/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,11 @@ pub async fn get_registered_details(
) -> Result<RegisteredInfo, SubstrateError> {
tracing::info!("Querying chain for registration info.");

let registered_info_query =
entropy::storage().registry().registered(BoundedVec(verifying_key.clone()));
let registered_result = query_chain(api, rpc, registered_info_query, None).await?;
let registered_info_query = entropy::storage().registry().registered(BoundedVec(verifying_key));

let registration_info = if let Some(old_registration_info) = registered_result {
tracing::debug!("Found user in old `Registered` struct.");

old_registration_info
} else {
// We failed with the old registration path, let's try the new one
tracing::warn!("Didn't find user in old `Registered` struct, trying new one.");

let registered_info_query =
entropy::storage().registry().registered_on_chain(BoundedVec(verifying_key));

query_chain(api, rpc, registered_info_query, None)
.await?
.ok_or_else(|| SubstrateError::NotRegistered)?
};
let registration_info = query_chain(api, rpc, registered_info_query, None)
.await?
.ok_or_else(|| SubstrateError::NotRegistered)?;

Ok(registration_info)
}
Expand Down
2 changes: 0 additions & 2 deletions crates/client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ async fn test_remove_program_reference_counter() {
.unwrap();

// Register, using that program
let register_on_chain = true;
let (verifying_key, _registered_info) = register(
&api,
&rpc,
program_owner.clone(),
AccountId32(program_owner.public().0),
BoundedVec(vec![ProgramInstance { program_pointer, program_config: vec![] }]),
register_on_chain,
)
.await
.unwrap();
Expand Down
19 changes: 4 additions & 15 deletions crates/client/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,11 @@ pub struct UserSignatureRequest {
pub async fn get_signers_from_chain(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
with_parent_key: bool,
) -> Result<Vec<ValidatorInfo>, SubgroupGetError> {
let mut validators = if with_parent_key {
let signer_query = entropy::storage().staking_extension().signers();
query_chain(api, rpc, signer_query, None)
.await?
.ok_or_else(|| SubgroupGetError::ChainFetch("Get all validators error"))?
} else {
let all_validators_query = entropy::storage().session().validators();
let mut validators = query_chain(api, rpc, all_validators_query, None)
.await?
.ok_or_else(|| SubgroupGetError::ChainFetch("Get all validators error"))?;

validators.sort();
validators
};
let signer_query = entropy::storage().staking_extension().signers();
let mut validators = query_chain(api, rpc, signer_query, None)
.await?
.ok_or_else(|| SubgroupGetError::ChainFetch("Get all validators error"))?;

// TODO #898 For now we use a fix proportion of the number of validators as the threshold
let threshold = (validators.len() as f32 * 0.75) as usize;
Expand Down
6 changes: 1 addition & 5 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ enum CliCommand {
/// If giving a mnemonic it must be enclosed in quotes, eg: "--mnemonic-option "alarm mutual concert...""
#[arg(short, long)]
mnemonic_option: Option<String>,
/// Indicates that a user wants to register using the fully on-chain registration flow.
#[arg(long)]
on_chain: bool,
},
/// Ask the network to sign a given message
Sign {
Expand Down Expand Up @@ -186,7 +183,7 @@ pub async fn run_command(
let rpc = get_rpc(&endpoint_addr).await?;

match cli.command {
CliCommand::Register { mnemonic_option, programs, on_chain } => {
CliCommand::Register { mnemonic_option, programs } => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
Expand All @@ -211,7 +208,6 @@ pub async fn run_command(
program_keypair.clone(),
program_account,
BoundedVec(programs_info),
on_chain,
)
.await?;

Expand Down
9 changes: 0 additions & 9 deletions crates/threshold-signature-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@
//!
//! ### For the blockchain node
//!
//! #### `/user/new` - POST
//!
//! [crate::user::api::new_user()]
//!
//! Called by the off-chain worker (propagation pallet) during user registration.
//! This takes a parity scale encoded [entropy_shared::types::OcwMessageDkg] which tells us which
//! validators are in the registration group and will perform a DKG.
//!
//! ### For other instances of the threshold server
//!
//! Takes a [UserRegistrationInfo] containing the users account ID and associated keyshare, wrapped
Expand Down Expand Up @@ -176,7 +168,6 @@ impl AppState {
pub fn app(app_state: AppState) -> Router {
let mut routes = Router::new()
.route("/generate_network_key", post(generate_network_key))
.route("/user/new", post(new_user))
.route("/user/sign_tx", post(sign_tx))
.route("/signer/proactive_refresh", post(proactive_refresh))
.route("/validator/reshare", post(new_reshare))
Expand Down
Loading

0 comments on commit 590ad89

Please sign in to comment.