forked from onomyprotocol/onomy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request onomyprotocol#169 from decentrio/fix
Fix: remove invalid unbonding ids
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package upgrades | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// Fork defines a struct containing the requisite fields for a non-software upgrade proposal | ||
// Hard Fork at a given height to implement. | ||
// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`. | ||
// Any other change in the code should be height-gated, if the goal is to have old and new binaries | ||
// to be compatible prior to the upgrade height. | ||
type Fork struct { | ||
// Upgrade version name, for the upgrade handler, e.g. `v7` | ||
UpgradeName string | ||
// height the upgrade occurs at | ||
UpgradeHeight int64 | ||
|
||
// Function that runs some custom state transition code at the beginning of a fork. | ||
BeginForkLogic func(ctx sdk.Context) | ||
} |
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,10 @@ | ||
package v1_1_5_fix | ||
|
||
const ( | ||
// Name is migration name. | ||
Name = "v1.1.5-fix" | ||
|
||
// UpgradeHeight defines the block height at which the Osmosis v3 upgrade is | ||
// triggered. | ||
UpgradeHeight = 8_928_295 | ||
) |
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,89 @@ | ||
// Package v1_1_5 is contains chain upgrade of the corresponding version. | ||
package v1_1_5_fix //nolint:revive,stylecheck // app version | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" | ||
ibcprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" | ||
ccv "github.com/cosmos/interchain-security/x/ccv/types" | ||
"github.com/onomyprotocol/onomy/app/upgrades" | ||
) | ||
|
||
var targetIds = []uint64{uint64(3372), uint64(3374), uint64(3373)} | ||
|
||
func CreateFork( | ||
sk *stakingkeeper.Keeper, | ||
pk *ibcproviderkeeper.Keeper, | ||
providerStoreKey sdk.StoreKey, | ||
) upgrades.Fork { | ||
forkLogic := func(ctx sdk.Context) { | ||
for _, id := range targetIds { | ||
var consumerChainIDS []string | ||
|
||
for _, chain := range pk.GetAllConsumerChains(ctx) { | ||
consumerChainIDS = append(consumerChainIDS, chain.ChainId) | ||
} | ||
|
||
if len(consumerChainIDS) == 0 { | ||
break | ||
} | ||
// Add to indexes | ||
for _, consumerChainID := range consumerChainIDS { | ||
ubdOpIds := pk.GetAllUnbondingOpIndexes(ctx, consumerChainID) | ||
for _, ubdIds := range ubdOpIds { | ||
newIds := []uint64{} | ||
|
||
for _, ubdId := range ubdIds.UnbondingOpIds { | ||
if ubdId == id { | ||
continue | ||
} | ||
|
||
newIds = append(newIds, ubdId) | ||
} | ||
|
||
// filter out invalid ID | ||
pk.SetUnbondingOpIndex(ctx, consumerChainID, ubdIds.VscId, newIds) | ||
} | ||
} | ||
|
||
// remove ubd entries | ||
_, found := pk.GetUnbondingOp(ctx, id) | ||
if found { | ||
pk.DeleteUnbondingOp(ctx, id) | ||
} | ||
} | ||
|
||
// clear invalid mature ubd entries | ||
ids := []uint64{} | ||
for _, id := range pk.GetMaturedUnbondingOps(ctx) { | ||
if slices.Contains(targetIds, id) { | ||
continue | ||
} | ||
|
||
ids = append(ids, id) | ||
} | ||
|
||
maturedOps := ccv.MaturedUnbondingOps{ | ||
Ids: ids, | ||
} | ||
bz, err := maturedOps.Marshal() | ||
if err != nil { | ||
// An error here would indicate something is very wrong, | ||
// maturedOps is instantiated in this method and should be able to be marshaled. | ||
panic(fmt.Sprintf("failed to marshal matured unbonding operations: %s", err)) | ||
} | ||
|
||
// update mature ubd ids | ||
store := ctx.KVStore(providerStoreKey) | ||
store.Set(ibcprovidertypes.MaturedUnbondingOpsKey(), bz) | ||
} | ||
return upgrades.Fork{ | ||
UpgradeName: Name, | ||
UpgradeHeight: UpgradeHeight, | ||
BeginForkLogic: forkLogic, | ||
} | ||
} |