compiling

This commit is contained in:
rigelrozanski 2018-11-08 01:57:37 -05:00
parent 5f289e5fdd
commit a9ef83bc4a
4 changed files with 18 additions and 20 deletions

View File

@ -10,12 +10,9 @@ type eventStats map[string]uint
func newEventStats() eventStats {
events := make(map[string]uint)
return events
event := func(what string) {
events[what]++
}
}
func (es *eventStats) tally(eventDesc string) {
func (es eventStats) tally(eventDesc string) {
es[eventDesc]++
}

View File

@ -20,9 +20,10 @@ type mockValidator struct {
type mockValidators map[string]mockValidator
// get mockValidators from abci validators
func newMockValidators(abciVals abci.ValidatorUpdate) mockValidators {
func newMockValidators(r *rand.Rand, abciVals []abci.ValidatorUpdate,
params Params) mockValidators {
validators = make(mockValidators)
validators := make(mockValidators)
for _, validator := range abciVals {
str := fmt.Sprintf("%v", validator.PubKey)
liveliness := GetMemberOfInitialState(r,
@ -39,9 +40,9 @@ func newMockValidators(abciVals abci.ValidatorUpdate) mockValidators {
// TODO describe usage
func (vals mockValidators) getKeys() []string {
keys := make([]string, len(validators))
keys := make([]string, len(vals))
i := 0
for key := range validators {
for key := range vals {
keys[i] = key
i++
}
@ -52,13 +53,13 @@ func (vals mockValidators) getKeys() []string {
//_________________________________________________________________________________
// randomProposer picks a random proposer from the current validator set
func randomProposer(r *rand.Rand, validators map[string]mockValidator) cmn.HexBytes {
keys := validators.getKeys()
func (vals mockValidators) randomProposer(r *rand.Rand) cmn.HexBytes {
keys := vals.getKeys()
if len(keys) == 0 {
return nil
}
key := keys[r.Intn(len(keys))]
proposer := validators[key].val
proposer := vals[key].val
pk, err := tmtypes.PB2TM.PubKey(proposer.PubKey)
if err != nil {
panic(err)

View File

@ -86,17 +86,17 @@ type WeightedOperation struct {
// WeightedOperations is the group of all weighted operations to simulate.
type WeightedOperations []WeightedOperation
func (w WeightedOperations) totalWeight() int {
func (ops WeightedOperations) totalWeight() int {
totalOpWeight := 0
for i := 0; i < len(w); i++ {
totalOpWeight += w[i].Weight
for _, op := range ops {
totalOpWeight += op.Weight
}
return totalOpWeight
}
type selectOpFn func(r *rand.Rand) Operation
func (w WeightedOperations) getSelectOpFn() selectOpFn {
func (ops WeightedOperations) getSelectOpFn() selectOpFn {
totalOpWeight := ops.totalWeight()
return func(r *rand.Rand) Operation {
x := r.Intn(totalOpWeight)

View File

@ -43,7 +43,7 @@ func initChain(r *rand.Rand, params Params, accounts []Account,
AppStateBytes: appStateFn(r, accounts),
}
res := app.InitChain(req)
validators = newMockValidators(res.Validators)
validators := newMockValidators(r, res.Validators, params)
for i := 0; i < len(setups); i++ {
setups[i](r, accounts)
@ -76,16 +76,16 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
timeDiff := maxTimePerBlock - minTimePerBlock
accs := RandomAccounts(r, params.NumKeys)
eventStats := newEventStats()
validators := initChain(r, params, accs, setups, app, appStateFn)
// Second variable to keep pending validator set (delayed one block since
// TM 0.24) Initially this is the same as the initial validator set
nextValidators := validators()
validators := initChain(r, params, accs, setups, app, appStateFn)
nextValidators := validators
header := abci.Header{
Height: 1,
Time: timestamp,
ProposerAddress: randomProposer(r, validators),
ProposerAddress: validators.randomProposer(r),
}
opCount := 0
@ -186,7 +186,7 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
time.Duration(minTimePerBlock) * time.Second)
header.Time = header.Time.Add(
time.Duration(int64(r.Intn(int(timeDiff)))) * time.Second)
header.ProposerAddress = randomProposer(r, validators)
header.ProposerAddress = validators.randomProposer(r)
logWriter("EndBlock")
if testingMode {