Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix simulation bugs; Incorprates #2676 from Sunny #2677

Merged
merged 26 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4e44ddf
Print out initial update on every block
cwgoes Oct 28, 2018
38ceea1
Randomize simulation parameters
cwgoes Oct 28, 2018
4e48217
Randomize initial liveness weightings
cwgoes Oct 28, 2018
46e6b40
Randomize genesis parameters
cwgoes Oct 28, 2018
3884b13
Update PENDING.md
cwgoes Oct 28, 2018
991573e
Avoid dividing-by-zero
cwgoes Oct 28, 2018
f5918db
More simulation seeds, more blocks in CI version
cwgoes Oct 29, 2018
e2aa3e9
Update cmd/gaia/app/sim_test.go
zmanian Oct 29, 2018
01c235d
Update cmd/gaia/app/sim_test.go
zmanian Oct 29, 2018
f13f602
Update cmd/gaia/app/sim_test.go
zmanian Oct 29, 2018
1868ee3
Merge remote-tracking branch 'origin/develop' into cwgoes/simulation-…
rigelrozanski Oct 31, 2018
a84cf4f
Merge tag 'v0.25.0' into develop
cwgoes Nov 1, 2018
fb0f4a4
Merge branch 'develop' into cwgoes/simulation-transubstantiated
cwgoes Nov 1, 2018
d9907cc
Address comments
cwgoes Nov 1, 2018
f695a66
Minimize variable passing
cwgoes Nov 1, 2018
39165c9
fixed power store invariant
sunnya97 Nov 2, 2018
3cf6687
PENDING
sunnya97 Nov 2, 2018
42eb4e2
IterateValidatorsBonded -> IterateBondedValidatorsByPower
sunnya97 Nov 2, 2018
888c061
WriteValidators uses IterateLastValidators rather than IterateBondedV…
sunnya97 Nov 2, 2018
13d933f
fixed democoin interface
sunnya97 Nov 2, 2018
191a732
fixed comment
sunnya97 Nov 3, 2018
559ebb7
Merge PR #2671: Power Store Invariant
rigelrozanski Nov 3, 2018
7b10ac4
Merge branch 'develop' into cwgoes/simulation-transubstantiated
Nov 3, 2018
4068d8a
Fix simulation bugs; Incorprates #2676 from Sunny
jaekwon Nov 4, 2018
ace50be
Address review feedback; Update PENDING
jaekwon Nov 5, 2018
95cf0c3
Merge branch 'develop' into jae/simulation-transubstantiated
jaekwon Nov 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minimize variable passing
  • Loading branch information
