Skip to content

Commit

Permalink
Revert "feat: CNS-945-remove-frozen-from-epochstorage (lavanet#1397)" (
Browse files Browse the repository at this point in the history
…lavanet#1399)

This reverts commit 6a97f43.
  • Loading branch information
Yaroms authored May 1, 2024
1 parent 501d7da commit f5250a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
18 changes: 9 additions & 9 deletions x/dualstaking/keeper/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,14 @@ func TestDualstakingUnbondStakeIsLowerThanMinStakeCausesFreeze(t *testing.T) {
_, err := ts.TxDualstakingUnbond(provider1Addr, provider1Addr, ts.spec.Name, amountToUnbond)
require.NoError(t, err)

stakeEntry := ts.getStakeEntryCurrent(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, staked.Sub(amountToUnbond).IsEqual(stakeEntry.Stake))
stakeEntry := ts.getStakeEntry(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, staked.IsEqual(stakeEntry.Stake))

// advance epoch to digest the delegate
ts.AdvanceEpoch()
// now in effect
staked = staked.Sub(staked.Sub(minSelfDelegation.AddAmount(math.OneInt())))
stakeEntry = ts.getStakeEntryCurrent(provider1Acct.Addr.String(), ts.spec.Name)
stakeEntry = ts.getStakeEntry(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, staked.IsEqual(stakeEntry.Stake))
require.True(t, stakeEntry.IsFrozen())
}
Expand Down Expand Up @@ -617,11 +617,11 @@ func TestDualstakingRedelegateFreezeOneUnFreezeOther(t *testing.T) {
ts.AdvanceEpoch()
// now in effect

stakeEntry := ts.getStakeEntryCurrent(provider1Acct.Addr.String(), ts.spec.Name)
stakeEntry := ts.getStakeEntry(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, stakeEntry.Stake.Amount.Equal(amountToUnbond.Amount))
require.True(t, stakeEntry.IsFrozen())

stakeEntry = ts.getStakeEntryCurrent(provider2Acct.Addr.String(), ts.spec.Name)
stakeEntry = ts.getStakeEntry(provider2Acct.Addr.String(), ts.spec.Name)
require.True(t, stake.IsEqual(stakeEntry.Stake))
require.True(t, stakeEntry.DelegateTotal.IsEqual(stake.SubAmount(amountToUnbond.Amount)))
require.False(t, stakeEntry.IsFrozen())
Expand All @@ -634,12 +634,12 @@ func TestDualstakingRedelegateFreezeOneUnFreezeOther(t *testing.T) {
ts.AdvanceEpoch()
// now in effect

stakeEntry = ts.getStakeEntryCurrent(provider1Acct.Addr.String(), ts.spec.Name)
stakeEntry = ts.getStakeEntry(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, stakeEntry.Stake.Amount.Equal(amountToUnbond.Amount))
require.True(t, stakeEntry.DelegateTotal.IsEqual(stake.SubAmount(amountToUnbond.Amount)))
require.True(t, stakeEntry.IsFrozen())

stakeEntry = ts.getStakeEntryCurrent(provider2Acct.Addr.String(), ts.spec.Name)
stakeEntry = ts.getStakeEntry(provider2Acct.Addr.String(), ts.spec.Name)
require.True(t, stakeEntry.Stake.Amount.Equal(amountToUnbond.Amount))
require.True(t, stakeEntry.DelegateTotal.IsEqual(stake.SubAmount(amountToUnbond.Amount)))
require.True(t, stakeEntry.IsFrozen())
Expand All @@ -657,7 +657,7 @@ func TestStakingUnbondStakeIsLowerThanMinStakeCausesFreeze(t *testing.T) {
stakeInt := sdk.NewInt(testStake)
stake := sdk.NewCoin("ulava", stakeInt)

stakeEntry := ts.getStakeEntryCurrent(provider1Acct.Addr.String(), ts.spec.Name)
stakeEntry := ts.getStakeEntry(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, stake.IsEqual(stakeEntry.Stake))
require.False(t, stakeEntry.IsFrozen())

Expand All @@ -671,7 +671,7 @@ func TestStakingUnbondStakeIsLowerThanMinStakeCausesFreeze(t *testing.T) {
ts.AdvanceEpoch()
// now in effect

stakeEntry = ts.getStakeEntryCurrent(provider1Acct.Addr.String(), ts.spec.Name)
stakeEntry = ts.getStakeEntry(provider1Acct.Addr.String(), ts.spec.Name)
require.True(t, stakeEntry.Stake.Amount.Equal(amountToUnbond.Amount))
require.True(t, stakeEntry.IsFrozen())
}
10 changes: 8 additions & 2 deletions x/dualstaking/keeper/delegator_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,15 @@ func (k Keeper) ClaimRewards(ctx sdk.Context, delegator string, provider string)
// RewardProvidersAndDelegators is the main function handling provider rewards with delegations
// it returns the provider reward amount and updates the delegatorReward map with the reward portion for each delegator
func (k Keeper) RewardProvidersAndDelegators(ctx sdk.Context, provider string, chainID string, totalReward sdk.Coins, senderModule string, calcOnlyProvider bool, calcOnlyDelegators bool, calcOnlyContributer bool) (providerReward sdk.Coins, claimableRewards sdk.Coins, err error) {
block := uint64(ctx.BlockHeight())
zeroCoins := sdk.NewCoins()
epoch := k.epochstorageKeeper.GetCurrentNextEpoch(ctx)
stakeEntry, found := k.epochstorageKeeper.GetStakeEntryByAddressCurrent(ctx, chainID, provider)
epoch, _, err := k.epochstorageKeeper.GetEpochStartForBlock(ctx, block)
if err != nil {
return zeroCoins, zeroCoins, utils.LavaFormatError(types.ErrCalculatingProviderReward.Error(), err,
utils.Attribute{Key: "block", Value: block},
)
}
stakeEntry, found := k.epochstorageKeeper.GetStakeEntryForProviderEpoch(ctx, chainID, provider, epoch)
if !found {
return zeroCoins, zeroCoins, err
}
Expand Down
12 changes: 0 additions & 12 deletions x/dualstaking/keeper/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ func (ts *tester) getStakeEntry(provider string, chainID string) epochstoragetyp
return stakeEntry
}

// getStakeEntry find the stake entry of a given provider + chainID
func (ts *tester) getStakeEntryCurrent(provider string, chainID string) epochstoragetypes.StakeEntry {
keeper := ts.Keepers.Epochstorage

stakeEntry, found := keeper.GetStakeEntryByAddressCurrent(ts.Ctx, chainID, provider)
if !found {
panic("getStakeEntry: no stake entry: " + provider + " " + chainID)
}

return stakeEntry
}

func (ts *tester) verifyDelegatorsBalance() {
accounts := ts.AccountsMap()
for key, account := range accounts {
Expand Down
4 changes: 0 additions & 4 deletions x/epochstorage/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ func (stksto StakeStorage) Copy() (returnedStorage StakeStorage) {
}

for _, stakeEntry := range stksto.StakeEntries {
if stakeEntry.IsFrozen() {
continue
}

newStakeEntry := stakeEntry

endpoints := make([]Endpoint, len(stakeEntry.Endpoints))
Expand Down

0 comments on commit f5250a8

Please sign in to comment.