Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Document (non-)custodial staking #720

Merged
merged 58 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a18ba42
feat: Implement non-custodial staking
red-0ne Jul 30, 2024
676c2c4
chore: Address review change requests
red-0ne Aug 1, 2024
14ea326
Merge remote-tracking branch 'origin/main' into refactor/non-custodia…
red-0ne Aug 1, 2024
bae1f00
refactor: unit/integration tests
red-0ne Aug 2, 2024
b44e07b
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 2, 2024
5f5e98b
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 2, 2024
473e042
fix: Remove tabs and non-printable chars
red-0ne Aug 2, 2024
3d01f53
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 2, 2024
2d064fd
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 2, 2024
0699a35
fix: Remove shadowed variable
red-0ne Aug 2, 2024
85e6b81
Merge remote-tracking branch 'origin/main' into refactor/non-custodia…
red-0ne Aug 2, 2024
bb84ab1
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 2, 2024
498fc26
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 2, 2024
853724a
fix: All tests working
red-0ne Aug 3, 2024
6d7151e
fix: Revert merge changes
red-0ne Aug 3, 2024
20b26e7
chore: Remove imoprt newline
red-0ne Aug 3, 2024
b33a013
fix: Add missing sender address
red-0ne Aug 3, 2024
b02af2f
fix: Use higher context err variable
red-0ne Aug 3, 2024
7b3555a
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 3, 2024
604224d
fix: Enfore sender to be owner or operator
red-0ne Aug 3, 2024
540f5db
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 3, 2024
ac07b43
fix: Remove err shadow declaration
red-0ne Aug 3, 2024
79e4c39
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 5, 2024
50629dc
docs: Document (non-)custodial staking
red-0ne Aug 5, 2024
473e047
fix: Err var shadowing
red-0ne Aug 6, 2024
088e675
chore: Log default operator address fallback
red-0ne Aug 6, 2024
428104b
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 7, 2024
ef62442
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 7, 2024
365ee96
fix: Add missing ctx argument
red-0ne Aug 7, 2024
d096d02
fix: Add polylog as side effect
red-0ne Aug 7, 2024
20e8ed5
fix: Address review changes, mimic Morse behavior
red-0ne Aug 8, 2024
b543120
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 8, 2024
fdfd9b9
fix: Duplicate supplierKeeper declaration
red-0ne Aug 8, 2024
4843c21
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 8, 2024
095571a
fix: Reward the owner instead of the operator
red-0ne Aug 8, 2024
611f583
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 8, 2024
3a7c0ba
fix: Update tests
red-0ne Aug 9, 2024
e34634b
chore: Add test external signer test case
red-0ne Aug 9, 2024
910c85b
fix: Allow owner to change its aaddress
red-0ne Aug 9, 2024
e092a4e
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 9, 2024
b3ac63c
fix: Wrong word added
red-0ne Aug 9, 2024
1f26789
fix: Stake auth contidional
red-0ne Aug 9, 2024
0a43775
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 9, 2024
85d84ec
fix: Missing owner address in test
red-0ne Aug 9, 2024
f9b0070
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 9, 2024
0510041
docs: Update stake command long description
red-0ne Aug 9, 2024
2d54f69
docs: Update documentation to reflect the current workflow
red-0ne Aug 9, 2024
1ab8488
docs: Update unstaking help text
red-0ne Aug 9, 2024
90b059a
Merge remote-tracking branch 'origin/refactor/non-custodial-staking-t…
red-0ne Aug 9, 2024
1ad8bf4
Merge remote-tracking branch 'origin/main' into docs/non-custodial-st…
red-0ne Aug 14, 2024
da67274
chore: Update proto generated files
red-0ne Aug 14, 2024
bb3acb9
docs: Fix typo
red-0ne Aug 14, 2024
6b92e50
chore: Address review change requests
red-0ne Aug 15, 2024
b7b93cc
Merge remote-tracking branch 'origin/main' into docs/non-custodial-st…
red-0ne Aug 15, 2024
1a2285a
fix: Owner role
red-0ne Aug 15, 2024
e50b27c
Merge remote-tracking branch 'origin/main' into docs/non-custodial-st…
red-0ne Aug 26, 2024
ff32460
chore: Address review change requests
red-0ne Aug 26, 2024
9d1f2e8
chore: Address review change requests
red-0ne Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ supplier3_stake: ## Stake supplier3

