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

feat: adds withdrawal finalizing logic. #56

Merged
merged 38 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c7b69c8
adds finalization_data table migrations
montekki Jul 18, 2023
409e5c5
add_withdrawals_data method implementation
montekki Jul 18, 2023
92ea78f
adds a query to all newly executed withdrawals
montekki Jul 19, 2023
5e655b2
change l2_block_number type and fix sender address conversion
montekki Jul 19, 2023
40851b2
add finalizer main loop and adding data to new table
montekki Jul 19, 2023
1011fb1
adds a storage method to query previously unfinalized withdrawals
montekki Jul 19, 2023
574bcb3
fixes is null check in storage
montekki Jul 21, 2023
402cba3
withdrawal log data is rlp encoded
montekki Jul 21, 2023
2947f83
conversion method from withdrawal data into requestfinalizewithdrawal
montekki Jul 21, 2023
9293005
adds finalizer specific values to config
montekki Jul 23, 2023
21e9df0
adds finalization status updates to db
montekki Jul 23, 2023
d34fd6f
adds finalizing logic
montekki Jul 23, 2023
e7d2fba
clippy
montekki Jul 23, 2023
f10302d
refactors code
montekki Jul 23, 2023
d298f21
refactor a couple of iterators
montekki Jul 23, 2023
0cf0f62
adds config value for the account private key
montekki Jul 23, 2023
a78aa64
squash two structures together
montekki Jul 24, 2023
99112cf
rename finalizer contract variable
montekki Jul 24, 2023
c201952
refactor a bit and add comments
montekki Jul 24, 2023
17656d1
do not request finalization status in watcher
montekki Jul 24, 2023
a2de82d
remove redundant clone
montekki Jul 24, 2023
a1dcb9e
adds btreemap to accumulator
montekki Jul 24, 2023
d3098b3
document middlewares used by finalizer
montekki Jul 24, 2023
4b89636
cap tx fee limit const
montekki Jul 24, 2023
b53fc8d
reset accumulator with new gas price
montekki Jul 24, 2023
95bdf8e
rename migrator to params fetcher
montekki Jul 24, 2023
5c0d0e6
use hashset for are withdrawals finalized results
montekki Jul 24, 2023
b16ce08
use monotonically increasing id field for withdrawals
montekki Jul 24, 2023
d667fc3
remove is_finalized field from withdrawals table
montekki Jul 24, 2023
db1938d
change tx_fee_limit expect message
montekki Jul 24, 2023
acb5ec9
rename id and make it a foreign key
montekki Jul 24, 2023
d783dee
a single foreign key on withdrawals
montekki Jul 25, 2023
5c6fe54
Merge branch 'main' into fvs-pla-410-finalization-implementation
montekki Jul 25, 2023
1778cca
no lower boundary on finalization
montekki Jul 25, 2023
fd02358
only use withdrawal id as a foreign key in finalization_data
montekki Jul 25, 2023
a44e247
updates comment
montekki Jul 25, 2023
22b750a
if no money do not bump failed attempts counter
montekki Jul 26, 2023
e8916f8
rename migrator handle
montekki Jul 26, 2023
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
4 changes: 2 additions & 2 deletions chain-events/src/l2_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ impl L2EventsListener {
WithdrawalFilter::signature(),
];

let tokens = self.tokens.iter().cloned().collect::<Vec<_>>();

vlog::debug!("last_seen_l2_token_block {last_seen_l2_token_block:?}");
vlog::debug!("from_block {from_block:?}");

Expand All @@ -345,6 +343,8 @@ impl L2EventsListener {
.await?;
}

let tokens = self.tokens.iter().cloned().collect::<Vec<_>>();

let past_filter = Filter::new()
.from_block(from_block)
.to_block(latest_block)
Expand Down
8 changes: 7 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl WithdrawalParams {
}

/// A key that uniquely identifies each withdrawal
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct WithdrawalKey {
/// A transaction in which the withdrawal has happened
pub tx_hash: H256,
Expand All @@ -104,6 +104,11 @@ pub struct WithdrawalParams {
/// Event index in the transaction.
pub event_index_in_tx: u32,

/// ID serial number.
///
/// A monotonically increasing counter for every withdrawal.
pub id: u64,

/// Block number on l2 withdrawal transaction happened in.
pub l2_block_number: u64,

Expand Down Expand Up @@ -333,6 +338,7 @@ impl<P: JsonRpcClient> ZksyncMiddleware for Provider<P> {
Ok(Some(WithdrawalParams {
tx_hash: withdrawal_hash,
event_index_in_tx: index as u32,
id: 0,
l2_block_number: log
.block_number
.expect("log always has a block number; qed")
Expand Down
11 changes: 9 additions & 2 deletions finalizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,17 @@ where

let hash_and_index: Vec<_> = newly_executed_withdrawals
.iter()
.map(|p| (p.0, p.1))
.map(|p| (p.key.tx_hash, p.key.event_index_in_tx as u16))
.collect();

let params = request_finalize_params(&middleware, &hash_and_index).await?;
let mut params = request_finalize_params(&middleware, &hash_and_index).await?;

for (param, id) in params
.iter_mut()
.zip(newly_executed_withdrawals.iter().map(|v| v.id))
{
param.id = id;
}

storage::add_withdrawals_data(&pool, &params).await?;
}
Expand Down

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

This file was deleted.

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

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

This file was deleted.

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

1 change: 1 addition & 0 deletions storage/migrations/20230717075048_finalizer.down.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DROP TABLE finalization_data;
ALTER TABLE withdrawals DROP COLUMN id;
5 changes: 5 additions & 0 deletions storage/migrations/20230717075048_finalizer.up.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
ALTER TABLE withdrawals ADD id BIGSERIAL NOT NULL UNIQUE;

CREATE TABLE finalization_data (
tx_hash BYTEA NOT NULL,
event_index_in_tx INT NOT NULL,

id BIGINT NOT NULL UNIQUE,
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved

l2_block_number BIGINT NOT NULL,
l1_batch_number BIGINT NOT NULL,
l2_message_index INT NOT NULL,
Expand All @@ -17,3 +21,4 @@ CREATE TABLE finalization_data (

FOREIGN KEY (tx_hash, event_index_in_tx) REFERENCES withdrawals (tx_hash, event_index_in_tx)
);

Loading