Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/pools-change-fee
Browse files Browse the repository at this point in the history
* origin/main:
  Feat: don't include dust btc amounts on rotation (#4063)
  chore: update dependency and config.toml for RUSTSEC-2023-0065 (#4066)
  fix: loop_select conditions (PRO-587) (#4061)
  chore: remove unused config items (#4064)
  feat: size limit for CCM (#4015)
  fix: warn -> info (#4060)
  Fix: correctly handle peer updates while waiting to reconnect (#4052)

# Conflicts:
#	state-chain/chains/src/lib.rs
  • Loading branch information
syan095 committed Oct 3, 2023
2 parents 7acd54b + 73f4bc8 commit b1d340d
Show file tree
Hide file tree
Showing 25 changed files with 498 additions and 395 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tree --no-default-features --depth 1 --edges=features,normal
# - RUSTSEC-2021-0060: This is a transitive dependency of libp2p and will be fixed in an upcoming release.
# - RUSTSEC-2021-0059: This is a transitive dependency of libp2p and will be fixed in an upcoming release.
# - RUSTSEC-2023-0063: This is a transitive dependency of libp2p and it is not used.
# - RUSTSEC-2023-0065: This is a transitive dependency of ethers and is only applicable when using as a server for untrusted traffic.
cf-audit = '''
audit --ignore RUSTSEC-2022-0061
--ignore RUSTSEC-2020-0071
Expand All @@ -49,4 +50,5 @@ audit --ignore RUSTSEC-2022-0061
--ignore RUSTSEC-2021-0060
--ignore RUSTSEC-2021-0059
--ignore RUSTSEC-2023-0063
--ignore RUSTSEC-2023-0065
'''
39 changes: 19 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/bin/chainflip-broker-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ name = "chainflip-broker-api"
[dependencies]
chainflip-api = { path = "../../lib" }
cf-utilities = { package = "utilities", path = "../../../utilities" }
cf-chains = { path = '../../../state-chain/chains', default-features = false }

anyhow = "1.0.66"
clap = { version = "3.2.23", features = ["derive"] }
Expand Down
63 changes: 2 additions & 61 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::anyhow;
use cf_utilities::{
task_scope::{task_scope, Scope},
AnyhowRpcError,
Expand All @@ -11,10 +10,8 @@ use chainflip_api::{
};
use clap::Parser;
use futures::FutureExt;
use hex::FromHexError;
use jsonrpsee::{core::async_trait, proc_macros::rpc, server::ServerBuilder};
use serde::{Deserialize, Serialize};
use sp_rpc::number::NumberOrHex;
use std::path::PathBuf;
use tracing::log;

Expand All @@ -38,39 +35,6 @@ impl From<chainflip_api::SwapDepositAddress> for BrokerSwapDepositAddress {
}
}

#[derive(Serialize, Deserialize)]
pub struct BrokerCcmChannelMetadata {
gas_budget: NumberOrHex,
message: String,
cf_parameters: Option<String>,
}

fn parse_hex_bytes(string: &str) -> Result<Vec<u8>, FromHexError> {
hex::decode(string.strip_prefix("0x").unwrap_or(string))
}

impl TryInto<CcmChannelMetadata> for BrokerCcmChannelMetadata {
type Error = anyhow::Error;

fn try_into(self) -> Result<CcmChannelMetadata, Self::Error> {
let gas_budget = self
.gas_budget
.try_into()
.map_err(|_| anyhow!("Failed to parse {:?} as gas budget", self.gas_budget))?;
let message =
parse_hex_bytes(&self.message).map_err(|e| anyhow!("Failed to parse message: {e}"))?;

let cf_parameters = self
.cf_parameters
.map(|parameters| parse_hex_bytes(&parameters))
.transpose()
.map_err(|e| anyhow!("Failed to parse cf parameters: {e}"))?
.unwrap_or_default();

Ok(CcmChannelMetadata { gas_budget, message, cf_parameters })
}
}

#[rpc(server, client, namespace = "broker")]
pub trait Rpc {
#[method(name = "registerAccount")]
Expand All @@ -83,7 +47,7 @@ pub trait Rpc {
destination_asset: Asset,
destination_address: String,
broker_commission_bps: BasisPoints,
channel_metadata: Option<BrokerCcmChannelMetadata>,
channel_metadata: Option<CcmChannelMetadata>,
) -> Result<BrokerSwapDepositAddress, AnyhowRpcError>;
}

Expand Down Expand Up @@ -120,10 +84,8 @@ impl RpcServer for RpcServerImpl {
destination_asset: Asset,
destination_address: String,
broker_commission_bps: BasisPoints,
channel_metadata: Option<BrokerCcmChannelMetadata>,
channel_metadata: Option<CcmChannelMetadata>,
) -> Result<BrokerSwapDepositAddress, AnyhowRpcError> {
let channel_metadata = channel_metadata.map(TryInto::try_into).transpose()?;

Ok(self
.api
.broker_api()
Expand Down Expand Up @@ -186,24 +148,3 @@ async fn main() -> anyhow::Result<()> {
})
.await
}

#[cfg(test)]
mod test {
use super::*;
use cf_utilities::assert_err;

#[test]
fn test_decoding() {
assert_eq!(parse_hex_bytes("0x00").unwrap(), vec![0]);
assert_eq!(parse_hex_bytes("cf").unwrap(), vec![0xcf]);
assert_eq!(
parse_hex_bytes("0x00112233445566778899aabbccddeeff").unwrap(),
vec![
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
0xee, 0xff
]
);
assert_eq!(parse_hex_bytes("").unwrap(), b"");
assert_err!(parse_hex_bytes("abc"));
}
}
2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ x25519-dalek = { version = "1.1", features = ["serde"] }
zmq = { git = "https://github.com/chainflip-io/rust-zmq.git", tag = "chainflip-v0.9.2+1", features = [
"vendored",
] }
warp = { version = "0.3.5" }
warp = { version = "0.3.6" }

# Local deps
cf-chains = { path = "../state-chain/chains" }
Expand Down
Loading

0 comments on commit b1d340d

Please sign in to comment.