Skip to content

Commit

Permalink
[Supplier] refactor: SupplierStakingFee var usage to param usage (#948
Browse files Browse the repository at this point in the history
)

## Summary

Replace usage of `supplierkeeper.SupplierStakingFee` with the new param
and delete it.

## Issue

- `TODO_BETA`

## Type of change

Select one or more from the following:

- [ ] New feature, functionality or library
- [ ] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [x] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [x] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [x] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [ ] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: red-0ne <[email protected]>
  • Loading branch information
bryanchriswhite and red-0ne authored Dec 2, 2024
1 parent ac4c779 commit a248666
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
11 changes: 3 additions & 8 deletions x/supplier/keeper/msg_server_stake_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/app/volatile"
"github.com/pokt-network/poktroll/telemetry"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

var (
// TODO_BETA(@bryanchriswhite): Make supplier staking fee a governance parameter
// TODO_BETA(@red-0ne): Update supplier staking documentation to remove the upstaking requirement and introduce the staking fee.
SupplierStakingFee = sdk.NewInt64Coin(volatile.DenomuPOKT, 1)
)

// TODO_BETA(@red-0ne): Update supplier staking documentation to remove the upstaking requirement and introduce the staking fee.
func (k msgServer) StakeSupplier(ctx context.Context, msg *suppliertypes.MsgStakeSupplier) (*suppliertypes.MsgStakeSupplierResponse, error) {
isSuccessful := false
defer telemetry.EventSuccessCounter(
Expand Down Expand Up @@ -147,7 +141,8 @@ func (k msgServer) StakeSupplier(ctx context.Context, msg *suppliertypes.MsgStak
}

// Send the coins from the message signer account to the staked supplier pool
stakeWithFee := sdk.NewCoins(coinsToEscrow.Add(SupplierStakingFee))
supplierStakingFee := k.GetParams(ctx).StakingFee
stakeWithFee := sdk.NewCoins(coinsToEscrow.Add(*supplierStakingFee))
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, msgSignerAddress, suppliertypes.ModuleName, stakeWithFee)
if err != nil {
logger.Info(fmt.Sprintf("ERROR: could not send %v coins from %q to %q module account due to %v", coinsToEscrow, msgSignerAddress, suppliertypes.ModuleName, err))
Expand Down
3 changes: 2 additions & 1 deletion x/supplier/keeper/msg_server_stake_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestMsgServer_StakeSupplier_SuccessfulCreateAndUpdate(t *testing.T) {
require.Len(t, foundSupplier.Services[0].Endpoints, 1)
require.Equal(t, "http://localhost:8080", foundSupplier.Services[0].Endpoints[0].Url)
// Assert that the supplier's account balance was reduced by the staking fee
balanceDecrease := keeper.SupplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
supplierStakingFee := supplierModuleKeepers.Keeper.GetParams(ctx).StakingFee
balanceDecrease := supplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
// SupplierBalanceMap reflects the relative changes to the supplier's balance
// (i.e. it starts from 0 and can go below it).
// It is not using coins that enforce non-negativity of the balance nor account
Expand Down
5 changes: 3 additions & 2 deletions x/supplier/keeper/msg_server_unstake_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ func TestMsgServer_UnstakeSupplier_OperatorCanUnstake(t *testing.T) {

// Balance decrease is the total amount deducted from the supplier's balance, including
// the initial stake and the staking fee.
balanceDecrease := keeper.SupplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
supplierStakingFee := supplierModuleKeepers.Keeper.GetParams(ctx).StakingFee
balanceDecrease := supplierStakingFee.Amount.Int64() + foundSupplier.Stake.Amount.Int64()
// Ensure that the initial stake is not returned to the owner yet
require.Equal(t, -balanceDecrease, supplierModuleKeepers.SupplierBalanceMap[ownerAddr])

Expand All @@ -415,5 +416,5 @@ func TestMsgServer_UnstakeSupplier_OperatorCanUnstake(t *testing.T) {

// Ensure that the initial stake is returned to the owner while the staking fee
// remains deducted from the supplier's balance.
require.Equal(t, -keeper.SupplierStakingFee.Amount.Int64(), supplierModuleKeepers.SupplierBalanceMap[ownerAddr])
require.Equal(t, -supplierStakingFee.Amount.Int64(), supplierModuleKeepers.SupplierBalanceMap[ownerAddr])
}

0 comments on commit a248666

Please sign in to comment.