diff --git a/contracts/babylon-finality/src/contract.rs b/contracts/babylon-finality/src/contract.rs index a4dd570d..55674139 100644 --- a/contracts/babylon-finality/src/contract.rs +++ b/contracts/babylon-finality/src/contract.rs @@ -1,10 +1,8 @@ -use babylon_contract::msg::btc_header::BtcHeaderResponse; - #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Deps, DepsMut, Empty, Env, MessageInfo, QueryResponse, Reply, Response, - StdResult, + to_json_binary, Addr, CustomQuery, Deps, DepsMut, Empty, Env, MessageInfo, QuerierWrapper, + QueryRequest, QueryResponse, Reply, Response, StdResult, WasmQuery, }; use cw2::set_contract_version; use cw_utils::{maybe_addr, nonpayable}; @@ -19,7 +17,7 @@ use crate::finality::{ use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::state::config::{Config, ADMIN, CONFIG, PARAMS}; use crate::{finality, queries, state}; -use babylon_contract::msg::contract::QueryMsg as BabylonQueryMsg; +use btc_staking::msg::ActivatedHeightResponse; pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -36,6 +34,7 @@ pub fn instantiate( let config = Config { denom, babylon: info.sender, + staking: Addr::unchecked("staking"), // TODO: instantiate staking contract and set address in reply }; CONFIG.save(deps.storage, &config)?; @@ -61,37 +60,6 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result Ok(to_json_binary(&queries::config(deps)?)?), QueryMsg::Params {} => Ok(to_json_binary(&queries::params(deps)?)?), QueryMsg::Admin {} => to_json_binary(&ADMIN.query_admin(deps)?).map_err(Into::into), - QueryMsg::FinalityProvider { btc_pk_hex } => Ok(to_json_binary( - &queries::finality_provider(deps, btc_pk_hex)?, - )?), - QueryMsg::FinalityProviders { start_after, limit } => Ok(to_json_binary( - &queries::finality_providers(deps, start_after, limit)?, - )?), - QueryMsg::Delegation { - staking_tx_hash_hex, - } => Ok(to_json_binary(&queries::delegation( - deps, - staking_tx_hash_hex, - )?)?), - QueryMsg::Delegations { - start_after, - limit, - active, - } => Ok(to_json_binary(&queries::delegations( - deps, - start_after, - limit, - active, - )?)?), - QueryMsg::DelegationsByFP { btc_pk_hex } => Ok(to_json_binary( - &queries::delegations_by_fp(deps, btc_pk_hex)?, - )?), - QueryMsg::FinalityProviderInfo { btc_pk_hex, height } => Ok(to_json_binary( - &queries::finality_provider_info(deps, btc_pk_hex, height)?, - )?), - QueryMsg::FinalityProvidersByPower { start_after, limit } => Ok(to_json_binary( - &queries::finality_providers_by_power(deps, start_after, limit)?, - )?), QueryMsg::FinalitySignature { btc_pk_hex, height } => Ok(to_json_binary( &queries::finality_signature(deps, btc_pk_hex, height)?, )?), @@ -115,7 +83,6 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result Ok(to_json_binary( &state::public_randomness::get_last_pub_rand_commit(deps.storage, &btc_pk_hex)?, )?), - QueryMsg::ActivatedHeight {} => Ok(to_json_binary(&queries::activated_height(deps)?)?), QueryMsg::Block { height } => Ok(to_json_binary(&queries::block(deps, height)?)?), QueryMsg::Blocks { start_after, @@ -153,20 +120,6 @@ pub fn execute( ExecuteMsg::UpdateAdmin { admin } => ADMIN .execute_update_admin(deps, info, maybe_addr(api, admin)?) .map_err(Into::into), - ExecuteMsg::BtcStaking { - new_fp, - active_del, - slashed_del, - unbonded_del, - } => handle_btc_staking( - deps, - env, - &info, - &new_fp, - &active_del, - &slashed_del, - &unbonded_del, - ), ExecuteMsg::SubmitFinalitySignature { fp_pubkey_hex, height, @@ -217,40 +170,13 @@ pub fn sudo( } fn handle_begin_block(deps: &mut DepsMut, env: Env) -> Result, ContractError> { - // Index BTC height at the current height - index_btc_height(deps, env.block.height)?; - // Compute active finality provider set let max_active_fps = PARAMS.load(deps.storage)?.max_active_finality_providers as usize; - compute_active_finality_providers(deps.storage, env, max_active_fps)?; + compute_active_finality_providers(deps, env, max_active_fps)?; Ok(Response::new()) } -// index_btc_height indexes the current BTC height, and saves it to the state -fn index_btc_height(deps: &mut DepsMut, height: u64) -> Result<(), ContractError> { - // FIXME: Turn this into a hard error. Requires `babylon-contract` instance, and up and running - // BTC light client loop (which requires a running BTC node / simulator) - let btc_tip_height = get_btc_tip_height(deps) //?; - .ok() - .unwrap_or_default(); - - Ok(BTC_HEIGHT.save(deps.storage, height, &btc_tip_height)?) -} - -/// get_btc_tip_height queries the Babylon contract for the latest BTC tip height -fn get_btc_tip_height(deps: &DepsMut) -> Result { - // Get the BTC tip from the babylon contract through a raw query - let babylon_addr = CONFIG.load(deps.storage)?.babylon; - - // Query the Babylon contract - // 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)?; - - Ok(tip.height) -} - fn handle_end_block( deps: &mut DepsMut, env: Env, @@ -259,8 +185,10 @@ fn handle_end_block( ) -> Result, ContractError> { // If the BTC staking protocol is activated i.e. there exists a height where at least one // finality provider has voting power, start indexing and tallying blocks + let cfg = CONFIG.load(deps.storage)?; let mut res = Response::new(); - if let Some(activated_height) = ACTIVATED_HEIGHT.may_load(deps.storage)? { + let activated_height = get_activated_height(&cfg.staking, &deps.querier)?; + if activated_height > 0 { // Index the current block let ev = finality::index_block(deps, env.block.height, &hex::decode(app_hash_hex)?)?; res = res.add_event(ev); @@ -271,6 +199,27 @@ fn handle_end_block( Ok(res) } +pub fn get_activated_height(staking_addr: &Addr, querier: &QuerierWrapper) -> StdResult { + // TODO: Use a raw query + let query = encode_smart_query( + staking_addr, + &btc_staking::msg::QueryMsg::ActivatedHeight {}, + )?; + let res: ActivatedHeightResponse = querier.query(&query)?; + Ok(res.height) +} + +pub(crate) fn encode_smart_query( + addr: &Addr, + msg: &btc_staking::msg::QueryMsg, +) -> StdResult> { + Ok(WasmQuery::Smart { + contract_addr: addr.to_string(), + msg: to_json_binary(&msg)?, + } + .into()) +} + #[cfg(test)] pub(crate) mod tests { use std::str::FromStr; diff --git a/contracts/babylon-finality/src/finality.rs b/contracts/babylon-finality/src/finality.rs index 654fc8af..d4ec7921 100644 --- a/contracts/babylon-finality/src/finality.rs +++ b/contracts/babylon-finality/src/finality.rs @@ -4,21 +4,23 @@ use k256::sha2::{Digest, Sha256}; use std::cmp::max; use std::collections::HashSet; -use cosmwasm_std::Order::Ascending; -use cosmwasm_std::{ - to_json_binary, DepsMut, Env, Event, Order, Response, StdResult, Storage, WasmMsg, -}; - +use crate::contract::encode_smart_query; use crate::error::ContractError; use crate::state::config::{CONFIG, PARAMS}; use crate::state::finality::{BLOCKS, EVIDENCES, FP_SET, NEXT_HEIGHT, SIGNATURES, TOTAL_POWER}; use crate::state::public_randomness::{ get_last_pub_rand_commit, get_pub_rand_commit_for_height, PUB_RAND_COMMITS, PUB_RAND_VALUES, }; +use babylon_apis::btc_staking_api::FinalityProvider; use babylon_apis::finality_api::{Evidence, IndexedBlock, PubRandCommit}; use babylon_bindings::BabylonMsg; use babylon_merkle::Proof; -use btc_staking::msg::FinalityProviderInfo; +use btc_staking::msg::{FinalityProviderInfo, FinalityProvidersByPowerResponse}; +use cosmwasm_std::Order::Ascending; +use cosmwasm_std::{ + to_json_binary, Addr, DepsMut, Env, Event, QuerierWrapper, Response, StdResult, Storage, + WasmMsg, +}; pub fn handle_public_randomness_commit( deps: DepsMut, @@ -38,7 +40,9 @@ pub fn handle_public_randomness_commit( // Ensure the finality provider is registered if !deps.querier.query_wasm_smart( CONFIG.load(deps.storage)?.staking, - btc_staking::msg::QueryMsg::FinalityProvider {}, + &btc_staking::msg::QueryMsg::FinalityProvider { + btc_pk_hex: fp_pubkey_hex.to_string(), + }, )? { return Err(ContractError::FinalityProviderNotFound( fp_pubkey_hex.to_string(), @@ -129,8 +133,9 @@ pub fn handle_finality_signature( signature: &[u8], ) -> Result, ContractError> { // Ensure the finality provider exists - let fp = deps.querier.query_wasm_smart( - CONFIG.load(deps.storage)?.staking, + let staking_addr = CONFIG.load(deps.storage)?.staking; + let fp: FinalityProvider = deps.querier.query_wasm_smart( + staking_addr.clone(), &btc_staking::msg::QueryMsg::FinalityProvider { btc_pk_hex: fp_btc_pk_hex.to_string(), }, @@ -161,21 +166,17 @@ pub fn handle_finality_signature( } // Ensure the finality provider has voting power at this height - // if fps() - // .may_load_at_height(deps.storage, fp_btc_pk_hex, height)? - // .ok_or_else(|| ContractError::NoVotingPower(fp_btc_pk_hex.to_string(), height))? - // .power - // == 0 - if deps.querier.query_wasm_smart( - CONFIG.load(deps.storage)?.staking, - btc_staking::msg::QueryMsg::FinalityProvider {}, - )? { - return Err(ContractError::NoVotingPower( - fp_btc_pk_hex.to_string(), - height, - )); - } - { + let fp: FinalityProviderInfo = deps + .querier + .query_wasm_smart( + staking_addr.clone(), + &btc_staking::msg::QueryMsg::FinalityProviderInfo { + btc_pk_hex: fp_btc_pk_hex.to_string(), + height: Some(height), + }, + ) + .map_err(|_| ContractError::NoVotingPower(fp_btc_pk_hex.to_string(), height))?; + if fp.power == 0 { return Err(ContractError::NoVotingPower( fp_btc_pk_hex.to_string(), height, @@ -247,8 +248,13 @@ pub fn handle_finality_signature( evidence.canonical_finality_sig = canonical_sig; // Slash this finality provider, including setting its voting power to zero, extracting // its BTC SK, and emitting an event - let (msg, ev) = slash_finality_provider(&mut deps, env, fp_btc_pk_hex, &evidence)?; - res = res.add_message(msg); + let (msgs, ev) = slash_finality_provider( + &mut deps, + &staking_addr.clone(), + fp_btc_pk_hex, + &evidence, + )?; + res = res.add_messages(msgs); res = res.add_event(ev); } // TODO?: Also slash if this finality provider has signed another fork before @@ -276,8 +282,9 @@ pub fn handle_finality_signature( // Slash this finality provider, including setting its voting power to zero, extracting its // BTC SK, and emitting an event - let (msg, ev) = slash_finality_provider(&mut deps, env, fp_btc_pk_hex, &evidence)?; - res = res.add_message(msg); + let (msgs, ev) = + slash_finality_provider(&mut deps, &staking_addr, fp_btc_pk_hex, &evidence)?; + res = res.add_messages(msgs); res = res.add_event(ev); } @@ -288,13 +295,21 @@ pub fn handle_finality_signature( /// its voting power to zero, extracting its BTC SK, and emitting an event fn slash_finality_provider( deps: &mut DepsMut, - env: Env, + staking_addr: &Addr, fp_btc_pk_hex: &str, evidence: &Evidence, -) -> Result<(WasmMsg, Event), ContractError> { +) -> Result<(Vec, Event), ContractError> { + let mut wasm_msgs = vec![]; // Slash this finality provider, i.e., set its slashing height to the block height - staking::slash_finality_provider(deps, env, fp_btc_pk_hex, evidence.block_height) - .map_err(|err| ContractError::FailedToSlashFinalityProvider(err.to_string()))?; + let msg = btc_staking::msg::ExecuteMsg::Slash { + fp_btc_pk_hex: fp_btc_pk_hex.to_string(), + }; + let staking_msg = WasmMsg::Execute { + contract_addr: staking_addr.to_string(), + msg: to_json_binary(&msg)?, + funds: vec![], + }; + wasm_msgs.push(staking_msg); // Extract BTC SK using the evidence let pk = eots::PublicKey::from_hex(fp_btc_pk_hex)?; @@ -317,11 +332,12 @@ fn slash_finality_provider( let babylon_addr = CONFIG.load(deps.storage)?.babylon; - let wasm_msg = WasmMsg::Execute { + let babylon_msg = WasmMsg::Execute { contract_addr: babylon_addr.to_string(), msg: to_json_binary(&msg)?, funds: vec![], }; + wasm_msgs.push(babylon_msg); let ev = Event::new("slashed_finality_provider") .add_attribute("module", "finality") @@ -341,7 +357,7 @@ fn slash_finality_provider( hex::encode(&evidence.fork_finality_sig), ) .add_attribute("secret_key", hex::encode(btc_sk.to_bytes())); - Ok((wasm_msg, ev)) + Ok((wasm_msgs, ev)) } /// Verifies the finality signature message w.r.t. the public randomness commitment: @@ -526,47 +542,67 @@ fn finalize_block( Ok(ev) } +const QUERY_LIMIT: Option = Some(30); + /// `compute_active_finality_providers` sorts all finality providers, counts the total voting /// power of top finality providers, and records them in the contract state pub fn compute_active_finality_providers( - storage: &mut dyn Storage, + deps: &mut DepsMut, env: Env, max_active_fps: usize, ) -> Result<(), ContractError> { - // Sort finality providers by power - let (finality_providers, running_total): (_, Vec<_>) = fps() - .idx - .power - .range(storage, None, None, Order::Descending) - .take(max_active_fps) - .scan(0u64, |acc, item| { - let (pk_hex, fp_state) = item.ok()?; // Error ends the iteration - - let fp_info = FinalityProviderInfo { - btc_pk_hex: pk_hex, - power: fp_state.power, - }; - *acc += fp_state.power; - Some((fp_info, *acc)) - }) - .filter(|(fp, _)| { - // Filter out FPs with no voting power - fp.power > 0 - }) - .unzip(); + let cfg = CONFIG.load(deps.storage)?; + // Get all finality providers from the staking contract, filtered + let mut batch = list_fps_by_power(&cfg.staking, &deps.querier, None, QUERY_LIMIT)?; + + let mut finality_providers = vec![]; + let mut total_power: u64 = 0; + while !batch.is_empty() && finality_providers.len() < max_active_fps { + let last = batch.last().cloned(); + + let (filtered, running_total): (Vec<_>, Vec<_>) = batch + .into_iter() + .filter(|fp| { + // Filter out FPs with no voting power + fp.power > 0 + }) + .scan(total_power, |acc, fp| { + *acc += fp.power; + Some((fp, *acc)) + }) + .unzip(); + finality_providers.extend_from_slice(&filtered); + total_power = running_total.last().copied().unwrap_or_default(); + + // and get the next page + batch = list_fps_by_power(&cfg.staking, &deps.querier, last, QUERY_LIMIT)?; + } // TODO: Online FPs verification // TODO: Filter out slashed / offline / jailed FPs // Save the new set of active finality providers // TODO: Purge old (height - finality depth) FP_SET entries to avoid bloating the storage - FP_SET.save(storage, env.block.height, &finality_providers)?; + FP_SET.save(deps.storage, env.block.height, &finality_providers)?; // Save the total voting power of the top n finality providers - let total_power = running_total.last().copied().unwrap_or_default(); - TOTAL_POWER.save(storage, &total_power)?; + TOTAL_POWER.save(deps.storage, &total_power)?; Ok(()) } +pub fn list_fps_by_power( + staking_addr: &Addr, + querier: &QuerierWrapper, + start_after: Option, + limit: Option, +) -> StdResult> { + let query = encode_smart_query( + staking_addr, + &btc_staking::msg::QueryMsg::FinalityProvidersByPower { start_after, limit }, + )?; + let res: FinalityProvidersByPowerResponse = querier.query(&query)?; + Ok(res.fps) +} + #[cfg(test)] mod tests { use crate::contract::instantiate; diff --git a/contracts/babylon-finality/src/msg.rs b/contracts/babylon-finality/src/msg.rs index 891500f9..ff521ed0 100644 --- a/contracts/babylon-finality/src/msg.rs +++ b/contracts/babylon-finality/src/msg.rs @@ -1,7 +1,6 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cw_controllers::AdminResponse; -use babylon_apis::btc_staking_api::{ActiveBtcDelegation, FinalityProvider}; use babylon_apis::finality_api::{Evidence, IndexedBlock, PubRandCommit}; use crate::state::config::{Config, Params}; diff --git a/contracts/babylon-finality/src/queries.rs b/contracts/babylon-finality/src/queries.rs index 1f8dcffa..dbcedd69 100644 --- a/contracts/babylon-finality/src/queries.rs +++ b/contracts/babylon-finality/src/queries.rs @@ -1,20 +1,14 @@ -use std::str::FromStr; - -use bitcoin::hashes::Hash; -use bitcoin::Txid; - use cosmwasm_std::Order::{Ascending, Descending}; -use cosmwasm_std::{Deps, Order, StdResult}; +use cosmwasm_std::{Deps, StdResult}; use cw_storage_plus::Bound; -use babylon_apis::btc_staking_api::FinalityProvider; use babylon_apis::finality_api::IndexedBlock; use crate::error::ContractError; use crate::msg::{BlocksResponse, EvidenceResponse, FinalitySignatureResponse}; use crate::state::config::{Config, Params}; use crate::state::config::{CONFIG, PARAMS}; -use crate::state::finality::{BLOCKS, EVIDENCES}; +use crate::state::finality::{BLOCKS, EVIDENCES, SIGNATURES}; pub fn config(deps: Deps) -> StdResult { CONFIG.load(deps.storage) @@ -24,156 +18,16 @@ pub fn params(deps: Deps) -> StdResult { PARAMS.load(deps.storage) } -pub fn finality_provider(deps: Deps, btc_pk_hex: String) -> StdResult { - FPS.load(deps.storage, &btc_pk_hex) -} - // Settings for pagination const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 10; -pub fn finality_providers( - deps: Deps, - start_after: Option, - limit: Option, -) -> StdResult { - let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - let start_after = start_after.as_ref().map(|s| Bound::exclusive(&**s)); - let fps = FPS - .range_raw(deps.storage, start_after, None, Order::Ascending) - .take(limit) - .map(|item| item.map(|(_, v)| v)) - .collect::>>()?; - Ok(FinalityProvidersResponse { fps }) -} - -/// Get the delegation info by staking tx hash. -/// `staking_tx_hash_hex`: The (reversed) staking tx hash, in hex -pub fn delegation(deps: Deps, staking_tx_hash_hex: String) -> Result { - let staking_tx_hash = Txid::from_str(&staking_tx_hash_hex)?; - Ok(DELEGATIONS.load(deps.storage, staking_tx_hash.as_ref())?) -} - -/// Get list of delegations. -/// `start_after`: The (reversed) associated staking tx hash of the delegation in hex, if provided. -/// `active`: List only active delegations if true, otherwise list all delegations. -pub fn delegations( - deps: Deps, - start_after: Option, - limit: Option, - active: Option, -) -> Result { - let active = active.unwrap_or_default(); - let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - let start_after = start_after - .as_ref() - .map(|s| Txid::from_str(s)) - .transpose()?; - let start_after = start_after.as_ref().map(|s| s.as_ref()); - let start_after = start_after.map(Bound::exclusive); - let delegations = DELEGATIONS - .range_raw(deps.storage, start_after, None, Order::Ascending) - .filter(|item| { - if let Ok((_, del)) = item { - !active || del.is_active() - } else { - true // don't filter errors - } - }) - .take(limit) - .map(|item| item.map(|(_, v)| v)) - .collect::, _>>()?; - Ok(BtcDelegationsResponse { delegations }) -} - -/// Delegation hashes by FP query. -/// -/// `btc_pk_hex`: The BTC public key of the finality provider, in hex -pub fn delegations_by_fp( - deps: Deps, - btc_pk_hex: String, -) -> Result { - let tx_hashes = FP_DELEGATIONS.load(deps.storage, &btc_pk_hex)?; - let tx_hashes = tx_hashes - .iter() - .map(|h| Ok(Txid::from_slice(h)?.to_string())) - .collect::>()?; - Ok(DelegationsByFPResponse { hashes: tx_hashes }) -} - -/// Active / all delegations by FP convenience query. -/// -/// This is an alternative to `delegations_by_fp` that returns the actual delegations instead of -/// just the hashes. -/// -/// `btc_pk_hex`: The BTC public key of the finality provider, in hex. -/// `active` is a filter to return only active delegations -pub fn active_delegations_by_fp( - deps: Deps, - btc_pk_hex: String, - active: bool, -) -> Result { - let tx_hashes = FP_DELEGATIONS.load(deps.storage, &btc_pk_hex)?; - let delegations = tx_hashes - .iter() - .map(|h| Ok(DELEGATIONS.load(deps.storage, Txid::from_slice(h)?.as_ref())?)) - .filter(|item| { - if let Ok(del) = item { - !active || del.is_active() - } else { - true // don't filter errors - } - }) - .collect::, ContractError>>()?; - Ok(BtcDelegationsResponse { delegations }) -} - -pub fn finality_provider_info( - deps: Deps, - btc_pk_hex: String, - height: Option, -) -> StdResult { - let fp_state = match height { - Some(h) => fps().may_load_at_height(deps.storage, &btc_pk_hex, h), - None => fps().may_load(deps.storage, &btc_pk_hex), - }? - .unwrap_or_default(); - - Ok(FinalityProviderInfo { - btc_pk_hex, - power: fp_state.power, - }) -} - -pub fn finality_providers_by_power( - deps: Deps, - start_after: Option, - limit: Option, -) -> StdResult { - let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - let start = start_after.map(|fpp| Bound::exclusive((fpp.power, fpp.btc_pk_hex.clone()))); - let fps = fps() - .idx - .power - .range(deps.storage, None, start, Descending) - .take(limit) - .map(|item| { - let (btc_pk_hex, FinalityProviderState { power }) = item?; - Ok(FinalityProviderInfo { btc_pk_hex, power }) - }) - .collect::>>()?; - - Ok(FinalityProvidersByPowerResponse { fps }) -} - pub fn finality_signature( deps: Deps, btc_pk_hex: String, height: u64, ) -> StdResult { - match babylon_finality::state::finality::SIGNATURES - .may_load(deps.storage, (height, &btc_pk_hex))? - { + match SIGNATURES.may_load(deps.storage, (height, &btc_pk_hex))? { Some(sig) => Ok(FinalitySignatureResponse { signature: sig }), None => Ok(FinalitySignatureResponse { signature: Vec::new(), @@ -181,13 +35,6 @@ pub fn finality_signature( } } -pub fn activated_height(deps: Deps) -> Result { - let activated_height = ACTIVATED_HEIGHT.may_load(deps.storage)?.unwrap_or_default(); - Ok(ActivatedHeightResponse { - height: activated_height, - }) -} - pub fn block(deps: Deps, height: u64) -> StdResult { BLOCKS.load(deps.storage, height) } diff --git a/contracts/babylon-finality/src/state/config.rs b/contracts/babylon-finality/src/state/config.rs index 113d6790..6755a032 100644 --- a/contracts/babylon-finality/src/state/config.rs +++ b/contracts/babylon-finality/src/state/config.rs @@ -6,8 +6,6 @@ use cosmwasm_std::Addr; use cw_controllers::Admin; use cw_storage_plus::Item; -use babylon_bitcoin::chain_params::Network; - pub(crate) const CONFIG: Item = Item::new("config"); pub(crate) const PARAMS: Item = Item::new("params"); /// Storage for admin @@ -27,17 +25,6 @@ pub struct Config { #[derive(Derivative)] #[derivative(Default)] pub struct Params { - // covenant_pks is the list of public keys held by the covenant committee each PK - // follows encoding in BIP-340 spec on Bitcoin - pub covenant_pks: Vec, - // covenant_quorum is the minimum number of signatures needed for the covenant multi-signature - pub covenant_quorum: u32, - #[derivative(Default(value = "Network::Regtest"))] - // ntc_network is the network the BTC staking protocol is running on - pub btc_network: Network, - // `min_commission_rate` is the chain-wide minimum commission rate that a finality provider - // can charge their delegators - // pub min_commission_rate: Decimal, /// `max_active_finality_providers` is the maximum number of active finality providers in the /// BTC staking protocol #[derivative(Default(value = "100"))] @@ -46,16 +33,4 @@ pub struct Params { /// should commit #[derivative(Default(value = "1"))] pub min_pub_rand: u64, - /// `slashing_address` is the address that the slashed BTC goes to. - /// The address is in string format on Bitcoin. - #[derivative(Default(value = "String::from(\"n4cV57jePmAAue2WTTBQzH3k3R2rgWBQwY\")"))] - pub slashing_address: String, - /// `min_slashing_tx_fee_sat` is the minimum amount of tx fee (quantified in Satoshi) needed for - /// the pre-signed slashing tx - #[derivative(Default(value = "1000"))] - pub min_slashing_tx_fee_sat: u64, - /// `slashing_rate` determines the portion of the staked amount to be slashed, - /// expressed as a decimal (e.g. 0.5 for 50%). - #[derivative(Default(value = "String::from(\"0.1\")"))] - pub slashing_rate: String, } diff --git a/contracts/babylon-finality/src/state/finality.rs b/contracts/babylon-finality/src/state/finality.rs index 42dcb02d..06202abf 100644 --- a/contracts/babylon-finality/src/state/finality.rs +++ b/contracts/babylon-finality/src/state/finality.rs @@ -1,6 +1,7 @@ use cw_storage_plus::{Item, Map}; use babylon_apis::finality_api::{Evidence, IndexedBlock}; +use btc_staking::msg::FinalityProviderInfo; /// Map of signatures by block height and FP pub const SIGNATURES: Map<(u64, &str), Vec> = Map::new("fp_sigs"); diff --git a/contracts/babylon-finality/src/state/public_randomness.rs b/contracts/babylon-finality/src/state/public_randomness.rs index 40862755..68227626 100644 --- a/contracts/babylon-finality/src/state/public_randomness.rs +++ b/contracts/babylon-finality/src/state/public_randomness.rs @@ -2,6 +2,7 @@ use cosmwasm_std::Order::{Ascending, Descending}; use cosmwasm_std::{StdResult, Storage}; use cw_storage_plus::{Bound, Map}; +use crate::error::ContractError; use babylon_apis::finality_api::PubRandCommit; /// Map of public randomness commitments by fp and block height