Skip to content

Commit

Permalink
fix: pick hotfixes from 1.8 branch (#5645)
Browse files Browse the repository at this point in the history
* fix: delete Solana channel state when closed

* chore: CHANGELOG and a version bump

* test: invalid fetches should not block valid fetches

* fix: only decrement counter if we can actually fetch

* feat: add account id / withdrawal address to affiliate events (#5634)

* feat: Added broker_id to WithdrawalRequest event

* chore: changed broker_id to account_id

I think this is a better name since it could be either a broker or an affiliate but in the end both is an account.

* feat: Added withdrawal address to AffiliateRegistration

* feat: returning detailed account information for affiliate in the cf_account_info rpc for brokers (#5641)

* feat: Added asset_balances to Unregistered Account variant

* chore: added deprecate note

* fix: simplify asset map conversion

* feat: add optional affiliate withdrawal address to broker account info

* fix: clippy and test

* fix: make BrokerInfo non-breaking

* fix: unused import

---------

Co-authored-by: Daniel <daniel@chainflip.io>

* fix: ensure correct affiliate account creation/removal

* fix: typo

* fix: missing version bumps

---------

Co-authored-by: kylezs <kyle@chainflip.io>
Co-authored-by: Janislav <jan@chainflip.io>
  • Loading branch information
3 people authored Feb 20, 2025
1 parent 50a300d commit 4cc134d
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 174 deletions.
170 changes: 170 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub trait Rpc {
#[method(name = "get_affiliates", aliases = ["broker_getAffiliates"])]
async fn get_affiliates(
&self,
affilate: Option<AccountId32>,
affiliate: Option<AccountId32>,
) -> RpcResult<Vec<(AccountId32, AffiliateDetails)>>;

#[method(name = "affiliate_withdrawal_request", aliases = ["broker_affiliateWithdrawalRequest"])]
Expand Down
4 changes: 2 additions & 2 deletions engine-runner-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ assets = [
# The old version gets put into target/release/deps by the package github actions workflow.
# It downloads the correct version from the releases page.
[
"target/release/libchainflip_engine_v1_8_0.so",
"target/release/libchainflip_engine_v1_8_2.so",
# This is the path where the engine dylib is searched for on linux.
# As set in the build.rs file.
"usr/lib/chainflip-engine/libchainflip_engine_v1_8_0.so",
"usr/lib/chainflip-engine/libchainflip_engine_v1_8_2.so",
"755",
],
]
Expand Down
2 changes: 1 addition & 1 deletion engine-runner-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use engine_upgrade_utils::{CStrArray, NEW_VERSION, OLD_VERSION};

// Declare the entrypoints into each version of the engine
mod old {
#[engine_proc_macros::link_engine_library_version("1.8.0")]
#[engine_proc_macros::link_engine_library_version("1.8.2")]
extern "C" {
pub fn cfe_entrypoint(
c_args: engine_upgrade_utils::CStrArray,
Expand Down
2 changes: 1 addition & 1 deletion engine-upgrade-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod build_helpers;
// rest of the places the version needs changing on build using the build scripts in each of the
// relevant crates.
// Should also check that the compatibility function below `args_compatible_with_old` is correct.
pub const OLD_VERSION: &str = "1.8.0";
pub const OLD_VERSION: &str = "1.8.2";
pub const NEW_VERSION: &str = "1.9.0";

pub const ENGINE_LIB_PREFIX: &str = "chainflip_engine_v";
Expand Down
11 changes: 10 additions & 1 deletion state-chain/chains/src/sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl DepositDetailsToTransactionInId<SolanaCrypto> for () {}
#[cfg(test)]
mod test {
use super::*;
use crate::sol::compute_units_costs::*;
use crate::{sol::compute_units_costs::*, ChannelLifecycleHooks};

#[test]
fn can_calculate_gas_limit() {
Expand Down Expand Up @@ -510,4 +510,13 @@ mod test {
assert_eq!(tx_compute_limit, default_compute_limit);
}
}

#[test]
fn solana_channel_recycling_is_assumed_to_be_deactivated() {
assert!(
<<Solana as Chain>::DepositChannelState as ChannelLifecycleHooks>::maybe_recycle(0).is_none(),
"It looks like Solana channel recycling is active. If this is intentional, ensure that the corresponding
unsynchronised state map in the delta_based_ingress election is not deleted when channels are closed."
);
}
}
67 changes: 53 additions & 14 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use cf_chains::{
};
use cf_primitives::{
chains::assets::any::{self, AssetMap},
AccountId, AccountRole, AffiliateShortId, Affiliates, Asset, AssetAmount, BasisPoints,
BlockNumber, BroadcastId, DcaParameters, EpochIndex, ForeignChain, NetworkEnvironment, SemVer,
SwapId, SwapRequestId,
AccountRole, Affiliates, Asset, AssetAmount, BasisPoints, BlockNumber, BroadcastId,
DcaParameters, EpochIndex, ForeignChain, NetworkEnvironment, SemVer, SwapId, SwapRequestId,
};
use cf_utilities::rpc::NumberOrHex;
use core::ops::Range;
Expand Down Expand Up @@ -45,11 +44,11 @@ use sc_rpc_spec_v2::chain_head::{
api::ChainHeadApiServer, ChainHead, ChainHeadConfig, FollowEvent,
};
use serde::{Deserialize, Serialize};
use sp_api::{ApiError, CallApiAt};
use sp_api::{ApiError, ApiExt, CallApiAt};
use sp_core::U256;
use sp_runtime::{
traits::{Block as BlockT, Header as HeaderT, UniqueSaturatedInto},
Percent, Permill,
AccountId32, Percent, Permill,
};
use sp_state_machine::InspectState;
use state_chain_runtime::{
Expand Down Expand Up @@ -230,18 +229,35 @@ impl From<&LiquidityProviderBoostPoolInfo> for RpcLiquidityProviderBoostPoolInfo
}
}

#[derive(Serialize, Deserialize, Clone)]
pub struct RpcAffiliate {
pub account_id: AccountId32,
#[serde(flatten)]
pub details: AffiliateDetails,
}

impl From<(AccountId32, AffiliateDetails)> for RpcAffiliate {
fn from((account_id, details): (AccountId32, AffiliateDetails)) -> Self {
Self { account_id, details }
}
}

#[allow(clippy::large_enum_variant)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "role", rename_all = "snake_case")]
pub enum RpcAccountInfo {
Unregistered {
flip_balance: NumberOrHex,
asset_balances: any::AssetMap<NumberOrHex>,
},
Broker {
flip_balance: NumberOrHex,
bond: NumberOrHex,
#[deprecated(note = "This field is deprecated and will be replaced in a future release")]
earned_fees: any::AssetMap<NumberOrHex>,
affiliates: Vec<(AffiliateShortId, AccountId)>,
#[serde(skip_serializing_if = "Vec::is_empty")]
affiliates: Vec<RpcAffiliate>,
#[serde(skip_serializing_if = "Option::is_none")]
btc_vault_deposit_address: Option<String>,
},
LiquidityProvider {
Expand Down Expand Up @@ -269,8 +285,11 @@ pub enum RpcAccountInfo {
}

impl RpcAccountInfo {
fn unregistered(balance: u128) -> Self {
Self::Unregistered { flip_balance: balance.into() }
fn unregistered(balance: u128, asset_balances: any::AssetMap<u128>) -> Self {
Self::Unregistered {
flip_balance: balance.into(),
asset_balances: asset_balances.map(Into::into),
}
}

fn broker(broker_info: BrokerInfo, balance: u128) -> Self {
Expand All @@ -284,7 +303,7 @@ impl RpcAccountInfo {
.iter()
.map(|(asset, balance)| (*asset, (*balance).into())),
),
affiliates: broker_info.affiliates,
affiliates: broker_info.affiliates.into_iter().map(Into::into).collect(),
}
}

Expand Down Expand Up @@ -1374,15 +1393,25 @@ where
) -> RpcResult<RpcAccountInfo> {
self.with_runtime_api(at, |api, hash| {
let balance = api.cf_account_flip_balance(hash, &account_id)?;
let asset_balances = api.cf_free_balances(hash, account_id.clone())?;

Ok::<_, CfApiError>(
match api
.cf_account_role(hash, account_id.clone())?
.unwrap_or(AccountRole::Unregistered)
{
AccountRole::Unregistered => RpcAccountInfo::unregistered(balance),
AccountRole::Unregistered =>
RpcAccountInfo::unregistered(balance, asset_balances),
AccountRole::Broker => {
let info = api.cf_broker_info(hash, account_id)?;
let api_version = api
.api_version::<dyn CustomRuntimeApi<state_chain_runtime::Block>>(hash)?
.unwrap_or_default();

let info = if api_version < 3 {
api.cf_broker_info_before_version_3(hash, account_id.clone())?.into()
} else {
api.cf_broker_info(hash, account_id.clone())?
};

RpcAccountInfo::broker(info, balance)
},
Expand Down Expand Up @@ -2158,7 +2187,11 @@ mod test {

#[test]
fn test_no_account_serialization() {
insta::assert_snapshot!(serde_json::to_value(RpcAccountInfo::unregistered(0)).unwrap());
insta::assert_snapshot!(serde_json::to_value(RpcAccountInfo::unregistered(
0,
any::AssetMap::default()
))
.unwrap());
}

#[test]
Expand All @@ -2181,12 +2214,18 @@ mod test {
btc_vault_deposit_address: Some(
ScriptPubkey::Taproot([1u8; 32]).to_address(&BitcoinNetwork::Testnet),
),
affiliates: vec![(cf_primitives::AffiliateShortId(1), AccountId32::new([1; 32]))],
bond: 0,
affiliates: vec![(
AccountId32::new([1; 32]),
AffiliateDetails {
short_id: 1.into(),
withdrawal_address: H160::from([0xcf; 20]),
},
)],
},
0,
);
insta::assert_snapshot!(serde_json::to_value(broker).unwrap());
insta::assert_json_snapshot!(broker);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
---
source: state-chain/custom-rpc/src/lib.rs
expression: "serde_json::to_value(broker).unwrap()"
snapshot_kind: text
expression: broker
---
{"affiliates":[[1,"5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT"]],"bond":"0x0","btc_vault_deposit_address":"tb1pqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsn60vlk","earned_fees":{"Arbitrum":{"ETH":"0x0","USDC":"0x0"},"Bitcoin":{"BTC":"0x0"},"Ethereum":{"ETH":"0x0","FLIP":"0xde0b6b3a7640000","USDC":"0x0","USDT":"0x0"},"Polkadot":{"DOT":"0x0"},"Solana":{"SOL":"0x0","USDC":"0x0"}},"flip_balance":"0x0","role":"broker"}
{
"role": "broker",
"flip_balance": "0x0",
"bond": "0x0",
"earned_fees": {
"Ethereum": {
"ETH": "0x0",
"FLIP": "0xde0b6b3a7640000",
"USDC": "0x0",
"USDT": "0x0"
},
"Polkadot": {
"DOT": "0x0"
},
"Bitcoin": {
"BTC": "0x0"
},
"Arbitrum": {
"ETH": "0x0",
"USDC": "0x0"
},
"Solana": {
"SOL": "0x0",
"USDC": "0x0"
}
},
"affiliates": [
{
"account_id": "5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT",
"short_id": 1,
"withdrawal_address": "0xcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcf"
}
],
"btc_vault_deposit_address": "tb1pqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsn60vlk"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: state-chain/custom-rpc/src/lib.rs
expression: "serde_json::to_value(RpcAccountInfo::unregistered(0)).unwrap()"
expression: "serde_json::to_value(RpcAccountInfo::unregistered(0,\nany::AssetMap::default())).unwrap()"
snapshot_kind: text
---
{"flip_balance":"0x0","role":"unregistered"}
{"asset_balances":{"Arbitrum":{"ETH":"0x0","USDC":"0x0"},"Bitcoin":{"BTC":"0x0"},"Ethereum":{"ETH":"0x0","FLIP":"0x0","USDC":"0x0","USDT":"0x0"},"Polkadot":{"DOT":"0x0"},"Solana":{"SOL":"0x0","USDC":"0x0"}},"flip_balance":"0x0","role":"unregistered"}
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ where
// confirmed deposits have been ingressed.
if ready_total.block_number >= details.close_block {
Sink::on_channel_closed(account.clone());
// Removes the state.
// We need to remove this if we decide to recycle Solana channels.
ElectoralAccess::set_unsynchronised_state_map(
(account.clone(), details.asset),
None,
);
new_channel_properties.remove(account);
}
}
Expand Down
Loading

0 comments on commit 4cc134d

Please sign in to comment.