Skip to content

Gas pricing#9

Merged
PlasmaPower merged 19 commits intoclean-up-dead-retryablesfrom
gas-pricing
Oct 18, 2021
Merged

Gas pricing#9
PlasmaPower merged 19 commits intoclean-up-dead-retryablesfrom
gas-pricing

Conversation

@edfelten
Copy link
Copy Markdown
Contributor

Track the gas pool and adjust gas price according to the Arbitrum L2 gas pricing algorithm. This price will appear to clients as the EVM base fee.

Comment thread arbos/block_processor.go
Comment thread arbos/block_processor.go Outdated
Comment thread arbos/block_processor.go Outdated

for i, tx := range segment.txes[startIndex:] {
if tx.Gas() > perBlockGasLimit {
if tx.Gas() > MaxPerBlockGasLimit() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use b.header.GasLimit here since that we can adjust it if we want to without changing multiple places in the code

Copy link
Copy Markdown
Contributor Author

@edfelten edfelten Oct 14, 2021

Choose a reason for hiding this comment

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

The idea here is that we want to apply the max block size rather than the current gas pool, because we're flat-out rejecting the tx if the condition is true. If a tx fits within the max block size but there isn't enough gas left for it in the current block, then we shouldn't reject the tx but should instead start a new block.

Copy link
Copy Markdown
Contributor Author

@edfelten edfelten Oct 14, 2021

Choose a reason for hiding this comment

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

This is actually trickier, for a few reasons.

(1) At this point in the code, tx.gas is the tx's original gas request minus the L1 gas charge. Just like in Classic, a tx sender won't be able to predict the L1 charge exactly, so it might be difficult for the sender to avoid asking for more than the max gas allowed. So maybe we should adjust tx.gas down to the max limit here, if it would otherwise be above the limit, like we did in Classic.

(2) If the tx's request is less than PerBlockGasLimit, but greater than the block's remaining gas pool, then the right step is to end the block, so that the current tx can go into the next block where there could be more gas pool available.

(3) But if we're in case (2) and it's also the case that ArbOS's gas pool is empty or near-empty, then the next block might not have enough gas available in its gas pool, so pushing to the next block won't help and we should congestion-reject the tx.

The upshot is that we're going to need to change the logic here. We can do that in this PR, or maybe a separate PR makes more sense because it's a separate design decision.

Comment thread arbos/gaspricing.go
numeratorBase := new(big.Int).Mul(big.NewInt(121), maxProd)
denominator := new(big.Int).Mul(big.NewInt(120), maxProd)

for i := uint64(0); i < secondsElapsed; i++ {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a way we could get rid of this loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could reduce the number of iterations by jumping forward in chunks of say 15 seconds. I figured that wasn't worth the trouble since this only runs one iteration per wall-clock second.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's not a simple closed-form equation for the result of this loop, because of the combination of non-linear compounding and clipping of the gas pool amounts.

@edfelten edfelten requested a review from hkalodner October 14, 2021 12:13
@PlasmaPower PlasmaPower merged commit ac27997 into clean-up-dead-retryables Oct 18, 2021
@hkalodner hkalodner deleted the gas-pricing branch October 18, 2021 21:38
tsahee pushed a commit that referenced this pull request Dec 1, 2021
Implement memory.size and memory.grow
rachel-bousfield added a commit that referenced this pull request Apr 19, 2024
code-xD pushed a commit to Nexus-2023/nitro that referenced this pull request Aug 1, 2024
…-verification-v2.3.1

Integration with Avail DA layer in Arbitrum nitro stack
tsahee pushed a commit that referenced this pull request Jul 29, 2025
wurdum pushed a commit to wurdum/nitro that referenced this pull request Oct 13, 2025
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.

3 participants