simulate staker preference

This commit is contained in:
Darioush Jalali 2025-01-28 12:18:10 -08:00
parent d3cc618951
commit 2419cfe7de
No known key found for this signature in database
GPG key ID: E351C2382B7EA3E3
2 changed files with 45 additions and 4 deletions

View file

@ -18,6 +18,7 @@ package core
import ( import (
"math/big" "math/big"
"math/rand"
"testing" "testing"
"time" "time"
@ -265,3 +266,40 @@ func TestCalcGasLimit(t *testing.T) {
} }
} }
} }
func TestSimulateGasLimit(t *testing.T) {
minLimit, maxLimit := params.MinGasLimit, params.MaxGasLimit // can change these
params.MinGasLimit, params.MaxGasLimit = minLimit, maxLimit
rand.Seed(time.Now().UnixNano())
type weightedPreference struct {
weight float32
limit uint64
}
stakerPreference := []weightedPreference{
{0.1, 100_000},
{0.1, 200_000},
{0.1, 300_000},
{0.1, 400_000},
{0.1, 500_000},
{0.1, 600_000},
{0.1, 700_000},
{0.1, 800_000},
{0.1, 900_000},
{0.1, 1_000_000},
}
start := params.MinGasLimit
currentGasLimit := start
for i := 0; i < 100_000; i++ {
r := rand.Float32()
for _, p := range stakerPreference {
r -= p.weight
if r <= 0 {
currentGasLimit = CalcGasLimit(currentGasLimit, p.limit)
break
}
}
t.Logf("Gas limit: %d", currentGasLimit)
}
}

View file

@ -22,10 +22,13 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
const ( var (
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1). MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
)
const (
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.