Skip to content

Commit

Permalink
feat(minor-multisig-prover)!: remove automatic worker set rotation (#295
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fish-sammy authored Mar 9, 2024
1 parent f2e7f17 commit 8d91126
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 170 deletions.
4 changes: 1 addition & 3 deletions contracts/multisig-prover/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
match msg {
ExecuteMsg::ConstructProof { message_ids } => {
execute::construct_proof(deps, env, message_ids)
}
ExecuteMsg::ConstructProof { message_ids } => execute::construct_proof(deps, message_ids),
ExecuteMsg::UpdateWorkerSet {} => execute::update_worker_set(deps, env),
ExecuteMsg::ConfirmWorkerSet {} => execute::confirm_worker_set(deps),
}
Expand Down
21 changes: 6 additions & 15 deletions contracts/multisig-prover/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{

pub fn construct_proof(
deps: DepsMut,
env: Env,
message_ids: Vec<CrossChainId>,
) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
Expand All @@ -35,21 +34,8 @@ pub fn construct_proof(
let command_batch = match COMMANDS_BATCH.may_load(deps.storage, &batch_id)? {
Some(batch) => batch,
None => {
let new_worker_set = get_next_worker_set(&deps, &env, &config)?;
let mut builder = CommandBatchBuilder::new(config.destination_chain_id, config.encoder);

if let Some(new_worker_set) = new_worker_set {
match save_next_worker_set(deps.storage, &new_worker_set) {
Ok(()) => {
builder.add_new_worker_set(new_worker_set)?;
}
Err(ContractError::WorkerSetConfirmationInProgress) => {}
Err(other_error) => {
return Err(other_error);
}
}
}

for msg in messages {
builder.add_message(msg)?;
}
Expand All @@ -64,7 +50,12 @@ pub fn construct_proof(
// keep track of the batch id to use during submessage reply
REPLY_BATCH.save(deps.storage, &command_batch.id)?;

let worker_set_id = CURRENT_WORKER_SET.load(deps.storage)?.id();
let worker_set_id = match CURRENT_WORKER_SET.may_load(deps.storage)? {
Some(worker_set) => worker_set.id(),
None => {
return Err(ContractError::NoWorkerSet);
}
};
let start_sig_msg = multisig::msg::ExecuteMsg::StartSigningSession {
worker_set_id,
msg: command_batch.msg_digest(),
Expand Down
33 changes: 14 additions & 19 deletions integration-tests/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,6 @@ pub fn deregister_workers(
}
}

pub fn update_worker_set(app: &mut App, relayer_addr: Addr, multisig_prover: Addr) -> AppResponse {
let response = app.execute_contract(
relayer_addr.clone(),
multisig_prover.clone(),
&multisig_prover::msg::ExecuteMsg::UpdateWorkerSet,
&[],
);

assert!(response.is_ok());

response.unwrap()
}

pub fn confirm_worker_set(app: &mut App, relayer_addr: Addr, multisig_prover: Addr) {

Check warning on line 496 in integration-tests/tests/test_utils/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

function `confirm_worker_set` is never used
let response = app.execute_contract(
relayer_addr.clone(),
Expand Down Expand Up @@ -594,7 +581,7 @@ pub fn create_new_workers_vec(
.collect()
}

pub fn update_registry_and_construct_proof(
pub fn update_registry_and_construct_worker_set_update_proof(

Check warning on line 584 in integration-tests/tests/test_utils/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

function `update_registry_and_construct_worker_set_update_proof` is never used
protocol: &mut Protocol,
new_workers: &Vec<Worker>,
workers_to_remove: &Vec<Worker>,
Expand Down Expand Up @@ -623,13 +610,21 @@ pub fn update_registry_and_construct_proof(
protocol.service_name.clone(),
);

// Construct proof and sign
construct_proof_and_sign(
let response = protocol
.app
.execute_contract(
Addr::unchecked("relayer"),
chain_multisig_prover_address.clone(),
&multisig_prover::msg::ExecuteMsg::UpdateWorkerSet,
&[],
)
.unwrap();

sign_proof(
&mut protocol.app,
&chain_multisig_prover_address,
&protocol.multisig_address,
&Vec::<Message>::new(),
&current_workers,
current_workers,
response,
)
}

Expand Down
176 changes: 43 additions & 133 deletions integration-tests/tests/update_worker_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use connection_router_api::Message;
use cosmwasm_std::Addr;
use cw_multi_test::Executor;
use test_utils::Worker;
Expand Down Expand Up @@ -58,11 +57,15 @@ fn worker_set_can_be_initialized_and_then_manually_updated() {
protocol.service_name.clone(),
);

let response = test_utils::update_worker_set(
&mut protocol.app,
Addr::unchecked("relayer"),
ethereum.multisig_prover_address.clone(),
);
let response = protocol
.app
.execute_contract(
Addr::unchecked("relayer"),
ethereum.multisig_prover_address.clone(),
&multisig_prover::msg::ExecuteMsg::UpdateWorkerSet,
&[],
)
.unwrap();

// sign with old workers
let session_id = test_utils::sign_proof(
Expand Down Expand Up @@ -120,7 +123,7 @@ fn worker_set_can_be_initialized_and_then_manually_updated() {
}

#[test]
fn worker_set_can_be_initialized_and_then_automatically_updated_during_proof_construction() {
fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed() {
let chains = vec![
"Ethereum".to_string().try_into().unwrap(),
"Polygon".to_string().try_into().unwrap(),
Expand All @@ -135,35 +138,24 @@ fn worker_set_can_be_initialized_and_then_automatically_updated_during_proof_con

assert_eq!(worker_set, simulated_worker_set);

// add third and fourth worker
let mut new_workers = Vec::new();
let new_worker = Worker {
addr: Addr::unchecked("worker3"),
supported_chains: chains.clone(),
key_pair: test_utils::generate_key(2),
};
new_workers.push(new_worker);
let new_worker = Worker {
addr: Addr::unchecked("worker4"),
supported_chains: chains.clone(),
key_pair: test_utils::generate_key(3),
};
new_workers.push(new_worker);

let expected_new_worker_set = test_utils::workers_to_worker_set(&mut protocol, &new_workers);
// creating a new worker set that only consists of two new workers
let first_wave_of_new_workers = test_utils::create_new_workers_vec(
chains.clone(),
vec![("worker3".to_string(), 2), ("worker4".to_string(), 3)],
);

test_utils::register_workers(
&mut protocol.app,
protocol.service_registry_address.clone(),
protocol.multisig_address.clone(),
protocol.governance_address.clone(),
protocol.genesis_address.clone(),
&new_workers,
&first_wave_of_new_workers,
protocol.service_name.clone(),
min_worker_bond,
);

// remove old workers
// Deregister old workers
test_utils::deregister_workers(
&mut protocol.app,
protocol.service_registry_address.clone(),
Expand All @@ -172,94 +164,21 @@ fn worker_set_can_be_initialized_and_then_automatically_updated_during_proof_con
protocol.service_name.clone(),
);

let session_id = test_utils::construct_proof_and_sign(
&mut protocol.app,
&ethereum.multisig_prover_address,
&protocol.multisig_address,
&Vec::<Message>::new(),
&initial_workers,
);

let proof = test_utils::get_proof(
&mut protocol.app,
&ethereum.multisig_prover_address,
&session_id,
);
assert!(matches!(
proof.status,
multisig_prover::msg::ProofStatus::Completed { .. }
));

assert_eq!(proof.message_ids.len(), 0);

let (poll_id, expiry) = test_utils::create_worker_set_poll(
&mut protocol.app,
Addr::unchecked("relayer"),
ethereum.voting_verifier_address.clone(),
expected_new_worker_set.clone(),
);
let response = protocol
.app
.execute_contract(
Addr::unchecked("relayer"),
ethereum.multisig_prover_address.clone(),
&multisig_prover::msg::ExecuteMsg::UpdateWorkerSet,
&[],
)
.unwrap();

// do voting
test_utils::vote_true_for_worker_set(
&mut protocol.app,
&ethereum.voting_verifier_address,
&new_workers,
poll_id,
);

test_utils::advance_at_least_to_height(&mut protocol.app, expiry);

test_utils::end_poll(
&mut protocol.app,
&ethereum.voting_verifier_address,
poll_id,
);

test_utils::confirm_worker_set(
let session_id = test_utils::sign_proof(
&mut protocol.app,
Addr::unchecked("relayer"),
ethereum.multisig_prover_address.clone(),
);

let new_worker_set =
test_utils::get_worker_set(&mut protocol.app, &ethereum.multisig_prover_address);

assert_eq!(new_worker_set, expected_new_worker_set);
}

#[test]
fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed() {
let chains = vec![
"Ethereum".to_string().try_into().unwrap(),
"Polygon".to_string().try_into().unwrap(),
];
let (mut protocol, ethereum, _, initial_workers, min_worker_bond) =
test_utils::setup_test_case();

let simulated_worker_set = test_utils::workers_to_worker_set(&mut protocol, &initial_workers);

let worker_set =
test_utils::get_worker_set(&mut protocol.app, &ethereum.multisig_prover_address);

assert_eq!(worker_set, simulated_worker_set);

// creating a new worker set that only consists of two new workers
let first_wave_of_new_workers = test_utils::create_new_workers_vec(
chains.clone(),
vec![("worker3".to_string(), 2), ("worker4".to_string(), 3)],
);

let first_wave_worker_set =
test_utils::workers_to_worker_set(&mut protocol, &first_wave_of_new_workers);

// register the new workers (3 and 4), deregister all old workers, then create proof and get id
let session_id = test_utils::update_registry_and_construct_proof(
&mut protocol,
&first_wave_of_new_workers,
&initial_workers,
&protocol.multisig_address,
&initial_workers,
&ethereum.multisig_prover_address,
min_worker_bond,
response,
);

let proof = test_utils::get_proof(
Expand Down Expand Up @@ -287,39 +206,30 @@ fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed(
let second_wave_of_new_workers =
test_utils::create_new_workers_vec(chains.clone(), vec![("worker5".to_string(), 5)]);

let _second_wave_session_id = test_utils::update_registry_and_construct_proof(
&mut protocol,
test_utils::register_workers(
&mut protocol.app,
protocol.service_registry_address.clone(),
protocol.multisig_address.clone(),
protocol.governance_address.clone(),
protocol.genesis_address.clone(),
&second_wave_of_new_workers,
&first_wave_of_new_workers,
&initial_workers,
&ethereum.multisig_prover_address,
protocol.service_name.clone(),
min_worker_bond,
);

// confirm the first rotation's set of workers
test_utils::confirm_worker_set(
// Deregister old workers
test_utils::deregister_workers(
&mut protocol.app,
Addr::unchecked("relayer"),
ethereum.multisig_prover_address.clone(),
);

// get the latest worker set, it should be equal to the first wave worker set
let latest_worker_set =
test_utils::get_worker_set(&mut protocol.app, &ethereum.multisig_prover_address);
assert_eq!(latest_worker_set, first_wave_worker_set);

// attempt to confirm the second rotation
test_utils::execute_worker_set_poll(
&mut protocol,
&Addr::unchecked("relayer"),
&ethereum.voting_verifier_address,
&second_wave_of_new_workers,
protocol.service_registry_address.clone(),
protocol.governance_address.clone(),
&first_wave_of_new_workers,
protocol.service_name.clone(),
);

let response = protocol.app.execute_contract(
Addr::unchecked("relayer"),
ethereum.multisig_prover_address.clone(),
&multisig_prover::msg::ExecuteMsg::ConfirmWorkerSet,
&multisig_prover::msg::ExecuteMsg::UpdateWorkerSet,
&[],
);

Expand Down

0 comments on commit 8d91126

Please sign in to comment.