Skip to content

Commit

Permalink
[bridge] provide raw metadata for BridgeCommitteeRegistration commands (
Browse files Browse the repository at this point in the history
MystenLabs#17782)

## Description 

When validators register their info, most likely they don't have
BridgeNodeConfig yet. In this PR we provide the authority key path
directly to avoid depending on the config.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
longbowlu authored May 17, 2024
1 parent 398650a commit 3457cd3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
10 changes: 5 additions & 5 deletions crates/sui-bridge/src/sui_transaction_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use fastcrypto::traits::{KeyPair, ToFromBytes};
use fastcrypto::traits::ToFromBytes;
use move_core_types::ident_str;
use std::{collections::HashMap, str::FromStr};
use sui_types::bridge::{
Expand All @@ -17,7 +17,6 @@ use sui_types::{
};
use sui_types::{Identifier, BRIDGE_PACKAGE_ID};

use crate::crypto::BridgeAuthorityKeyPair;
use crate::{
error::{BridgeError, BridgeResult},
types::{BridgeAction, VerifiedCertifiedBridgeAction},
Expand Down Expand Up @@ -551,16 +550,17 @@ pub fn build_committee_register_transaction(
validator_address: SuiAddress,
gas_object_ref: &ObjectRef,
bridge_object_arg: ObjectArg,
bridge_key: BridgeAuthorityKeyPair,
bridge_authority_pub_key_bytes: Vec<u8>,
bridge_url: &str,
ref_gas_price: u64,
) -> BridgeResult<TransactionData> {
let mut builder = ProgrammableTransactionBuilder::new();
let system_state = builder.obj(ObjectArg::SUI_SYSTEM_MUT).unwrap();
let bridge = builder.obj(bridge_object_arg).unwrap();
let pub_key = bridge_key.public().as_bytes().to_vec();
let bridge_pubkey = builder
.input(CallArg::Pure(bcs::to_bytes(&pub_key).unwrap()))
.input(CallArg::Pure(
bcs::to_bytes(&bridge_authority_pub_key_bytes).unwrap(),
))
.unwrap();
let url = builder
.input(CallArg::Pure(bcs::to_bytes(bridge_url.as_bytes()).unwrap()))
Expand Down
4 changes: 2 additions & 2 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sui_swarm_config::network_config::NetworkConfig;
use sui_swarm_config::network_config_builder::ConfigBuilder;
use sui_swarm_config::node_config_builder::FullnodeConfigBuilder;
use sui_types::base_types::SuiAddress;
use sui_types::crypto::{SignatureScheme, SuiKeyPair};
use sui_types::crypto::{SignatureScheme, SuiKeyPair, ToFromBytes};
use tracing::info;

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -404,7 +404,7 @@ impl SuiCommand {
sui_address,
&gas_obj_ref,
bridge_arg,
kp,
kp.public().as_bytes().to_vec(),
&format!("http://127.0.0.1:{port}"),
rgp,
)
Expand Down
21 changes: 7 additions & 14 deletions crates/sui/src/validator_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ use fastcrypto::{
};
use serde::Serialize;
use shared_crypto::intent::{Intent, IntentMessage, IntentScope};
use sui_bridge::config::BridgeNodeConfig;
use sui_bridge::sui_client::SuiClient as SuiBridgeClient;
use sui_bridge::sui_transaction_builder::build_committee_register_transaction;
use sui_config::Config;
use sui_json_rpc_types::{
SuiObjectDataOptions, SuiTransactionBlockResponse, SuiTransactionBlockResponseOptions,
};
Expand Down Expand Up @@ -169,9 +167,9 @@ pub enum SuiValidatorCommand {
},
/// Sui native bridge committee member registration
BridgeCommitteeRegistration {
/// Path to bridge node config
/// Path to Bridge Authority Key file
#[clap(long)]
bridge_node_config_path: PathBuf,
bridge_authority_key_path: PathBuf,
/// Bridge authority URL which clients collects action signatures from
#[clap(long)]
bridge_authority_url: String,
Expand Down Expand Up @@ -469,24 +467,19 @@ impl SuiValidatorCommand {
}
}
SuiValidatorCommand::BridgeCommitteeRegistration {
bridge_node_config_path,
bridge_authority_key_path,
bridge_authority_url,
} => {
let bridge_config = match BridgeNodeConfig::load(bridge_node_config_path) {
Ok(config) => config,
Err(e) => panic!("Couldn't load BridgeNodeConfig, caused by: {e}"),
};
// Read bridge keypair
let ecdsa_keypair = match read_key(&bridge_config.bridge_authority_key_path, true)?
{
let ecdsa_keypair = match read_key(&bridge_authority_key_path, true)? {
SuiKeyPair::Secp256k1(key) => key,
_ => unreachable!("we required secp256k1 key in `read_key`"),
};

let address = context.active_address()?;
println!("Starting bridge committee registration for Sui validator: {address}, with bridge public key: {}", ecdsa_keypair.public);

let bridge_client = SuiBridgeClient::new(&bridge_config.sui.sui_rpc_url).await?;
let sui_rpc_url = &context.config.get_active_env().unwrap().rpc;
let bridge_client = SuiBridgeClient::new(sui_rpc_url).await?;
let bridge = bridge_client
.get_mutable_bridge_object_arg_must_succeed()
.await;
Expand All @@ -501,7 +494,7 @@ impl SuiValidatorCommand {
address,
&gas,
bridge,
ecdsa_keypair,
ecdsa_keypair.public().as_bytes().to_vec(),
&bridge_authority_url,
gas_price,
)
Expand Down
4 changes: 2 additions & 2 deletions crates/test-cluster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ use sui_types::bridge::{get_bridge, TOKEN_ID_BTC, TOKEN_ID_ETH, TOKEN_ID_USDC, T
use sui_types::bridge::{get_bridge_obj_initial_shared_version, BridgeSummary, BridgeTrait};
use sui_types::committee::CommitteeTrait;
use sui_types::committee::{Committee, EpochId};
use sui_types::crypto::KeypairTraits;
use sui_types::crypto::SuiKeyPair;
use sui_types::crypto::{KeypairTraits, ToFromBytes};
use sui_types::effects::{TransactionEffects, TransactionEvents};
use sui_types::error::SuiResult;
use sui_types::governance::MIN_VALIDATOR_JOINING_STAKE_MIST;
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl TestClusterBuilder {
validator_address,
&gas,
bridge_arg,
kp.copy(),
kp.public().as_bytes().to_vec(),
&server_url,
ref_gas_price,
)
Expand Down

0 comments on commit 3457cd3

Please sign in to comment.