-
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
Improve set supply #8950
Improve set supply #8950
Conversation
…s-sdk into jonathan/supply-improvement
Codecov Report
@@ Coverage Diff @@
## master #8950 +/- ##
==========================================
+ Coverage 58.88% 58.90% +0.01%
==========================================
Files 571 571
Lines 32120 32115 -5
==========================================
+ Hits 18914 18917 +3
+ Misses 10984 10977 -7
+ Partials 2222 2221 -1
|
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.
LGTM! maybe a changelog entry?
|
||
bz := k.cdc.MustMarshalBinaryBare(&coin) | ||
supplyStore.Set([]byte(coin.GetDenom()), bz) | ||
} |
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.
Why not keeping a loop here?
- in all places where we use this function we have the following pattern: https://github.com/cosmos/cosmos-sdk/pull/8950/files#diff-9994bff9a7f71878caa036e9c924ab8b06e31490a17874fab72648ed3404d220R346
- if we move the loop here, we don't need to recreate and
store
and do additional allocations. @odeke-em was shaving recently such places.
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.
An argument could be made for doing all of this logic inline inside MintCoins
and BurnCoins
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.
@jgimeno I wonder if there's value in making this setSupply(sdk.KVStore, sdk.Coin)
to avoid the allocations from ctx.KVStore
as @robert-zaremba is suggesting. Wdyt?
…s-sdk into jonathan/supply-improvement
…s-sdk into jonathan/supply-improvement
x/bank/keeper/keeper.go
Outdated
supply = supply.Sub(amount) | ||
newSupply = append(newSupply, supply) | ||
} | ||
k.setSupply(ctx, newSupply) |
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.
I don't see a need to bundle this into Coins at all. Instead I think we should just be setting supply by denom in the above for loop. The whole Coins abstraction is just unnecessary here IMHO.
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.
+1 for inlining. The function is used only 2 times, so not a big trade off.
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.
Would be good to get this supply store stuff right once and for all. So blocking until we have a clear path on these issues.
Mainly:
- it's maybe unnecessary to have a
setSupply
method takingsdk.Coins
. Can this stuff be dealt with:- inline in
MintCoins
orBurnCoins
, or - we have
setSupply(sdk.Context, sdk.Coin)
for a single coin?
- inline in
- we don't need
Coin
serialized in the value of supply keys, just the amount
What do you think @jgimeno ?
x/bank/keeper/keeper.go
Outdated
supplyStore := prefix.NewStore(store, types.SupplyKey) | ||
|
||
for i := range coins { | ||
bz := k.cdc.MustMarshalBinaryBare(&coins[i]) |
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.
Also noticing that this doesn't seem quite right. There's no need to serialize the whole Coin
. We just need the amount serialized in the value. The denom is already serialized in the key.
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 was the first approach I took, setSupply to get one coin, I can revert it. I agree on the coin serialization. Thanks!
Benchmark beginning. Status page: https://github.orijtech.com/benchmark/status?commit=2591510637b4e33288b6e77a478ceb940baa2fa7 |
Benchmark finished. See the result: https://github.orijtech.com/benchmark/result?id=a617ee308cdf43a9b7767738deae5f2e |
Benchmark beginning. Status page: https://github.orijtech.com/benchmark/status?commit=7b5645f80581c18479db489ec58c366f47038886 |
Benchmark finished. See the result: https://github.orijtech.com/benchmark/result?id=84db01cd6d67430eae7142a4c39b314b |
Benchmark finished. See the result: https://github.orijtech.com/benchmark/result?id=57815b5e488c4752992f4193ec238658 |
Benchmark beginning. Status page: https://github.orijtech.com/benchmark/status?commit=7ac436d2f759bd09e012f05ab1d10ebd97d782a5 |
Description
closes: #8931
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes