Skip to content
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

feat(x/ecocredit): add basket simulations #769

Merged
merged 31 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3c4f955
wip: add simulations
aleem1314 Feb 14, 2022
449f5d0
feat: implement simulate msg-create-basket
aleem1314 Feb 14, 2022
b08d3cf
Merge branch 'release/v2.2.x' into aleem/basket-sims
aleem1314 Feb 15, 2022
83a23d2
feat: add put into basket sim
aleem1314 Feb 15, 2022
8abdf8b
wip: sims
aleem1314 Feb 15, 2022
a5bdfc3
wip: try fix sims
aleem1314 Feb 15, 2022
b7fa656
feat: add msg-take
aleem1314 Feb 15, 2022
1719045
chore: cleanup
aleem1314 Feb 15, 2022
d17301c
chore: inc basket sims gas
aleem1314 Feb 15, 2022
1b08beb
Merge branch 'release/v2.2.x' into aleem/basket-sims
aleem1314 Feb 16, 2022
c4ca68d
add logs
aleem1314 Feb 16, 2022
a15a783
fix error
aleem1314 Feb 16, 2022
b7f0d56
add basket fee check
aleem1314 Feb 16, 2022
ec8c8f9
try fix sims
aleem1314 Feb 17, 2022
adf93eb
Merge branch 'release/v3.0.x' into aleem/basket-sims
aaronc Feb 17, 2022
1996c2f
convert basket decimal to integer using string
aaronc Feb 17, 2022
d1c0eca
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 18, 2022
eeb3525
cleanup
aleem1314 Feb 18, 2022
876e156
update app/app.go
aleem1314 Feb 18, 2022
74cbc4d
fix random amt issue
aleem1314 Feb 18, 2022
7d10eb4
fix sim error
aleem1314 Feb 18, 2022
116082e
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 18, 2022
ec18dc2
chore: create helpers
aleem1314 Feb 18, 2022
ac7826f
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 18, 2022
246ac8d
add date criteria
aleem1314 Feb 18, 2022
fdfa386
Merge branch 'release/v3.0.x' into aleem/basket-sims
robert-zaremba Feb 18, 2022
361a49a
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 20, 2022
0e9c364
fix supply invariant
ryanchristo Feb 22, 2022
a5c9594
chore: review changes
aleem1314 Feb 23, 2022
df30c09
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 23, 2022
c23a926
Merge branch 'release/v3.0.x' into aleem/basket-sims
robert-zaremba Feb 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), // enable after updating sdk version v0.46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? when is this supposed to happen?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need authz - it's already used and it could break some existing flows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why simulation tests were passing before and now the following error occurs when uncommented:

    simulate.go:300: error on block  26/100, operation (8/738) from x/authz:
        failed to execute message; message index: 0: requested amount is more than spend limit: insufficient funds [regen-network/cosmos-sdk@v0.44.2-regen-1/types/errors/errors.go:273]
        Comment: failed to execute message; message index: 0: requested amount is more than spend limit: insufficient funds

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clevinson and I dug into this a bit and we were trying to figure out if this was in fact an issue with the authz module. The error is insufficient funds so we were thinking it might be related to the basket fee. We were able to successfully run the simulation tests with authz uncommented and skipping SimulateMsgCreate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The issue is with authz simulation. We should ignore MsgExec simulation if a grantee tries to spend more than the allowed spend limit. I've raised a PR on the SDK to fix this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for confirming. cosmos/cosmos-sdk#11252

ibc.NewAppModule(app.IBCKeeper),
transferModule,
ecocreditmodule.NewModule(app.GetSubspace(ecocredit.DefaultParamspace), app.AccountKeeper, app.BankKeeper, app.DistrKeeper),
Expand Down
13 changes: 9 additions & 4 deletions x/ecocredit/server/basket/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ func BasketSupplyInvariant(ctx sdk.Context, store basketv1.BasketStore, bank ban

var inbalances []string
for _, bid := range bids {
b, err := store.Get(goCtx, bid)
if err != nil {
return fmt.Sprintf("Can't get basket %v: %v", bid, err), true
}
bal := basketBalances[bid]
balInt, err := bal.BigInt()
exp := math.NewDecFinite(1, int32(b.Exponent))
mul, err := bal.Mul(exp)
if err != nil {
return fmt.Sprintf("Can't convert Dec to big.Int, %v", err), true
return fmt.Sprintf("Can't multiply balance by exponent, %v", err), true
}
b, err := store.Get(goCtx, bid)
balInt, err := mul.BigInt()
if err != nil {
return fmt.Sprintf("Can't get basket %v: %v", bid, err), true
return fmt.Sprintf("Can't convert Dec to big.Int, %v", err), true
}
c := bank.GetSupply(ctx, b.BasketDenom)
balSdkInt := sdk.NewIntFromBigInt(balInt)
Expand Down
3 changes: 3 additions & 0 deletions x/ecocredit/server/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
servermodule "github.com/regen-network/regen-ledger/types/module/server"

"github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/regen-network/regen-ledger/x/ecocredit/basket"
"github.com/regen-network/regen-ledger/x/ecocredit/simulation"
)

// WeightedOperations returns all the ecocredit module operations with their respective weights.
func (s serverImpl) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
key := s.storeKey.(servermodule.RootModuleKey)
queryClient := ecocredit.NewQueryClient(key)
basketQryClient := basket.NewQueryClient(key)

return simulation.WeightedOperations(
simState.AppParams, simState.Cdc,
s.accountKeeper, s.bankKeeper,
queryClient,
basketQryClient,
)
}
Loading