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

GasTracker split #202

Merged
merged 28 commits into from
Aug 9, 2022
Merged

GasTracker split #202

merged 28 commits into from
Aug 9, 2022

Conversation

iTiky
Copy link
Contributor

@iTiky iTiky commented Jul 27, 2022

No description provided.


// Params implements the types.QueryServer interface.
func (s *QueryServer) Params(c context.Context, request *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if request == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can avoid checking for this as the gRPC stub should handle this seamlessly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done in the Cosmos SDK so I did the same 🤷‍♂️

Copy link
Contributor

@fdymylja fdymylja left a comment

Choose a reason for hiding this comment

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

Reviewed tracking part, LGTM.

…imited (LT 1.0) as 1.0 triggers an error on x/mint BeginBlocker
app/ante.go Outdated Show resolved Hide resolved
Copy link
Contributor

@fdymylja fdymylja left a comment

Choose a reason for hiding this comment

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

rewards protos ACK.

if err := dfd.bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), authTypes.FeeCollectorName, fees); err != nil {
return sdkErrors.Wrapf(sdkErrors.ErrInsufficientFunds, err.Error())
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to be conscious about this approach for tracking pruning, because tracking can have records of this TX whilst rewards does not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also side note, we're fetching the Dec twice here, for performance we could just fetch the tx fee rebate ratio here, and apply the isZero() logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dec usage fixed. As for pruning. If there were no TxRebate rewards a corresponding rewards tracking entry is not created and this is handled by the x/rewards distribution logic.

iTiky and others added 7 commits August 1, 2022 13:48
…; Ante handlers reordered; ContractMetadata has ContractAddress in it.

Tests fixes
x/rewards, x/tracking: state tests added.
E2E tests: Sudo test enabled (after the wasmd upgrade), Stargate query test disabled (removed by the wasmvm developers).
x/rewards/ante/fee_deduction.go Outdated Show resolved Hide resolved
}

// Check that only one coin has been minted
if len(dappRewards) != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we making an assumption here that only one coin can be minted?

I understand current version of cosmos sdk only support one coin for inflation, but that could change in future. Besides, if we go by that then input will always contain one coin anyway. So there is no point in this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fdymylja Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from your code so need yours feedback.

Copy link
Contributor

Choose a reason for hiding this comment

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

This mocks the behaviour of the current minting module in the SDK, once we upgrade to a different SDK version if there are changes in the minting module we can change this.

x/rewards/types/params.go Show resolved Hide resolved
x/rewards/client/cli/tx.go Outdated Show resolved Hide resolved
// estimateBlockRewards update block distribution state with tracked rewards calculating reward shares per contract.
// Func iterates over all tracked transactions and estimates inflation (on block level) and fee rebate (merging
// tokens for each transaction contract has operation at) rewards for each contract.
func (k Keeper) estimateBlockRewards(ctx sdk.Context, blockDistrState *blockRewardsDistributionState) *blockRewardsDistributionState {
Copy link
Contributor

@edjroz edjroz Aug 3, 2022

Choose a reason for hiding this comment

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

I'm a bit concerened on GC overhead of passing a pointer, golang pointers are a bit quirky since it passes pointers to heap which takes longer to clean than stack values, the GC cycle is probably longer than block times so it would accumulate over time.
Once that is done the GC has to dereference which is a costly implementation in itself.

This might be over panicking however, in case performance analysis is neccesary in the future we can always make a escape analysis build with go build -gcflags="-m"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right about pointers in general. Goway is to be as immutable as possible. But here, since we are not "escaping" (not in terms of the compiler) the DistributeRewards func, this is kind of OK. But if that really bothers you, I can pass an object and return an updated one. BTW maps in the State object are "heaped" (probably 🤷‍♂️).

Copy link
Contributor

@edjroz edjroz Aug 3, 2022

Choose a reason for hiding this comment

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

Let's not get ahead of ourselves here, If we switch to rewards distribution using a smart contract then this change would be moot. I'll just keep a mental note on it as we observe further growth.

P.D: yeah maps are notoriously bad in golang for memory growth more on this golang issue

Co-authored-by: Eduardo Díaz <edjroz@users.noreply.github.com>
@edjroz edjroz marked this pull request as ready for review August 9, 2022 14:02
@codecov
Copy link

codecov bot commented Aug 9, 2022

Codecov Report

Merging #202 (b1fc078) into main (f9fcee9) will increase coverage by 6.77%.
The diff coverage is 71.67%.

@@            Coverage Diff             @@
##             main     #202      +/-   ##
==========================================
+ Coverage   56.68%   63.45%   +6.77%     
==========================================
  Files          20       47      +27     
  Lines        1302     1929     +627     
==========================================
+ Hits          738     1224     +486     
- Misses        527      664     +137     
- Partials       37       41       +4     
Impacted Files Coverage Δ
app/test_access.go 0.00% <ø> (ø)
pkg/cli_args.go 0.00% <0.00%> (ø)
pkg/cli_flags.go 0.00% <0.00%> (ø)
pkg/coin.go 0.00% <0.00%> (ø)
pkg/dec.go 0.00% <0.00%> (ø)
x/rewards/types/events.go 0.00% <0.00%> (ø)
x/tracking/types/query.go 0.00% <0.00%> (ø)
x/rewards/keeper/grpc_query.go 3.77% <3.77%> (ø)
x/rewards/keeper/msg_server.go 14.28% <14.28%> (ø)
x/rewards/types/msg.go 21.73% <21.73%> (ø)
... and 47 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants