-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
R4R: Display number of operations which actually got ran #2683
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,9 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, | |
accs := RandomAccounts(r, params.NumKeys) | ||
|
||
// Setup event stats | ||
events := make(map[string]uint) | ||
event := func(what string) { | ||
events[what]++ | ||
events := make(map[event]uint) | ||
eventFn := func(what string, success bool) { | ||
events[event{what, success}]++ | ||
} | ||
|
||
validators := initChain(r, params, accs, setups, app, appStateFn) | ||
|
@@ -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, pastTimes, pastVoteInfos, event, header) | ||
request := RandomRequestBeginBlock(r, params, validators, pastTimes, pastVoteInfos, eventFn, header) | ||
// These are operations which have been queued by previous operations | ||
operationQueue := make(map[int][]Operation) | ||
timeOperationQueue := []FutureOperation{} | ||
|
@@ -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, params, event, invariants, ops, operationQueue, timeOperationQueue, numBlocks, blockSize, displayLogs) | ||
blockSimulator := createBlockSimulator(testingMode, tb, t, params, eventFn, invariants, ops, operationQueue, timeOperationQueue, numBlocks, blockSize, displayLogs) | ||
if !testingMode { | ||
b.ResetTimer() | ||
} else { | ||
|
@@ -147,8 +147,8 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, | |
|
||
// Run queued operations. Ignores blocksize if blocksize is too small | ||
logWriter("Queued operations") | ||
numQueuedOpsRan := runQueuedOperations(operationQueue, int(header.Height), tb, r, app, ctx, accs, logWriter, displayLogs, event) | ||
numQueuedTimeOpsRan := runQueuedTimeOperations(timeOperationQueue, header.Time, tb, r, app, ctx, accs, logWriter, displayLogs, event) | ||
numQueuedOpsRan := runQueuedOperations(operationQueue, int(header.Height), tb, r, app, ctx, accs, logWriter, displayLogs, eventFn) | ||
numQueuedTimeOpsRan := runQueuedTimeOperations(timeOperationQueue, header.Time, tb, r, app, ctx, accs, logWriter, displayLogs, eventFn) | ||
if testingMode && onOperation { | ||
// Make sure invariants hold at end of queued operations | ||
assertAllInvariants(t, app, invariants, "QueuedOperations", displayLogs) | ||
|
@@ -183,11 +183,11 @@ 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, pastTimes, pastVoteInfos, event, header) | ||
request = RandomRequestBeginBlock(r, params, validators, pastTimes, pastVoteInfos, eventFn, header) | ||
|
||
// Update the validator set, which will be reflected in the application on the next block | ||
validators = nextValidators | ||
nextValidators = updateValidators(tb, r, params, validators, res.ValidatorUpdates, event) | ||
nextValidators = updateValidators(tb, r, params, validators, res.ValidatorUpdates, eventFn) | ||
} | ||
if stopEarly { | ||
DisplayEvents(events) | ||
|
@@ -206,7 +206,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, params Params, | ||
event func(string), invariants []Invariant, | ||
eventFn EventFn, invariants []Invariant, | ||
ops []WeightedOperation, operationQueue map[int][]Operation, timeOperationQueue []FutureOperation, | ||
totalNumBlocks int, avgBlockSize int, displayLogs func()) blockSimFn { | ||
|
||
|
@@ -236,7 +236,7 @@ func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T, params | |
fmt.Printf("\rSimulating... block %d/%d, operation %d/%d. ", header.Height, totalNumBlocks, opCount, blocksize) | ||
lastBlocksizeState, blocksize = getBlockSize(r, params, lastBlocksizeState, avgBlockSize) | ||
for j := 0; j < blocksize; j++ { | ||
logUpdate, futureOps, err := selectOp(r)(r, app, ctx, accounts, event) | ||
logUpdate, futureOps, err := selectOp(r)(r, app, ctx, accounts, eventFn) | ||
logWriter(logUpdate) | ||
if err != nil { | ||
displayLogs() | ||
|
@@ -313,7 +313,7 @@ func queueOperations(queuedOperations map[int][]Operation, queuedTimeOperations | |
|
||
// nolint: errcheck | ||
func runQueuedOperations(queueOperations map[int][]Operation, height int, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, | ||
accounts []Account, logWriter func(string), displayLogs func(), event func(string)) (numOpsRan int) { | ||
accounts []Account, logWriter func(string), displayLogs func(), event func(string, bool)) (numOpsRan int) { | ||
if queuedOps, ok := queueOperations[height]; ok { | ||
numOps := len(queuedOps) | ||
for i := 0; i < numOps; i++ { | ||
|
@@ -334,7 +334,7 @@ func runQueuedOperations(queueOperations map[int][]Operation, height int, tb tes | |
} | ||
|
||
func runQueuedTimeOperations(queueOperations []FutureOperation, currentTime time.Time, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, | ||
accounts []Account, logWriter func(string), displayLogs func(), event func(string)) (numOpsRan int) { | ||
accounts []Account, logWriter func(string), displayLogs func(), event EventFn) (numOpsRan int) { | ||
|
||
numOpsRan = 0 | ||
for len(queueOperations) > 0 && currentTime.After(queueOperations[0].BlockTime) { | ||
|
@@ -382,7 +382,7 @@ func randomProposer(r *rand.Rand, validators map[string]mockValidator) cmn.HexBy | |
// 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, | ||
pastTimes []time.Time, pastVoteInfos [][]abci.VoteInfo, event func(string), header abci.Header) abci.RequestBeginBlock { | ||
pastTimes []time.Time, pastVoteInfos [][]abci.VoteInfo, eventFn EventFn, header abci.Header) abci.RequestBeginBlock { | ||
if len(validators) == 0 { | ||
return abci.RequestBeginBlock{Header: header} | ||
} | ||
|
@@ -402,11 +402,7 @@ func RandomRequestBeginBlock(r *rand.Rand, params Params, validators map[string] | |
// offline | ||
signed = false | ||
} | ||
if signed { | ||
event("beginblock/signing/signed") | ||
} else { | ||
event("beginblock/signing/missed") | ||
} | ||
eventFn("beginblock/signing/signed", signed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a useful stat? I really don't think it is, since the information it provides is unhelpful after a very small number of blocks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's still worth recording for an idea of the overall distribution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm dubious. I'd opt to remove just b/c it also skews the "number of operations" count, though I guess we could create a fix for this. This is essentially looking at the result of a binomial distribution after a very large number of runs. Maybe we make this one display the percentage between the two, and not the raw number? |
||
pubkey, err := tmtypes.PB2TM.PubKey(mVal.val.PubKey) | ||
if err != nil { | ||
panic(err) | ||
|
@@ -445,7 +441,7 @@ func RandomRequestBeginBlock(r *rand.Rand, params Params, validators map[string] | |
Time: time, | ||
TotalVotingPower: totalVotingPower, | ||
}) | ||
event("beginblock/evidence") | ||
eventFn("beginblock/evidence", true) | ||
} | ||
} | ||
return abci.RequestBeginBlock{ | ||
|
@@ -459,7 +455,7 @@ func RandomRequestBeginBlock(r *rand.Rand, params Params, validators map[string] | |
|
||
// updateValidators mimicks Tendermint's update logic | ||
// nolint: unparam | ||
func updateValidators(tb testing.TB, r *rand.Rand, params Params, current map[string]mockValidator, updates []abci.ValidatorUpdate, event func(string)) map[string]mockValidator { | ||
func updateValidators(tb testing.TB, r *rand.Rand, params Params, current map[string]mockValidator, updates []abci.ValidatorUpdate, eventFn EventFn) map[string]mockValidator { | ||
|
||
for _, update := range updates { | ||
str := fmt.Sprintf("%v", update.PubKey) | ||
|
@@ -469,17 +465,17 @@ func updateValidators(tb testing.TB, r *rand.Rand, params Params, current map[st | |
tb.Fatalf("tried to delete a nonexistent validator") | ||
} | ||
|
||
event("endblock/validatorupdates/kicked") | ||
eventFn("endblock/validatorupdates/kicked", true) | ||
delete(current, str) | ||
default: | ||
// Does validator already exist? | ||
if mVal, ok := current[str]; ok { | ||
mVal.val = update | ||
event("endblock/validatorupdates/updated") | ||
eventFn("endblock/validatorupdates/updated", true) | ||
} else { | ||
// Set this new validator | ||
current[str] = mockValidator{update, GetMemberOfInitialState(r, params.InitialLivenessWeightings)} | ||
event("endblock/validatorupdates/added") | ||
eventFn("endblock/validatorupdates/added", true) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ this