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

[Canyon Hard Fork] Change EIP 1559 Denominator with Canyon #98

Merged
merged 2 commits into from
Nov 6, 2023

Conversation

pcw109550
Copy link
Member

@pcw109550 pcw109550 commented Nov 2, 2023

All codes referenced from

Description

For canyon, EIP 1559 denominator is updated from 50 to 250. Adding explicit timestamp parameter to CalcBaseFee method. In some cases(for pending transactions, fee history)the base fee may not be accurate if the exact timestamp of the block is not known.

Lets review why this change is needed. Referring EIP 1559 and current Linear EIP 1559 mechanics,

Let $T$ be the gas target, and $A$ be max base fee change denominator. Each block $B_{i}$ where $i$ is a block number has a base fee of $b_{i}$ and let $g_{i}$ be the total gas consumed in the block $B_{i}$. Update rule for base fee:

$$b_{i + 1} = b_{i} \left( 1 + \frac{1}{A} \frac{g_{i} - T}{T} \right)$$

In this PR, we are increasing the value of $A$, the base fee change denominator. Therefore, fee update will be much more stable(not moving much). Users/Wallets will experience less failure of transactions because the fees got less volatile.

Testing

Unit tests added. In this PR, I will verify the values manually in this description. Here are the test cases:

tests := []struct {
		parentBaseFee   int64
		parentGasLimit  uint64
		parentGasUsed   uint64
		expectedBaseFee int64
		postCanyon      bool
	}{
		{params.InitialBaseFee, 30_000_000, 5_000_000, params.InitialBaseFee, false}, // usage == target
		{params.InitialBaseFee, 30_000_000, 4_000_000, 996000000, false},             // usage below target
		{params.InitialBaseFee, 30_000_000, 10_000_000, 1020000000, false},           // usage above target
		{params.InitialBaseFee, 30_000_000, 5_000_000, params.InitialBaseFee, true},  // usage == target
		{params.InitialBaseFee, 30_000_000, 4_000_000, 999200000, true},              // usage below target
		{params.InitialBaseFee, 30_000_000, 10_000_000, 1004000000, true},            // usage above target
	}

params.InitialBaseFee == 1_000_000_000
T = parentGasTarget = parent.GasLimit / ElasticityMultiplier = 30_000_000 / 6 = 5_000_000

For {2,3,5,6}th sub task,
Before Canyon: A = 50

  • 2: 1_000_000_000 * (1 + (1 / 50) * (5_000_000 - 5_000_000) / 5_000_000) == 1_000_000_000
  • 3: 1_000_000_000 * (1 + (1 / 50) * (4_000_000 - 5_000_000) / 5_000_000) == 996_000_000
    Canyon: A = 250
  • 5: 1_000_000_000 * (1 + (1 / 250) * (4_000_000 - 5_000_000) / 5_000_000) == 999_200_000
  • 6: 1_000_000_000 * (1 + (1 / 250) * (10_000_000 - 5_000_000) / 5_000_000) == 1_004_000_000

Misc

@pcw109550 pcw109550 mentioned this pull request Nov 2, 2023
6 tasks
@pcw109550 pcw109550 merged commit 88a18c0 into tip/canyon Nov 6, 2023
4 checks passed
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.

2 participants