-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
all: switch gas limits from big.Int to uint64 #15466
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
core/block_validator.go
Outdated
contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3)) | ||
contrib = contrib.Div(contrib, big.NewInt(2)) | ||
contrib = contrib.Div(contrib, params.GasLimitBoundDivisor) | ||
contrib := ((parent.GasUsed() / 2) * 3) / params.GasLimitBoundDivisor // div-mul order change is fine due to last 10 bit shift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of changing the order, you could do
(x/2 * 3) / 1024
eq (x/2 + x) / 1024
Which could be further reduced to
(x >> 1 + x) >> 10
or x >> 11 + x >> 10
Where it's trivial to see that the last expression is overflow-safe.
If you want to maintain the params
, you could do
parent.gasUsed / params.GasLimitBoundDivisor + (parent.gasUsed / 2 ) / params.GasLimitBoundDivisor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to your first suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that means that there will be errors if gasUsed
ever goes above 2/3 of a full uint64
?
Which I think we can live with
i.Add(i, amount) | ||
func (gp *GasPool) AddGas(amount uint64) *GasPool { | ||
if uint64(*gp) > math.MaxUint64-amount { | ||
panic("gas pool pushed above uint64") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure a panic
is right here - perhaps can be used to cause DoS over RPC, by performing calls with very large gas values?
35a275a
to
74907b6
Compare
Maybe I don't see the big picture. But wouldn't be better to create a type alias for |
@ricardohsd |
@fjl that's true. Thanks for the explanation. |
74907b6
to
6f69cdd
Compare
This PR continues the uint64 gas rewrite from a long time ago, by transitioning all remaining types (headers, blocks, receipts, transactions) to 64 bit gas fields. This is mostly needed to unify our APIs (old APIs use big.Ints, new ones use uint64s).
I also need this PR to revamp gas estimation (currently it's not automatic if no gas limit is provided), but that turned out to require yet again a large API overhaul, so I'll just submit this massive PR first, and follow up with the API reorgs afterwards.