Skip to content

Commit b6d2c2f

Browse files
committed
Slash jailed validators
1 parent e3bed5f commit b6d2c2f

File tree

1 file changed

+30
-4
lines changed
  • contracts/provider/external-staking/src

1 file changed

+30
-4
lines changed

contracts/provider/external-staking/src/ibc.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use cosmwasm_std::{
99
use cw_storage_plus::Item;
1010
use mesh_apis::ibc::{
1111
ack_success, validate_channel_order, AckWrapper, AddValidator, AddValidatorsAck,
12-
ConsumerPacket, DistributeAck, ProtocolVersion, ProviderPacket, RemoveValidator,
13-
RemoveValidatorsAck,
12+
ConsumerPacket, DistributeAck, JailValidatorsAck, ProtocolVersion, ProviderPacket,
13+
RemoveValidator, RemoveValidatorsAck,
1414
};
1515

1616
use crate::contract::ExternalStakingContract;
@@ -149,8 +149,8 @@ pub fn ibc_packet_receive(
149149
let mut msgs = vec![];
150150
for RemoveValidator {
151151
valoper,
152-
end_height,
153-
end_time: _end_time,
152+
height: end_height,
153+
time: _end_time,
154154
} in to_remove
155155
{
156156
// Check that the validator is active at height and slash it if that is the case
@@ -170,6 +170,32 @@ pub fn ibc_packet_receive(
170170
let ack = ack_success(&RemoveValidatorsAck {})?;
171171
IbcReceiveResponse::new().set_ack(ack).add_messages(msgs)
172172
}
173+
ConsumerPacket::JailValidators(to_jail) => {
174+
let mut msgs = vec![];
175+
for RemoveValidator {
176+
valoper,
177+
height: end_height,
178+
time: _end_time,
179+
} in to_jail
180+
{
181+
// Check that the validator is active at height and slash it if that is the case
182+
let active = contract.val_set.is_active_validator_at_height(
183+
deps.storage,
184+
&valoper,
185+
end_height,
186+
)?;
187+
// We don't change the validator's state here, as that's currently not supported
188+
// (only Active and Tombstoned)
189+
if active {
190+
// slash the validator
191+
// TODO: Slash with a different slash ratio! (downtime / offline slash ratio)
192+
let msg = contract.handle_slashing(deps.storage, &valoper)?;
193+
msgs.push(msg);
194+
}
195+
}
196+
let ack = ack_success(&JailValidatorsAck {})?;
197+
IbcReceiveResponse::new().set_ack(ack).add_messages(msgs)
198+
}
173199
ConsumerPacket::Distribute { validator, rewards } => {
174200
let contract = ExternalStakingContract::new();
175201
let evt = contract.distribute_rewards(deps, &validator, rewards)?;

0 commit comments

Comments
 (0)