From 8bb505a013ad3ef24494c584ccc7ad33ee7111d9 Mon Sep 17 00:00:00 2001 From: Hamed Afshar Date: Tue, 8 Oct 2024 15:55:46 +0200 Subject: [PATCH 1/4] feat: expose deposit transaction hash from ingress-egress-tracker [WEB-1511] --- .../src/witnessing/state_chain.rs | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs index 1035c0019d..4292ec21d2 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs @@ -60,13 +60,15 @@ enum TransactionId { #[derive(Serialize)] #[serde(untagged)] -enum WitnessInformation { +enum WitnessInformation { Deposit { deposit_chain_block_height: ::ChainBlockNumber, #[serde(skip_serializing)] deposit_address: String, amount: NumberOrHex, asset: cf_chains::assets::any::Asset, + #[serde(skip_serializing)] + deposit_details: ::DepositDetails, }, Broadcast { #[serde(skip_serializing)] @@ -76,7 +78,7 @@ enum WitnessInformation { }, } -impl WitnessInformation { +impl WitnessInformation { fn to_foreign_chain(&self) -> ForeignChain { match self { Self::Deposit { asset, .. } => (*asset).into(), @@ -90,7 +92,7 @@ impl WitnessInformation { } } -impl Storable for WitnessInformation { +impl Storable for WitnessInformation { fn get_key(&self) -> String { let chain = self.to_foreign_chain().to_string(); @@ -114,46 +116,50 @@ impl Storable for WitnessInformation { type DepositInfo = (DepositWitness, ::ChainBlockNumber, NetworkEnvironment); -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, _): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height, deposit_address: hex_encode_bytes(value.deposit_address.as_bytes()), amount: value.amount.into(), asset: value.asset.into(), + deposit_details: value.deposit_details, } } } -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, network): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height, deposit_address: value.deposit_address.to_humanreadable(network), amount: value.amount.into(), asset: value.asset.into(), + deposit_details: value.deposit_details, } } } -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, _): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height as u64, deposit_address: hex_encode_bytes(value.deposit_address.aliased_ref()), amount: value.amount.into(), asset: value.asset.into(), + deposit_details: value.deposit_details, } } } -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, _): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height, deposit_address: hex_encode_bytes(value.deposit_address.as_bytes()), amount: value.amount.into(), asset: value.asset.into(), + deposit_details: value.deposit_details, } } } @@ -165,7 +171,7 @@ async fn save_deposit_witnesses( chainflip_network: NetworkEnvironment, ) -> anyhow::Result<()> where - WitnessInformation: + WitnessInformation: From<(DepositWitness, ::ChainBlockNumber, NetworkEnvironment)>, { for witness in deposit_witnesses { @@ -208,15 +214,8 @@ where deposit_witnesses, block_height, }) => - for witness in deposit_witnesses as Vec> { - store - .save_to_array(&WitnessInformation::from(( - witness, - block_height, - chainflip_network, - ))) - .await?; - }, + save_deposit_witnesses(store, deposit_witnesses, block_height, chainflip_network) + .await?, ArbitrumIngressEgress(IngressEgressCall::process_deposits { deposit_witnesses, block_height, @@ -238,7 +237,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::Broadcast { + .save_singleton(&WitnessInformation::::Broadcast { broadcast_id, tx_out_id: TransactionId::Ethereum { signature: tx_out_id }, tx_ref: TransactionRef::Ethereum { hash: transaction_ref }, @@ -256,7 +255,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::Broadcast { + .save_singleton(&WitnessInformation::::Broadcast { broadcast_id, tx_out_id: TransactionId::Bitcoin { hash: BitcoinHash(tx_out_id) }, tx_ref: TransactionRef::Bitcoin { hash: BitcoinHash(transaction_ref) }, @@ -276,7 +275,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::Broadcast { + .save_singleton(&WitnessInformation::::Broadcast { broadcast_id, tx_out_id: TransactionId::Polkadot { signature: DotSignature(*tx_out_id.aliased_ref()), @@ -297,7 +296,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::Broadcast { + .save_singleton(&WitnessInformation::::Broadcast { broadcast_id, tx_out_id: TransactionId::Arbitrum { signature: tx_out_id }, tx_ref: TransactionRef::Arbitrum { hash: transaction_ref }, From e06bd8f0028986218a64e2bd69cb682d03c75869 Mon Sep 17 00:00:00 2001 From: Hamed Afshar Date: Tue, 15 Oct 2024 14:29:59 +0200 Subject: [PATCH 2/4] fixes --- .../src/witnessing/state_chain.rs | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs index 4292ec21d2..b5debe48b4 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs @@ -4,7 +4,7 @@ use crate::{ }; use cf_chains::{ address::ToHumanreadableAddress, - dot::PolkadotTransactionId, + dot::{PolkadotExtrinsicIndex, PolkadotTransactionId}, evm::{SchnorrVerificationComponents, H256}, AnyChain, Arbitrum, Bitcoin, Chain, Ethereum, Polkadot, }; @@ -60,15 +60,23 @@ enum TransactionId { #[derive(Serialize)] #[serde(untagged)] -enum WitnessInformation { +enum DepositDetails { + Bitcoin { tx_id: H256, vout: u32 }, + Ethereum { tx_hashes: Option> }, + Polkadot { extrinsic_index: PolkadotExtrinsicIndex }, + Arbitrum { tx_hashes: Option> }, +} + +#[derive(Serialize)] +#[serde(untagged)] +enum WitnessInformation { Deposit { deposit_chain_block_height: ::ChainBlockNumber, #[serde(skip_serializing)] deposit_address: String, amount: NumberOrHex, asset: cf_chains::assets::any::Asset, - #[serde(skip_serializing)] - deposit_details: ::DepositDetails, + deposit_details: DepositDetails, }, Broadcast { #[serde(skip_serializing)] @@ -78,7 +86,7 @@ enum WitnessInformation { }, } -impl WitnessInformation { +impl WitnessInformation { fn to_foreign_chain(&self) -> ForeignChain { match self { Self::Deposit { asset, .. } => (*asset).into(), @@ -92,7 +100,7 @@ impl WitnessInformation { } } -impl Storable for WitnessInformation { +impl Storable for WitnessInformation { fn get_key(&self) -> String { let chain = self.to_foreign_chain().to_string(); @@ -116,50 +124,57 @@ impl Storable for WitnessInformation { type DepositInfo = (DepositWitness, ::ChainBlockNumber, NetworkEnvironment); -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, _): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height, deposit_address: hex_encode_bytes(value.deposit_address.as_bytes()), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: value.deposit_details, + deposit_details: DepositDetails::Ethereum { + tx_hashes: value.deposit_details.tx_hashes, + }, } } } -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, network): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height, deposit_address: value.deposit_address.to_humanreadable(network), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: value.deposit_details, + deposit_details: DepositDetails::Bitcoin { + tx_id: value.deposit_details.tx_id, + vout: value.deposit_details.vout, + }, } } } -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, _): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height as u64, deposit_address: hex_encode_bytes(value.deposit_address.aliased_ref()), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: value.deposit_details, + deposit_details: DepositDetails::Polkadot { extrinsic_index: value.deposit_details }, } } } -impl From> for WitnessInformation { +impl From> for WitnessInformation { fn from((value, height, _): DepositInfo) -> Self { Self::Deposit { deposit_chain_block_height: height, deposit_address: hex_encode_bytes(value.deposit_address.as_bytes()), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: value.deposit_details, + deposit_details: DepositDetails::Arbitrum { + tx_hashes: value.deposit_details.tx_hashes, + }, } } } @@ -171,7 +186,7 @@ async fn save_deposit_witnesses( chainflip_network: NetworkEnvironment, ) -> anyhow::Result<()> where - WitnessInformation: + WitnessInformation: From<(DepositWitness, ::ChainBlockNumber, NetworkEnvironment)>, { for witness in deposit_witnesses { @@ -237,7 +252,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::::Broadcast { + .save_singleton(&WitnessInformation::Broadcast { broadcast_id, tx_out_id: TransactionId::Ethereum { signature: tx_out_id }, tx_ref: TransactionRef::Ethereum { hash: transaction_ref }, @@ -255,7 +270,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::::Broadcast { + .save_singleton(&WitnessInformation::Broadcast { broadcast_id, tx_out_id: TransactionId::Bitcoin { hash: BitcoinHash(tx_out_id) }, tx_ref: TransactionRef::Bitcoin { hash: BitcoinHash(transaction_ref) }, @@ -275,7 +290,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::::Broadcast { + .save_singleton(&WitnessInformation::Broadcast { broadcast_id, tx_out_id: TransactionId::Polkadot { signature: DotSignature(*tx_out_id.aliased_ref()), @@ -296,7 +311,7 @@ where if let Some(broadcast_id) = broadcast_id { store - .save_singleton(&WitnessInformation::::Broadcast { + .save_singleton(&WitnessInformation::Broadcast { broadcast_id, tx_out_id: TransactionId::Arbitrum { signature: tx_out_id }, tx_ref: TransactionRef::Arbitrum { hash: transaction_ref }, From 01e0dd34cb279d41481acd9877716cff7355c17e Mon Sep 17 00:00:00 2001 From: Hamed Afshar Date: Tue, 15 Oct 2024 15:59:04 +0200 Subject: [PATCH 3/4] make deposit_details optional --- .../src/witnessing/state_chain.rs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs index b5debe48b4..85818481de 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs @@ -62,9 +62,9 @@ enum TransactionId { #[serde(untagged)] enum DepositDetails { Bitcoin { tx_id: H256, vout: u32 }, - Ethereum { tx_hashes: Option> }, + Ethereum { tx_hashes: Vec }, Polkadot { extrinsic_index: PolkadotExtrinsicIndex }, - Arbitrum { tx_hashes: Option> }, + Arbitrum { tx_hashes: Vec }, } #[derive(Serialize)] @@ -76,7 +76,7 @@ enum WitnessInformation { deposit_address: String, amount: NumberOrHex, asset: cf_chains::assets::any::Asset, - deposit_details: DepositDetails, + deposit_details: Option, }, Broadcast { #[serde(skip_serializing)] @@ -131,9 +131,10 @@ impl From> for WitnessInformation { deposit_address: hex_encode_bytes(value.deposit_address.as_bytes()), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: DepositDetails::Ethereum { - tx_hashes: value.deposit_details.tx_hashes, - }, + deposit_details: value + .deposit_details + .tx_hashes + .map(|tx_hashes| DepositDetails::Ethereum { tx_hashes }), } } } @@ -145,10 +146,10 @@ impl From> for WitnessInformation { deposit_address: value.deposit_address.to_humanreadable(network), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: DepositDetails::Bitcoin { + deposit_details: Some(DepositDetails::Bitcoin { tx_id: value.deposit_details.tx_id, vout: value.deposit_details.vout, - }, + }), } } } @@ -160,7 +161,9 @@ impl From> for WitnessInformation { deposit_address: hex_encode_bytes(value.deposit_address.aliased_ref()), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: DepositDetails::Polkadot { extrinsic_index: value.deposit_details }, + deposit_details: Some(DepositDetails::Polkadot { + extrinsic_index: value.deposit_details, + }), } } } @@ -172,9 +175,10 @@ impl From> for WitnessInformation { deposit_address: hex_encode_bytes(value.deposit_address.as_bytes()), amount: value.amount.into(), asset: value.asset.into(), - deposit_details: DepositDetails::Arbitrum { - tx_hashes: value.deposit_details.tx_hashes, - }, + deposit_details: value + .deposit_details + .tx_hashes + .map(|tx_hashes| DepositDetails::Arbitrum { tx_hashes }), } } } From 80c0e9a61b3764ad2d1355701954adca61de1ce5 Mon Sep 17 00:00:00 2001 From: Hamed Afshar Date: Wed, 16 Oct 2024 13:13:49 +0200 Subject: [PATCH 4/4] fix tests --- ..._witnessing__state_chain__tests__handle_deposit_calls-2.snap | 2 +- ..._witnessing__state_chain__tests__handle_deposit_calls-3.snap | 2 +- ..._witnessing__state_chain__tests__handle_deposit_calls-4.snap | 2 +- ...r__witnessing__state_chain__tests__handle_deposit_calls.snap | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-2.snap b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-2.snap index 2bc2890ef3..024d4127f4 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-2.snap +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-2.snap @@ -3,4 +3,4 @@ source: api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs assertion_line: 487 expression: "store.storage.get(format!(\"deposit:Polkadot:{}\", format!\n (\"0x{}\", hex ::\n encode(polkadot_account_id.aliased_ref()))).as_str()).unwrap()" --- -[{"amount":"0x64","asset":{"asset":"DOT","chain":"Polkadot"},"deposit_chain_block_height":1}] +[{"amount":"0x64","asset":{"asset":"DOT","chain":"Polkadot"},"deposit_chain_block_height":1,"deposit_details":{"extrinsic_index":1}}] diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-3.snap b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-3.snap index aafc0683b6..a12dc7e5ef 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-3.snap +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-3.snap @@ -3,4 +3,4 @@ source: api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs assertion_line: 497 expression: "store.storage.get(format!(\"deposit:Ethereum:{}\",\n eth_address_str2.to_lowercase()).as_str()).unwrap()" --- -[{"amount":"0x64","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1}] +[{"amount":"0x64","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1,"deposit_details":null}] diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-4.snap b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-4.snap index 242c6f9a20..911ef47e1e 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-4.snap +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls-4.snap @@ -3,4 +3,4 @@ source: api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs assertion_line: 521 expression: "store.storage.get(format!(\"deposit:Ethereum:{}\",\n eth_address_str1.to_lowercase()).as_str()).unwrap()" --- -[{"amount":"0x64","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1},{"amount":"0x1e8480","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1}] +[{"amount":"0x64","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1,"deposit_details":null},{"amount":"0x1e8480","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1,"deposit_details":null}] diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls.snap b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls.snap index fa3c0c426d..417a687ccd 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls.snap +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/snapshots/chainflip_ingress_egress_tracker__witnessing__state_chain__tests__handle_deposit_calls.snap @@ -3,4 +3,4 @@ source: api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs assertion_line: 483 expression: "store.storage.get(format!(\"deposit:Ethereum:{}\",\n eth_address_str1.to_lowercase()).as_str()).unwrap()" --- -[{"amount":"0x64","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1}] +[{"amount":"0x64","asset":{"asset":"ETH","chain":"Ethereum"},"deposit_chain_block_height":1,"deposit_details":null}]