Skip to content

Conversation

@MauroToscano
Copy link
Contributor

@MauroToscano MauroToscano commented Sep 15, 2025

Restore flush logic (Nuclear option for state recovery)

Description

Restore flush logic (Nuclear option for state recovery)

How to test

You can test it with an anvil rich account private key:

  1. Insert the following line in the batcher (crates/batcher/src/lib.rs) code so that you have enough time to unlock and withdraw eth from the batcher payment contract:
2012+       warn!("SLEEPING FOR 60 SECONDS BEFORE FINALIZING BLOCK ADVANCE BLOCKS NOW!!!!");
2013+       tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
  1. Fund an account:
cd crates/cli
cargo run --release -- deposit-to-batcher --amount 1ether --private_key 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97  --network devnet --rpc_url http://localhost:8545
  1. Send a proof:
cargo run --release -- submit \
                --proving_system Risc0 \
                --proof ../../scripts/test_files/risc_zero/no_public_inputs/risc_zero_no_pub_input_3_0_3.proof \
                --vm_program ../../scripts/test_files/risc_zero/no_public_inputs/risc_zero_no_pub_input_id_3_0_3.bin \
                --rpc_url http://localhost:8545 \
                --network devnet \
                --instant_fee_estimate \
                --private_key 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 \
                --random_address
  1. Wait until you see the message:
[2025-09-15T15:13:17Z WARN  aligned_batcher] SLEEPING BEFORE FINALIZING BLOCK ADVANCE BLOCKS NOW!!!!

Now hurry up (you only have 60 seconds to unlock, advance blocks and withdraw from the batcher payment service)

  1. Unlock balance:
cast send 0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650  "unlock()" --rpc-url http://localhost:8545 --private-key 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
  1. Advance anvil seconds to not wait:
curl http://localhost:8545 \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"evm_increaseTime","params":[20000],"id":1}'
  1. Get your balance and copy the value:
cast call 0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650 "user_balances(address)" --rpc-url  http://localhost:8545 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f 
  1. Finally withdraw passing the copied value from the previous step:
cast send 0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650  "withdraw(uint256)" <PREV_VALUE> --rpc-url http://localhost:8545 --private-key 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97      
  1. See that the queue is in effect flushed and the CLI receives the BatcherReset message

@MauroToscano MauroToscano changed the base branch from testnet to staging September 15, 2025 20:26
Copy link
Member

@MarcosNicolau MarcosNicolau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with description from #2119.

Copy link
Collaborator

@JuArce JuArce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queue is being nuked, but the users connection is not being closed

Logs from batcher:

...
...
[2025-09-17T17:28:44Z WARN  aligned_batcher] User 0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f has insufficient balance, flushing entire queue as safety measure
[2025-09-17T17:28:44Z WARN  aligned_batcher] Resetting state... Flushing queue and nonces
[2025-09-17T17:28:44Z ERROR aligned_batcher] Batch finalization failed: Batcher state was corrupted and flushed: Queue and user states flushed due to insufficient balance for user 0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f
[2025-09-17T17:28:44Z INFO  aligned_batcher] State was corrupted and flushed - not restoring proofs
[2025-09-17T17:28:44Z ERROR aligned_batcher] Error when handling new block: Batcher state was corrupted and flushed: Queue and user states flushed due to insufficient balance for user 0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f
...
...

Logs from user

...
...
[2025-09-17T17:25:42Z WARN  aligned] Nonce: 0
[2025-09-17T17:25:42Z INFO  aligned] Randomizing proof generator address for each proof...
[2025-09-17T17:25:42Z INFO  aligned] Submitting proofs to the Aligned batcher...
[2025-09-17T17:25:42Z INFO  aligned_sdk::communication::messaging] All proofs sent

@MarcosNicolau
Copy link
Member

Following Juli's comment, it seems we are not sending the message to the FinalizedBatch entries, only to those that are in the queue.

@JuArce JuArce added this pull request to the merge queue Oct 2, 2025
Merged via the queue into staging with commit fe21a4a Oct 2, 2025
3 checks passed
@JuArce JuArce deleted the restore_flush_logic branch October 2, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants