val comments
This commit is contained in:
parent
bbf574cedb
commit
bfc7944b55
|
@ -2,12 +2,11 @@
|
||||||
Package simulation implements a simulation framework for any state machine
|
Package simulation implements a simulation framework for any state machine
|
||||||
built on the SDK which utilizes auth.
|
built on the SDK which utilizes auth.
|
||||||
|
|
||||||
It is primarily intended for fuzz testing the integration of modules. It will
|
It is primarily intended for fuzz testing the integration of modules. It will
|
||||||
test that the provided operations are interoperable, and that the desired
|
test that the provided operations are interoperable, and that the desired
|
||||||
invariants hold. It can additionally be used to detect what the performance
|
invariants hold. It can additionally be used to detect what the performance
|
||||||
benchmarks in the system are, by using benchmarking mode and cpu / mem
|
benchmarks in the system are, by using benchmarking mode and cpu / mem
|
||||||
profiling. If it detects a failure, it provides the entire log of what was
|
profiling. If it detects a failure, it provides the entire log of what was ran.
|
||||||
ran,
|
|
||||||
|
|
||||||
The simulator takes as input: a random seed, the set of operations to run, the
|
The simulator takes as input: a random seed, the set of operations to run, the
|
||||||
invariants to test, and additional parameters to configure how long to run, and
|
invariants to test, and additional parameters to configure how long to run, and
|
||||||
|
@ -15,12 +14,12 @@ misc. parameters that affect simulation speed.
|
||||||
|
|
||||||
It is intended that every module provides a list of Operations which will
|
It is intended that every module provides a list of Operations which will
|
||||||
randomly create and run a message / tx in a manner that is interesting to fuzz,
|
randomly create and run a message / tx in a manner that is interesting to fuzz,
|
||||||
and verify that the state transition was executed as expected. Each module
|
and verify that the state transition was executed as expected. Each module
|
||||||
should additionally provide methods to assert that the desired invariants hold.
|
should additionally provide methods to assert that the desired invariants hold.
|
||||||
|
|
||||||
Then to perform a randomized simulation, select the set of desired operations,
|
Then to perform a randomized simulation, select the set of desired operations,
|
||||||
the weightings for each, the invariants you want to test, and how long to run
|
the weightings for each, the invariants you want to test, and how long to run
|
||||||
it for. Then run simulation.Simulate! The simulator will handle things like
|
it for. Then run simulation.Simulate! The simulator will handle things like
|
||||||
ensuring that validators periodically double signing, or go offline.
|
ensuring that validators periodically double signing, or go offline.
|
||||||
*/
|
*/
|
||||||
package simulation
|
package simulation
|
||||||
|
|
|
@ -44,29 +44,6 @@ type Params struct {
|
||||||
BlockSizeTransitionMatrix TransitionMatrix
|
BlockSizeTransitionMatrix TransitionMatrix
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBlockSize returns a block size as determined from the transition matrix.
|
|
||||||
// It targets making average block size the provided parameter. The three
|
|
||||||
// states it moves between are:
|
|
||||||
// - "over stuffed" blocks with average size of 2 * avgblocksize,
|
|
||||||
// - normal sized blocks, hitting avgBlocksize on average,
|
|
||||||
// - and empty blocks, with no txs / only txs scheduled from the past.
|
|
||||||
func getBlockSize(r *rand.Rand, params Params,
|
|
||||||
lastBlockSizeState, avgBlockSize int) (state, blocksize int) {
|
|
||||||
|
|
||||||
// TODO: Make default blocksize transition matrix actually make the average
|
|
||||||
// blocksize equal to avgBlockSize.
|
|
||||||
state = params.BlockSizeTransitionMatrix.NextState(r, lastBlockSizeState)
|
|
||||||
switch state {
|
|
||||||
case 0:
|
|
||||||
blocksize = r.Intn(avgBlockSize * 4)
|
|
||||||
case 1:
|
|
||||||
blocksize = r.Intn(avgBlockSize * 2)
|
|
||||||
default:
|
|
||||||
blocksize = 0
|
|
||||||
}
|
|
||||||
return state, blocksize
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return default simulation parameters
|
// Return default simulation parameters
|
||||||
func DefaultParams() Params {
|
func DefaultParams() Params {
|
||||||
return Params{
|
return Params{
|
||||||
|
|
|
@ -51,7 +51,7 @@ func (t TransitionMatrix) NextState(r *rand.Rand, i int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMemberOfInitialState takes an initial array of weights, of size n.
|
// GetMemberOfInitialState takes an initial array of weights, of size n.
|
||||||
// It returns a weighted random number in [0,n].
|
// It returns a weighted random number in [0,n).
|
||||||
func GetMemberOfInitialState(r *rand.Rand, weights []int) int {
|
func GetMemberOfInitialState(r *rand.Rand, weights []int) int {
|
||||||
n := len(weights)
|
n := len(weights)
|
||||||
total := 0
|
total := 0
|
||||||
|
|
|
@ -2,6 +2,7 @@ package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -78,3 +79,26 @@ func logPrinter(testingmode bool, logs []*strings.Builder) func() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getBlockSize returns a block size as determined from the transition matrix.
|
||||||
|
// It targets making average block size the provided parameter. The three
|
||||||
|
// states it moves between are:
|
||||||
|
// - "over stuffed" blocks with average size of 2 * avgblocksize,
|
||||||
|
// - normal sized blocks, hitting avgBlocksize on average,
|
||||||
|
// - and empty blocks, with no txs / only txs scheduled from the past.
|
||||||
|
func getBlockSize(r *rand.Rand, params Params,
|
||||||
|
lastBlockSizeState, avgBlockSize int) (state, blocksize int) {
|
||||||
|
|
||||||
|
// TODO: Make default blocksize transition matrix actually make the average
|
||||||
|
// blocksize equal to avgBlockSize.
|
||||||
|
state = params.BlockSizeTransitionMatrix.NextState(r, lastBlockSizeState)
|
||||||
|
switch state {
|
||||||
|
case 0:
|
||||||
|
blocksize = r.Intn(avgBlockSize * 4)
|
||||||
|
case 1:
|
||||||
|
blocksize = r.Intn(avgBlockSize * 2)
|
||||||
|
default:
|
||||||
|
blocksize = 0
|
||||||
|
}
|
||||||
|
return state, blocksize
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue