This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial push, update challenge003 link * first writing, ready for review * first review * updated files mentioning the new challenge * final review
- Loading branch information
Stefano Pepe
authored
Jun 22, 2020
1 parent
c8f5467
commit 73a567b
Showing
4 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Stake Wars Challenge 004 | ||
Published on: June 22 2020 | ||
|
||
Create a warchest of staked tokens, and dynamically maintain **no more than one seat**. | ||
This challenge is designed to learn how to monitor the minimum stake to become a validator, and dynamically manage your staking pool. Your achievement will be to control a liquid reserve of tokens, the _warchest_, that you can leverage if your validator risks to be kicked out from the current set for insufficient stake. | ||
|
||
## Acceptance Criteria | ||
|
||
1. Monitor your stake | ||
2. Manage the seat price | ||
|
||
## 1.Monitor your stake | ||
Use [near-shell](https://github.com/near/near-shell) or the `validators` method in the [JSON RPC](https://docs.near.org/docs/interaction/rpc) to query the validators state: | ||
| Action | near-shell | validators JSON RPC | | ||
| ------ | ---------- | -------- | | ||
| current set (t0) | `near validators current` | `result.current_validators` | | ||
| next set (t+1) | `near validators next` | `result.next_validators` | | ||
| proposals (t+2) | `near proposals` | `result.current_proposals` | | ||
|
||
Where `t0` is the current epoch, and `t+n` epochs in the future. | ||
|
||
### Monitor the current set of validators with near-shell | ||
Use | ||
``` | ||
near validators current | awk '/<POOL_ID>/ {print $4}' | ||
``` | ||
This command will generate a string with an integer in NEAR tokens, where: | ||
- `near validators current` is used to show the current set of validators | ||
- `awk '/<POOL_ID> {print $4}'` filters by POOL_ID, and prints an integer with its current stake | ||
|
||
### Monitor the current set with the RPC | ||
Use | ||
``` | ||
curl -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' https://rpc.betanet.near.org | jq -c '.result.current_validators[] | select(.account_id | contains ("<POOL_ID>"))' | jq .stake | ||
``` | ||
This command query the JSON RPC with: | ||
- `"method": "validators"` | ||
- `jq -c '.result.current_validators` to visualize only the current set | ||
- `select(.account_id | contains ("<POOL_ID>"))'` to filter only <POOL_ID> from the results | ||
- `jq .stake` to filter again via jq the results and take only the total stake in YoctoNEAR | ||
|
||
If compared with near-shell, this query provides a more accurate stake of the <POOL_ID>. | ||
|
||
You can use similar filters to check if your pool will be in the next set or not: | ||
|
||
### Monitor the next set with near-shell | ||
Use the command below to see if your node will lose its seat in the next epoch: | ||
``` | ||
near validators next | grep "Kicked out" | grep "<POOL_ID>" | ||
``` | ||
If the result is not empty, <POOL_ID> will not be in the next validators set, and will lose its seat. | ||
|
||
Alternatively, you can use | ||
``` | ||
near proposals | grep "Rollover" | grep "<POOL_ID>" | ||
``` | ||
If this result is not empty, <POOL_ID> will be in the Rollover set, and will maintain the validator seat. | ||
|
||
|
||
### Monitor the next set with the JSON RPC: | ||
Similar to the commands above, use | ||
``` | ||
curl -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' https://rpc.betanet.near.org | jq -c '.result.next_validators[] | select(.account_id | contains ("<POOL_ID>"))' | ||
``` | ||
If the result is not empty, <POOL_ID> will be in the next validators set. | ||
|
||
The RPC provides data on the previous epoch, to investigate the reason why a node is not in the current set: | ||
``` | ||
curl -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' https://rpc.betanet.near.org | jq -c '.result.prev_epoch_kickout[] | select(.account_id | contains ("<POOL_ID>"))' | jq .reason | ||
``` | ||
Similar to the other command above above: | ||
- `jq -c '.result.prev_epoch_kickout` filters the previous epoch set kick out | ||
- `jq .reason` filters the reason, eg insufficient stake or insufficient number of blocks generated | ||
|
||
### Monitor the epoch progress | ||
- get the current block height | ||
- get the current epoch start | ||
|
||
As an example, you can use the command | ||
``` | ||
curl https://rpc.betanet.near.org/status | jq .sync_info.latest_block_height | ||
``` | ||
to return an integer of the current block height. | ||
|
||
As of today, you can retrieve the `epoch_start` from the JSON RPC: | ||
``` | ||
curl -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' https://rpc.betanet.near.org | jq .result.epoch_start_height | ||
``` | ||
This query will generate an integer with the block number that started the current epoch | ||
|
||
As a final step, estimate how many blocks are left in the current epoch by subtracting the `latest_block_height` from `epoch_start_height + 10000`. | ||
|
||
**Heads up:** BetaNet, TestNet and MainNet have different epoch lengths: | ||
|
||
| Network | Epoch Blocks | | ||
| ------- | ------ | | ||
| BetaNet | 10,000 | | ||
| TestNet | 43,200 | | ||
| MainNet | 43,200 | | ||
|
||
### Monitor the seat price | ||
Measure or calculate yourself the cost of a seat to become validator. | ||
|
||
As an example, you may use near-shell to know: | ||
- the current epoch seat price with `near validators current | awk '/price/ {print substr($6, 1, length($6)-2)}'` | ||
- the next epoch seat price price with `near validators next | awk '/price/ {print substr($7, 1, length($7)-2)}'` | ||
- the estimated t+2 seat price with `near proposals | awk '/price =/ {print substr($15, 1, length($15)-1)}'` | ||
|
||
|
||
## 2.Manage the seat price | ||
This challenge is complete when you can dynamically adjust the locked balance of your staking pool, and maintain **one seat**. | ||
|
||
You can use the commands `stake` and `unstake` with near shell, dynamically locking your funds: | ||
``` | ||
near call <POOL_ID> stake '{"amount": "<STAKE_AMOUNT>"}' --accountId <WARCHEST_ID> | ||
``` | ||
Where: | ||
- `POOL_ID` is the name of your staking pool | ||
- `STAKE_AMOUNT` is calculated from the data collected above | ||
- `WARCHEST_ID` is the account that you use to delegate funds to your pool | ||
|
||
If your current stake provides two seats or more, your funds should be unstaked and held in the warchest balance. | ||
|
||
To prove that your _warchest_ is deployed, provide a list of 4 transactions that staked or unstaked funds based on the seat pric following these principles. Reply to this [Form](https://nearprotocol1001.typeform.com/to/x4Bval) to receive 100,000 extra betanet tokens delegated to your pool and begin the challenge. | ||
|
||
**Heads up:** we will run our monitoring scripts too, and will un-delegate the 100,000 tokens from your pool if: | ||
- you retain **two or more seats** for three epochs in a row | ||
- you retain **two or more seats** for 15 epochs in total | ||
|
||
Overall, we suggest to use NEAR's delegated tokens as your main stake in the pool, and keep your own token reserves (earned from previous challenges and contributions) as liquid tokens within the pool. | ||
Once you are running your _warchest_, reply to the [Issue #500](https://github.com/nearprotocol/stakewars/issues/500) posting your accomplishment. Use also the same issue if we undelegated your funds, and you want to try again. | ||
|
||
## Contribution Opportunities | ||
|
||
Do you want to earn extra tokens? We have contribution opportunities available below! | ||
|
||
Reply to the challenges application thread on [Github](https://github.com/nearprotocol/stakewars/issues/350) specifying: | ||
- which contribution you want to do, and the link to this challenge | ||
- the type of document you will release | ||
- the date when you will publish the content (you can postpone a few days, no worries) | ||
|
||
Once your work is done, you will be added to the list below. Please note that rewards in tokens will need to pass basic KYC checks from NEAR Foundation, and comply with regulations. | ||
|
||
### List of available contributions | ||
|
||
| Abstract | Description | Contributor | Date | Link | NEAR Tokens | Maintenance | Language | | ||
| -------- | ------------------------------ | ----------- | ------ | ---- | ----------- | --- | ---- | | ||
| Monitor the Stake | Create a tutorial, in the form of a video, a blogpost or Github document, that shows how to monitor your stake, and the current seat price. The goal is to help users integrate this system with their monitoring platform, such as Grafana or Datadog. Updates to this guide, reflecting any updates of the tools involved, will be paid a % of the initial bounty per each revision, up to once per month, until Stake Wars is over. Contributions in other languages are encouraged, but considered case by case basis. | - | - | - | 1,000 | 15% | - | | ||
| Release the Warchest Bot | Release a Warchest Bot, in your favorite programming language, capable to manage your validator seat and maintain its number to **one**. It doesn't have to be production-ready, but it should document how to install and run it. | - | - | - | 2,500 | 10% | - | | ||
|
||
## Previous Challenge | ||
Monitor your node health, and setup automated email alerts: [challenge003](challenge003.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters