Skip to content

feat: Make minPrice and excessScalingFactor Configurable#80

Open
ceyonur wants to merge 39 commits intomainfrom
ceyonur/acp-224-gastime-parameters
Open

feat: Make minPrice and excessScalingFactor Configurable#80
ceyonur wants to merge 39 commits intomainfrom
ceyonur/acp-224-gastime-parameters

Conversation

@ceyonur
Copy link
Contributor

@ceyonur ceyonur commented Jan 22, 2026

This PR makes minPrice and excessScalingFactor Configurable, also adds a static pricing mode. These parameters will be required by ACP-224, which intends to set these via a system contract.

Closes: #77

@ceyonur ceyonur added the acp224 label Jan 22, 2026
@ceyonur ceyonur changed the title parametrize minPrice and excessScalingFactor Make minPrice and excessScalingFactor configurable Jan 22, 2026
@ceyonur ceyonur changed the title Make minPrice and excessScalingFactor configurable feat: Make minPrice and excessScalingFactor Configurable Jan 22, 2026
@ceyonur ceyonur marked this pull request as ready for review January 22, 2026 10:58
Copy link
Collaborator

@ARR4N ARR4N left a comment

Choose a reason for hiding this comment

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

This is an elegant approach, thank you. The devil is in the details, but I'm generally very keen to merge this.

ceyonur and others added 2 commits January 24, 2026 19:23
Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
ceyonur and others added 4 commits January 24, 2026 19:36
Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
…abs/strevm into ceyonur/acp-224-gastime-parameters
@ceyonur ceyonur marked this pull request as ready for review January 30, 2026 20:33
Copy link
Contributor

@alarso16 alarso16 left a comment

Choose a reason for hiding this comment

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

I didn't finish reviewing, but this was as much overflow math as I could deal with today :)

Copy link
Contributor

@alarso16 alarso16 left a comment

Choose a reason for hiding this comment

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

A few nits, got distracted before I finished

@ceyonur ceyonur marked this pull request as draft February 8, 2026 15:24
@ceyonur ceyonur marked this pull request as ready for review February 9, 2026 13:55
hook/hook.go Outdated
Comment on lines 41 to 46
// GasTargetAfter returns the gas target that should go into effect
// immediately after the provided block.
GasTargetAfter(*types.Header) gas.Gas
// GasConfigAfter returns the gas configuration that should go into effect
// immediately after the provided block.
GasConfigAfter(*types.Header) GasConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on merging these two functions?

Suggested change
// GasTargetAfter returns the gas target that should go into effect
// immediately after the provided block.
GasTargetAfter(*types.Header) gas.Gas
// GasConfigAfter returns the gas configuration that should go into effect
// immediately after the provided block.
GasConfigAfter(*types.Header) GasConfig
// GasConfigAfter returns the gas target and configuration that should go
// into effect immediately after the provided block.
GasConfigAfter(*types.Header) (target gas.Gas, c GasConfig)

We always call them together (except in tests) and externally from sae, the target does seem like a gas configuration.

Alternatively (or perhaps additionally), we could rename GasConfig to GasPriceConfig, because then there is a clear separation between the target and the rest of the params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not %100 sure that these both will be handled in the same hook (After vs Before). I think if we want to merge them we should probably merge them in the canoto as well right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only call-site makes me doubt merging these is a clean approach as we don't need the price config here. https://github.com/ava-labs/strevm/blob/ceyonur/acp-224-gastime-parameters/blocks/time.go#L34-L36

k := tm.excessScalingFactor()

// Binary search over [0, maxExcessSearchCap(k)] for smallest excess where price >= targetPrice.
lo, hi := gas.Gas(0), maxExcessSearchCap(k)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment w.r.t. if this is an optimization or not. I believe it is an optimization (or perhaps inspired from avalanchego's maxTargetExcess usage)... Should we be benchmarking this function?

In avalanchego I mainly calculated the cap so that I could use sort.Search (which works over int rather than uint64)... But here we could feasibly hit uint64 values, so we need to implement our own binary search anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was from a first attempt to cap it for int type as well, but then I kept it for optimization. There is a ~2x in smaller prices and small/default K. I think we can just remove it though.

Comment on lines 29 to 31
if err := tm.SetTarget(target); err != nil {
return fmt.Errorf("%T.SetTarget() after block: %w", tm, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know that SetTarget is really safe anymore. It errors if excess would exceed MaxUint64, which would be crazy on the C-chain, but could definitely happen with the right sequence of config modifications.

In other parts of the code, we just silently cap excess at MaxUint64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR already has become a beast, let's handle it in #164


R, T := tm.Rate(), tm.Target()
quo, _, _ := intmath.MulDiv(g, R-T, R) // overflow is impossible as (R-T)/R < 1
tm.excess += quo
Copy link
Contributor

@StephenButtolph StephenButtolph Feb 10, 2026

Choose a reason for hiding this comment

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

This (adding to excess) can overflow now right?

Copy link
Contributor Author

@ceyonur ceyonur Feb 13, 2026

Choose a reason for hiding this comment

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

@ceyonur ceyonur marked this pull request as draft February 12, 2026 18:23
@ceyonur ceyonur marked this pull request as ready for review February 13, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make ACP-176 math configurable

4 participants