-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: execute
PreBlocker
for upgrade module (#707)
- Loading branch information
1 parent
72c7d4e
commit f2e9bd8
Showing
6 changed files
with
105 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package vanilla | ||
|
||
import ( | ||
"context" | ||
|
||
store "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/babylonchain/babylon/app/keepers" | ||
"github.com/babylonchain/babylon/app/upgrades" | ||
bbn "github.com/babylonchain/babylon/types" | ||
btcstakingkeeper "github.com/babylonchain/babylon/x/btcstaking/keeper" | ||
bstypes "github.com/babylonchain/babylon/x/btcstaking/types" | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: "vanilla", | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: store.StoreUpgrades{}, | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
cfg module.Configurator, | ||
_ upgrades.BaseAppParamManager, | ||
keepers *keepers.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
|
||
ctx := sdk.UnwrapSDKContext(context) | ||
|
||
propVanilla(ctx, &keepers.AccountKeeper, &keepers.BTCStakingKeeper) | ||
|
||
return mm.RunMigrations(ctx, cfg, fromVM) | ||
} | ||
} | ||
|
||
func propVanilla( | ||
ctx sdk.Context, | ||
accountKeeper *authkeeper.AccountKeeper, | ||
bsKeeper *btcstakingkeeper.Keeper, | ||
) { | ||
// remove an account | ||
allAccounts := accountKeeper.GetAllAccounts(ctx) | ||
accountKeeper.RemoveAccount(ctx, allAccounts[len(allAccounts)-1]) | ||
|
||
// insert a FP | ||
sk, err := btcec.NewPrivateKey() | ||
if err != nil { | ||
panic(err) | ||
} | ||
btcPK := bbn.NewBIP340PubKeyFromBTCPK(sk.PubKey()) | ||
fp := &bstypes.FinalityProvider{ | ||
Addr: allAccounts[0].GetAddress().String(), | ||
BtcPk: btcPK, | ||
} | ||
bsKeeper.SetFinalityProvider(ctx, fp) | ||
} |
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