foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.1k stars 1.67k forks source link

Batch transactions with multiple private keys #4099

Open 0xask3 opened 1 year ago

0xask3 commented 1 year ago

Component

Forge

Describe the feature you would like

Can we introduce batching of transactions made by wallets with different private keys and include them in the same block? So instead of waiting for the previous transaction to be mined, we can order the transactions and broadcast them all at once. As of now, it is waiting for confirmation from transaction made by wallet with private key x to proceed broadcasting the transaction made by private key y (shown in additional context)

Additional context

[⠢] Compiling...
No files changed, compilation skipped
Script ran successfully.

==========================

Estimated total gas used for script: 58010

Estimated amount required: 0.0005801 ETH

==========================

###
Finding wallets for all the necessary addresses...
##
Sending transactions [0 - 1].
⠁ [00:00:01] [#################################>--------------------------------] 1/2 txes (1.2s)
⠉ [00:00:07] [##############################################################] 1/1 receipts (0.0s)
#####
✅ Hash: 0x2ed7a4df9bf55806999ac7777463ae20267f98adfcb3af9ca61bcaba543b214b
Block: 26379340
Paid: 0.00021 ETH (21000 gas * 10 gwei)

⠉ [00:00:10] [##################################################################] 2/2 txes (0.0s)
⠉ [00:00:07] [##############################################################] 1/1 receipts (0.0s)
#####
✅ Hash: 0xe41081004a74c83e90ebb1917254a41e65ec9ad8f4eeabecf7386b69c8da4317
Block: 26379344
Paid: 0.00021 ETH (21000 gas * 10 gwei)

Transactions saved to: /Users/******/run-latest.json

==========================
emiliolanzalaco commented 1 year ago

I second this - it would be really useful for scripting!

samlaf commented 2 months ago

Would also very much benefit from this! Need to register thousands of operators on holesky and its taking forever.

m-quigley commented 1 month ago

+1 - incredibly useful for many of my use cases

a flow along the lines of

vm.StartBroadcast(pk)
.. queue some txs
vm.ChangeBroadcast(pk2)
.. queue some txs
.. etc
vm.StopBroadcast()   -> sends all txs together

would be great. this already works for a single pk, i.e all txs queued within start/stop are fired together and land in the same block. and extension of this to multiple pkeys would be great.

@zerosnacks I see its been included in a milestone - does this mean the feature is being worked on?

zerosnacks commented 1 month ago

@zerosnacks I see its been included in a milestone - does this mean the feature is being worked on?

Not necessarily, I'm going through a process of filtering currently after adding all tickets to the milestone.

A natural primitive to achieve this sort of thing would be a Flashbots bundle on L1 but there is an open question on how to achieve this in L2.

After broadcasting there is currently no guarantee of complete inclusion or ordering with multiple senders in a single block.