diff --git a/app/ante.go b/app/ante.go index c3b81efdbe..362d4af8af 100644 --- a/app/ante.go +++ b/app/ante.go @@ -5,9 +5,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + dualstakingante "github.com/lavanet/lava/x/dualstaking/ante" + dualstakingkeeper "github.com/lavanet/lava/x/dualstaking/keeper" ) -func NewAnteHandler(accountKeeper ante.AccountKeeper, bankKeeper authtypes.BankKeeper, signModeHandler signing.SignModeHandler, feegrantKeeper ante.FeegrantKeeper, sigGasConsumer ante.SignatureVerificationGasConsumer) sdk.AnteHandler { +func NewAnteHandler(accountKeeper ante.AccountKeeper, bankKeeper authtypes.BankKeeper, dualstakingKeeper dualstakingkeeper.Keeper, signModeHandler signing.SignModeHandler, feegrantKeeper ante.FeegrantKeeper, sigGasConsumer ante.SignatureVerificationGasConsumer) sdk.AnteHandler { anteDecorators := []sdk.AnteDecorator{ ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first ante.NewExtensionOptionsDecorator(nil), @@ -21,6 +23,7 @@ func NewAnteHandler(accountKeeper ante.AccountKeeper, bankKeeper authtypes.BankK ante.NewSigGasConsumeDecorator(accountKeeper, sigGasConsumer), ante.NewSigVerificationDecorator(accountKeeper, signModeHandler), ante.NewIncrementSequenceDecorator(accountKeeper), + dualstakingante.NewRedelegationFlager(dualstakingKeeper), } return sdk.ChainAnteDecorators(anteDecorators...) } diff --git a/app/app.go b/app/app.go index 8c53a1881e..10c0649170 100644 --- a/app/app.go +++ b/app/app.go @@ -162,6 +162,7 @@ var Upgrades = []upgrades.Upgrade{ upgrades.Upgrade_0_30_1, upgrades.Upgrade_0_30_2, upgrades.Upgrade_0_31_0, + upgrades.Upgrade_0_31_1, } // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals @@ -801,6 +802,7 @@ func New( NewAnteHandler( app.AccountKeeper, app.BankKeeper, + app.DualstakingKeeper, encodingConfig.TxConfig.SignModeHandler(), app.FeeGrantKeeper, ante.DefaultSigVerificationGasConsumer), diff --git a/app/upgrades/empty_upgrades.go b/app/upgrades/empty_upgrades.go index b2cea62038..da2d702f8c 100644 --- a/app/upgrades/empty_upgrades.go +++ b/app/upgrades/empty_upgrades.go @@ -164,3 +164,9 @@ var Upgrade_0_31_0 = Upgrade{ CreateUpgradeHandler: defaultUpgradeHandler, StoreUpgrades: store.StoreUpgrades{}, } + +var Upgrade_0_31_1 = Upgrade{ + UpgradeName: "v0.31.1", + CreateUpgradeHandler: defaultUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/scripts/add_validator.sh b/scripts/add_validator.sh new file mode 100644 index 0000000000..a53986307f --- /dev/null +++ b/scripts/add_validator.sh @@ -0,0 +1,21 @@ +# this script is adding another validator to the chain (without a running node) (this validator will be soon jailed due to inactivity) +clear +rm -rf ~/.lava_test +lavad init validator2 --chain-id lava --home ~/.lava_test +lavad config broadcast-mode sync --home ~/.lava_test +lavad config keyring-backend test --home ~/.lava_test +lavad keys add validator2 --home ~/.lava_test + +GASPRICE="0.000000001ulava" +lavad tx bank send $(lavad keys show alice -a) $(lavad keys show validator2 -a --home ~/.lava_test) 500000ulava -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE + +lavad tx staking create-validator -y --from validator2 --amount="50000ulava" --pubkey=$(lavad tendermint show-validator --home ~/.lava_test) --commission-rate="0.10" \ + --commission-max-rate="0.20" \ + --commission-max-change-rate="0.01" \ + --min-self-delegation="1000" \ + --gas-adjustment "1.5" \ + --gas "auto" \ + --gas-prices $GASPRICE \ + --home ~/.lava_test + +lavad tx staking redelegate lava@valoper1yhzkfrcdwf2hwpc4cre8er5tamp6wdm4stx2ec lava@valoper1z025w20ms6cpdht585nhsw682jph4yc7hx0gqc 500000000000ulava -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE diff --git a/x/dualstaking/ante/ante_handler.go b/x/dualstaking/ante/ante_handler.go new file mode 100644 index 0000000000..9ff59686c4 --- /dev/null +++ b/x/dualstaking/ante/ante_handler.go @@ -0,0 +1,40 @@ +package ante + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/lavanet/lava/x/dualstaking/keeper" +) + +// RedelegationFlager sets the dualstaking redelegation flag when needed. +// when the user sends redelegation tx we dont want the hooks to do anything +type RedelegationFlager struct { + keeper.Keeper +} + +func NewRedelegationFlager(dualstaking keeper.Keeper) RedelegationFlager { + return RedelegationFlager{Keeper: dualstaking} +} + +func (rf RedelegationFlager) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { + redelegations := false + others := false + for _, msg := range tx.GetMsgs() { + if _, ok := msg.(*stakingtypes.MsgBeginRedelegate); ok { + redelegations = true + } else { + others = true + } + } + + if redelegations && others { + return ctx, fmt.Errorf("cannot send batch requests with redelegation messages") + } + + keeper.DisableDualstakingHook = redelegations + + return next(ctx, tx, simulate) +} diff --git a/x/dualstaking/keeper/hooks.go b/x/dualstaking/keeper/hooks.go index 1fd8251741..72b77c6a9c 100644 --- a/x/dualstaking/keeper/hooks.go +++ b/x/dualstaking/keeper/hooks.go @@ -46,6 +46,10 @@ func (h Hooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAd // create new delegation period record // add description func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { + if DisableDualstakingHook { + return nil + } + diff, err := h.k.VerifyDelegatorBalance(ctx, delAddr) if err != nil { return err @@ -138,6 +142,10 @@ func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ } func (h Hooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { + if DisableDualstakingHook { + return nil + } + delegation, found := h.k.stakingKeeper.GetDelegation(ctx, delAddr, valAddr) if !found { return fmt.Errorf("could not find delegation for dualstaking hook") diff --git a/x/dualstaking/keeper/keeper.go b/x/dualstaking/keeper/keeper.go index a6fabb47c8..5c32a98a93 100644 --- a/x/dualstaking/keeper/keeper.go +++ b/x/dualstaking/keeper/keeper.go @@ -14,6 +14,11 @@ import ( "github.com/lavanet/lava/x/dualstaking/types" ) +// DisableDualstakingHook : dualstaking uses hookd to catch delegations/unbonding tx's to do the same action on the providers delegations. +// in the case of redelegation, since the user doesnt put/takes tokens back we dont want to take action in the providers delegations. +// this flag is a local flag used to mark the next hooks to do nothing since this was cause by redelegation tx (redelegation = delegation + unbond) +var DisableDualstakingHook bool + type ( Keeper struct { cdc codec.BinaryCodec diff --git a/x/protocol/module.go b/x/protocol/module.go index f0cd7584f2..5dbd3fcd4e 100644 --- a/x/protocol/module.go +++ b/x/protocol/module.go @@ -192,10 +192,15 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // panic:ok: at start up, migration cannot proceed anyhow panic(fmt.Errorf("%s: failed to register migration to v14: %w", types.ModuleName, err)) } + + if err := cfg.RegisterMigration(types.ModuleName, 14, migrator.MigrateVersion); err != nil { + // panic:ok: at start up, migration cannot proceed anyhow + panic(fmt.Errorf("%s: failed to register migration to v15: %w", types.ModuleName, err)) + } } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 14 } +func (AppModule) ConsensusVersion() uint64 { return 15 } // RegisterInvariants registers the capability module's invariants. func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} diff --git a/x/protocol/types/params.go b/x/protocol/types/params.go index 8d56bb76bc..cf99c326c8 100644 --- a/x/protocol/types/params.go +++ b/x/protocol/types/params.go @@ -12,7 +12,7 @@ import ( var _ paramtypes.ParamSet = (*Params)(nil) const ( - TARGET_VERSION = "0.31.0" + TARGET_VERSION = "0.31.1" MIN_VERSION = "0.30.1" )