Skip to content

Commit

Permalink
Merge branch 'main' into CNS-891-same-provider-conflict-is-disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet authored May 2, 2024
2 parents 266e515 + 7253596 commit 273de69
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 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
11 changes: 10 additions & 1 deletion x/pairing/keeper/pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@ func (k Keeper) getPairingForClient(ctx sdk.Context, chainID string, block uint6
}

if providersType == spectypes.Spec_static {
return stakeEntries, strictestPolicy.EpochCuLimit, nil
frozenFilter := pairingfilters.FrozenProvidersFilter{}
frozenFilter.InitFilter(*strictestPolicy)
filterResults := frozenFilter.Filter(ctx, stakeEntries, epoch)
stakeEntriesFiltered := []epochstoragetypes.StakeEntry{}
for i := 0; i < len(stakeEntries); i++ {
if filterResults[i] {
stakeEntriesFiltered = append(stakeEntriesFiltered, stakeEntries[i])
}
}
return stakeEntriesFiltered, strictestPolicy.EpochCuLimit, nil
}

filters := pairingfilters.GetAllFilters()
Expand Down
5 changes: 5 additions & 0 deletions x/pairing/keeper/pairing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ func TestPairingStatic(t *testing.T) {
require.NoError(t, err)
}

// add one frozen provider
_, addr := ts.AddAccount(common.PROVIDER, int(ts.plan.PlanPolicy.MaxProvidersToPair)*2, testBalance)
err = ts.StakeProvider(addr, ts.spec, ts.spec.MinStakeProvider.Amount.Int64()-1)
require.NoError(t, err)

// we expect to get all the providers in static spec

ts.AdvanceEpoch()
Expand Down

0 comments on commit 273de69

Please sign in to comment.