Skip to content

Commit

Permalink
feat: improved schema for finalized bundles query (#104)
Browse files Browse the repository at this point in the history
(cherry picked from commit cf4857f)

# Conflicts:
#	CHANGELOG.md
#	app/upgrades/v1_3/upgrade.go
#	proto/kyve/bundles/v1beta1/bundles.proto
#	x/bundles/types/bundles.pb.go
#	x/bundles/types/keys.go
  • Loading branch information
mbreithecker authored and mergify[bot] committed Jul 10, 2023
1 parent 2f2bbdd commit 1574c0d
Show file tree
Hide file tree
Showing 16 changed files with 3,249 additions and 1,255 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@

## [Unreleased]

<<<<<<< HEAD
=======
### Features

- (ibc) [#30](https://github.com/KYVENetwork/chain/pull/30) Integrate [Packet Forward Middleware](https://github.com/strangelove-ventures/packet-forward-middleware).
- (`x/bundles`) [#99](https://github.com/KYVENetwork/chain/pull/99) Use weighted round-robin approach for uploader selection.

### Improvements

- (`x/bundles`) [#62](https://github.com/KYVENetwork/chain/pull/62) Payout storage cost directly to the bundle uploader.
- (`x/pool`) [#74](https://github.com/KYVENetwork/chain/pull/74) Improve parameter validation in pool proposals.
- (`x/stakers`) [#46](https://github.com/KYVENetwork/chain/pull/46) Allow protocol validator commission rewards to be claimed.

### Bug Fixes

- [#96](https://github.com/KYVENetwork/chain/pull/96) Track investor delegation inside auth module.

### Client Breaking

- (`x/stakers`) [#46](https://github.com/KYVENetwork/chain/pull/46) Include `MsgClaimCommissionRewards` for claiming commission rewards.
- (`x/bundles`) [#104](https://github.com/KYVENetwork/chain/pull/104) Improve schema for finalized bundles query.

>>>>>>> cf4857f (feat: improved schema for finalized bundles query (#104))
### API Breaking

- (`x/query`) [#87](https://github.com/KYVENetwork/chain/pull/87) Correctly return pools that an account has funded.
Expand Down
74 changes: 74 additions & 0 deletions app/upgrades/v1_3/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package v1_3

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/tendermint/tendermint/libs/log"

// Auth
authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
vestingExported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
// Staking
stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
// Upgrade
upgradeTypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
accountKeeper authKeeper.AccountKeeper,
bankKeeper bankKeeper.Keeper,
stakingKeeper stakingKeeper.Keeper,
) upgradeTypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradeTypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

if ctx.ChainID() == MainnetChainID {
for _, address := range InvestorAccounts {
TrackInvestorDelegation(ctx, logger, sdk.MustAccAddressFromBech32(address), accountKeeper, bankKeeper, stakingKeeper)
}
}

return mm.RunMigrations(ctx, configurator, vm)
}
}

// TrackInvestorDelegation performs a correction of the delegation tracking inside the vesting account.
// The correction is done by performing a full untracking and then tracking the actual total delegated amount
// (including slashed amounts).
func TrackInvestorDelegation(ctx sdk.Context, logger log.Logger, address sdk.AccAddress, ak authKeeper.AccountKeeper, bk bankKeeper.Keeper, sk stakingKeeper.Keeper) {
denom := sk.BondDenom(ctx)
account, _ := ak.GetAccount(ctx, address).(vestingExported.VestingAccount)

// Obtain total delegation of address
totalDelegation := sdk.NewInt(0)
for _, delegation := range sk.GetAllDelegatorDelegations(ctx, address) {
// We take the shares as the total delegation as this is the amount which is
// tracked inside the vesting account. (slashes are ignored, which is correct)
totalDelegation = totalDelegation.Add(delegation.GetShares().TruncateInt())
}

// Fetch current balance.
balanceCoin := bk.GetBalance(ctx, address, denom)

// This is the balance a user would have if all tokens are unbonded (even the ones which got slashed).
maxPossibleBalance := balanceCoin.Amount.Add(totalDelegation)
maxPossibleBalanceCoins := sdk.NewCoins().Add(sdk.NewCoin(denom, maxPossibleBalance))

if totalDelegation.GT(sdk.ZeroInt()) {

// Untrack entire vesting delegation using maximum amount. This will set both `delegated_free`
// and `delegated_vesting` back to zero.
account.TrackUndelegation(sdk.NewCoins(sdk.NewCoin("ukyve", maxPossibleBalance)))

// Track the delegation using the total delegation
account.TrackDelegation(ctx.BlockTime(), maxPossibleBalanceCoins, sdk.NewCoins(sdk.NewCoin("ukyve", totalDelegation)))

logger.Info(fmt.Sprintf("tracked delegation of %s with %s", address.String(), totalDelegation.String()))
ak.SetAccount(ctx, account)
}
}
Loading

0 comments on commit 1574c0d

Please sign in to comment.