cwgoes committed Nov 1, 2018
commit f695a6645b20c6891cc71e232712c3dc37862202
10 changes: 8 additions & 2 deletions x/mock/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const (

var (
// Currently there are 3 different liveness types, fully online, spotty connection, offline.
livenessTransitionMatrix, _ = CreateTransitionMatrix([][]int{
defaultLivenessTransitionMatrix, _ = CreateTransitionMatrix([][]int{
{90, 20, 1},
{10, 50, 5},
{0, 10, 1000},
})

// 3 states: rand in range [0, 4*provided blocksize], rand in range [0, 2 * provided blocksize], 0
blockSizeTransitionMatrix, _ = CreateTransitionMatrix([][]int{
defaultBlockSizeTransitionMatrix, _ = CreateTransitionMatrix([][]int{
{85, 5, 0},
{15, 92, 1},
{0, 3, 99},
Expand All @@ -37,6 +37,8 @@ type Params struct {
NumKeys int
EvidenceFraction float64
InitialLivenessWeightings []int
LivenessTransitionMatrix TransitionMatrix
BlockSizeTransitionMatrix TransitionMatrix
}

// Return default simulation parameters
Expand All @@ -46,6 +48,8 @@ func DefaultParams() Params {
NumKeys: 250,
EvidenceFraction: 0.5,
InitialLivenessWeightings: []int{40, 5, 5},
LivenessTransitionMatrix: defaultLivenessTransitionMatrix,
BlockSizeTransitionMatrix: defaultBlockSizeTransitionMatrix,
}
}

Expand All @@ -56,5 +60,7 @@ func RandomParams(r *rand.Rand) Params {
NumKeys: r.Intn(250),
EvidenceFraction: r.Float64(),
InitialLivenessWeightings: []int{r.Intn(80), r.Intn(10), r.Intn(10)},
LivenessTransitionMatrix: defaultLivenessTransitionMatrix,
BlockSizeTransitionMatrix: defaultBlockSizeTransitionMatrix,
}
}
19 changes: 9 additions & 10 deletions x/mock/simulation/random_simulate_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
var pastTimes []time.Time
var pastVoteInfos [][]abci.VoteInfo

request := RandomRequestBeginBlock(r, params, validators, livenessTransitionMatrix, pastTimes, pastVoteInfos, event, header)
request := RandomRequestBeginBlock(r, params, validators, pastTimes, pastVoteInfos, event, header)
// These are operations which have been queued by previous operations
operationQueue := make(map[int][]Operation)
timeOperationQueue := []FutureOperation{}
Expand All @@ -110,7 +110,7 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
blockLogBuilders = make([]*strings.Builder, numBlocks)
}
displayLogs := logPrinter(testingMode, blockLogBuilders)
blockSimulator := createBlockSimulator(testingMode, tb, t, event, invariants, ops, operationQueue, timeOperationQueue, numBlocks, blockSize, displayLogs)
blockSimulator := createBlockSimulator(testingMode, tb, t, params, event, invariants, ops, operationQueue, timeOperationQueue, numBlocks, blockSize, displayLogs)
if !testingMode {
b.ResetTimer()
} else {
Expand Down Expand Up @@ -183,7 +183,7 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
}

// Generate a random RequestBeginBlock with the current validator set for the next block
request = RandomRequestBeginBlock(r, params, validators, livenessTransitionMatrix, pastTimes, pastVoteInfos, event, header)
request = RandomRequestBeginBlock(r, params, validators, pastTimes, pastVoteInfos, event, header)

// Update the validator set, which will be reflected in the application on the next block
validators = nextValidators
Expand All @@ -205,7 +205,7 @@ type blockSimFn func(

// Returns a function to simulate blocks. Written like this to avoid constant parameters being passed everytime, to minimize
// memory overhead
func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T,
func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T, params Params,
event func(string), invariants []Invariant,
ops []WeightedOperation, operationQueue map[int][]Operation, timeOperationQueue []FutureOperation,
totalNumBlocks int, avgBlockSize int, displayLogs func()) blockSimFn {
Expand Down Expand Up @@ -234,7 +234,7 @@ func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T,
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
accounts []Account, header abci.Header, logWriter func(string)) (opCount int) {
fmt.Printf("\rSimulating... block %d/%d, operation %d/%d. ", header.Height, totalNumBlocks, opCount, blocksize)
lastBlocksizeState, blocksize = getBlockSize(r, lastBlocksizeState, avgBlockSize)
lastBlocksizeState, blocksize = getBlockSize(r, params, lastBlocksizeState, avgBlockSize)
for j := 0; j < blocksize; j++ {
logUpdate, futureOps, err := selectOp(r)(r, app, ctx, accounts, event)
logWriter(logUpdate)
Expand Down Expand Up @@ -275,11 +275,10 @@ func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B
// "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, lastBlockSizeState, avgBlockSize int) (state, blocksize int) {
// TODO: Make blockSizeTransitionMatrix non-global
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 = blockSizeTransitionMatrix.NextState(r, lastBlockSizeState)
state = params.BlockSizeTransitionMatrix.NextState(r, lastBlockSizeState)
if state == 0 {
blocksize = r.Intn(avgBlockSize * 4)
} else if state == 1 {
Expand Down Expand Up @@ -382,7 +381,7 @@ func randomProposer(r *rand.Rand, validators map[string]mockValidator) common.He

// RandomRequestBeginBlock generates a list of signing validators according to the provided list of validators, signing fraction, and evidence fraction
// nolint: unparam
func RandomRequestBeginBlock(r *rand.Rand, params Params, validators map[string]mockValidator, livenessTransitions TransitionMatrix,
func RandomRequestBeginBlock(r *rand.Rand, params Params, validators map[string]mockValidator,
pastTimes []time.Time, pastVoteInfos [][]abci.VoteInfo, event func(string), header abci.Header) abci.RequestBeginBlock {
if len(validators) == 0 {
return abci.RequestBeginBlock{Header: header}
Expand All @@ -391,7 +390,7 @@ func RandomRequestBeginBlock(r *rand.Rand, params Params, validators map[string]
i := 0
for _, key := range getKeys(validators) {
mVal := validators[key]
mVal.livenessState = livenessTransitions.NextState(r, mVal.livenessState)
mVal.livenessState = params.LivenessTransitionMatrix.NextState(r, mVal.livenessState)
signed := true

if mVal.livenessState == 1 {
Expand Down