Skip to content

Commit

Permalink
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
Browse files Browse the repository at this point in the history
…ation/min-stake-param

* issues/612/app/msg-update-param:
  fix: test error message
  chore: review feedback improvements
  chore: review feedback improvements
  chore: review feedback improvements
  [Docs] Update README(s) (#842)
  • Loading branch information
bryanchriswhite committed Sep 30, 2024
2 parents 497ecd9 + d92eb59 commit 941b801
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
---
sidebar_position: 1
title: Poktroll
id: home-doc
slug: /
---

<div align="center">
<a href="https://www.pokt.network">
<img src="https://user-images.githubusercontent.com/2219004/151564884-212c0e40-3bfa-412e-a341-edb54b5f1498.jpeg" alt="Pocket Network logo" width="340"/>
Expand All @@ -13,17 +6,17 @@ slug: /

<div>
<a href="https://discord.gg/pokt"><img src="https://img.shields.io/discord/553741558869131266"/></a>
<a href="https://github.com/pokt-network/poktroll/releases"><img src="https://img.shields.io/github/release-pre/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/contributors/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/releases"><img src="https://img.shields.io/github/release-pre/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/contributors/pokt-network/poktroll.svg"/></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/last-commit/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulls"><img src="https://img.shields.io/github/issues-pr/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/last-commit/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulls"><img src="https://img.shields.io/github/issues-pr/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/releases"><img src="https://img.shields.io/badge/platform-linux%20%7C%20macos-pink.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues-closed/pokt-network/pocket.svg"/></a>
<a href="https://godoc.org/github.com/pokt-network/pocket"><img src="https://img.shields.io/badge/godoc-reference-blue.svg"/></a>
<a href="https://goreportcard.com/report/github.com/pokt-network/pocket"><img src="https://goreportcard.com/badge/github.com/pokt-network/pocket"/></a>
<a href="https://golang.org"><img src="https://img.shields.io/badge/golang-v1.20-green.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues-closed/pokt-network/poktroll.svg"/></a>
<a href="https://godoc.org/github.com/pokt-network/poktroll"><img src="https://img.shields.io/badge/godoc-reference-blue.svg"/></a>
<a href="https://goreportcard.com/report/github.com/pokt-network/poktroll"><img src="https://goreportcard.com/badge/github.com/pokt-network/poktroll"/></a>
<a href="https://golang.org"><img src="https://img.shields.io/badge/golang-v1.23-green.svg"/></a>
<a href="https://github.com/tools/godep" ><img src="https://img.shields.io/badge/godep-dependency-71a3d9.svg"/></a>
</div>

Expand Down
4 changes: 3 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ genesis:
gateway:
params:
# TODO_MAINNET: Determine realistic amount for minimum gateway stake amount.
min_stake: 100
min_stake:
amount: "1000000" # 1 POKT
denom: upokt
gatewayList:
- address: pokt15vzxjqklzjtlz7lahe8z2dfe9nm5vxwwmscne4
stake:
Expand Down
18 changes: 9 additions & 9 deletions docusaurus/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ slug: /

<div>
<a href="https://discord.gg/pokt"><img src="https://img.shields.io/discord/553741558869131266"/></a>
<a href="https://github.com/pokt-network/poktroll/releases"><img src="https://img.shields.io/github/release-pre/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/contributors/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/releases"><img src="https://img.shields.io/github/release-pre/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/contributors/pokt-network/poktroll.svg"/></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/last-commit/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulls"><img src="https://img.shields.io/github/issues-pr/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulse"><img src="https://img.shields.io/github/last-commit/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/pulls"><img src="https://img.shields.io/github/issues-pr/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/releases"><img src="https://img.shields.io/badge/platform-linux%20%7C%20macos-pink.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues/pokt-network/pocket.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues-closed/pokt-network/pocket.svg"/></a>
<a href="https://godoc.org/github.com/pokt-network/pocket"><img src="https://img.shields.io/badge/godoc-reference-blue.svg"/></a>
<a href="https://goreportcard.com/report/github.com/pokt-network/pocket"><img src="https://goreportcard.com/badge/github.com/pokt-network/pocket"/></a>
<a href="https://golang.org"><img src="https://img.shields.io/badge/golang-v1.20-green.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues/pokt-network/poktroll.svg"/></a>
<a href="https://github.com/pokt-network/poktroll/issues"><img src="https://img.shields.io/github/issues-closed/pokt-network/poktroll.svg"/></a>
<a href="https://godoc.org/github.com/pokt-network/poktroll"><img src="https://img.shields.io/badge/godoc-reference-blue.svg"/></a>
<a href="https://goreportcard.com/report/github.com/pokt-network/poktroll"><img src="https://goreportcard.com/badge/github.com/pokt-network/poktroll"/></a>
<a href="https://golang.org"><img src="https://img.shields.io/badge/golang-v1.23-green.svg"/></a>
<a href="https://github.com/tools/godep" ><img src="https://img.shields.io/badge/godep-dependency-71a3d9.svg"/></a>
</div>

Expand Down
16 changes: 16 additions & 0 deletions tools/scripts/params/gateway_all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"body": {
"messages": [
{
"@type": "/poktroll.gateway.MsgUpdateParams",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"params": {
"min_stake": {
"amount": "1000000",
"denom": "upokt"
}
}
}
]
}
}
5 changes: 4 additions & 1 deletion tools/scripts/params/gateway_min_stake.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"@type": "/poktroll.gateway.MsgUpdateParam",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"name": "min_stake",
"as_int64": "42"
"as_coin": {
"amount": "1000000",
"denom": "upokt"
}
}
]
}
Expand Down
9 changes: 2 additions & 7 deletions x/gateway/keeper/msg_server_stake_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ func (k msgServer) StakeGateway(
}

