-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(perf): protorev tracker coin array (#7240)
* remove tx fee tracker * add change log * track array of coins for performance * changelog * lints * lints * fixes * Auto: update go.mod after push to adam/protorev-tracker-perf that modified dependencies locally * fix tests * event * nil error * expect accounting height to always be exported * range backwards and add test * reduce code duplication * Auto: update go.mod after push to adam/protorev-tracker-perf that modified dependencies locally * init image should not check seq number * revert change to proto rev bc might expect error case * revert init tag for now * config tag * lint spelling * init tag * revert init image * remove osmoutils method for coins to coin array * continue tracking from same accounting height pre upgrade * Auto: update go.mod after push to adam/protorev-tracker-perf that modified dependencies locally * update store helper * Auto: update go.mod after push to adam/protorev-tracker-perf that modified dependencies locally * go mod updates * just use int * go mod updates * revert statistics.go * fix store key * update go mods * dont double append prefix * update go mod * go mod changes --------- Co-authored-by: github-actions <github-actions@github.com>
- Loading branch information
1 parent
370b381
commit 227c44c
Showing
33 changed files
with
658 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package v22_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
|
||
"github.com/osmosis-labs/osmosis/osmomath" | ||
"github.com/osmosis-labs/osmosis/osmoutils" | ||
"github.com/osmosis-labs/osmosis/v21/app/apptesting" | ||
"github.com/osmosis-labs/osmosis/v21/x/protorev/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" | ||
) | ||
|
||
const ( | ||
v22UpgradeHeight = int64(10) | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
} | ||
|
||
func TestUpgradeTestSuite(t *testing.T) { | ||
suite.Run(t, new(UpgradeTestSuite)) | ||
} | ||
|
||
func (s *UpgradeTestSuite) TestUpgrade() { | ||
s.Setup() | ||
|
||
expectedTakerFeeForStakers := []sdk.Coin{sdk.NewCoin("uakt", osmomath.NewInt(3000)), sdk.NewCoin("uatom", osmomath.NewInt(1000)), sdk.NewCoin("uosmo", osmomath.NewInt(2000))} | ||
expectedTakerFeeForCommunityPool := []sdk.Coin{sdk.NewCoin("uakt", osmomath.NewInt(2000)), sdk.NewCoin("uatom", osmomath.NewInt(3000)), sdk.NewCoin("uosmo", osmomath.NewInt(1000))} | ||
expectedTrackerStartHeight := int64(3) | ||
|
||
// Set up old protorev tracker prior to upgrade | ||
s.App.PoolManagerKeeper.SetTakerFeeTrackerStartHeight(s.Ctx, expectedTrackerStartHeight) | ||
newTakerFeeForStakers := poolmanagertypes.TrackedVolume{ | ||
Amount: expectedTakerFeeForStakers, | ||
} | ||
osmoutils.MustSet(s.Ctx.KVStore(s.App.GetKey(poolmanagertypes.StoreKey)), poolmanagertypes.KeyTakerFeeStakersProtoRev, &newTakerFeeForStakers) | ||
|
||
newTakerFeeForCommunityPool := poolmanagertypes.TrackedVolume{ | ||
Amount: expectedTakerFeeForCommunityPool, | ||
} | ||
osmoutils.MustSet(s.Ctx.KVStore(s.App.GetKey(poolmanagertypes.StoreKey)), poolmanagertypes.KeyTakerFeeCommunityPoolProtoRev, &newTakerFeeForCommunityPool) | ||
|
||
// Set up cyclic arb tracker just to double check that it is not affected by the upgrade | ||
s.App.ProtoRevKeeper.SetCyclicArbProfitTrackerStartHeight(s.Ctx, expectedTrackerStartHeight) | ||
cyclicArbProfits := sdk.NewCoins(sdk.NewCoin(types.OsmosisDenomination, osmomath.NewInt(9000)), sdk.NewCoin("Atom", osmomath.NewInt(3000))) | ||
err := s.App.AppKeepers.ProtoRevKeeper.UpdateStatistics(s.Ctx, poolmanagertypes.SwapAmountInRoutes{}, cyclicArbProfits[0].Denom, cyclicArbProfits[0].Amount) | ||
s.Require().NoError(err) | ||
err = s.App.AppKeepers.ProtoRevKeeper.UpdateStatistics(s.Ctx, poolmanagertypes.SwapAmountInRoutes{}, cyclicArbProfits[1].Denom, cyclicArbProfits[1].Amount) | ||
s.Require().NoError(err) | ||
|
||
dummyUpgrade(s) | ||
s.Require().NotPanics(func() { | ||
s.App.BeginBlocker(s.Ctx, abci.RequestBeginBlock{}) | ||
}) | ||
|
||
allProtocolRevenue := s.App.ProtoRevKeeper.GetAllProtocolRevenue(s.Ctx) | ||
|
||
// Check that the taker fee tracker for stakers has been migrated correctly | ||
s.Require().Equal(expectedTakerFeeForStakers, allProtocolRevenue.TakerFeesTracker.TakerFeesToStakers) | ||
s.Require().Equal(expectedTakerFeeForCommunityPool, allProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool) | ||
s.Require().Equal(expectedTrackerStartHeight, allProtocolRevenue.TakerFeesTracker.HeightAccountingStartsFrom) | ||
s.Require().Equal(expectedTrackerStartHeight, allProtocolRevenue.CyclicArbTracker.HeightAccountingStartsFrom) | ||
} | ||
|
||
func dummyUpgrade(s *UpgradeTestSuite) { | ||
s.Ctx = s.Ctx.WithBlockHeight(v22UpgradeHeight - 1) | ||
plan := upgradetypes.Plan{Name: "v22", Height: v22UpgradeHeight} | ||
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan) | ||
s.Require().NoError(err) | ||
_, exists := s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx) | ||
s.Require().True(exists) | ||
|
||
s.Ctx = s.Ctx.WithBlockHeight(v22UpgradeHeight) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.