-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simulation improvements (logging fix, random genesis parameters) (#2617)
* Print out initial update on every block * Randomize simulation parameters * Randomize initial liveness weightings * Randomize genesis parameters * fixed power store invariant * IterateValidatorsBonded -> IterateBondedValidatorsByPower * WriteValidators uses IterateLastValidators rather than IterateBondedValidatorsByPower * fixed democoin interface Closes #2556 Closes #2396 Via #2671: closes #2669 closes #2670 closes #2620 Offshoot issues: #2618 #2619 #2620 #2661
- Loading branch information
Showing
14 changed files
with
236 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
) | ||
|
||
const ( | ||
// Minimum time per block | ||
minTimePerBlock int64 = 10000 / 2 | ||
|
||
// Maximum time per block | ||
maxTimePerBlock int64 = 10000 | ||
|
||
// TODO Remove in favor of binary search for invariant violation | ||
onOperation bool = false | ||
) | ||
|
||
var ( | ||
// Currently there are 3 different liveness types, fully online, spotty connection, offline. | ||
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 | ||
defaultBlockSizeTransitionMatrix, _ = CreateTransitionMatrix([][]int{ | ||
{85, 5, 0}, | ||
{15, 92, 1}, | ||
{0, 3, 99}, | ||
}) | ||
) | ||
|
||
// Simulation parameters | ||
type Params struct { | ||
PastEvidenceFraction float64 | ||
NumKeys int | ||
EvidenceFraction float64 | ||
InitialLivenessWeightings []int | ||
LivenessTransitionMatrix TransitionMatrix | ||
BlockSizeTransitionMatrix TransitionMatrix | ||
} | ||
|
||
// Return default simulation parameters | ||
func DefaultParams() Params { | ||
return Params{ | ||
PastEvidenceFraction: 0.5, | ||
NumKeys: 250, | ||
EvidenceFraction: 0.5, | ||
InitialLivenessWeightings: []int{40, 5, 5}, | ||
LivenessTransitionMatrix: defaultLivenessTransitionMatrix, | ||
BlockSizeTransitionMatrix: defaultBlockSizeTransitionMatrix, | ||
} | ||
} | ||
|
||
// Return random simulation parameters | ||
func RandomParams(r *rand.Rand) Params { | ||
return Params{ | ||
PastEvidenceFraction: r.Float64(), | ||
NumKeys: r.Intn(250), | ||
EvidenceFraction: r.Float64(), | ||
InitialLivenessWeightings: []int{r.Intn(80), r.Intn(10), r.Intn(10)}, | ||
LivenessTransitionMatrix: defaultLivenessTransitionMatrix, | ||
BlockSizeTransitionMatrix: defaultBlockSizeTransitionMatrix, | ||
} | ||
} |
Oops, something went wrong.