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(cli): add get-user-first-nonce + get-user-number-queued-proofs cli commands #1553

Merged
merged 51 commits into from
Jan 21, 2025
Merged
Changes from 7 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9a62d14
add get_first_nonce command
PatStiles Dec 2, 2024
650beeb
fmt
PatStiles Dec 3, 2024
3f61db1
fix get first nonce
MarcosNicolau Dec 5, 2024
26b0138
refactor: nit
MarcosNicolau Dec 5, 2024
87e0e87
feat: GetAmountOfProofsInBatcherQueue
uri-99 Dec 5, 2024
934de62
fix: substraction
uri-99 Dec 5, 2024
6440e87
chore: cargo clippy
uri-99 Dec 5, 2024
b67cd0b
change command name
PatStiles Dec 6, 2024
5a7628a
join two futures
PatStiles Dec 6, 2024
5e8807e
remove invalid state check
PatStiles Dec 6, 2024
2612234
user_addr -> user_address
PatStiles Dec 6, 2024
9a2bdad
change user_addr
PatStiles Dec 10, 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
01412c1
Merge branch 'staging' into 1541-get-first-nonce-in-queue
uri-99 Jan 16, 2025
0e6c0a6
chore: docs
uri-99 Jan 16, 2025
10fedc6
chore: cargo fmt
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
2c5af7c
Merge branch 'feat/deprecate-batcher-url' into 1541-get-first-nonce-i…
uri-99 Jan 17, 2025
178faba
fix: compatibility with base branch
uri-99 Jan 17, 2025
9fe9c4a
Merge branch 'staging' into 1541-get-first-nonce-in-queue
uri-99 Jan 20, 2025
09489e0
fix: add missing new line
JuArce Jan 21, 2025
689e77a
fix: remove explorer mix.lock changes
JuArce Jan 21, 2025
7f17236
Merge branch 'refs/heads/staging' into 1541-get-first-nonce-in-queue
JuArce Jan 21, 2025
88559ca
docs: add get-user-nonce command
JuArce Jan 21, 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
115 changes: 114 additions & 1 deletion batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use aligned_sdk::core::{
};
use aligned_sdk::sdk::get_chain_id;
use aligned_sdk::sdk::get_nonce_from_batcher;
use aligned_sdk::sdk::get_nonce_from_ethereum;
use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned};
use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple};
use clap::Parser;
Expand All @@ -27,8 +28,10 @@ use log::{error, info};
use transaction::eip2718::TypedTransaction;

use crate::AlignedCommands::DepositToBatcher;
use crate::AlignedCommands::GetAmountOfProofsInBatcherQueue;
use crate::AlignedCommands::GetUserBalance;
use crate::AlignedCommands::GetUserNonce;
use crate::AlignedCommands::GetUserNonceFromEthereum;
use crate::AlignedCommands::GetVkCommitment;
use crate::AlignedCommands::Submit;
use crate::AlignedCommands::VerifyProofOnchain;
Expand Down Expand Up @@ -56,8 +59,21 @@ pub enum AlignedCommands {
DepositToBatcher(DepositToBatcherArgs),
#[clap(about = "Get user balance from the batcher", name = "get-user-balance")]
GetUserBalance(GetUserBalanceArgs),
#[clap(about = "Get user nonce from the batcher", name = "get-user-nonce")]
#[clap(
about = "Gets user current nonce from the batcher. This is the nonce you should send in your next proof.",
name = "get-user-nonce"
)]
GetUserNonce(GetUserNonceArgs),
#[clap(
about = "Gets the user nonce directly from the BatcherPaymentService contract. Useful for validating the on-chain state and check if your transactions are pending in the batcher.",
name = "get-user-nonce-from-ethereum"
)]
GetUserNonceFromEthereum(GetUserNonceFromEthereumArgs),
#[clap(
about = "Gets the amount of proofs a user has queued in the Batcher.",
name = "get-amount-of-proofs-in-batcher-queue"
)]
GetAmountOfProofsInBatcherQueue(GetAmountOfProofsInBatcherQueueArgs),
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -218,6 +234,58 @@ pub struct GetUserNonceArgs {
address: String,
}

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct GetUserNonceFromEthereumArgs {
#[arg(
name = "Ethereum RPC provider address",
long = "rpc_url",
default_value = "http://localhost:8545"
)]
eth_rpc_url: String,
#[arg(
name = "The user's Ethereum address",
long = "user_addr",
required = true
)]
address: String,
#[arg(
name = "The working network's name",
long = "network",
default_value = "devnet"
)]
network: NetworkArg,
}

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct GetAmountOfProofsInBatcherQueueArgs {
#[arg(
name = "Ethereum RPC provider address",
long = "rpc_url",
default_value = "http://localhost:8545"
)]
eth_rpc_url: String,
#[arg(
name = "The user's Ethereum address",
long = "user_addr",
required = true
)]
address: String,
#[arg(
name = "The working network's name",
long = "network",
default_value = "devnet"
)]
network: NetworkArg,
#[arg(
name = "Batcher connection address",
long = "batcher_url",
default_value = "ws://localhost:8080"
)]
batcher_url: String,
}

#[derive(Debug, Clone, ValueEnum, Copy)]
enum NetworkArg {
Devnet,
Expand Down Expand Up @@ -528,6 +596,51 @@ async fn main() -> Result<(), AlignedError> {
}
}
}
GetUserNonceFromEthereum(args) => {
let address = H160::from_str(&args.address).unwrap();
let network = args.network.into();
match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await {
Ok(nonce) => {
info!(
"Nonce for address {} in BatcherPaymentService contract is {}",
address, nonce
);
}
Err(e) => {
error!("Error while getting nonce: {:?}", e);
return Ok(());
}
}
}
GetAmountOfProofsInBatcherQueue(args) => {
let address = H160::from_str(&args.address).unwrap();
let network = args.network.into();
let ethereum_nonce =
match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await {
Ok(nonce) => nonce,
Err(e) => {
error!("Error while getting nonce: {:?}", e);
return Ok(());
}
};
let batcher_nonce = match get_nonce_from_batcher(&args.batcher_url, address).await {
Ok(nonce) => nonce,
Err(e) => {
error!("Error while getting nonce: {:?}", e);
return Ok(());
}
};
if ethereum_nonce > batcher_nonce {
error!("User {} is in an invalid state.", address);
} else {
info!(
"User {} has {} proofs in the batcher queue",
address,
batcher_nonce - ethereum_nonce
);
}
return Ok(());
}
}

Ok(())
Expand Down
Loading