Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: Improve skipBalance logic #1849

Merged
merged 14 commits into from
May 4, 2022
Merged

vm: Improve skipBalance logic #1849

merged 14 commits into from
May 4, 2022

Conversation

acolytec3
Copy link
Contributor

Fixes #1839

This addresses the fact that skipBalance in runTx doesn't handle skipping balance checks correctly after the initial transaction options are parsed. Now, if skipBalance is set to true and the calling account balance is less than the transaction cost (i.e. intrinsic gas + value), it sets the balance equal to the transaction cost so the transaction will not fail due to an account having an insufficient balance.

It adds similar logic in runCall that checks to verify that the account has sufficient balance for any value transferred in the call.

@acolytec3 acolytec3 changed the base branch from master to develop April 7, 2022 17:54
@acolytec3 acolytec3 marked this pull request as draft April 7, 2022 17:55
@codecov
Copy link

codecov bot commented Apr 7, 2022

Codecov Report

Merging #1849 (c6c47e0) into develop (478fb97) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head c6c47e0 differs from pull request most recent head ddb663f. Consider uploading reports for the commit ddb663f to get more accurate results

Impacted file tree graph

Flag Coverage Δ
block 85.17% <ø> (-0.05%) ⬇️
blockchain 83.06% <ø> (ø)
client 77.45% <ø> (-0.02%) ⬇️
common 94.94% <ø> (ø)
devp2p 82.67% <ø> (-0.14%) ⬇️
ethash 90.71% <ø> (-0.11%) ⬇️
statemanager 84.07% <ø> (-0.06%) ⬇️
trie 80.17% <ø> (+0.02%) ⬆️
tx 92.48% <ø> (-0.05%) ⬇️
util 89.16% <ø> (+1.79%) ⬆️
vm 82.27% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@acolytec3
Copy link
Contributor Author

I'm not sure if this is the best approach or not but this solves the immediate issue of a call to reduceSenderBalance where the cost is greater than the sender's balance. It does so for skipBalance by ensuring the sender's balance equals the cost of the transaction whatever balance was set so nets out that the sender's balance gets reduced to 0 in runTx and then checks the sender's balance against the message.value in runCall if skipBalance is set to true.

Then, in reduceSenderBalance we throw an error if the balance is negative and this gets handled with an exceptionError message in executeMessage.

@acolytec3
Copy link
Contributor Author

Okay, I think all of the current feedback has been addressed so I'm going to call this ready for review.

@ryanio
Copy link
Contributor

ryanio commented Apr 8, 2022

looks great, thanks for all the requested updates, looks like ci is failing with a nonce off by one error

@acolytec3
Copy link
Contributor Author

looks great, thanks for all the requested updates, looks like ci is failing with a nonce off by one error

Fixed that last issue. I forgot to add the nonce to the modifyAccountFields method.

@ryanio ryanio changed the title Add better skipBalance checks vm: Improve skipBalance logic Apr 8, 2022
ryanio
ryanio previously approved these changes Apr 8, 2022
Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

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

lgtm! since this is rather delicate let's wait for one more 👀 and approval before merging

ryanio
ryanio previously approved these changes May 3, 2022
Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

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

this still lgtm :)

@holgerd77
Copy link
Member

@ryanio in doubt maybe just merge if you feel good with it. 🙂

@holgerd77
Copy link
Member

Rebased this on latest develop.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Also had a quick look, this looks good to me as well.

Will merge.

@holgerd77 holgerd77 merged commit f9c21cd into develop May 4, 2022
@holgerd77 holgerd77 deleted the skipbalance-checks branch May 4, 2022 08:01
holgerd77 pushed a commit that referenced this pull request May 4, 2022
* Add better skipBalance handling

* New runCall check for insufficient balance

* Move skipbalance check to top

* Add coverage for insufficient balance check

* Make skipBalance adjust just + balance

* Test more cases with skipBalance

* update docs

* Doc nits

* Requested fixes

* Add missing nonce check

* Update packages/vm/src/runTx.ts

* nits

* improve comments

* remove leftover tape.only

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
g11tech pushed a commit that referenced this pull request Jun 2, 2022
* Add better skipBalance handling

* New runCall check for insufficient balance

* Move skipbalance check to top

* Add coverage for insufficient balance check

* Make skipBalance adjust just + balance

* Test more cases with skipBalance

* update docs

* Doc nits

* Requested fixes

* Add missing nonce check

* Update packages/vm/src/runTx.ts

* nits

* improve comments

* remove leftover tape.only

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
g11tech pushed a commit that referenced this pull request Jun 2, 2022
* Add better skipBalance handling

* New runCall check for insufficient balance

* Move skipbalance check to top

* Add coverage for insufficient balance check

* Make skipBalance adjust just + balance

* Test more cases with skipBalance

* update docs

* Doc nits

* Requested fixes

* Add missing nonce check

* Update packages/vm/src/runTx.ts

* nits

* improve comments

* remove leftover tape.only

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
g11tech pushed a commit that referenced this pull request Jun 2, 2022
* Add better skipBalance handling

* New runCall check for insufficient balance

* Move skipbalance check to top

* Add coverage for insufficient balance check

* Make skipBalance adjust just + balance

* Test more cases with skipBalance

* update docs

* Doc nits

* Requested fixes

* Add missing nonce check

* Update packages/vm/src/runTx.ts

* nits

* improve comments

* remove leftover tape.only

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
g11tech pushed a commit that referenced this pull request Jun 3, 2022
* Add better skipBalance handling

* New runCall check for insufficient balance

* Move skipbalance check to top

* Add coverage for insufficient balance check

* Make skipBalance adjust just + balance

* Test more cases with skipBalance

* update docs

* Doc nits

* Requested fixes

* Add missing nonce check

* Update packages/vm/src/runTx.ts

* nits

* improve comments

* remove leftover tape.only

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
holgerd77 pushed a commit that referenced this pull request Jun 8, 2022
* Add better skipBalance handling

* New runCall check for insufficient balance

* Move skipbalance check to top

* Add coverage for insufficient balance check

* Make skipBalance adjust just + balance

* Test more cases with skipBalance

* update docs

* Doc nits

* Requested fixes

* Add missing nonce check

* Update packages/vm/src/runTx.ts

* nits

* improve comments

* remove leftover tape.only

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative sender balance throws error in _executeCall
4 participants