From d60f802add215f2610d32beebd4b61c2d4bcdadc Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Thu, 10 Oct 2024 15:29:00 +0300 Subject: [PATCH] pr changes --- x/epochstorage/README.md | 1 + x/pairing/README.md | 1 + x/pairing/keeper/delegator_rewards_test.go | 2 +- x/pairing/keeper/single_provider_test.go | 28 +++++++++++++--------- x/pairing/keeper/staking.go | 17 +++++++------ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/x/epochstorage/README.md b/x/epochstorage/README.md index 9c7f399dd0..5a197c3c21 100644 --- a/x/epochstorage/README.md +++ b/x/epochstorage/README.md @@ -162,6 +162,7 @@ The epochstorage module supports the following queries: | `show-fixated-params` | chainid | a specific fixated param | | `list-stake-storage` | chainid | list of all stake storages indices | | `show-stake-storage` | chainid | show a specific stake storage | +| `provider-metadata` | provider-address | shows the metadata of a specific provider, if left empty returns metadata for all providers | ## Transactions diff --git a/x/pairing/README.md b/x/pairing/README.md index c5a231a86f..a89b0eda88 100644 --- a/x/pairing/README.md +++ b/x/pairing/README.md @@ -364,6 +364,7 @@ The pairing module supports the following transactions: | `stake-provider` | chain-id (string), amount (Coin), endpoints ([]Endpoint), geolocation (int32), validator (string, optional), --provider-moniker (string) --grant-provider-gas-fees-auth (bool)| stake a provider in a chain with multiple endpoints | | `unfreeze` | chain-ids ([]string) | unfreeze a provider in multiple chains | | `unstake-provider` | chain-ids ([]string), validator (string, optional) | unstake a provider from multiple chains | +| `move-provider-stake` | src-chain dst-chain amount (Coin)| move provider stake amount from one chain to another | Note, the `Coin` type is from Cosmos-SDK (`cosmos.base.v1beta1.Coin`). From the CLI, use `100ulava` to assign a `Coin` argument. The `Endpoint` type defines a provider endpoint. From the CLI, use "my-provider-grpc-addr.com:9090,1" for one endpoint (includes the endpoint's URL+port and the endpoint's geolocation). When it comes to staking-related transactions, the geolocation argument should encompass the geolocations of all the endpoints combined. diff --git a/x/pairing/keeper/delegator_rewards_test.go b/x/pairing/keeper/delegator_rewards_test.go index 2a62f81ab3..17baf1e5bb 100644 --- a/x/pairing/keeper/delegator_rewards_test.go +++ b/x/pairing/keeper/delegator_rewards_test.go @@ -688,7 +688,7 @@ func TestDelegatorRewardProviderAddingChain(t *testing.T) { ts.AdvanceEpoch() ts.AdvanceBlocks(ts.BlocksToSave() + 1) - // delegator should get half of the payment + // delegator should get third of the payment res, err = ts.QueryDualstakingDelegatorRewards(delegator, provider, "") require.Nil(ts.T, err) require.Equal(ts.T, ts.plan.Price.Amount.QuoRaw(3).AddRaw(1), res.Rewards[0].Amount[0].Amount) diff --git a/x/pairing/keeper/single_provider_test.go b/x/pairing/keeper/single_provider_test.go index a8994aed53..29c33cd6c9 100644 --- a/x/pairing/keeper/single_provider_test.go +++ b/x/pairing/keeper/single_provider_test.go @@ -58,10 +58,10 @@ func TestUnstakeStake(t *testing.T) { ts.AdvanceEpoch() - for i := 0; i < 5; i++ { - res, err := ts.QueryPairingProvider(provider0.Addr.String(), SpecName(i)) - require.NoError(t, err) - require.Equal(t, int64(1000), res.StakeEntries[0].DelegateTotal.Amount.Int64()) + stakeEntries := ts.Keepers.Epochstorage.GetAllStakeEntriesForEpoch(ts.Ctx, ts.EpochStart()) + require.Len(t, stakeEntries, 5) + for _, entry := range stakeEntries { + require.Equal(t, int64(1000), entry.DelegateTotal.Amount.Int64()) } // unstake spec0 provider @@ -110,13 +110,11 @@ func TestUnstakeStake(t *testing.T) { ts.AdvanceEpoch() - res1, err = ts.QueryPairingProvider(provider0.Addr.String(), SpecName(0)) - require.NoError(t, err) - require.Equal(t, int64(2500), res1.StakeEntries[0].DelegateTotal.Amount.Int64()) - - res1, err = ts.QueryPairingProvider(provider0.Addr.String(), SpecName(1)) - require.NoError(t, err) - require.Equal(t, int64(2500), res1.StakeEntries[0].DelegateTotal.Amount.Int64()) + stakeEntries = ts.Keepers.Epochstorage.GetAllStakeEntriesForEpoch(ts.Ctx, ts.EpochStart()) + require.Len(t, stakeEntries, 2) + for _, entry := range stakeEntries { + require.Equal(t, int64(2500), entry.DelegateTotal.Amount.Int64()) + } } // * unstake to see the delegations distributions @@ -152,6 +150,14 @@ func TestUnstakeStakeNewVault(t *testing.T) { for i := 0; i < 5; i++ { _, err = ts.TxPairingUnstakeProvider(provider0.GetVaultAddr(), SpecName(i)) require.NoError(t, err) + + md, err := ts.Keepers.Epochstorage.GetMetadata(ts.Ctx, provider0.Addr.String()) + if i == 4 { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Len(t, md.Chains, 4-i) + } } res, err := ts.QueryDualstakingDelegatorProviders(delegator.Addr.String()) diff --git a/x/pairing/keeper/staking.go b/x/pairing/keeper/staking.go index cd6b4389a7..a2e0850e03 100644 --- a/x/pairing/keeper/staking.go +++ b/x/pairing/keeper/staking.go @@ -261,15 +261,14 @@ func (k Keeper) StakeNewEntry(ctx sdk.Context, validator, creator, chainID strin } stakeEntry := epochstoragetypes.StakeEntry{ - Stake: stakeAmount, - Address: provider, - StakeAppliedBlock: stakeAppliedBlock, - Endpoints: endpointsVerified, - Geolocation: geolocation, - Chain: chainID, - DelegateTotal: sdk.NewCoin(k.stakingKeeper.BondDenom(ctx), delegateTotal), - DelegateCommission: 0, - Vault: creator, // the stake-provider TX creator is always regarded as the vault address + Stake: stakeAmount, + Address: provider, + StakeAppliedBlock: stakeAppliedBlock, + Endpoints: endpointsVerified, + Geolocation: geolocation, + Chain: chainID, + DelegateTotal: sdk.NewCoin(k.stakingKeeper.BondDenom(ctx), delegateTotal), + Vault: creator, // the stake-provider TX creator is always regarded as the vault address } metadata.DelegateCommission = delegationCommission