Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/slashing undelegations #35

Merged
merged 18 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/babylon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ publish = false
crate-type = ["cdylib", "rlib"]
# See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false
doctest = false

[[bin]]
name = "schema"
path = "src/bin/schema.rs"
bench = false
test = false

[features]
# Add feature "cranelift" to default if you need 32 bit or ARM support
Expand Down
10 changes: 9 additions & 1 deletion contracts/babylon/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn ibc_packet_receive(
pub(crate) mod ibc_packet {
use super::*;
use crate::state::config::CONFIG;
use babylon_apis::btc_staking_api::SlashedBtcDelegation;
use babylon_apis::ibc_consumer::{consumer_packet_data, ConsumerPacketData};
use babylon_apis::{
btc_staking_api::{
Expand Down Expand Up @@ -285,7 +286,14 @@ pub(crate) mod ibc_packet {
})
})
.collect::<StdResult<_>>()?,
slashed_del: vec![], // FIXME: Route this
slashed_del: btc_staking
.slashed_del
.iter()
.map(|d| SlashedBtcDelegation {
staking_tx_hash: d.staking_tx_hash.clone(),
recovered_fp_btc_sk: d.recovered_fp_btc_sk.clone(),
})
.collect(),
unbonded_del: btc_staking
.unbonded_del
.iter()
Expand Down
2 changes: 2 additions & 0 deletions contracts/btc-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ publish = false

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[[bin]]
name = "btcstaking-schema"
path = "src/bin/schema.rs"
test = false

[features]
# Add feature "cranelift" to default if you need 32 bit or ARM support
Expand Down
9 changes: 7 additions & 2 deletions contracts/btc-staking/schema/btc-staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
"type": "string"
},
"BtcUndelegationInfo": {
"description": "BTCUndelegationInfo provides all necessary info about the undeleagation",
"description": "BTCUndelegationInfo provides all necessary info about the undelegation",
"type": "object",
"required": [
"covenant_slashing_sigs",
Expand Down Expand Up @@ -1396,7 +1396,7 @@
"type": "string"
},
"BtcUndelegationInfo": {
"description": "BTCUndelegationInfo provides all necessary info about the undeleagation",
"description": "BTCUndelegationInfo provides all necessary info about the undelegation",
"type": "object",
"required": [
"covenant_slashing_sigs",
Expand Down Expand Up @@ -1527,6 +1527,7 @@
"end_height",
"fp_btc_pk_list",
"params_version",
"slashed",
"slashing_tx",
"staker_addr",
"staking_output_idx",
Expand Down Expand Up @@ -1576,6 +1577,10 @@
"format": "uint32",
"minimum": 0.0
},
"slashed": {
"description": "slashed is used to indicate whether a given delegation is related to a slashed FP",
"type": "boolean"
},
"slashing_tx": {
"description": "slashing_tx is the slashing tx",
"type": "array",
Expand Down
2 changes: 1 addition & 1 deletion contracts/btc-staking/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"type": "string"
},
"BtcUndelegationInfo": {
"description": "BTCUndelegationInfo provides all necessary info about the undeleagation",
"description": "BTCUndelegationInfo provides all necessary info about the undelegation",
"type": "object",
"required": [
"covenant_slashing_sigs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"type": "string"
},
"BtcUndelegationInfo": {
"description": "BTCUndelegationInfo provides all necessary info about the undeleagation",
"description": "BTCUndelegationInfo provides all necessary info about the undelegation",
"type": "object",
"required": [
"covenant_slashing_sigs",
Expand Down
5 changes: 5 additions & 0 deletions contracts/btc-staking/schema/raw/response_to_delegations.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"end_height",
"fp_btc_pk_list",
"params_version",
"slashed",
"slashing_tx",
"staker_addr",
"staking_output_idx",
Expand Down Expand Up @@ -73,6 +74,10 @@
"format": "uint32",
"minimum": 0.0
},
"slashed": {
"description": "slashed is used to indicate whether a given delegation is related to a slashed FP",
"type": "boolean"
},
"slashing_tx": {
"description": "slashing_tx is the slashing tx",
"type": "array",
Expand Down
10 changes: 6 additions & 4 deletions contracts/btc-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ fn get_btc_tip_height(deps: &DepsMut) -> Result<u64, ContractError> {
let babylon_addr = CONFIG.load(deps.storage)?.babylon;

// Query the Babylon contract
// TODO: use raw query
// TODO: use a raw query for performance / efficiency
let query_msg = BabylonQueryMsg::BtcTipHeader {};
let tip: BtcHeaderResponse = deps.querier.query_wasm_smart(&babylon_addr, &query_msg)?;
let tip: BtcHeaderResponse = deps.querier.query_wasm_smart(babylon_addr, &query_msg)?;

Ok(tip.height)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ pub(crate) mod tests {
total_sat: del.total_sat,
staking_tx: Binary::new(del.staking_tx.to_vec()),
slashing_tx: Binary::new(del.slashing_tx.to_vec()),
delegator_slashing_sig: Binary::new(vec![]),
delegator_slashing_sig: Binary::new(del.delegator_sig.to_vec()),
covenant_sigs: del
.covenant_sigs
.iter()
Expand All @@ -334,7 +334,9 @@ pub(crate) mod tests {
undelegation_info: BtcUndelegationInfo {
unbonding_tx: Binary::new(btc_undelegation.unbonding_tx.to_vec()),
slashing_tx: Binary::new(btc_undelegation.slashing_tx.to_vec()),
delegator_unbonding_sig: Binary::new(vec![]),
delegator_unbonding_sig: Binary::new(
btc_undelegation.delegator_unbonding_sig.to_vec(),
),
delegator_slashing_sig: Binary::new(
btc_undelegation.delegator_slashing_sig.to_vec(),
),
Expand Down
Loading