From 7f49af9752e0cf6db6e0a67ec848eefebcdfdf61 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 25 Sep 2023 10:43:42 +0200 Subject: [PATCH] Sync ValsetUpdate message fields with the SDK --- contracts/consumer/converter/src/contract.rs | 13 +++------- contracts/consumer/converter/src/ibc.rs | 5 ++-- contracts/consumer/converter/src/multitest.rs | 7 +----- .../consumer/virtual-staking/src/contract.rs | 24 +++++++++++++------ .../consumer/virtual-staking/src/multitest.rs | 19 +++++---------- packages/apis/src/converter_api.rs | 2 +- packages/apis/src/virtual_staking_api.rs | 18 +++++++++----- 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/contracts/consumer/converter/src/contract.rs b/contracts/consumer/converter/src/contract.rs index 1492cd54..bc77a80b 100644 --- a/contracts/consumer/converter/src/contract.rs +++ b/contracts/consumer/converter/src/contract.rs @@ -337,7 +337,7 @@ impl ConverterApi for ConverterContract<'_> { &self, ctx: ExecCtx, additions: Vec, - tombstones: Vec, + tombstoned: Vec, ) -> Result { let virtual_stake = self.virtual_stake.load(ctx.deps.storage)?; ensure_eq!( @@ -349,7 +349,7 @@ impl ConverterApi for ConverterContract<'_> { // Send over IBC to the Consumer let channel = IBC_CHANNEL.load(ctx.deps.storage)?; let add_msg = add_validators_msg(&ctx.env, &channel, &additions)?; - let tomb_msg = tombstone_validators_msg(&ctx.env, &channel, &tombstones)?; + let tomb_msg = tombstone_validators_msg(&ctx.env, &channel, &tombstoned)?; let event = Event::new("valset_update").add_attribute( "additions", @@ -359,14 +359,7 @@ impl ConverterApi for ConverterContract<'_> { .collect::>() .join(","), ); - let event = event.add_attribute( - "tombstones", - tombstones - .iter() - .map(|v| v.address.clone()) - .collect::>() - .join(","), - ); + let event = event.add_attribute("tombstoned", tombstoned.join(",")); let resp = Response::new() .add_event(event) .add_message(add_msg) diff --git a/contracts/consumer/converter/src/ibc.rs b/contracts/consumer/converter/src/ibc.rs index e777759f..32bda7ea 100644 --- a/contracts/consumer/converter/src/ibc.rs +++ b/contracts/consumer/converter/src/ibc.rs @@ -148,10 +148,9 @@ pub(crate) fn add_validators_msg( pub(crate) fn tombstone_validators_msg( env: &Env, channel: &IbcChannel, - validators: &[Validator], + validators: &[String], ) -> Result { - let updates = validators.iter().map(|v| v.address.clone()).collect(); - let packet = ConsumerPacket::RemoveValidators(updates); + let packet = ConsumerPacket::RemoveValidators(Vec::from(validators)); let msg = IbcMsg::SendPacket { channel_id: channel.endpoint.channel_id.clone(), data: to_binary(&packet)?, diff --git a/contracts/consumer/converter/src/multitest.rs b/contracts/consumer/converter/src/multitest.rs index 3885b9fc..a6849f49 100644 --- a/contracts/consumer/converter/src/multitest.rs +++ b/contracts/consumer/converter/src/multitest.rs @@ -237,12 +237,7 @@ fn valset_update_works() { max_change_rate: Default::default(), }, ]; - let rem_validators = vec![Validator { - address: "validator3".to_string(), - commission: Default::default(), - max_commission: Default::default(), - max_change_rate: Default::default(), - }]; + let rem_validators = vec!["validator3".to_string()]; // Check that only the virtual staking contract can call this handler let res = converter diff --git a/contracts/consumer/virtual-staking/src/contract.rs b/contracts/consumer/virtual-staking/src/contract.rs index 88ee4004..aa7acea9 100644 --- a/contracts/consumer/virtual-staking/src/contract.rs +++ b/contracts/consumer/virtual-staking/src/contract.rs @@ -139,22 +139,26 @@ impl VirtualStakingContract<'_> { * This is called every time there's a change of the active validator set. * */ + #[allow(clippy::too_many_arguments)] fn handle_valset_update( &self, deps: DepsMut, additions: &[Validator], - removals: &[Validator], - tombstones: &[Validator], + removals: &[String], + updated: &[Validator], + jailed: &[String], + unjailed: &[String], + tombstoned: &[String], ) -> Result, ContractError> { - // TODO: Store/process removals (and additions) locally, so that they are filtered out from + // TODO: Store/process removals, jailed and additions locally, so that they are filtered out from // the `bonded` list - let _ = removals; + let _ = (removals, updated, jailed, unjailed); // Send additions and tombstones to the Converter. Removals are non-permanent and ignored let cfg = self.config.load(deps.storage)?; let msg = converter_api::ExecMsg::ValsetUpdate { additions: additions.to_vec(), - tombstones: tombstones.to_vec(), + tombstoned: tombstoned.to_vec(), }; let msg = WasmMsg::Execute { contract_addr: cfg.converter.to_string(), @@ -359,12 +363,18 @@ pub fn sudo( SudoMsg::ValsetUpdate { additions, removals, - tombstones, + updated, + jailed, + unjailed, + tombstoned, } => VirtualStakingContract::new().handle_valset_update( deps, &additions, &removals, - &tombstones, + &updated, + &jailed, + &unjailed, + &tombstoned, ), } } diff --git a/contracts/consumer/virtual-staking/src/multitest.rs b/contracts/consumer/virtual-staking/src/multitest.rs index d8eb6a5d..90218716 100644 --- a/contracts/consumer/virtual-staking/src/multitest.rs +++ b/contracts/consumer/virtual-staking/src/multitest.rs @@ -147,22 +147,15 @@ fn valset_update_sudo() { max_change_rate: Default::default(), }, ]; - let rems = vec![Validator { - address: "cosmosval2".to_string(), - commission: Decimal::percent(2), - max_commission: Decimal::percent(20), - max_change_rate: Default::default(), - }]; - let tombs = vec![Validator { - address: "cosmosval3".to_string(), - commission: Decimal::percent(3), - max_commission: Decimal::percent(30), - max_change_rate: Default::default(), - }]; + let rems = vec!["cosmosval2".to_string()]; + let tombs = vec!["cosmosval3".to_string()]; let msg = SudoMsg::ValsetUpdate { additions: adds, removals: rems, - tombstones: tombs, + updated: vec![], + jailed: vec![], + unjailed: vec![], + tombstoned: tombs, }; let res = app diff --git a/packages/apis/src/converter_api.rs b/packages/apis/src/converter_api.rs index adbb1d07..ce79bb93 100644 --- a/packages/apis/src/converter_api.rs +++ b/packages/apis/src/converter_api.rs @@ -41,7 +41,7 @@ pub trait ConverterApi { &self, ctx: ExecCtx, additions: Vec, - tombstones: Vec, + tombstoned: Vec, ) -> Result; } diff --git a/packages/apis/src/virtual_staking_api.rs b/packages/apis/src/virtual_staking_api.rs index 98c32115..56f8ba86 100644 --- a/packages/apis/src/virtual_staking_api.rs +++ b/packages/apis/src/virtual_staking_api.rs @@ -36,13 +36,19 @@ pub enum SudoMsg { /// /// It should also withdraw all pending rewards here, and send them to the converter contract. Rebalance {}, - /// SudoMsg::ValsetUpdate{} should be called every time there's a validator set update: addition - /// of a new validator to the active validator set, removal of a validator from the - /// active validator set, or permanent removal (i.e. tombstoning) of a validator from the active - /// validator set. + /// SudoMsg::ValsetUpdate{} should be called every time there's a validator set update: + /// - Addition of a new validator to the active validator set. + /// - Temporary removal of a validator from the active set. (i.e. `unbonded` state). + /// - Update of validator data. + /// - Temporary removal of a validator from the active set due to jailing. Implies slashing. + /// - Addition of an existing validator to the active validator set. + /// - Permanent removal (i.e. tombstoning) of a validator from the active set. Implies slashing ValsetUpdate { additions: Vec, - removals: Vec, - tombstones: Vec, + removals: Vec, + updated: Vec, + jailed: Vec, + unjailed: Vec, + tombstoned: Vec, }, }