mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
save
This commit is contained in:
parent
16bf471151
commit
f2ecd7a833
2 changed files with 45 additions and 0 deletions
21
consensus/misc/eip7783/eip7783.go
Normal file
21
consensus/misc/eip7783/eip7783.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package eip7783
|
||||
|
||||
import "math/big"
|
||||
|
||||
/*
|
||||
Implementation of EIP-7783:
|
||||
|
||||
def compute_gas_limit(blockNum: int, blockNumStart: int, initialGasLimit: int, r: int, gasLimitCap: int) -> int:
|
||||
|
||||
if blockNum < blockNumStart:
|
||||
return initialGasLimit
|
||||
else:
|
||||
return min(gasLimitCap, initialGasLimit + r * (blockNum - blockNumStart))
|
||||
*/
|
||||
func CalcGasLimitEIP7783(blockNum, startBlockNum *big.Int, initialGasLimit, gasIncreaseRate, gasLimitCap uint64) uint64 {
|
||||
if blockNum.Cmp(startBlockNum) < 0 {
|
||||
return initialGasLimit
|
||||
} else {
|
||||
return min(gasLimitCap, initialGasLimit+gasIncreaseRate*(blockNum.Uint64()-startBlockNum.Uint64()))
|
||||
}
|
||||
}
|
||||
24
consensus/misc/eip7783/eip7783_test.go
Normal file
24
consensus/misc/eip7783/eip7783_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package eip7783
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCalcGasLimitEIP7783Test(t *testing.T) {
|
||||
// Do multiple tests here
|
||||
tests := []struct {
|
||||
blockNum, startBlockNum *big.Int
|
||||
initialGasLimit, gasIncreaseRate, gasLimitCap, expectedGasLimit uint64
|
||||
}{
|
||||
{big.NewInt(100), big.NewInt(50), 100000, 10, 200000, 100500},
|
||||
{big.NewInt(100), big.NewInt(100), 100000, 10, 200000, 100000},
|
||||
{big.NewInt(99), big.NewInt(100), 100000, 10, 200000, 100000},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
if have, want := CalcGasLimitEIP7783(test.blockNum, test.startBlockNum, test.initialGasLimit, test.gasIncreaseRate, test.gasLimitCap), test.expectedGasLimit; have != want {
|
||||
t.Errorf("test %d: have %d want %d, ", i, have, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue