Skip to content

Commit

Permalink
fix(chain-events): do not listen to withdrawalinitiated events (#347)
Browse files Browse the repository at this point in the history
# What ❔

Change was introduced for a custom birdge but on the main bridge this
will detect the same withdrawal event twice.

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `cargo fmt`.
  • Loading branch information
montekki committed Jan 16, 2024
1 parent 17d10be commit 08e6971
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
29 changes: 1 addition & 28 deletions chain-events/src/l2_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use futures::{Sink, SinkExt, StreamExt};
use client::{
contracts_deployer::codegen::ContractDeployedFilter,
ethtoken::codegen::WithdrawalFilter,
l2bridge::codegen::WithdrawalInitiatedFilter,
l2standard_token::codegen::{
BridgeBurnFilter, BridgeInitializationFilter, BridgeInitializeFilter,
},
Expand Down Expand Up @@ -39,7 +38,6 @@ pub struct L2EventsListener {
enum L2Events {
BridgeBurn(BridgeBurnFilter),
Withdrawal(WithdrawalFilter),
WithdrawalInitiated(WithdrawalInitiatedFilter),
ContractDeployed(ContractDeployedFilter),
}

Expand Down Expand Up @@ -337,17 +335,12 @@ impl L2EventsListener {
let last_seen_l2_token_block: BlockNumber = last_seen_l2_token_block.into();
let from_block: BlockNumber = from_block.into();

let past_topic0 = vec![
BridgeBurnFilter::signature(),
WithdrawalFilter::signature(),
WithdrawalInitiatedFilter::signature(),
];
let past_topic0 = vec![BridgeBurnFilter::signature(), WithdrawalFilter::signature()];

let topic0 = vec![
ContractDeployedFilter::signature(),
BridgeBurnFilter::signature(),
WithdrawalFilter::signature(),
WithdrawalInitiatedFilter::signature(),
];

tracing::info!("topic0 {topic0:?}");
Expand Down Expand Up @@ -486,26 +479,6 @@ impl L2EventsListener {
.await
.map_err(|_| Error::ChannelClosing)?;
}
L2Events::WithdrawalInitiated(WithdrawalInitiatedFilter {
amount,
l_2_token,
..
}) => {
CHAIN_EVENTS_METRICS.withdrawal_events.inc();

let we = WithdrawalEvent {
tx_hash,
block_number: block_number.as_u64(),
token: *l_2_token,
amount: *amount,
};
let event = we.into();
tracing::info!("sending withdrawal event {event:?}");
sender
.send(event)
.await
.map_err(|_| Error::ChannelClosing)?;
}
L2Events::ContractDeployed(_) => {
let tx = middleware
.zks_get_transaction_receipt(log.transaction_hash.unwrap_or_else(|| {
Expand Down
9 changes: 0 additions & 9 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn is_eth(address: Address) -> bool {
enum WithdrawalEvents {
BridgeBurn(BridgeBurnFilter),
Withdrawal(WithdrawalFilter),
WithdrawalInitiated(WithdrawalInitiatedFilter),
}

lazy_static! {
Expand Down Expand Up @@ -340,7 +339,6 @@ impl<P: JsonRpcClient> ZksyncMiddleware for Provider<P> {
.filter(|log| {
log.topics[0] == BridgeBurnFilter::signature()
|| log.topics[0] == WithdrawalFilter::signature()
|| log.topics[0] == WithdrawalInitiatedFilter::signature()
})
.nth(index)
.ok_or(Error::WithdrawalLogNotFound(index, withdrawal_hash))?;
Expand All @@ -349,13 +347,6 @@ impl<P: JsonRpcClient> ZksyncMiddleware for Provider<P> {
let withdrawal_event = WithdrawalEvents::decode_log(&raw_log)?;

let l2_to_l1_message_hash = match withdrawal_event {
WithdrawalEvents::WithdrawalInitiated(w) => {
let addr_lock = TOKEN_ADDRS.lock().await;
let l_1_token = addr_lock
.get(&w.l_2_token)
.ok_or(Error::L2TokenUnknown(w.l_2_token))?;
get_l1_bridge_burn_message_keccak(w.amount, w.l_1_receiver, *l_1_token)?
}
WithdrawalEvents::BridgeBurn(b) => {
let mut addr_lock = TOKEN_ADDRS.lock().await;

Expand Down

0 comments on commit 08e6971

Please sign in to comment.