Skip to content

Commit 4b73027

Browse files
PatStilesMarcosNicolauuri-99JuArce
authored
feat(cli): add get-user-first-nonce + get-user-number-queued-proofs cli commands (#1553)
Co-authored-by: Marcos Nicolau <[email protected]> Co-authored-by: Urix <[email protected]> Co-authored-by: JuArce <[email protected]>
1 parent 3a47b87 commit 4b73027

File tree

2 files changed

+188
-11
lines changed

2 files changed

+188
-11
lines changed

batcher/aligned/src/main.rs

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use aligned_sdk::core::{
1414
use aligned_sdk::sdk::estimate_fee;
1515
use aligned_sdk::sdk::get_chain_id;
1616
use aligned_sdk::sdk::get_nonce_from_batcher;
17+
use aligned_sdk::sdk::get_nonce_from_ethereum;
1718
use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned};
1819
use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple};
1920
use clap::Args;
@@ -25,13 +26,16 @@ use ethers::prelude::*;
2526
use ethers::utils::format_ether;
2627
use ethers::utils::hex;
2728
use ethers::utils::parse_ether;
29+
use futures_util::future;
2830
use log::warn;
2931
use log::{error, info};
3032
use transaction::eip2718::TypedTransaction;
3133

3234
use crate::AlignedCommands::DepositToBatcher;
35+
use crate::AlignedCommands::GetUserAmountOfQueuedProofs;
3336
use crate::AlignedCommands::GetUserBalance;
3437
use crate::AlignedCommands::GetUserNonce;
38+
use crate::AlignedCommands::GetUserNonceFromEthereum;
3539
use crate::AlignedCommands::GetVkCommitment;
3640
use crate::AlignedCommands::Submit;
3741
use crate::AlignedCommands::VerifyProofOnchain;
@@ -59,8 +63,21 @@ pub enum AlignedCommands {
5963
DepositToBatcher(DepositToBatcherArgs),
6064
#[clap(about = "Get user balance from the batcher", name = "get-user-balance")]
6165
GetUserBalance(GetUserBalanceArgs),
62-
#[clap(about = "Get user nonce from the batcher", name = "get-user-nonce")]
66+
#[clap(
67+
about = "Gets user current nonce from the batcher. This is the nonce you should send in your next proof.",
68+
name = "get-user-nonce"
69+
)]
6370
GetUserNonce(GetUserNonceArgs),
71+
#[clap(
72+
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.",
73+
name = "get-user-nonce-from-ethereum"
74+
)]
75+
GetUserNonceFromEthereum(GetUserNonceFromEthereumArgs),
76+
#[clap(
77+
about = "Gets the number of proofs a user has queued in the Batcher.",
78+
name = "get-user-amount-of-queued-proofs"
79+
)]
80+
GetUserAmountOfQueuedProofs(GetUserAmountOfQueuedProofsArgs),
6481
}
6582

6683
#[derive(Parser, Debug)]
@@ -225,6 +242,44 @@ pub struct GetUserNonceArgs {
225242
address: String,
226243
}
227244

245+
#[derive(Parser, Debug)]
246+
#[command(version, about, long_about = None)]
247+
pub struct GetUserNonceFromEthereumArgs {
248+
#[arg(
249+
name = "Ethereum RPC provider address",
250+
long = "rpc_url",
251+
default_value = "http://localhost:8545"
252+
)]
253+
eth_rpc_url: String,
254+
#[arg(
255+
name = "The user's Ethereum address",
256+
long = "user_addr",
257+
required = true
258+
)]
259+
address: String,
260+
#[clap(flatten)]
261+
network: NetworkArg,
262+
}
263+
264+
#[derive(Parser, Debug)]
265+
#[command(version, about, long_about = None)]
266+
pub struct GetUserAmountOfQueuedProofsArgs {
267+
#[arg(
268+
name = "Ethereum RPC provider address",
269+
long = "rpc_url",
270+
default_value = "http://localhost:8545"
271+
)]
272+
eth_rpc_url: String,
273+
#[arg(
274+
name = "The user's Ethereum address",
275+
long = "user_addr",
276+
required = true
277+
)]
278+
address: String,
279+
#[clap(flatten)]
280+
network: NetworkArg,
281+
}
282+
228283
#[derive(Args, Debug)]
229284
#[group(required = true, multiple = false)]
230285
pub struct PrivateKeyType {
@@ -642,6 +697,40 @@ async fn main() -> Result<(), AlignedError> {
642697
}
643698
}
644699
}
700+
GetUserNonceFromEthereum(args) => {
701+
let address = H160::from_str(&args.address).unwrap();
702+
let network = args.network.into();
703+
match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await {
704+
Ok(nonce) => {
705+
info!(
706+
"Nonce for address {} in BatcherPaymentService contract is {}",
707+
address, nonce
708+
);
709+
}
710+
Err(e) => {
711+
error!("Error while getting nonce: {:?}", e);
712+
return Ok(());
713+
}
714+
}
715+
}
716+
GetUserAmountOfQueuedProofs(args) => {
717+
let address = H160::from_str(&args.address).unwrap();
718+
let network: Network = args.network.into();
719+
let Ok((ethereum_nonce, batcher_nonce)) = future::try_join(
720+
get_nonce_from_ethereum(&args.eth_rpc_url, address, network.clone()),
721+
get_nonce_from_batcher(network, address),
722+
)
723+
.await
724+
.map_err(|e| error!("Error while getting nonce: {:?}", e)) else {
725+
return Ok(());
726+
};
727+
info!(
728+
"User {} has {} proofs in the batcher queue",
729+
address,
730+
batcher_nonce - ethereum_nonce
731+
);
732+
return Ok(());
733+
}
645734
}
646735

