Skip to content

Commit

Permalink
Merge #1472
Browse files Browse the repository at this point in the history
1472: Fix reorg risks with forced exits r=Deniallugo a=StanislavBreadless

We do accept transactions after small amount of confirmations, but in order to protect against the reorgs we check also past blocks multiple times.

Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
  • Loading branch information
2 parents d322c9c + 674650a commit 1a4400d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/bin/zksync_forced_exit_requests/src/eth_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,13 @@ where
return;
};

let block_to_watch_from = self
.last_viewed_block
.saturating_sub(self.config.forced_exit_requests.blocks_check_amount);

let events = self
.eth_client
.get_funds_received_events(self.last_viewed_block + 1, last_confirmed_block)
.get_funds_received_events(block_to_watch_from, last_confirmed_block)
.await;

let events = match events {
Expand Down
3 changes: 3 additions & 0 deletions core/lib/config/src/configs/forced_exit_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct ForcedExitRequestsInternalConfig {
pub sender_eth_private_key: H256,
pub sender_account_address: Address,
pub expiration_period: u64,
pub blocks_check_amount: u64,
pub eth_node_poll_interval: u64,
}

Expand All @@ -42,6 +43,7 @@ pub struct ForcedExitRequestsConfig {
pub sender_eth_private_key: H256,
pub sender_account_address: Address,
pub expiration_period: u64,
pub blocks_check_amount: u64,
pub eth_node_poll_interval: u64,
}

Expand Down Expand Up @@ -83,6 +85,7 @@ impl ForcedExitRequestsConfig {
sender_eth_private_key: config.sender_eth_private_key,
sender_account_address: config.sender_account_address,
expiration_period: config.expiration_period,
blocks_check_amount: config.blocks_check_amount,
eth_node_poll_interval: config.eth_node_poll_interval,
}
}
Expand Down
7 changes: 7 additions & 0 deletions etc/env/base/forced_exit_requests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ withdrawal_threshold=1000000000000000000
# to set the same account as the one that sends the txs for retrieving the fees from the smart contract
fee_receiver="0x1963917ba0b44A879cf6248387C1d51A0F11669d"


# The amount of blocks we look into beyound the waiting confirmations
# Basically this ensures that we do not skip a transaction that has become too old due to a
# reorg
blocks_check_amount=10

# How often we want to poll the Ethereum node (in milliseconds).
eth_node_poll_interval=300

0 comments on commit 1a4400d

Please sign in to comment.