diff --git a/x/staketia/keeper/msg_server.go b/x/staketia/keeper/msg_server.go index a68c3897e6..c7f3fa8c05 100644 --- a/x/staketia/keeper/msg_server.go +++ b/x/staketia/keeper/msg_server.go @@ -112,6 +112,18 @@ func (k msgServer) AdjustDelegatedBalance(goCtx context.Context, msg *types.MsgA } k.SetHostZone(ctx, hostZone) + // Repeat the same thing on the stakeibc host zone + stakeibcHostZone, found := k.stakeibcKeeper.GetHostZone(ctx, types.CelestiaChainId) + if !found { + return nil, errors.New("celestia host zone not found in stakeibc") + } + stakeibcHostZone.TotalDelegations = stakeibcHostZone.TotalDelegations.Add(msg.DelegationOffset) + + if stakeibcHostZone.TotalDelegations.IsNegative() { + return nil, types.ErrNegativeNotAllowed.Wrapf("offset would cause the delegated balance to be negative") + } + k.stakeibcKeeper.SetHostZone(ctx, stakeibcHostZone) + // create a corresponding slash record latestSlashRecordId := k.IncrementSlashRecordId(ctx) slashRecord := types.SlashRecord{ diff --git a/x/staketia/keeper/msg_server_test.go b/x/staketia/keeper/msg_server_test.go index 2a7c380a3f..332d637e75 100644 --- a/x/staketia/keeper/msg_server_test.go +++ b/x/staketia/keeper/msg_server_test.go @@ -4,6 +4,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + stakeibctypes "github.com/Stride-Labs/stride/v22/x/stakeibc/types" "github.com/Stride-Labs/stride/v22/x/staketia/types" ) @@ -156,11 +157,15 @@ func (s *KeeperTestSuite) TestAdjustDelegatedBalance() { safeAddress := "safe" - // Create the host zone + // Create the host zones s.App.StaketiaKeeper.SetHostZone(s.Ctx, types.HostZone{ SafeAddressOnStride: safeAddress, RemainingDelegatedBalance: sdk.NewInt(0), }) + s.App.StakeibcKeeper.SetHostZone(s.Ctx, stakeibctypes.HostZone{ + ChainId: types.CelestiaChainId, + TotalDelegations: sdk.NewInt(0), + }) // we're halting the zone to test that the tx works even when the host zone is halted s.App.StaketiaKeeper.HaltZone(s.Ctx) @@ -187,7 +192,11 @@ func (s *KeeperTestSuite) TestAdjustDelegatedBalance() { s.Require().NoError(err, "no error expected when adjusting delegated bal properly for %s", tc.address) hostZone := s.MustGetHostZone() - s.Require().Equal(tc.endDelegation, hostZone.RemainingDelegatedBalance, "delegation after change for %s", tc.address) + s.Require().Equal(tc.endDelegation, hostZone.RemainingDelegatedBalance, "remaining delegation after change for %s", tc.address) + + stakeibcHostZone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, types.CelestiaChainId) + s.Require().True(found) + s.Require().Equal(tc.endDelegation, stakeibcHostZone.TotalDelegations, "total delegation after change for %s", tc.address) } // Attempt to call it with an amount that would make it negative, it should fail