647736
Ok(())

docs/3_guides/9_aligned_cli.md

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@ This document serves as a reference for the commands of the Aligned CLI.
88

99
1. Download and install Aligned from the Aligned GitHub repo `https://github.com/yetanotherco/aligned_layer`:
1010

11-
```bash
12-
curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batcher/aligned/install_aligned.sh | bash
13-
```
11+
```bash
12+
curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batcher/aligned/install_aligned.sh | bash
13+
```
1414

1515
2. A source command will be printed in your terminal after installation. Execute that command to update your shell environment.
1616

1717
3. Verify that the installation was successful:
18-
```bash
19-
aligned --version
20-
```
18+
19+
```bash
20+
aligned --version
21+
```
2122

2223
## Help:
2324

2425
To see the available commands, run:
26+
2527
```bash
2628
aligned --help
2729
```
2830

2931
To see the usage of a command, run:
32+
3033
```bash
3134
aligned [COMMAND] --help
3235
```
@@ -44,6 +47,7 @@ Submit a proof to the Aligned Layer batcher.
4447
`submit [OPTIONS] --proving_system <proving_system> --proof <proof_file_path>`
4548

4649
#### Options:
50+
4751
- `--batcher_url <batcher_connection_address>`: Websocket URL for the Aligned Layer batcher
4852
- Default: `ws://localhost:8080`
4953
- Mainnet: `wss://mainnet.batcher.alignedlayer.com`
@@ -85,6 +89,7 @@ Submit a proof to the Aligned Layer batcher.
8589

8690

8791
#### Example:
92+
8893
```bash
8994
aligned submit \
9095
--proving_system Risc0 \
@@ -111,6 +116,7 @@ Check if a proof was verified by Aligned on Ethereum.
111116
`verify-proof-onchain [OPTIONS] --aligned-verification-data <aligned_verification_data>`
112117

113118
#### Options:
119+
114120
- `--aligned-verification-data <aligned_verification_data>`: Path to the aligned verification data file.
115121
- `--rpc_url <RPC_provider_url>`: User's Ethereum RPC provider connection address.
116122
- Default: `http://localhost:8545`
@@ -127,6 +133,7 @@ Check if a proof was verified by Aligned on Ethereum.
127133
- `--batcher_url <batcher_websocket_url>`
128134
129135
#### Example:
136+
130137
```bash
131138
aligned verify-proof-onchain \
132139
--aligned-verification-data ./aligned_verification_data/<VERIFICATION_DATA_FILE> \
@@ -147,6 +154,7 @@ Computes the verification data commitment from the verification data file.
147154
`get-vk-commitment [OPTIONS] --verification_key_file <verification_key_file_path> --proving_system <proving_system>`
148155
149156
#### Options:
157+
150158
- `--verification_key_file <path_to_file>`: Path to the verification key file.
151159
- `--proving_system <proving_system>`: Proof system of the verification data file.
152160
- Possible values: `GnarkPlonkBls12_381`, `GnarkPlonkBn254`, `Groth16Bn254`, `SP1`, `Risc0`
@@ -165,6 +173,7 @@ Deposits Ethereum into the Aligned Layer's `BatcherPaymentService.sol` contract.
165173
`deposit-to-batcher [OPTIONS] --keystore_path <path_to_local_keystore> --amount <amount_to_deposit>`
166174

167175
#### Options:
176+
168177
- `--keystore_path <path_to_local_keystore>`: Path to the local keystore.
169178
- `--private_key <private_key>`: User's wallet private key.
170179
- `--rpc_url <RPC_provider_url>`: User's Ethereum RPC provider connection address.
@@ -183,6 +192,7 @@ Deposits Ethereum into the Aligned Layer's `BatcherPaymentService.sol` contract.
183192
- `--batcher_url <batcher_websocket_url>`
184193

185194
#### Example:
195+
186196
```bash
187197
aligned deposit-to-batcher \
188198
--network holesky \
@@ -205,6 +215,7 @@ Retrieves the user's balance in the Aligned Layer's contract.
205215

206216

