Skip to content

Commit

Permalink
randomizing params
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay committed Dec 4, 2023
1 parent 7d30033 commit 5a86d58
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
42 changes: 40 additions & 2 deletions x/feemarket/fuzz/aimd_eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
func TestAIMDLearningRate(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
state := types.DefaultAIMDState()
params := types.DefaultAIMDParams()
window := rapid.Int64Range(1, 50).Draw(t, "window")
state.Window = make([]uint64, window)

params := CreateRandomAIMDParams(t)

// Randomly generate the block utilization.
numBlocks := rapid.Uint64Range(0, 1000).Draw(t, "num_blocks")
Expand Down Expand Up @@ -63,7 +66,10 @@ func TestAIMDBaseFee(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
state := types.DefaultAIMDState()
state.BaseFee = state.BaseFee.Mul(math.NewInt(10))
params := types.DefaultAIMDParams()
window := rapid.Int64Range(1, 50).Draw(t, "window")
state.Window = make([]uint64, window)

params := CreateRandomAIMDParams(t)

// Randomly generate the block utilization.
numBlocks := rapid.Uint64Range(0, 1000).Draw(t, "num_blocks")
Expand Down Expand Up @@ -101,3 +107,35 @@ func TestAIMDBaseFee(t *testing.T) {
}
})
}

// CreateRandomAIMDParams returns a random set of parameters for the AIMD
// EIP-1559 fee market implementation.
func CreateRandomAIMDParams(t *rapid.T) types.Params {
// Randomly generate the learning rate parameters.
a := rapid.Uint64Range(1, 1000).Draw(t, "alpha")
alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(1000))

b := rapid.Uint64Range(50, 99).Draw(t, "beta")
beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100))

// Randomly generate the block utilization parameters.
th := rapid.Uint64Range(10, 90).Draw(t, "theta")
theta := math.LegacyNewDec(int64(th)).Quo(math.LegacyNewDec(100))

d := rapid.Uint64Range(1, 1000).Draw(t, "delta")
delta := math.LegacyNewDec(int64(d)).Quo(math.LegacyNewDec(1000))

// Randomly generate the block utilization.
maxBlockUtilization := rapid.Uint64Range(1, 15_000_000).Draw(t, "max_block_utilization")
targetBlockUtilization := rapid.Uint64Range(15_000_00, 30_000_000).Draw(t, "target_block_utilization")

params := types.DefaultAIMDParams()
params.Alpha = alpha
params.Beta = beta
params.Theta = theta
params.Delta = delta
params.MaxBlockUtilization = maxBlockUtilization
params.TargetBlockUtilization = targetBlockUtilization

return params
}
41 changes: 30 additions & 11 deletions x/feemarket/fuzz/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@ import (
func TestLearningRate(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
state := types.DefaultState()
params := types.DefaultParams()
params := CreateRandomParams(t)

// Randomly generate alpha and beta.
a := rapid.Uint64Range(1, 50).Draw(t, "alpha")
alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(100))

b := rapid.Uint64Range(50, 99).Draw(t, "beta")
beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100))

params.Alpha = alpha
params.Beta = beta

prevLearningRate := state.LearningRate

// Randomly generate the block utilization.
Expand All @@ -48,7 +39,7 @@ func TestLearningRate(t *testing.T) {
func TestBaseFee(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
state := types.DefaultState()
params := types.DefaultParams()
params := CreateRandomParams(t)

// Update the current base fee to be 10% higher than the minimum base fee.
prevBaseFee := state.BaseFee.Mul(math.NewInt(11)).Quo(math.NewInt(10))
Expand Down Expand Up @@ -80,3 +71,31 @@ func TestBaseFee(t *testing.T) {
}
})
}

// CreateRandomParams returns a random set of parameters for the default
// EIP-1559 fee market implementation.
func CreateRandomParams(t *rapid.T) types.Params {
// Randomly generate the learning rate parameters.
a := rapid.Uint64Range(1, 1000).Draw(t, "alpha")
alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(1000))

b := rapid.Uint64Range(50, 99).Draw(t, "beta")
beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100))

// Randomly generate the block utilization parameters.
th := rapid.Uint64Range(10, 90).Draw(t, "theta")
theta := math.LegacyNewDec(int64(th)).Quo(math.LegacyNewDec(100))

// Randomly generate the block utilization.
maxBlockUtilization := rapid.Uint64Range(1, 15_000_000).Draw(t, "max_block_utilization")
targetBlockUtilization := rapid.Uint64Range(15_000_00, 30_000_000).Draw(t, "target_block_utilization")

params := types.DefaultParams()
params.Alpha = alpha
params.Beta = beta
params.Theta = theta
params.MaxBlockUtilization = maxBlockUtilization
params.TargetBlockUtilization = targetBlockUtilization

return params
}

0 comments on commit 5a86d58

Please sign in to comment.