Skip to content

Commit

Permalink
Merge pull request #195 from joeabbey/quid-est-veritas
Browse files Browse the repository at this point in the history
Veritas
  • Loading branch information
joeabbey authored May 4, 2022
2 parents 83f7935 + 0b9ce40 commit bd0a4b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 341 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

unity "github.com/CosmosContracts/juno/app/upgrade"
veritas "github.com/CosmosContracts/juno/app/upgrade"
"github.com/CosmosContracts/juno/docs"
"github.com/CosmosContracts/juno/x/mint"
mintkeeper "github.com/CosmosContracts/juno/x/mint/keeper"
Expand Down Expand Up @@ -756,7 +756,7 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
// RegisterUpgradeHandlers returns upgrade handlers
func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
bankBaseKeeper, _ := app.BankKeeper.(bankkeeper.BaseKeeper)
app.UpgradeKeeper.SetUpgradeHandler(unity.UpgradeName, unity.CreateUpgradeHandler(app.mm, cfg, &app.StakingKeeper, &bankBaseKeeper))
app.UpgradeKeeper.SetUpgradeHandler(veritas.UpgradeName, veritas.CreateUpgradeHandler(app.mm, cfg, &app.StakingKeeper, &bankBaseKeeper))
}

// GetMaccPerms returns a copy of the module account permissions
Expand Down
4 changes: 2 additions & 2 deletions app/upgrade/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unity
package veritas

// UpgradeName is upgrade name in proposal
const UpgradeName = "unity"
const UpgradeName = "veritas"
110 changes: 12 additions & 98 deletions app/upgrade/upgrade_handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unity
package veritas

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -9,113 +9,27 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
)

// Address of the account which will have all juno sent to the unity proposal
var addressesToBeAdjusted = []string{
"juno1aeh8gqu9wr4u8ev6edlgfq03rcy6v5twfn0ja8",
}

// UnityContractByteAddress is the bytes of the public key for the address of the Unity contract
// $ junod keys parse juno1nz96hjc926e6a74gyvkwvtt0qhu22wx049c6ph6f4q8kp3ffm9xq5938mr
// human: juno
// bytes: 5BEF9E5318ED6716A11179C70B06656E9FB91D241A1C594F344B325D9110D94C
const UnityContractByteAddress = "5BEF9E5318ED6716A11179C70B06656E9FB91D241A1C594F344B325D9110D94C"

// ClawbackCoinFromAccount undelegate all amount in adjusted address (bypass 28 day unbonding), and send it to dead address
func ClawbackCoinFromAccount(ctx sdk.Context, accAddr sdk.AccAddress, staking *stakingkeeper.Keeper, bank *bankkeeper.BaseKeeper) {
bondDenom := staking.BondDenom(ctx)

now := ctx.BlockHeader().Time

// this loop will complete all delegator's active redelegations
for _, activeRedelegation := range staking.GetRedelegations(ctx, accAddr, 65535) {
// src/dest validator addresses of this redelegation
redelegationSrc, _ := sdk.ValAddressFromBech32(activeRedelegation.ValidatorSrcAddress)
redelegationDst, _ := sdk.ValAddressFromBech32(activeRedelegation.ValidatorDstAddress)

// set all entry completionTime to now so we can complete redelegation
for i := range activeRedelegation.Entries {
activeRedelegation.Entries[i].CompletionTime = now
}

staking.SetRedelegation(ctx, activeRedelegation)
_, err := staking.CompleteRedelegation(ctx, accAddr, redelegationSrc, redelegationDst)
if err != nil {
panic(err)
}
}

// this loop will turn all delegator's delegations into unbonding delegations
for _, delegation := range staking.GetAllDelegatorDelegations(ctx, accAddr) {
validatorValAddr := delegation.GetValidatorAddr()
_, found := staking.GetValidator(ctx, validatorValAddr)
if !found {
continue
}
_, err := staking.Undelegate(ctx, accAddr, validatorValAddr, delegation.GetShares()) //nolint:errcheck // nolint because otherwise we'd have a time and nothing to do with it.
if err != nil {
panic(err)
}
}

// this loop will complete all delegator's unbonding delegations
for _, unbondingDelegation := range staking.GetAllUnbondingDelegations(ctx, accAddr) {
// validator address of this unbonding delegation
validatorStringAddr := unbondingDelegation.ValidatorAddress
validatorValAddr, _ := sdk.ValAddressFromBech32(validatorStringAddr)

// set all entry completionTime to now so we can complete unbonding delegation
for i := range unbondingDelegation.Entries {
unbondingDelegation.Entries[i].CompletionTime = now
}
staking.SetUnbondingDelegation(ctx, unbondingDelegation)
_, err := staking.CompleteUnbonding(ctx, accAddr, validatorValAddr)
if err != nil {
panic(err)
}
}

// account balance after finishing unbonding
accCoin := bank.GetBalance(ctx, accAddr, bondDenom)
// bytes: 988BABCB0556B3AEFAA8232CE62D6F05F8A538CFA971A0DF49A80F60C529D94C
const UnityContractByteAddress = "988BABCB0556B3AEFAA8232CE62D6F05F8A538CFA971A0DF49A80F60C529D94C"

// get Unity Contract Address and send coin to this address
destAcc, _ := sdk.AccAddressFromHex(UnityContractByteAddress)
err := bank.SendCoins(ctx, accAddr, destAcc, sdk.NewCoins(accCoin))
if err != nil {
panic(err)
}
}
const UnityContractPlaceHolderAddress = "5BEF9E5318ED6716A11179C70B06656E9FB91D241A1C594F344B325D9110D94C"

// CreateUpgradeHandler make upgrade handler
func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, staking *stakingkeeper.Keeper, bank *bankkeeper.BaseKeeper) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
for _, addrString := range addressesToBeAdjusted {
accAddr, _ := sdk.AccAddressFromBech32(addrString)
ClawbackCoinFromAccount(ctx, accAddr, staking, bank)
}
// force an update of validator min commission
// we already did this for moneta
// but validators could have snuck in changes in the
// interim
// and via state sync to post-moneta
validators := staking.GetAllValidators(ctx)
// hard code this because we don't want
// a) a fork or
// b) immediate reaction with additional gov props
minCommissionRate := sdk.NewDecWithPrec(5, 2)
for _, v := range validators {
if v.Commission.Rate.LT(minCommissionRate) {
if v.Commission.MaxRate.LT(minCommissionRate) {
v.Commission.MaxRate = minCommissionRate
}

v.Commission.Rate = minCommissionRate
v.Commission.UpdateTime = ctx.BlockHeader().Time
bondDenom := staking.BondDenom(ctx)

// call the before-modification hook since we're about to update the commission
staking.BeforeValidatorModified(ctx, v.GetOperator())
accAddr, _ := sdk.AccAddressFromBech32(UnityContractPlaceHolderAddress)
accCoin := bank.GetBalance(ctx, accAddr, bondDenom)

staking.SetValidator(ctx, v)
}
// get Unity Contract Address and send coin to this address
destAcc, _ := sdk.AccAddressFromHex(UnityContractByteAddress)
err := bank.SendCoins(ctx, accAddr, destAcc, sdk.NewCoins(accCoin))
if err != nil {
panic(err)
}

// Set wasm old version to 1 if we want to call wasm's InitGenesis ourselves
Expand Down
239 changes: 0 additions & 239 deletions app/upgrade/upgrade_test.go

This file was deleted.

0 comments on commit bd0a4b1

Please sign in to comment.