Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate logging #3939

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine/src/witness/btc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where

btc_source
.clone()
.shared(scope)
.chunk_by_time(epoch_source.clone())
.chain_tracking(state_chain_client.clone(), btc_client.clone())
.logging("chain tracking")
Expand All @@ -62,6 +63,7 @@ where
(header.data, block.txdata)
}
})
.shared(scope)
.chunk_by_vault(epoch_source.vaults().await)
.deposit_addresses(scope, state_chain_stream.clone(), state_chain_client.clone())
.await
Expand Down
65 changes: 31 additions & 34 deletions engine/src/witness/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use state_chain_runtime::PolkadotInstance;
use subxt::{
config::PolkadotConfig,
events::{EventDetails, Phase, StaticEvent},
utils::AccountId32,
};

use tracing::error;
Expand Down Expand Up @@ -38,11 +39,11 @@ use super::common::{epoch_source::EpochSourceBuilder, STATE_CHAIN_CONNECTION};
#[subxt::subxt(runtime_metadata_path = "metadata.polkadot.scale")]
pub mod polkadot {}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum EventWrapper {
ProxyAdded(ProxyAdded),
Transfer(Transfer),
TransactionFeePaid(TransactionFeePaid),
ProxyAdded { delegator: AccountId32, delegatee: AccountId32 },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to do this so the events could be Clone

Transfer { to: AccountId32, from: AccountId32, amount: PolkadotBalance },
TransactionFeePaid { actual_fee: PolkadotBalance, tip: PolkadotBalance },
}

