foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(`forge-script`): add `--confirmations` flag to wait for `n` confirmations

Open PatrickAlphaC opened this issue 2 years ago • 2 comments
trafficstars

Component

Forge

Describe the feature you would like

Right now, the forge script verifier gets a little confused if it doesn't find any bytecode, and just exists. An easy solution I use with Brownie, Hardhat, Truffle, and Ape is to just wait X confirmations before attempting a verification.

Having a flag to wait x confirmations would be great.

forge script script/MyScript.sol --wait-confirmations 6

And this will result in:

##
Waiting for receipts.
⠉ [00:00:12] [######################################################################################################################################################################################] 6/6 receipts (0.0s)

Additional context

No response

PatrickAlphaC avatar Apr 15 '23 16:04 PatrickAlphaC

@PatrickAlphaC I think you were planning to work on this so I assigned it to you, if that changes lmk and I can unassign

mds1 avatar Apr 16 '23 22:04 mds1

Seems it might take me a lot longer than I thought it would 😅

sorry... could we unassign?

PatrickAlphaC avatar Apr 21 '23 02:04 PatrickAlphaC

Hey @zerosnacks, is this still relevant? if so I'd like to work on it.

caiquejjx avatar Sep 14 '24 17:09 caiquejjx

Hi @caiquejjx, sorry for my rate reply. This ticket is still relevant and we would love to get it in. Assigned to you :)

zerosnacks avatar Oct 10 '24 12:10 zerosnacks

thank you @zerosnacks, just to be sure I understood this task, what we want is that if the --verify flag is passed along the --confirmations one we should wait for x confirmations and the logic for what it concerns the wait part should be done somewhere inside this function https://github.com/foundry-rs/foundry/blob/15fdb2a19ee2a038f7e72523c6a0b0c3cdc6c3e4/crates/script/src/sequence.rs#L256

caiquejjx avatar Oct 10 '24 15:10 caiquejjx

thank you @zerosnacks, just to be sure I understood this task, what we want is that if the --verify flag is passed along the --confirmations one we should wait for x confirmations and the logic for what it concerns the wait part should be done somewhere inside this function https://github.com/foundry-rs/foundry/blob/15fdb2a19ee2a038f7e72523c6a0b0c3cdc6c3e4/crates/script/src/sequence.rs#L256

--confirmations should specify how many blocks we should wait before proceeding (with the verification step). In that sense it is more generalized.

This is useful if the chain experiences re-orgs or the transaction is not included in the next block.

zerosnacks avatar Oct 10 '24 16:10 zerosnacks

Thanks @zerosnacks I can understand the concept but I don't completely get the implementation part, what I understand is:

  • We can count the amount of blocks by counting the receipts inside the sequence object, as per what I understood each receipt is a block confirmation
  • If the script has more than one contract we should wait the confirmations for each contract
  • If the --confirmations flag is specified it should be automatically infered that args.verify is true

Can you confirm or correct me? Sorry for the noobie questions, I'm still starting to learn blockchain dev and the foundry project itself, thanks for your patience

caiquejjx avatar Oct 10 '24 23:10 caiquejjx

We can count the amount of blocks by counting the receipts inside the sequence object, as per what I understood each receipt is a block confirmation

We should implement it here:

https://github.com/foundry-rs/foundry/blob/0ed43cefa9c9cb93fa9f9b18ff73d04c1a07cf56/crates/script/src/broadcast.rs#L196-L197

https://github.com/foundry-rs/foundry/blob/0ed43cefa9c9cb93fa9f9b18ff73d04c1a07cf56/crates/script/src/broadcast.rs#L163

https://github.com/foundry-rs/foundry/blob/0ed43cefa9c9cb93fa9f9b18ff73d04c1a07cf56/crates/script/src/progress.rs#L169

If the script has more than one contract we should wait the confirmations for each contract

This is correct, the --confirmations flag applies to each contract deployment. We should start the verification process once all deployed contracts have been included in blocks > confirmations count.

If the --confirmations flag is specified it should be automatically infered that args.verify is true

No, the --confirmations flag should not infer verification, it is also a useful flag in other contexts (like re-orgs)

zerosnacks avatar Oct 11 '24 07:10 zerosnacks

It is needed

askucher avatar Nov 03 '24 00:11 askucher

Hi @caiquejjx are you running into any blockers or do you have any questions?

zerosnacks avatar Nov 04 '24 09:11 zerosnacks

Hey, sorry I just got back from vacation and wasn't able to get it working before going away. I was having a bit of a hard time with it but I still would like to push it a little more if that's ok, but also if someone more experienced wants to take this to speed things up it's fine for me, i'm mostly here for the learning and doing what's best for the project.

caiquejjx avatar Nov 04 '24 16:11 caiquejjx

@caiquejjx not a problem! Let me know how you get on, hopping on another ticket is also fine - this one is more complex than it seems on the surface

zerosnacks avatar Nov 04 '24 16:11 zerosnacks

thanks @zerosnacks, I'll take a bit more time then and if it's really a no go I'll let you know

caiquejjx avatar Nov 04 '24 16:11 caiquejjx

@zerosnacks I have unassigned me, I still didn't had time to look into it again but I'm also not hopeful I'll be able to solve it, guess it's above my current knowledge 😅

caiquejjx avatar Nov 06 '24 18:11 caiquejjx