Skip to content

Commit

Permalink
compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Nov 8, 2018
1 parent 5f289e5 commit a9ef83b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
5 changes: 1 addition & 4 deletions x/mock/simulation/event_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]++
}

Expand Down
15 changes: 8 additions & 7 deletions x/mock/simulation/mock_tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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++
}
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions x/mock/simulation/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions x/mock/simulation/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a9ef83b

Please sign in to comment.