-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix: fix sim test state persistence issue #19771
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 |
---|---|---|
|
@@ -229,7 +229,7 @@ func simulateMsgSubmitProposal( | |
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
simAccount, _ := simtypes.RandomAcc(r, accs) | ||
expedited := r.Intn(2) == 0 | ||
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true, expedited) | ||
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true, true, expedited) | ||
switch { | ||
case skip: | ||
return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "skip deposit"), nil, nil | ||
|
@@ -278,11 +278,20 @@ func simulateMsgSubmitProposal( | |
|
||
opMsg := simtypes.NewOperationMsg(msg, true, "") | ||
|
||
// get the submitted proposal ID | ||
// Get the submitted proposal ID (current sequence value minus one). | ||
proposalID, err := k.ProposalID.Peek(ctx) | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate proposalID"), nil, err | ||
} | ||
proposalID-- | ||
hacheigriega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
proposal, err := k.Proposals.Get(ctx, proposalID) | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to retrieve proposal"), nil, err | ||
} | ||
|
||
unixDiff := proposal.VotingEndTime.Unix() - proposal.VotingStartTime.Unix() | ||
voteTime := time.Unix(r.Int63n(unixDiff), 0) | ||
|
||
// 2) Schedule operations for votes | ||
// 2.1) first pick a number of people to vote. | ||
|
@@ -294,14 +303,11 @@ func simulateMsgSubmitProposal( | |
|
||
// didntVote := whoVotes[numVotes:] | ||
whoVotes = whoVotes[:numVotes] | ||
params, _ := k.Params.Get(ctx) | ||
votingPeriod := params.VotingPeriod | ||
|
||
fops := make([]simtypes.FutureOperation, numVotes+1) | ||
for i := 0; i < numVotes; i++ { | ||
whenVote := ctx.HeaderInfo().Time.Add(time.Duration(r.Int63n(int64(votingPeriod.Seconds()))) * time.Second) | ||
fops[i] = simtypes.FutureOperation{ | ||
BlockTime: whenVote, | ||
BlockTime: voteTime, | ||
Op: operationSimulateMsgVote(txGen, ak, bk, k, accs[whoVotes[i]], int64(proposalID)), | ||
} | ||
} | ||
|
@@ -332,7 +338,7 @@ func SimulateMsgDeposit( | |
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "unable to get proposal"), nil, err | ||
} | ||
|
||
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, false, p.Expedited) | ||
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, false, false, p.Expedited) | ||
switch { | ||
case skip: | ||
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "skip deposit"), nil, nil | ||
|
@@ -555,7 +561,8 @@ func randomDeposit( | |
bk types.BankKeeper, | ||
k *keeper.Keeper, | ||
addr sdk.AccAddress, | ||
useMinAmount bool, | ||
useMinInitAmt bool, | ||
useMinAmt bool, | ||
expedited bool, | ||
) (deposit sdk.Coins, skip bool, err error) { | ||
account := ak.GetAccount(ctx, addr) | ||
|
@@ -587,21 +594,26 @@ func randomDeposit( | |
|
||
threshold := minDepositAmount.ToLegacyDec().Mul(minDepositRatio).TruncateInt() | ||
|
||
minAmount := sdkmath.ZeroInt() | ||
if useMinAmount { | ||
minInitAmt := sdkmath.ZeroInt() | ||
if useMinInitAmt { | ||
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. can you explain this? 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. Yeah, I was trying to keep the original code as much as possible. I made these changes to get the proposal to immediately enter the voting period. So the deposit amount has to satisfy both the "minimum initial deposit requirement" and the "minimum deposit requirement". |
||
minDepositPercent, err := sdkmath.LegacyNewDecFromStr(params.MinInitialDepositRatio) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
|
||
minAmount = sdkmath.LegacyNewDecFromInt(minDepositAmount).Mul(minDepositPercent).TruncateInt() | ||
minInitAmt = sdkmath.LegacyNewDecFromInt(minDepositAmount).Mul(minDepositPercent).TruncateInt() | ||
} | ||
|
||
minAmt := sdkmath.ZeroInt() | ||
if useMinAmt { | ||
minAmt = minDepositAmount | ||
} | ||
|
||
amount, err := simtypes.RandPositiveInt(r, minDepositAmount.Sub(minAmount)) | ||
amount, err := simtypes.RandPositiveInt(r, minDepositAmount) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
amount = amount.Add(minAmount) | ||
amount = amount.Add(minInitAmt).Add(minAmt) | ||
|
||
if amount.GT(spendableBalance) || amount.LT(threshold) { | ||
return nil, true, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,8 @@ func SimulateFromSeed( | |
|
||
logWriter.AddEntry(EndBlockEntry(blockHeight)) | ||
|
||
app.WorkingHash() | ||
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 we should not make this function public but see if all operations are run in the context of a FinalizeBlock call. Given that this function is called in there |
||
|
||
if config.Commit { | ||
_, err := app.Commit() | ||
if err != nil { | ||
|
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.
We shouldn't make this one public, if calling this solves the issue then the problem is that there are operations running outside of a FinalizeBlock call context. Because this function is called at the end of FinalizeBlock.