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

batching delegations and undelegations #1263

Merged
merged 46 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
10a1abd
Batched delegations (#1201)
sampocs Jun 13, 2024
74c51cb
batched undelegations (#1195)
sampocs Jun 13, 2024
99d773f
staketia migration (#1212)
sampocs Jun 13, 2024
a5b31a6
fixed unit tests
sampocs Jun 13, 2024
1582770
V23 upgrade handler (batching and stTIA) (#1219)
sampocs Jun 13, 2024
95f12fd
added TODO
sampocs Jun 14, 2024
cd8d976
[AUDIT FIX] - short circuit callback on completed records
sampocs Jun 14, 2024
def6f4a
[AUDIT FIX] - decrement remaining delegated balance in redeem stake
sampocs Jun 20, 2024
f1fe92c
[AUDIT FIX] - set min/max inner redemption rate after migration
sampocs Jun 20, 2024
df38a31
[AUDIT FIX] - updated total delegations in confirm delegation
sampocs Jun 20, 2024
c3ffbf6
Merge branch 'main' into v23
sampocs Jun 20, 2024
25ed61b
[AUDIT FIX] migrate halted field, remove prepare delegation, clarifyi…
sampocs Jun 29, 2024
66041f3
[AUDIT FIX] decrement total delegations in adjust delegated balance
sampocs Jul 9, 2024
82a007b
[AUDIT FIX] enable stakeibc redemptions with if exact remaining amoun…
sampocs Jul 9, 2024
7e4a9a9
[AUDIT FIX] set delegation/undelegationTxsInProgress in migration
sampocs Jul 10, 2024
07d8a83
reset delegation txs in progress to 0 in restore-ica
sampocs Jul 18, 2024
639777d
addressed riley and vishal pr comments
sampocs Jul 26, 2024
38555eb
updated package from v22 -> v23
sampocs Jul 26, 2024
81f7cc9
generated protos
sampocs Jul 26, 2024
68deb54
moved upgrade to v24
sampocs Jul 26, 2024
8fdf6c6
removed trade route migration from v24 upgrade
sampocs Jul 26, 2024
d35a8e8
Merge branch 'main' into v23
sampocs Jul 26, 2024
72b9b41
fixed unit tests
sampocs Jul 26, 2024
13288dd
copied over the redemption rate update functions into staketia migration
sampocs Jul 26, 2024
ec24683
fixed build errors and updated RR functions
sampocs Jul 26, 2024
046f992
added invariant from RR change
sampocs Jul 26, 2024
5c79959
removed debug logs
sampocs Jul 26, 2024
07f1411
fixed unit test
sampocs Jul 26, 2024
c9b390d
nit
sampocs Jul 26, 2024
059843d
moved up RR invariant check and removed balance check
sampocs Aug 6, 2024
a57552d
nit, used GetActiveHostZone and moved epoch tracker
sampocs Aug 6, 2024
f5574b1
fixed unit tests
sampocs Aug 6, 2024
19e3617
nit: fixed comment typo in icacallbacks_undelegate.go
sampocs Aug 7, 2024
b58fea0
Merge branch 'main' into v23
assafmo Aug 8, 2024
afa4bfb
Merge branch 'main' into v23
sampocs Aug 16, 2024
308de94
reverted all stTIA migration changes
sampocs Aug 16, 2024
79a0028
removed net new files from sttia
sampocs Aug 16, 2024
6d39b4e
removed staketia migration call from upgrade handler
sampocs Aug 16, 2024
3db83e2
added full upgrade handler test
sampocs Aug 16, 2024
3a3745f
moved redemption sweep to stride epoch (#1265)
sampocs Aug 16, 2024
c176fe6
fixed unit tests
sampocs Aug 23, 2024
af9debb
fixed lint errors in claim/utils/icacallbacks/mint/icaoracle/intercha…
sampocs Aug 23, 2024
ad10e1e
fixed lint errors in icacallbacks
sampocs Aug 23, 2024
a0ef012
fixed lint errors in the rest of stakeibc
sampocs Aug 23, 2024
c3642aa
fixed lint errors in upgrades, autopilot, icacallbacks, and mint
sampocs Aug 26, 2024
90d4085
addressed riley pr comments
sampocs Aug 27, 2024
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/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s *AppTestHelper) Setup() {
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
}
s.TestAccs = CreateRandomAccounts(3)
s.TestAccs = CreateRandomAccounts(4)
s.IbcEnabled = false
s.IcaAddresses = make(map[string]string)

Expand Down
13 changes: 13 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
v21 "github.com/Stride-Labs/stride/v23/app/upgrades/v21"
v22 "github.com/Stride-Labs/stride/v23/app/upgrades/v22"
v23 "github.com/Stride-Labs/stride/v23/app/upgrades/v23"
v24 "github.com/Stride-Labs/stride/v23/app/upgrades/v24"
v3 "github.com/Stride-Labs/stride/v23/app/upgrades/v3"
v4 "github.com/Stride-Labs/stride/v23/app/upgrades/v4"
v5 "github.com/Stride-Labs/stride/v23/app/upgrades/v5"
Expand Down Expand Up @@ -311,6 +312,18 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
),
)

// v24 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v24.UpgradeName,
v24.CreateUpgradeHandler(
app.mm,
app.configurator,
app.BankKeeper,
app.RecordsKeeper,
app.StakeibcKeeper,
),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err))
Expand Down
8 changes: 4 additions & 4 deletions app/upgrades/v10/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ func (s *UpgradeTestSuite) TestMigrateCallbackData() {
}
initialUndelegateCallbackArgs := stakeibctypes.UndelegateCallback{
HostZoneId: "host-0",
SplitDelegations: []*types.SplitDelegation{{
Validator: "val-0",
Amount: sdkmath.NewInt(1),
}},
// SplitDelegations: []*types.SplitDelegation{{
// Validator: "val-0",
// Amount: sdkmath.NewInt(1),
// }},
}
initialTransferCallbackArgs := recordstypes.TransferCallback{
DepositRecordId: 1,
Expand Down
119 changes: 119 additions & 0 deletions app/upgrades/v24/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package v24

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

recordskeeper "github.com/Stride-Labs/stride/v23/x/records/keeper"
recordstypes "github.com/Stride-Labs/stride/v23/x/records/types"
stakeibckeeper "github.com/Stride-Labs/stride/v23/x/stakeibc/keeper"
)

