Skip to content

Commit

Permalink
Merge pull request #130 from osmosis-labs/f/valset-updates-2
Browse files Browse the repository at this point in the history
Sync `ValsetUpdate` members
  • Loading branch information
maurolacy authored Sep 28, 2023
2 parents d501412 + 7f49af9 commit fafecb0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 46 deletions.
13 changes: 3 additions & 10 deletions contracts/consumer/converter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ impl ConverterApi for ConverterContract<'_> {
&self,
ctx: ExecCtx,
additions: Vec<Validator>,
tombstones: Vec<Validator>,
tombstoned: Vec<String>,
) -> Result<Response, Self::Error> {
self.ensure_authorized(&ctx.deps, &ctx.info)?;

// 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",
Expand All @@ -368,14 +368,7 @@ impl ConverterApi for ConverterContract<'_> {
.collect::<Vec<String>>()
.join(","),
);
let event = event.add_attribute(
"tombstones",
tombstones
.iter()
.map(|v| v.address.clone())
.collect::<Vec<String>>()
.join(","),
);
let event = event.add_attribute("tombstoned", tombstoned.join(","));
let resp = Response::new()
.add_event(event)
.add_message(add_msg)
Expand Down
5 changes: 2 additions & 3 deletions contracts/consumer/converter/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ pub(crate) fn add_validators_msg(
pub(crate) fn tombstone_validators_msg(
env: &Env,
channel: &IbcChannel,
validators: &[Validator],
validators: &[String],
) -> Result<IbcMsg, ContractError> {
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)?,
Expand Down
7 changes: 1 addition & 6 deletions contracts/consumer/converter/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,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
Expand Down
24 changes: 17 additions & 7 deletions contracts/consumer/virtual-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,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<VirtualStakeCustomQuery>,
additions: &[Validator],
removals: &[Validator],
tombstones: &[Validator],
removals: &[String],
updated: &[Validator],
jailed: &[String],
unjailed: &[String],
tombstoned: &[String],
) -> Result<Response<VirtualStakeCustomMsg>, 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(),
Expand Down Expand Up @@ -445,12 +449,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,
),
}
}
Expand Down
19 changes: 6 additions & 13 deletions contracts/consumer/virtual-staking/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/converter_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait ConverterApi {
&self,
ctx: ExecCtx,
additions: Vec<Validator>,
tombstones: Vec<Validator>,
tombstoned: Vec<String>,
) -> Result<Response, Self::Error>;
}

Expand Down
18 changes: 12 additions & 6 deletions packages/apis/src/virtual_staking_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Validator>,
removals: Vec<Validator>,
tombstones: Vec<Validator>,
removals: Vec<String>,
updated: Vec<Validator>,
jailed: Vec<String>,
unjailed: Vec<String>,
tombstoned: Vec<String>,
},
}

0 comments on commit fafecb0

Please sign in to comment.