Skip to content

Conversation

@Mechanix97
Copy link
Contributor

@Mechanix97 Mechanix97 commented Apr 16, 2025

Description

Added queue limit in the batcher. When a new proof is added and the queue limit is exceded, the least priority element is removed and the WS is closed with an UnderpricedProof to the sender.

How to test

  1. Modify the max_queue_size in the batcher to a lower number: config-files/config-batcher.yam
  2. Fund two accounts on aligned, if you are on anvil you can use anvil rich accounts:
cd batcher/aligned
cargo run --release -- deposit-to-batcher --amount 0.1ether --private_key 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
cargo run --release -- deposit-to-batcher --amount 0.1ether --private_key 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
  1. Send enough proofs from one sender to fill the queue but with a max fee that isn't enough to create a batch, for example if you set 10 as the max_queue_limit:
cd batcher/aligned
cargo run --release -- submit --proving_system SP1 --proof ../../scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof --vm_program ../../scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf --repetitions 10 --private_key 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 --custom_fee_estimate 15
  1. Now from the other sender, send the same, but with a higher max_fee, you should see the other ones are replaced:
cd batcher/aligned
cargo run --release -- submit --proving_system SP1 --proof ../../scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof --vm_program ../../scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf --repetitions 10 --private_key 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 --custom_fee_estimate 14
  1. You can also check the case where the max_fee is less than the lowest priority proof, they should be rejected in that case.

Type of change

  • New feature

Checklist

  • “Hotfix” to testnet, everything else to staging
  • Linked to Github Issue
  • This change depends on code or research by an external entity
    • Acknowledgements were updated to give credit
  • Unit tests added
  • This change requires new documentation.
    • Documentation has been added/updated.
  • This change is an Optimization
    • Benchmarks added/run
  • Has a known issue
  • If your PR changes the Operator compatibility (Ex: Upgrade prover versions)
    • This PR adds compatibility for operator for both versions and do not change batcher/docs/examples
    • This PR updates batcher and docs/examples to the newer version. This requires the operator are already updated to be compatible

@github-actions
Copy link

Changes to gas cost

Generated at commit: 9d3dd5257b488f03fd048648c24cb410850d2329, compared to commit: b77e8fdf474834f0b9d018c28322b5c29512002e

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
AlignedLayerServiceManager createNewTask +9 ❌ +0.01%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
AlignedLayerServiceManager 8,319,208 (0) createNewTask 57,842 (+48) +0.08% 77,797 (+9) +0.01% 77,922 (-24) -0.03% 78,792 (+24) +0.03% 256 (0)

@Mechanix97 Mechanix97 changed the base branch from testnet to staging April 21, 2025 18:17
@Mechanix97 Mechanix97 marked this pull request as ready for review April 21, 2025 19:46
@Mechanix97 Mechanix97 changed the title Feat/batch queue limit Feat(batcher) add queue limit Apr 22, 2025
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 and it works fine. I've introduced some changes to make it more readable and remove many assumptions that were not documented with hidden behavior. Also, the pr was missing a how to test section, so I've update it.

@MarcosNicolau MarcosNicolau changed the title Feat(batcher) add queue limit feat(batcher): add queue limit Apr 28, 2025
@MarcosNicolau MarcosNicolau self-assigned this Apr 29, 2025
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.

Use cases:

  • Queue is full (1 element). Same user
    • Send proof with less fee from same user ✅ new proof is rejected
    • Send proof with same fee from same user ✅ new proof is rejected
    • Send proof with greater fee from same user ✅ new proof is rejected
  • Queue is full (1 element). Diferent user
    • Send proof with less fee from diferent user ✅ new proof is rejected
    • Send proof with same fee from diferent user ✅ new proof is rejected
    • Send proof with greater fee from diferent user ✅ new proof is accepted
  • Queue is full (1 element). Replacement
    • Send proof with less fee, same nonce from same user ✅ new proof is rejected
    • Send proof with same fee, same nonce from same user ✅ new proof is accepted
    • Send proof with greater fee, same nonce from same user ✅ new proof is accepted
  • Queue is full (3 elements) Same user sends 3 proofs with the same fee
    • Send proof with less fee from same user ✅ new proof is rejected
    • Send proof with same fee from same user ✅ new proof is rejected
    • Send proof with greater fee from diferent user 🚧 new proof is accepted, but the old user connection is closed, despite it has 2 proof in the queue. Only one proof is removed

@MauroToscano MauroToscano added this pull request to the merge queue May 15, 2025
Merged via the queue into staging with commit f8db023 May 15, 2025
3 checks passed
@MauroToscano MauroToscano deleted the feat/batch_queue_limit branch May 15, 2025 14:54
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.

5 participants