mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
simulate staker preference
This commit is contained in:
parent
d3cc618951
commit
2419cfe7de
2 changed files with 45 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ package core
|
|||
|
||||
import (
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,14 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
var (
|
||||
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
|
||||
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.
|
||||
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
|
||||
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
|
||||
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
|
||||
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
|
||||
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
|
||||
|
||||
MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
|
||||
ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction.
|
||||
|
|
|
|||
Loading…
Reference in a new issue