207217
#### Options:
218+
208219
- One of the following, to specify which Network to interact with:
209220
- `--network <working_network_name>`: Network name to interact with.
210221
- Default: `devnet`
@@ -218,9 +229,10 @@ Retrieves the user's balance in the Aligned Layer's contract.
218229
- Mainnet: `https://ethereum-rpc.publicnode.com`
219230
- Holesky: `https://ethereum-holesky-rpc.publicnode.com`
220231
- Also, you can use your own Ethereum RPC providers.
221-
- **`--user_addr`**: User's Ethereum address.
232+
- `--user_addr`: User's Ethereum address.
222233

223234
#### Example:
235+
224236
```bash
225237
aligned get-user-balance \
226238
--user_addr <WALLET_ADDRESS> \
@@ -232,16 +244,48 @@ aligned get-user-balance \
232244

233245
### **get-user-nonce**
234246

235-
236247
#### Description:
237248

238-
Retrieves the user's current nonce from the batcher.
249+
Retrieves the user's current nonce from the Batcher.
239250
240251
#### Command:
241252
242253
`get-user-nonce [OPTIONS] --user_addr <user_ethereum_address>`
243254
244255
#### Options:
256+
257+
- `--user_addr <user_address>`: User's Ethereum address.
258+
- One of the following, to specify which Network to interact with:
259+
- `--network <working_network_name>`: Network name to interact with.
260+
- Default: `devnet`
261+
- Possible values: `devnet`, `holesky`, `mainnet`
262+
- For a custom Network, you must specify the following parameters:
263+
- `--aligned_service_manager <aligned_service_manager_contract_address>`
264+
- `--batcher_payment_service <batcher_payment_service_contract_address>`
265+
- `--batcher_url <batcher_websocket_url>`
266+
267+
#### Example:
268+
269+
```bash
270+
aligned get-user-nonce \
271+
--user_addr <USER_ETH_ADDRESS> \
272+
--network holesky
273+
```
274+
275+
---
276+
277+
### **get-user-nonce-from-ethereum**
278+
279+
#### Description:
280+
281+
Retrieves the user's current nonce from the Blockhain, in the Batcher Payment Service Contract.
282+
283+
#### Command:
284+
285+
`get-user-nonce-from-ethereum [OPTIONS] --user_addr <user_ethereum_address>`
286+
287+
#### Options:
288+
245289
- `--user_addr <user_address>`: User's Ethereum address.
246290
- One of the following, to specify which Network to interact with:
247291
- `--network <working_network_name>`: Network name to interact with.
@@ -251,10 +295,54 @@ Retrieves the user's current nonce from the batcher.
251295
- `--aligned_service_manager <aligned_service_manager_contract_address>`
252296
- `--batcher_payment_service <batcher_payment_service_contract_address>`
253297
- `--batcher_url <batcher_websocket_url>`
298+
- `--rpc_url <RPC_provider_url>`: User's Ethereum RPC provider connection address.
299+
- Default: `http://localhost:8545`
300+
- Mainnet: `https://ethereum-rpc.publicnode.com`
301+
- Holesky: `https://ethereum-holesky-rpc.publicnode.com`
302+
- Also, you can use your own Ethereum RPC providers.
254303
255304
#### Example:
305+
256306
```bash
257-
aligned get-user-nonce \
307+
aligned get-user-nonce-from-ethereum \
258308
--user_addr <USER_ETH_ADDRESS> \
309+
--network holesky \
310+
--rpc_url https://ethereum-holesky-rpc.publicnode.com
311+
```
312+
313+
---
314+
315+
### **get-user-amount-of-queued-proofs**
316+
317+
#### Description:
318+
319+
Retrieves the user's amount of queued proofs in the Batcher.
320+
321+
#### Command:
322+
323+
`get-user-amount-of-queued-proofs [OPTIONS] --user_addr <user_ethereum_address>`
324+
325+
#### Options:
326+
327+
- `--user_addr <user_address>`: User's Ethereum address.
328+
- `--network <working_network_name>`: Network name to interact with.
329+
- Default: `devnet`
330+
- Possible values: `devnet`, `holesky`, `mainnet`
331+
- `--rpc_url <RPC_provider_url>`: User's Ethereum RPC provider connection address.
332+
- Default: `http://localhost:8545`
333+
- Mainnet: `https://ethereum-rpc.publicnode.com`
334+
- Holesky: `https://ethereum-holesky-rpc.publicnode.com`
335+
- Also, you can use your own Ethereum RPC providers.
336+
- `--batcher_url <batcher_connection_address>`: Websocket URL for the Aligned Layer batcher
337+
- Default: `ws://localhost:8080`
338+
- Mainnet: `wss://mainnet.batcher.alignedlayer.com`
339+
- Holesky: `wss://batcher.alignedlayer.com`
340+
341+
#### Example:
342+
343+
```bash
344+
aligned get-user-amount-of-queued-proofs \
345+
--user_addr <USER_ETH_ADDRESS> \
346+
--network holesky \
259347
--batcher_url wss://batcher.alignedlayer.com
260348
```

0 commit comments

Comments
 (0)