// Check if the gateway already exists or not
var (
coinsToEscrow sdk.Coin
totalStake sdk.Coin
)
var coinsToEscrow sdk.Coin
gateway, isGatewayFound := k.GetGateway(ctx, msg.Address)
if !isGatewayFound {
logger.Info(fmt.Sprintf("gateway not found. Creating new gateway for address %q", msg.Address))
gateway = k.createGateway(ctx, msg)
coinsToEscrow = *msg.Stake
totalStake = *msg.Stake
} else {
logger.Info(fmt.Sprintf("gateway found. About to try and update gateway for address %q", msg.Address))
currGatewayStake := *gateway.Stake
Expand All @@ -69,7 +65,6 @@ func (k msgServer) StakeGateway(
).Error(),
)
}
totalStake = currGatewayStake.Add(*msg.Stake)
logger.Info(fmt.Sprintf("gateway is going to escrow an additional %+v coins", coinsToEscrow))
}

Expand All @@ -85,7 +80,7 @@ func (k msgServer) StakeGateway(

// MUST ALWAYS have at least minimum stake.
minStake := k.GetParams(ctx).MinStake
if totalStake.Amount.LT(minStake.Amount) {
if msg.Stake.Amount.LT(minStake.Amount) {
errFmt := "gateway %q must stake at least %s"
logger.Info(fmt.Sprintf(errFmt, msg.Address, minStake))
return nil, status.Error(
Expand Down
6 changes: 3 additions & 3 deletions x/gateway/keeper/msg_server_stake_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func TestMsgServer_StakeGateway_FailBelowMinStake(t *testing.T) {
expectedErr := gatewaytypes.ErrGatewayInvalidStake.Wrapf("gateway %q must stake at least %s", addr, minStake)

// Set the minimum stake to be greater than the gateway stake.
err := k.SetParams(ctx, gatewaytypes.Params{
MinStake: &minStake,
})
params := k.GetParams(ctx)
params.MinStake = &minStake
err := k.SetParams(ctx, params)
require.NoError(t, err)

// Prepare the gateway.
Expand Down
2 changes: 1 addition & 1 deletion x/gateway/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestGetParams(t *testing.T) {
require.EqualValues(t, params, k.GetParams(ctx))
}

func TestParams_ValidateMinRelayDifficulty(t *testing.T) {
func TestParams_ValidateMinStake(t *testing.T) {
tests := []struct {
desc string
minStake any
Expand Down
25 changes: 8 additions & 17 deletions x/gateway/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,18 @@ func ValidateMinStake(minStakeAny any) error {
return ErrGatewayParamInvalid.Wrap("missing min_stake")
}

if err := ValidateMinStakeDenom(minStakeCoin); err != nil {
return err
if minStakeCoin.Denom != volatile.DenomuPOKT {
return ErrGatewayParamInvalid.Wrapf(
"invalid min_stake denom %q; expected %q",
minStakeCoin.Denom, volatile.DenomuPOKT,
)
}

if err := ValidateMinStakeAboveZero(minStakeCoin); err != nil {
return err
if minStakeCoin.IsZero() || minStakeCoin.IsNegative() {
return ErrGatewayParamInvalid.Wrapf("invalid min stake amount must be greater than zero: %s", minStakeCoin)
}

return nil
}

func ValidateMinStakeDenom(minStakeCoin *cosmostypes.Coin) error {
if minStakeCoin.Denom != volatile.DenomuPOKT {
return ErrGatewayParamInvalid.Wrapf("min stake denom must be %s: %s", volatile.DenomuPOKT, minStakeCoin)
return ErrGatewayParamInvalid.Wrapf("invalid min_stake amount denom %s", minStakeCoin)
}
return nil
}

func ValidateMinStakeAboveZero(minStakeCoin *cosmostypes.Coin) error {
if minStakeCoin.Amount.Int64() <= 0 {
return ErrGatewayParamInvalid.Wrapf("min stake amount must be greater than zero: %s", minStakeCoin)
}
return nil
}
2 changes: 1 addition & 1 deletion x/proof/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMsgUpdateParam_UpdateMinRelayDifficultyBitsOnly(t *testing.T) {
// Ensure the default values are different from the new values we want to set
require.NotEqual(t, expectedRelayDifficultyTargetHash, defaultParams.RelayDifficultyTargetHash)

// Update the min relay difficulty bits
// Update the min stake.
updateParamMsg := &prooftypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: prooftypes.ParamRelayDifficultyTargetHash,
Expand Down

0 comments on commit 941b801

Please sign in to comment.