use polkadot::{
Expand All @@ -55,15 +56,21 @@ fn filter_map_events(
) -> Option<(Phase, EventWrapper)> {
match res_event_details {
Ok(event_details) => match (event_details.pallet_name(), event_details.variant_name()) {
(ProxyAdded::PALLET, ProxyAdded::EVENT) => Some(EventWrapper::ProxyAdded(
event_details.as_event::<ProxyAdded>().unwrap().unwrap(),
)),
(Transfer::PALLET, Transfer::EVENT) =>
Some(EventWrapper::Transfer(event_details.as_event::<Transfer>().unwrap().unwrap())),
(TransactionFeePaid::PALLET, TransactionFeePaid::EVENT) =>
Some(EventWrapper::TransactionFeePaid(
event_details.as_event::<TransactionFeePaid>().unwrap().unwrap(),
)),
(ProxyAdded::PALLET, ProxyAdded::EVENT) => {
let ProxyAdded { delegator, delegatee, .. } =
event_details.as_event::<ProxyAdded>().unwrap().unwrap();
Some(EventWrapper::ProxyAdded { delegator, delegatee })
},
(Transfer::PALLET, Transfer::EVENT) => {
let Transfer { to, amount, from } =
event_details.as_event::<Transfer>().unwrap().unwrap();
Some(EventWrapper::Transfer { to, amount, from })
},
(TransactionFeePaid::PALLET, TransactionFeePaid::EVENT) => {
let TransactionFeePaid { actual_fee, tip, .. } =
event_details.as_event::<TransactionFeePaid>().unwrap().unwrap();
Some(EventWrapper::TransactionFeePaid { actual_fee, tip })
},
_ => None,
}
.map(|event| (event_details.phase(), event)),
Expand All @@ -87,8 +94,8 @@ where
StateChainStream: StateChainStreamApi + Clone,
{
DotUnfinalisedSource::new(dot_client.clone())
.shared(scope)
.then(|header| async move { header.data.iter().filter_map(filter_map_events).collect() })
.shared(scope)
kylezs marked this conversation as resolved.
Show resolved Hide resolved
.chunk_by_time(epoch_source.clone())
.chain_tracking(state_chain_client.clone(), dot_client.clone())
.logging("chain tracking")
Expand All @@ -109,12 +116,12 @@ where
.await;

DotFinalisedSource::new(dot_client.clone())
.shared(scope)
.strictly_monotonic()
.logging("finalised block produced")
.then(|header| async move {
header.data.iter().filter_map(filter_map_events).collect::<Vec<_>>()
})
.shared(scope)
.chunk_by_vault(epoch_source.vaults().await)
.deposit_addresses(scope, state_chain_stream.clone(), state_chain_client.clone())
.await
Expand Down Expand Up @@ -262,7 +269,7 @@ fn deposit_witnesses(
let mut extrinsic_indices = BTreeSet::new();
for (phase, wrapped_event) in events {
if let Phase::ApplyExtrinsic(extrinsic_index) = phase {
if let EventWrapper::Transfer(Transfer { to, amount, from }) = wrapped_event {
if let EventWrapper::Transfer { to, amount, from } = wrapped_event {
let deposit_address = PolkadotAccountId::from_aliased(to.0);
if monitored_addresses.contains(&deposit_address) {
deposit_witnesses.push(DepositWitness {
Expand Down Expand Up @@ -296,9 +303,7 @@ fn transaction_fee_paids(
for (phase, wrapped_event) in events {
if let Phase::ApplyExtrinsic(extrinsic_index) = phase {
if indices.contains(extrinsic_index) {
if let EventWrapper::TransactionFeePaid(TransactionFeePaid { actual_fee, .. }) =
wrapped_event
{
if let EventWrapper::TransactionFeePaid { actual_fee, .. } = wrapped_event {
indices_with_fees.insert((*extrinsic_index, *actual_fee));
}
}
Expand All @@ -317,8 +322,7 @@ fn proxy_addeds(
let mut extrinsic_indices = BTreeSet::new();
for (phase, wrapped_event) in events {
if let Phase::ApplyExtrinsic(extrinsic_index) = *phase {
if let EventWrapper::ProxyAdded(ProxyAdded { delegator, delegatee, .. }) = wrapped_event
{
if let EventWrapper::ProxyAdded { delegator, delegatee } = wrapped_event {
if &PolkadotAccountId::from_aliased(delegator.0) != our_vault {
continue
}
Expand All @@ -342,19 +346,18 @@ fn proxy_addeds(

#[cfg(test)]
mod test {

use super::{polkadot::runtime_types::polkadot_runtime::ProxyType as PolkadotProxyType, *};
use super::*;

fn mock_transfer(
from: &PolkadotAccountId,
to: &PolkadotAccountId,
amount: PolkadotBalance,
) -> EventWrapper {
EventWrapper::Transfer(Transfer {
EventWrapper::Transfer {
from: from.aliased_ref().to_owned().into(),
to: to.aliased_ref().to_owned().into(),
amount,
})
}
}

fn phase_and_events(
Expand All @@ -370,20 +373,14 @@ mod test {
delegator: &PolkadotAccountId,
delegatee: &PolkadotAccountId,
) -> EventWrapper {
EventWrapper::ProxyAdded(ProxyAdded {
EventWrapper::ProxyAdded {
delegator: delegator.aliased_ref().to_owned().into(),
delegatee: delegatee.aliased_ref().to_owned().into(),
proxy_type: PolkadotProxyType::Any,
delay: 0,
})
}
}

fn mock_tx_fee_paid(actual_fee: PolkadotBalance) -> EventWrapper {
EventWrapper::TransactionFeePaid(TransactionFeePaid {
actual_fee,
who: [0xab; 32].into(),
tip: Default::default(),
})
EventWrapper::TransactionFeePaid { actual_fee, tip: Default::default() }
}

#[test]
Expand Down
9 changes: 2 additions & 7 deletions engine/src/witness/dot/dot_chain_tracking.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use cf_chains::dot::{PolkadotHash, PolkadotTrackedData};
use subxt::events::Phase;

use crate::{
dot::retry_rpc::DotRetryRpcApi,
witness::dot::{EventWrapper, TransactionFeePaid},
};
use crate::{dot::retry_rpc::DotRetryRpcApi, witness::dot::EventWrapper};

use super::super::common::{
chain_source::Header, chunked_chain_source::chunked_by_time::chain_tracking::GetTrackedData,
Expand All @@ -27,9 +24,7 @@ impl<T: DotRetryRpcApi + Send + Sync + Clone>
let mut tips = Vec::new();
for (phase, wrapped_event) in events.iter() {
if let Phase::ApplyExtrinsic(_) = phase {
if let EventWrapper::TransactionFeePaid(TransactionFeePaid { tip, .. }) =
wrapped_event
{
if let EventWrapper::TransactionFeePaid { tip, .. } = wrapped_event {
tips.push(*tip);
}
}
Expand Down
1 change: 1 addition & 0 deletions engine/src/witness/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ where

eth_source
.clone()
.shared(scope)
.chunk_by_time(epoch_source.clone())
.chain_tracking(state_chain_client.clone(), eth_client.clone())
.logging("chain tracking")
Expand Down
Loading