var (
UpgradeName = "v24"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v23
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bankKeeper bankkeeper.Keeper,
recordsKeeper recordskeeper.Keeper,
stakeibcKeeper stakeibckeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v24...")

// Migrate data structures
MigrateHostZones(ctx, stakeibcKeeper)
MigrateDepositRecords(ctx, recordsKeeper)
MigrateEpochUnbondingRecords(ctx, recordsKeeper)

ctx.Logger().Info("Running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
}

// Migrate host zones to accomodate the staketia migration changes, adding a
// redemptions enabled field to each host zone
func MigrateHostZones(ctx sdk.Context, k stakeibckeeper.Keeper) {
ctx.Logger().Info("Migrating host zones...")

for _, hostZone := range k.GetAllHostZone(ctx) {
hostZone.RedemptionsEnabled = true
k.SetHostZone(ctx, hostZone)
}
}

// Migrates the deposit records to set the DelegationTxsInProgress field
// which should be 1 if the status was DELEGATION_IN_PROGRESS, and 0 otherwise
func MigrateDepositRecords(ctx sdk.Context, k recordskeeper.Keeper) {
ctx.Logger().Info("Migrating deposit records...")

for _, depositRecord := range k.GetAllDepositRecord(ctx) {
if depositRecord.Status == recordstypes.DepositRecord_DELEGATION_IN_PROGRESS {
depositRecord.DelegationTxsInProgress = 1
} else {
depositRecord.DelegationTxsInProgress = 0
}
k.SetDepositRecord(ctx, depositRecord)
}
}

// Migrates a single host zone unbonding record to add the new fields: StTokensToBurn,
// NativeTokensToUnbond, and ClaimableNativeTokens
//
// If the record is in status: UNBONDING_QUEUE, EXIT_TRANSFER_QUEUE, or EXIT_TRANSFER_IN_PROGRESS,
// set stTokensToBurn, NativeTokensToUnbond, and ClaimableNativeTokens all to 0
//
// If the record is in status: UNBONDING_IN_PROGRESS
// set StTokensToBurn to the value of StTokenAmount, NativeTokensToUnbond to the value of NativeTokenAmount,
// and ClaimableNativeTokens to 0
//
// If the record is in status CLAIMABLE,
// set StTokensToBurn and NativeTokensToUnbond to 0, and set ClaimableNativeTokens to the value of NativeTokenAmount
//
// If the record is in status UNBONDING_IN_PROGRESS, we need to also set UndelegationTxsInProgress to 1;
// otherwise, it should be set to 0
func MigrateHostZoneUnbondingRecords(hostZoneUnbonding *recordstypes.HostZoneUnbonding) *recordstypes.HostZoneUnbonding {
if hostZoneUnbonding.Status == recordstypes.HostZoneUnbonding_UNBONDING_QUEUE ||
hostZoneUnbonding.Status == recordstypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE ||
hostZoneUnbonding.Status == recordstypes.HostZoneUnbonding_EXIT_TRANSFER_IN_PROGRESS {

hostZoneUnbonding.StTokensToBurn = sdkmath.ZeroInt()
hostZoneUnbonding.NativeTokensToUnbond = sdkmath.ZeroInt()
hostZoneUnbonding.ClaimableNativeTokens = sdkmath.ZeroInt()
hostZoneUnbonding.UndelegationTxsInProgress = 0

} else if hostZoneUnbonding.Status == recordstypes.HostZoneUnbonding_UNBONDING_IN_PROGRESS {
hostZoneUnbonding.StTokensToBurn = hostZoneUnbonding.StTokenAmount
hostZoneUnbonding.NativeTokensToUnbond = hostZoneUnbonding.NativeTokenAmount
hostZoneUnbonding.ClaimableNativeTokens = sdkmath.ZeroInt()
hostZoneUnbonding.UndelegationTxsInProgress = 1

} else if hostZoneUnbonding.Status == recordstypes.HostZoneUnbonding_CLAIMABLE {
hostZoneUnbonding.StTokensToBurn = sdkmath.ZeroInt()
hostZoneUnbonding.NativeTokensToUnbond = sdkmath.ZeroInt()
hostZoneUnbonding.ClaimableNativeTokens = hostZoneUnbonding.NativeTokenAmount
hostZoneUnbonding.UndelegationTxsInProgress = 0
}

return hostZoneUnbonding
}

// Migrate epoch unbonding records to accomodate the batched undelegations code changes,
// adding the new accounting fields to the host zone unbonding records
func MigrateEpochUnbondingRecords(ctx sdk.Context, k recordskeeper.Keeper) {
ctx.Logger().Info("Migrating epoch unbonding records...")

for _, epochUnbondingRecord := range k.GetAllEpochUnbondingRecord(ctx) {
for i, oldHostZoneUnbondingRecord := range epochUnbondingRecord.HostZoneUnbondings {
updatedHostZoneUnbondingRecord := MigrateHostZoneUnbondingRecords(oldHostZoneUnbondingRecord)
epochUnbondingRecord.HostZoneUnbondings[i] = updatedHostZoneUnbondingRecord
}
k.SetEpochUnbondingRecord(ctx, epochUnbondingRecord)
}
}
Loading