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(batcher): has_enough_balance used current_max_fee + new_max_fee in replacement message #1559

Open
wants to merge 42 commits into
base: staging
Choose a base branch
from
Open
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
436ce43
feat: add mainnet values to sdk (#1536)
uri-99 Dec 3, 2024
a1bbd16
rearrange logic for user_balance check + subtract original_msg_max_fe…
PatStiles Dec 3, 2024
50efe9a
chore: cargo fmt
MarcosNicolau Dec 4, 2024
d7efa1b
chore: address clippy warnings
MarcosNicolau Dec 4, 2024
f8de225
Revert "feat: add mainnet values to sdk (#1536)"
MarcosNicolau Dec 5, 2024
f60e4ee
fix: remove extra param
uri-99 Dec 5, 2024
b5625ca
fix: close old sink only after replacement entry is valid
uri-99 Dec 5, 2024
cc568ea
Merge branch 'staging' into fix/computation-of-replacement-message-ac…
MarcosNicolau Dec 6, 2024
d55f58e
remove NetworkArg type
PatStiles Dec 10, 2024
bd1139b
add lock
PatStiles Dec 10, 2024
bab051a
pass by copy
PatStiles Jan 2, 2025
8c4049a
remove need for ValueEnum
PatStiles Jan 7, 2025
a289328
fmt + clippy
PatStiles Jan 7, 2025
82fa721
move values to constants
PatStiles Jan 8, 2025
510f6e2
add custom network arg
PatStiles Jan 8, 2025
9b2d37b
fmt
PatStiles Jan 8, 2025
a320ab0
change error messages
PatStiles Jan 8, 2025
587a5fa
enforce custom in right place + fix
PatStiles Jan 10, 2025
1a4ef29
remove clap from cargo.toml
PatStiles Jan 9, 2025
0ac4db3
deprecate batcher_url
PatStiles Jan 10, 2025
c765ecf
deprecate more
PatStiles Jan 10, 2025
2f6da7c
feat: better implementation of this pr
uri-99 Jan 15, 2025
0dab9a1
Merge branch 'staging' into feat/deprecate-batcher-url
uri-99 Jan 16, 2025
ec9685d
chore: cargo fmt
uri-99 Jan 16, 2025
9da8dcc
feat: migrate rust task sender
uri-99 Jan 16, 2025
5873fa4
chore: docs
uri-99 Jan 16, 2025
ceafba5
chore: cargo fmt
uri-99 Jan 16, 2025
ab87086
chore: cargo clippy
uri-99 Jan 16, 2025
51f576a
chore: add error failure on CI
uri-99 Jan 17, 2025
79a3b8a
chore: fix comment
uri-99 Jan 17, 2025
d7dc1c1
fix: debugging error in CI
uri-99 Jan 17, 2025
ce35d41
fix(wip): print .json contents
uri-99 Jan 17, 2025
f05869e
fix: prints
uri-99 Jan 17, 2025
1c3b245
fix: revert CI changes, they are in another pr
uri-99 Jan 17, 2025
8e582ca
Merge branch 'pull_fixes_testnet_17_01' into feat/deprecate-batcher-url
uri-99 Jan 17, 2025
5d32849
fix: docs
uri-99 Jan 17, 2025
5447237
chore: cargo fmt
uri-99 Jan 17, 2025
00a252c
fix: batcher urls
JuArce Jan 17, 2025
cc84f6e
fix: missing new line
JuArce Jan 17, 2025
5bd5fb9
fix: remove mix.lock changes
JuArce Jan 17, 2025
5a5447c
fix: remove mix.lock changes
JuArce Jan 17, 2025
1c16503
Merge branch 'feat/deprecate-batcher-url' into fix/computation-of-rep…
uri-99 Jan 17, 2025
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
45 changes: 34 additions & 11 deletions batcher/aligned-batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,6 @@ impl Batcher {
return Ok(());
};

if !self.verify_user_has_enough_balance(user_balance, user_accumulated_fee, msg_max_fee) {
std::mem::drop(batch_state_lock);
send_message(
ws_conn_sink.clone(),
SubmitProofResponseMessage::InsufficientBalance(addr),
)
.await;
self.metrics.user_error(&["insufficient_balance", ""]);
return Ok(());
}

let cached_user_nonce = batch_state_lock.get_user_nonce(&addr).await;
let Some(expected_nonce) = cached_user_nonce else {
error!("Failed to get cached user nonce: User not found in user states, but it should have been already inserted");
Expand Down Expand Up @@ -791,12 +780,26 @@ impl Batcher {
ws_conn_sink.clone(),
client_msg.signature,
addr,
user_balance,
user_accumulated_fee,
msg_max_fee,
)
.await;

return Ok(());
}

if !self.verify_user_has_enough_balance(user_balance, user_accumulated_fee, msg_max_fee) {
std::mem::drop(batch_state_lock);
send_message(
ws_conn_sink.clone(),
SubmitProofResponseMessage::InsufficientBalance(addr),
)
.await;
self.metrics.user_error(&["insufficient_balance", ""]);
return Ok(());
}

if msg_max_fee > user_last_max_fee_limit {
std::mem::drop(batch_state_lock);
warn!("Invalid max fee for address {addr}, had fee limit of {user_last_max_fee_limit:?}, sent {msg_max_fee:?}");
Expand Down Expand Up @@ -856,13 +859,17 @@ impl Batcher {
/// If the max fee is lower, sends an error message to the client
/// If the message is not in the batch, sends an error message to the client
/// Returns true if the message was replaced in the batch, false otherwise
#[allow(clippy::too_many_arguments)]
async fn handle_replacement_message(
&self,
mut batch_state_lock: MutexGuard<'_, BatchState>,
nonced_verification_data: NoncedVerificationData,
ws_conn_sink: WsMessageSink,
signature: Signature,
addr: Address,
user_balance: U256,
user_accumulated_fee: U256,
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
msg_max_fee: U256,
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
) {
let replacement_max_fee = nonced_verification_data.max_fee;
let nonce = nonced_verification_data.nonce;
Expand Down Expand Up @@ -892,6 +899,22 @@ impl Batcher {
return;
}

// For a replacement msg we must subtract the original_max_fee of the message from the user's accumulated max fee.
if !self.verify_user_has_enough_balance(
user_balance,
user_accumulated_fee - original_max_fee,
msg_max_fee,
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
) {
std::mem::drop(batch_state_lock);
send_message(
ws_conn_sink.clone(),
SubmitProofResponseMessage::InsufficientBalance(addr),
)
.await;
self.metrics.user_error(&["insufficient_balance", ""]);
return;
}

info!("Replacing message for address {addr} with nonce {nonce} and max fee {replacement_max_fee}");

// The replacement entry is built from the old entry and validated for then to be replaced
Expand Down
Loading