.PHONY: supplier_unstake
supplier_unstake: ## Unstake an supplier (must specify the SUPPLIER env var)
poktrolld --home=$(POKTROLLD_HOME) tx supplier unstake-supplier --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)
poktrolld --home=$(POKTROLLD_HOME) tx supplier unstake-supplier $(SUPPLIER) --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)

.PHONY: supplier1_unstake
supplier1_unstake: ## Unstake supplier1
Expand Down
141 changes: 139 additions & 2 deletions docusaurus/docs/operate/configs/supplier_staking_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ a stake transaction required to provide RPC services on Pocket Network._

- [Reference Example](#reference-example)
- [Usage](#usage)
- [Staking types](#staking-types)
- [Custodial Staking](#custodial-staking)
- [Non-Custodial Staking](#non-custodial-staking)
- [Configuration](#configuration)
- [`owner_address`](#owner_address)
- [`operator_address`](#operator_address)
- [`stake_amount`](#stake_amount)
- [`default_rev_share_percent`](#default_rev_share_percent)
- [`services`](#services)
Expand Down Expand Up @@ -44,20 +48,153 @@ poktrolld tx supplier stake-supplier \
--node tcp://poktroll-node:26657
```

## Staking types

The `Supplier` staking command supports `Custodial` and `Non-Custodial` staking
which can be illustrated in the following flowchart:

```mermaid
flowchart TD
AWF(["Account with funds <br> owner_address"])
ISC{Is custodial?}
US[Unstake]

AWF -- stake --> ISC
ISC -- yes --> CS
ISC -- no --> NCS


subgraph CS[Custodial Staking]
direction LR
subgraph S1[Supplier]
OW1["address: owner_address"]
end
subgraph RM1[RelayMiner]
OW2["address: owner_address"]
end
S1 --- RM1
end

subgraph NCS[Non Custodial Staking]
direction LR
subgraph S2[Supplier]
OW21["address: owner_address"]
end
subgraph RM2[RelayMiner]
OP22["address: operator_address"]
end
S2 -.- RM2
end

CS ---> |owner_address| US
NCS ---> |owner_address or operator_address| US

US -- funds --> OWA{{owner_address}}
US -- remove on-chain record --> OPA{{owner_address or operator_address}}

classDef owner fill:#f9f,stroke:#333,stroke-width:2px,color:#222;
classDef operator fill:#e05a46,stroke:#333,stroke-width:2px,color:#222;

class OW1,OW2,OW21,AWF owner
class OP22 operator
```

### Custodial Staking

The owner of the `Supplier` is the same as the operator.
This means the account that receives the rewards is the same as the one that
signs the `RelayResponse`s and submits claims and proofs.

Custodial staking is the simplest to set up and manage, as there is no need to
manage multiple accounts. It is suitable for `Supplier`s that do not have concerns
about using the private key of the staking or the rewarded account to operate the
`RelayMiner` or update the `Supplier`'s stake and services.

### Non-Custodial Staking

The owner of the `Supplier` is different from the operator.
This means the account that receives the rewards is different from the one signing
the `RelayResponse`s and submitting claims and proofs.

Non-custodial staking is suitable for `Supplier`s that want to separate the `RelayMiner`
staking operations from the account that has custody over the staked funds, and in turn,
the rewards being earned.

:::note

When staking a `Supplier`, the signing account specified with the `--from` flag
(which may differ from the `Supplier`'s owner or operator) will have its `upokt`
balance deducted to stake the `Supplier`.

When unstaking a `Supplier`, the staked `upokt` will be returned to the `owner_address`
account.

:::

## Configuration

### `owner_address`

_`Required`_, _`Non-empty`_
_`Required`_

```yaml
owner_address: <address>
```

The `owner_address` is used as the unique shareholder address for the `Supplier`
The `owner_address` is the address of the account that owns the `Supplier`s staked
funds, which will be returned to this account when the `Supplier` unstakes and finishes
unbonding.

For custodial staking, the `owner_address` is the same as the `operator_address`.

For non-custodial staking, the `owner_address` MUST be different from the `operator_address`.
This address receives the staked `upokt` when the `Supplier` is unstaked and finished unbonding.

The `owner_address` can only be changed with a stake message signed by the
`Supplier`'s owner account.

It is also used as the unique shareholder address for the `Supplier`
if none of `default_rev_share_percent` or `rev_share_percent` is defined in the
configuration file.

:::note

The `owner_address` does not identify a `Supplier`; multiple `Supplier`s can have
the same `owner_address`.

:::

### `operator_address`

_`Optional`_

```yaml
operator_address: <address>
```

The `operator_address` is the address that identifies the `Supplier`.
Its corresponding account is used for operational tasks such as signing `RelayResponse`s,
submitting `Claims` and `Proofs` as well as updating the `Supplier`'s info
(i.e. Adding or removing services, increasing the stake amount, etc).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Period to Abbreviation.

In American English, abbreviations like “etc.” require a period.

- etc)
+ etc.)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(i.e. Adding or removing services, increasing the stake amount, etc).
(i.e. Adding or removing services, increasing the stake amount, etc.).
Tools
LanguageTool

[style] ~128-~128: In American English, abbreviations like “etc.” require a period.
Context: ... services, increasing the stake amount, etc). The operator account can also be use...

(ETC_PERIOD)


The operator account can also be used to unstake the `Supplier`, which will cause
the staked `upokt` to be sent to the `owner_address` after unbonding finishes.

If the `operator_address` is empty or not specified, the `owner_address` is used
as the `operator_address`.

If the `operator_address` is the same as the `owner_address`, then the staking
is custodial.

:::warning

Since the `operator_address` is the unique identifier of a `Supplier`, it cannot
be changed once the `Supplier` is created. If it needs to be changed, then the
corresponding `Supplier` has to be unstaked and a new one staked with the new
`operator_address`.

:::

### `stake_amount`

_`Required`_, _`Non-empty`_
Expand Down
13 changes: 1 addition & 12 deletions localnet/poktrolld/config/supplier1_stake_config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
owner_address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4
# NB: The stake amount is exactly 1upokt greater than the value in genesis.json
# so that the stake command causes a state change.
operator_address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4
stake_amount: 1000069upokt
# If default_rev_share_percent is omitted, the owner receives 100% of the rewards.
# default_rev_share_percent cannot be empty - it must either be omitted completely
# or include at least one item.
default_rev_share_percent:
# The sum of all shares must equal 100%. Staking will fail otherwise.
- pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 80.5
- pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 19.5
services:
# The endpoint URL for the Anvil service is provided via the RelayMiner.
# The RelayMiner acts as a proxy, forwarding requests to the actual Anvil data node behind it.
# This setup allows for flexible and dynamic service provisioning within the network.
- service_id: anvil
endpoints:
- publicly_exposed_url: http://relayminer1:8545
rpc_type: JSON_RPC
- service_id: ollama
# Service specific rev share, if rev_share_percent is omitted for a specific
# service, default_rev_share_percent is used.
# The sum of all shares must equal 100%. Staking will fail otherwise.
rev_share_percent:
- pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 50
- pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 50
Expand Down
5 changes: 2 additions & 3 deletions localnet/poktrolld/config/supplier2_stake_config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
owner_address: pokt1re27pw4llwnatx4sq7rlggqzcm6j3f39epq2wa
operator_address: pokt1re27pw4llwnatx4sq7rlggqzcm6j3f39epq2wa
stake_amount: 1000070upokt
services:
- service_id: anvil
endpoints:
# The endpoint URL for the Anvil service is provided via the RelayMiner.
# The RelayMiner acts as a proxy, forwarding requests to the actual Anvil data node behind it.
# This setup allows for flexible and dynamic service provisioning within the network.
- publicly_exposed_url: http://relayminer2:8545
rpc_type: JSON_RPC
- service_id: ollama
Expand Down
5 changes: 2 additions & 3 deletions localnet/poktrolld/config/supplier3_stake_config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
owner_address: pokt1j6dun0x8eyq5mmsmq83zs3c2utt85q8478c89u
operator_address: pokt1j6dun0x8eyq5mmsmq83zs3c2utt85q8478c89u
stake_amount: 1000071upokt
services:
- service_id: anvil
endpoints:
# The endpoint URL for the Anvil service is provided via the RelayMiner.
# The RelayMiner acts as a proxy, forwarding requests to the actual Anvil data node behind it.
# This setup allows for flexible and dynamic service provisioning within the network.
- publicly_exposed_url: http://relayminer3:8545
rpc_type: JSON_RPC
- service_id: ollama
Expand Down
52 changes: 52 additions & 0 deletions localnet/poktrolld/config/supplier_stake_config_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This file is used to stake a Supplier or update an existing Supplier's information in the Pocket Network.
# Pocket Network supports two types of staking mechanisms: custodial and non-custodial staking:
# * Custodial staking is the default mechanism, where the owner address (i.e., the account that
# receives the rewards) is the same as the operator address (i.e., the address that operates
# the Supplier).
# * Non-custodial staking is an advanced mechanism, where the owner address is different from
# the operator address. This is useful to avoid overuse of the private key of the
# account that owns the staked funds and receives the rewards.

# The address of the supplier's owner. This address could stake a new Supplier or
# update any of its properties excluding the operator address which is immutable.
# The account corresponding to this address could also unstake the Suppliers it owns.
# The owner address does not identify the Supplier in the Pocket Network; the same owner
# account can stake multiple Suppliers.
owner_address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj

# The address of the operator of the Supplier. This address operates the Supplier,
# (i.e., signs relay responses, submits claims and proofs, updates service endpoints, etc.).
# This address can also used to stake a new Supplier or unstake an existing one.
# It uniquely identifies the Supplier in the Pocket Network and cannot be changed
# once the Supplier is created.
# The operator address is optional; if it is empty or not provided, the owner
# address is used as the operator address.
operator_address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
# NB: The stake amount is exactly 1upokt greater than the value in genesis.json
# so that the stake command causes a state change.
stake_amount: 1000069upokt
# If default_rev_share_percent is omitted, the owner receives 100% of the rewards.
# default_rev_share_percent cannot be empty - it MUST either be omitted completely
# or include at least one item.
default_rev_share_percent:
# The sum of all shares MUST equal 100%. Staking will fail otherwise.
- pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 80.5
- pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 19.5
services:
# The endpoint URL for the Anvil service is provided via the RelayMiner.
# The RelayMiner acts as a proxy, forwarding requests to the actual Anvil data node behind it.
# This setup allows for flexible and dynamic service provisioning within the network.
- service_id: anvil
endpoints:
- publicly_exposed_url: http://relayminer1:8545
rpc_type: JSON_RPC
- service_id: ollama
# Service specific rev share, if rev_share_percent is omitted for a specific
# service, default_rev_share_percent is used.
# The sum of all shares MUST equal 100%. Staking will fail otherwise.
rev_share_percent:
- pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 50
- pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 50
endpoints:
- publicly_exposed_url: http://relayminer1:8545
rpc_type: REST
8 changes: 6 additions & 2 deletions x/supplier/module/tx_stake_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ func CmdStakeSupplier() *cobra.Command {
cmd := &cobra.Command{
Use: "stake-supplier --config <config_file.yaml>",
Short: "Stake a supplier",
Long: `Stake an supplier with the provided parameters. This is a broadcast operation that
will stake the tokens and associate them with the supplier specified by the 'from' address.
Long: `Stake a supplier using the specified configuration file. This command
supports both custodial and non-custodial staking of the signer's tokens.
It sources the necessary information from the provided configuration file.

For more details on the staking process, please refer to the supplier staking documentation at:
https://dev.poktroll.com/operate/configs/supplier_staking_config

Example:
$ poktrolld tx supplier stake-supplier --config stake_config.yaml --keyring-backend test --from $(OWNER_ADDRESS) --node $(POCKET_NODE) --home $(POKTROLLD_HOME)`,
Expand Down
Loading