2018-11-04 20:44:43 -08:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2018-11-07 07:28:18 -08:00
|
|
|
// TODO explain transitional matrix usage
|
2018-11-04 20:44:43 -08:00
|
|
|
var (
|
2018-11-07 07:28:18 -08:00
|
|
|
// Currently there are 3 different liveness types,
|
|
|
|
// fully online, spotty connection, offline.
|
2018-11-04 20:44:43 -08:00
|
|
|
defaultLivenessTransitionMatrix, _ = CreateTransitionMatrix([][]int{
|
|
|
|
{90, 20, 1},
|
|
|
|
{10, 50, 5},
|
|
|
|
{0, 10, 1000},
|
|
|
|
})
|
|
|
|
|
2018-11-07 07:28:18 -08:00
|
|
|
// 3 states: rand in range [0, 4*provided blocksize],
|
|
|
|
// rand in range [0, 2 * provided blocksize], 0
|
2018-11-04 20:44:43 -08:00
|
|
|
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(),
|
2019-04-22 07:57:58 -07:00
|
|
|
NumKeys: RandIntBetween(r, 2, 250),
|
2018-11-04 20:44:43 -08:00
|
|
|
EvidenceFraction: r.Float64(),
|
|
|
|
InitialLivenessWeightings: []int{r.Intn(80), r.Intn(10), r.Intn(10)},
|
|
|
|
LivenessTransitionMatrix: defaultLivenessTransitionMatrix,
|
|
|
|
BlockSizeTransitionMatrix: defaultBlockSizeTransitionMatrix,
|
|
|
|
}
|
|
|
|
}
|