-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor(distribution)!: add cometinfo #20588
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/x/distribution/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
|
@@ -10,31 +12,33 @@ | |
// BeginBlocker sets the proposer for determining distribution during endblock | ||
// and distribute rewards for the previous block. | ||
// TODO: use context.Context after including the comet service | ||
func (k Keeper) BeginBlocker(ctx sdk.Context) error { | ||
func (k Keeper) BeginBlocker(ctx context.Context) error { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) | ||
|
||
// determine the total power signing the block | ||
var previousTotalPower int64 | ||
for _, vote := range ctx.CometInfo().LastCommit.Votes { | ||
header := k.HeaderService.HeaderInfo(ctx) | ||
ci := k.cometService.CometInfo(ctx) | ||
|
||
for _, vote := range ci.LastCommit.Votes { | ||
previousTotalPower += vote.Validator.Power | ||
} | ||
|
||
// TODO this is Tendermint-dependent | ||
// ref https://github.com/cosmos/cosmos-sdk/issues/3095 | ||
if ctx.BlockHeight() > 1 { | ||
if err := k.AllocateTokens(ctx, previousTotalPower, ctx.CometInfo().LastCommit.Votes); err != nil { | ||
if header.Height > 1 { | ||
if err := k.AllocateTokens(ctx, previousTotalPower, ci.LastCommit.Votes); err != nil { | ||
|
||
return err | ||
} | ||
|
||
// every 1000 blocks send whole coins from decimal pool to community pool | ||
if ctx.BlockHeight()%1000 == 0 { | ||
if header.Height%1000 == 0 { | ||
if err := k.sendDecimalPoolToCommunityPool(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
// record the proposer for when we payout on the next block | ||
consAddr := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) | ||
consAddr := sdk.ConsAddress(ci.ProposerAddress) | ||
return k.PreviousProposer.Set(ctx, consAddr) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ func TestCalculateRewardsBasic(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
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. Tip Codebase Verification The
Analysis chainEnsure Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that `testCometService` is properly initialized in all test functions where it's used.
# Test: Search for the initialization of `testCometService`. Expect: Initialization before use in each test function.
rg --type go 'testCometService ='
Length of output: 120 Script: #!/bin/bash
# Description: Verify that `testCometService` is properly initialized in the test file `x/distribution/keeper/delegation_test.go`.
# Test: Search for the initialization of `testCometService` in `x/distribution/keeper/delegation_test.go`.
rg --type go 'testCometService =' x/distribution/keeper/delegation_test.go
Length of output: 76 Script: #!/bin/bash
# Description: Verify the usage and initialization of `testCometService` in `x/distribution/keeper/delegation_test.go`.
# Test: Search for the usage of `testCometService` in `x/distribution/keeper/delegation_test.go`.
rg --type go 'testCometService' x/distribution/keeper/delegation_test.go
# Test: Search for the initialization of `testCometService` in setup functions or imports in `x/distribution/keeper/delegation_test.go`.
rg --type go 'func.*setup' x/distribution/keeper/delegation_test.go
rg --type go 'import' x/distribution/keeper/delegation_test.go
Length of output: 394 Script: #!/bin/bash
# Description: Verify the import of `testCometService` in `x/distribution/keeper/delegation_test.go`.
# Test: Search for the import of `testCometService` in `x/distribution/keeper/delegation_test.go`.
rg --type go 'testCometService' x/distribution/keeper/delegation_test.go
Length of output: 252 Script: #!/bin/bash
# Description: Verify the definition of `testCometService` in the codebase.
# Test: Search for the definition of `testCometService` in the codebase.
rg --type go 'var testCometService'
Length of output: 122 |
||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -167,6 +168,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -283,6 +285,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -420,6 +423,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -530,6 +534,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -618,6 +623,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -747,6 +753,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -900,6 +907,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
@@ -1114,6 +1122,7 @@ func Test100PercentCommissionReward(t *testing.T) { | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de | |
bankKeeper, | ||
stakingKeeper, | ||
poolKeeper, | ||
testCometService, | ||
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. Tip Codebase Verification The integration of
Ensure these files are updated to include the Analysis chainThe integration of Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify all tests using `initFixture` have been updated to include `testCometService`.
# Test: Search for the function usage without the new parameter. Expect: No occurrences.
rg --type go $'initFixture\(' | grep -v 'testCometService'
Length of output: 9095 |
||
"fee_collector", | ||
authorityAddr, | ||
) | ||
|
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.
Tip
Codebase Verification
The addition of
ProposerAddress
is not followed by any further usage or assertions in the test suite. This indicates that the new field might not be utilized correctly.ProposerAddress
is properly handled and validated in the test suite.Analysis chain
Addition of
ProposerAddress
to the context is a significant change. Ensure that this new field is utilized correctly throughout the test suite.Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 119
Script:
Length of output: 158