Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/fuzzy-event-e…
Browse files Browse the repository at this point in the history
…ncoding

* origin/main: (21 commits)
  chore: update chainspecs (#4615)
  feat: Add channel opening fee to *DepositAddressReady Events (#4609)
  refactor: pass out CFE incompatibility exit information to main (#4563)
  feat: Introduce tx fee multiplier storage item (#4594)
  fix: debug cli  (#4605)
  fix: patch 1.2 broker test (#4607)
  feat: add block height and deposit details to PrewitnessedDeposit (#4606)
  chore: add myself as codeowner to upgrade-test (#4603)
  fix: RUSTSEC-2024-0019 (#4604)
  fix: upgrade test pnpm install from commit (#4600)
  chore: add notification on failed release build (#4589)
  chore: add Zellic audit to Security.md (#4599)
  update changelog for 1.2.1 (#4597)
  fix: use correct pnpm deps for upgrade-test (#4596)
  chore(bouncer): Use stable sdk version (#4595)
  chore(bouncer): Update sdk to 1.2.1 (#4582)
  log meaningful message if docker login fails (#4553)
  Added bouncer command to download a runtime update from a proposal (#4592)
  chore: add asset to withdrawal event (#4590)
  ingress-egress-tracker: add tx_ref to redis (#4573)
  ...

# Conflicts:
#	state-chain/runtime/src/lib.rs
  • Loading branch information
syan095 committed Mar 7, 2024
2 parents 698000f + b4a1d71 commit e4c5bca
Show file tree
Hide file tree
Showing 91 changed files with 1,054 additions and 508 deletions.
21 changes: 16 additions & 5 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
/bouncer/ @martin-chainflip

/bouncer/shared/upgrade_network.ts @kylezs
/bouncer/commands/upgrade_network.ts @kylezs
.github/workflows/upgrade-test.yml @kylezs

/state-chain/custom-rpc/ @chainflip-io/web
/api/bin/chainflip-ingress-egress-tracker @chainflip-io/web

/engine/config/CI/config/Settings.toml @chainflip-io/platform
/localnet/ @chainflip-io/platform
/engine/src/witness/ @kylezs @AlastairHolmes
/engine/src/witness.rs @kylezs @AlastairHolmes
/engine/multisig/ @msgmaxim

/state-chain/pallets/cf-pools/ @AlastairHolmes
/state-chain/amm/ @AlastairHolmes

/state-chain/ @dandanlen

/utilities/with_std/task_scope @AlastairHolmes

/engine/multisig/ @msgmaxim
/engine/src/p2p/ @msgmaxim
/engine/src/p2p.rs @msgmaxim

/engine/state_chain_observer/client/ @AlastairHolmes
/engine/src/witness/ @kylezs @AlastairHolmes
/engine/src/witness.rs @kylezs @AlastairHolmes
/engine/src/eth/ @kylezs
/engine/src/btc/ @kylezs
/engine/src/dot/ @kylezs
/engine/src/p2p/ @msgmaxim
/engine/src/p2p.rs @msgmaxim
/engine/src/retrier.rs @kylezs
3 changes: 2 additions & 1 deletion .github/workflows/_40_post_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ jobs:
docker compose -f localnet/docker-compose.yml -p "chainflip-localnet" down --rmi all --volumes --remove-orphans
- name: Notify on failed bouncer 📢
if: failure() && github.ref_name == 'main' || cancelled() && github.ref_name == 'main'
if: failure() && github.ref_name == 'main' || cancelled() && github.ref_name == 'main' || failure() && contains(github.ref_name, 'release/') || cancelled() && contains(github.ref_name, 'release/')
env:
DISCORD_USERNAME: "HEUTE LEIDER NICHT"
DISCORD_WEBHOOK: ${{ secrets.CF_DISCORD_ALERTS_CRITICAL }}
uses: Ilshidur/action-discord@0c4b27844ba47cb1c7bee539c8eead5284ce9fa9
with:
args: |
❗️❗️❗️❗️ Sorry **${{ github.actor }}**, the Bouncer has rejected you ❗️❗️❗️❗️
The Bouncer has rejected the build on branch `${{ github.ref_name }}`
👾 Link to job: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>
#️⃣ Tagging: <@&939151218708709416>
11 changes: 6 additions & 5 deletions .github/workflows/upgrade-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ jobs:
MAIN_VERSION=$(./upgrade-to-bins/chainflip-node --version)
echo $MAIN_VERSION
- name: Install node dependencies
working-directory: bouncer
run: pnpm install

- name: Start a localnet from current release
env:
BINARY_ROOT_PATH: ./latest-release-bins
Expand All @@ -177,11 +173,14 @@ jobs:
- name: Run bouncer on latest release
id: pre-upgrade-bouncer
# TEMP: It should be: # git checkout ${{ steps.get-upgrade-from-commit.outputs.commit-sha }}
# But we need the fix for the broker test for 1.2 here for now
run: |
git fetch --all
git checkout ${{ steps.get-upgrade-from-commit.outputs.commit-sha }}
git checkout release-1.2-broker-test-fix
git rev-parse HEAD
cd bouncer
pnpm install
./run.sh
# we need to be sure that when this fails, we catch the error, any panics etc. that occur
Expand All @@ -193,6 +192,7 @@ jobs:
git checkout ${{ github.sha }}
git rev-parse HEAD
cd bouncer
pnpm install
./commands/upgrade_network.ts prebuilt \
--runtime ./../main-runtime/state_chain_runtime.compact.compressed.wasm \
--bins ./../upgrade-to-bins \
Expand All @@ -205,6 +205,7 @@ jobs:
git checkout ${{ env.UPGRADE_TO_COMMIT }}
git rev-parse HEAD
cd bouncer
pnpm install
./tests/all_concurrent_tests.ts
- name: Print old chainflip-engine logs
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes included in each Chainflip release will be documented in this file.

## [1.2.1] - 2024-03-04

### Features

- Price impact protection for swaps ([#4547](https://github.com/chainflip-io/chainflip-backend/pull/4547))

## [1.2.0] - 2024-02-02

### Features
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ By participating in the Bug Bounty Program, you acknowledge that you have read a
Chainflip has commissioned the following audits of the code in this repository:

- [Multisig TSS - Kudelski, Q1 2022](./audits/Multisig-Kudelski-Q1-2022.pdf)
- [Trail of Bits - Q3 2023](https://github.com/trailofbits/publications/blob/master/reviews/2023-04-chainflip-securityreview.pdf)
- [Trail of Bits - Q3 2023](./audits/2023-04-TrailOfBits-securityreview.pdf)
- [Zellic - Q4 2023 -> Q1 2024](./audits/Chainflip_Backend_-_Zellic_Audit_Report.pdf)
2 changes: 2 additions & 0 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct BrokerSwapDepositAddress {
pub issued_block: BlockNumber,
pub channel_id: ChannelId,
pub source_chain_expiry_block: NumberOrHex,
pub channel_opening_fee: u128,
}

impl From<chainflip_api::SwapDepositAddress> for BrokerSwapDepositAddress {
Expand All @@ -38,6 +39,7 @@ impl From<chainflip_api::SwapDepositAddress> for BrokerSwapDepositAddress {
issued_block: value.issued_block,
channel_id: value.channel_id,
source_chain_expiry_block: NumberOrHex::from(value.source_chain_expiry_block),
channel_opening_fee: value.channel_opening_fee,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/bin/chainflip-cli/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
};

#[derive(Parser, Clone, Debug)]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"), version_short = 'v')]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"))]
pub struct CLICommandLineOptions {
#[clap(short = 'c', long = "config-root", env = CONFIG_ROOT, default_value = DEFAULT_CONFIG_ROOT)]
pub config_root: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs
assertion_line: 598
expression: "store.storage.get(\"broadcast:Ethereum:1\").unwrap()"
---
{"tx_out_id":{"signature":{"k_times_g_address":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"s":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}}
{"tx_out_id":{"signature":{"k_times_g_address":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"s":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"tx_ref":{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000"}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,57 @@ use crate::{
utils::{get_broadcast_id, hex_encode_bytes},
};
use cf_chains::{
address::ToHumanreadableAddress, evm::SchnorrVerificationComponents, AnyChain, Bitcoin, Chain,
Ethereum, Polkadot,
address::ToHumanreadableAddress,
dot::PolkadotTransactionId,
evm::{SchnorrVerificationComponents, H256},
AnyChain, Bitcoin, Chain, Ethereum, Polkadot,
};
use cf_primitives::{BroadcastId, ForeignChain, NetworkEnvironment};
use chainflip_engine::state_chain_observer::client::{
chain_api::ChainApi, storage_api::StorageApi,
};
use pallet_cf_ingress_egress::DepositWitness;
use serde::Serialize;
use utilities::rpc::NumberOrHex;
use serde::{Serialize, Serializer};
use utilities::{rpc::NumberOrHex, ArrayCollect};

/// A wrapper type for bitcoin hashes that serializes the hash in reverse.
#[derive(Debug)]
struct BitcoinHash(pub H256);

impl Serialize for BitcoinHash {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
H256(self.0.to_fixed_bytes().into_iter().rev().collect_array()).serialize(serializer)
}
}

struct DotSignature([u8; 64]);

impl Serialize for DotSignature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
format!("0x{}", hex::encode(self.0)).serialize(serializer)
}
}

#[derive(Serialize)]
#[serde(untagged)]
enum TransactionRef {
Bitcoin { hash: BitcoinHash },
Ethereum { hash: H256 },
Polkadot { transaction_id: PolkadotTransactionId },
}

#[derive(Serialize)]
#[serde(untagged)]
enum TransactionId {
Bitcoin { hash: String },
Bitcoin { hash: BitcoinHash },
Ethereum { signature: SchnorrVerificationComponents },
Polkadot { signature: String },
Polkadot { signature: DotSignature },
}

#[derive(Serialize)]
Expand All @@ -36,6 +70,7 @@ enum WitnessInformation {
#[serde(skip_serializing)]
broadcast_id: BroadcastId,
tx_out_id: TransactionId,
tx_ref: TransactionRef,
},
}

Expand Down Expand Up @@ -163,7 +198,11 @@ where
)))
.await?;
},
EthereumBroadcaster(BroadcastCall::transaction_succeeded { tx_out_id, .. }) => {
EthereumBroadcaster(BroadcastCall::transaction_succeeded {
tx_out_id,
transaction_ref,
..
}) => {
let broadcast_id =
get_broadcast_id::<Ethereum, StateChainClient>(state_chain_client, &tx_out_id)
.await;
Expand All @@ -173,26 +212,35 @@ where
.save_singleton(&WitnessInformation::Broadcast {
broadcast_id,
tx_out_id: TransactionId::Ethereum { signature: tx_out_id },
tx_ref: TransactionRef::Ethereum { hash: transaction_ref },
})
.await?;
}
},
BitcoinBroadcaster(BroadcastCall::transaction_succeeded { tx_out_id, .. }) => {
BitcoinBroadcaster(BroadcastCall::transaction_succeeded {
tx_out_id,
transaction_ref,
..
}) => {
let broadcast_id =
get_broadcast_id::<Bitcoin, StateChainClient>(state_chain_client, &tx_out_id).await;

if let Some(broadcast_id) = broadcast_id {
store
.save_singleton(&WitnessInformation::Broadcast {
broadcast_id,
tx_out_id: TransactionId::Bitcoin {
hash: format!("0x{}", hex::encode(tx_out_id)),
},
tx_out_id: TransactionId::Bitcoin { hash: BitcoinHash(tx_out_id) },
tx_ref: TransactionRef::Bitcoin { hash: BitcoinHash(transaction_ref) },
})
.await?;
println!("{:?}", BitcoinHash(transaction_ref));
}
},
PolkadotBroadcaster(BroadcastCall::transaction_succeeded { tx_out_id, .. }) => {
PolkadotBroadcaster(BroadcastCall::transaction_succeeded {
tx_out_id,
transaction_ref,
..
}) => {
let broadcast_id =
get_broadcast_id::<Polkadot, StateChainClient>(state_chain_client, &tx_out_id)
.await;
Expand All @@ -202,8 +250,9 @@ where
.save_singleton(&WitnessInformation::Broadcast {
broadcast_id,
tx_out_id: TransactionId::Polkadot {
signature: format!("0x{}", hex::encode(tx_out_id.aliased_ref())),
signature: DotSignature(*tx_out_id.aliased_ref()),
},
tx_ref: TransactionRef::Polkadot { transaction_id: transaction_ref },
})
.await?;
}
Expand Down Expand Up @@ -554,4 +603,26 @@ mod tests {
assert_eq!(store.storage.len(), 1);
insta::assert_display_snapshot!(store.storage.get("broadcast:Ethereum:1").unwrap());
}

#[test]
fn serialization_works_as_expected() {
let h = BitcoinHash(
[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31,
]
.into(),
);
let s = DotSignature([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
]);

assert_eq!(
serde_json::to_string(&h).unwrap(),
"\"0x1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100\""
);
assert_eq!(serde_json::to_string(&s).unwrap(), "\"0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f\"");
}
}
5 changes: 5 additions & 0 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl StateChainApi {
false,
false,
false,
None,
)
.await?;

Expand Down Expand Up @@ -303,6 +304,7 @@ pub struct SwapDepositAddress {
pub issued_block: state_chain_runtime::BlockNumber,
pub channel_id: ChannelId,
pub source_chain_expiry_block: <AnyChain as cf_chains::Chain>::ChainBlockNumber,
pub channel_opening_fee: u128,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -365,6 +367,7 @@ pub trait BrokerApi: SignedExtrinsicApi {
deposit_address,
channel_id,
source_chain_expiry_block,
channel_opening_fee,
..
},
)) = events.iter().find(|event| {
Expand All @@ -380,6 +383,7 @@ pub trait BrokerApi: SignedExtrinsicApi {
issued_block: header.number,
channel_id: *channel_id,
source_chain_expiry_block: *source_chain_expiry_block,
channel_opening_fee: *channel_opening_fee,
})
} else {
bail!("No SwapDepositAddressReady event was found");
Expand All @@ -406,6 +410,7 @@ pub trait BrokerApi: SignedExtrinsicApi {
egress_fee,
destination_address,
egress_id,
..
},
)) = events.iter().find(|event| {
matches!(
Expand Down
1 change: 1 addition & 0 deletions api/lib/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl QueryApi {
false,
false,
false,
None,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/create_lp_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// initial price in USDC
// For example: ./commands/create_lp_pool.ts btc 10000

import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { createLpPool } from '../shared/create_lp_pool';
import { runWithTimeout } from '../shared/utils';

Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/get_balance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S pnpm tsx
import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { getBalance as getBalanceShared } from '../shared/get_balance';

async function getBalance(ccy: string, address: string) {
Expand Down
Loading

0 comments on commit e4c5bca

Please sign in to comment.