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

Set blockscout to work with staking app in POSDAO network #1709

Closed
saneery opened this issue Apr 8, 2019 · 3 comments
Closed

Set blockscout to work with staking app in POSDAO network #1709

saneery opened this issue Apr 8, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request Staking dApp

Comments

@saneery
Copy link
Contributor

saneery commented Apr 8, 2019

Description

POSDAO

There are some new essences in the staking app:

  • Validators
  • Candidates
  • Delegators

Every validator and candidate has mining address and pool address (staking address). Delegators can stake on these pools. When a user makes a stake on himself, he becomes a candidate.

Users make stakes during an epoch, at the end epoch new validators set will be elected from active pools.

Rules of POSDAO

  1. Delegators make stakes to pools and they can withdraw or move this stake in the same epoch
  2. Delegators can't withdraw or move a stake if a new epoch comes, but they can order a withdraw.
  3. Delegators can claim an order if a new epoch comes after epoch when they made the order.

Goals

  • Fetch a list of pools with their data from the POSDAO
  • Fetch information about current staking epoch
  • Set frontend to work with POSDAO through MetaMask/NiftyWallet

The interface is drawn here https://projects.invisionapp.com/share/YPQNPDTW4ZB#/screens/348397338
from #1476
The POSDAO contracts' methods: https://poanetwork.github.io/posdao-contracts/docs/

Description of updates

Database changes

There are new tables in the DB

staking_pools

  • staking_address_hash
  • mining_address_hash
  • is_active
  • delegators_count
  • staked_amount
  • self_staked_amount
  • is_validator
  • was_validator_count
  • is_banned
  • banned_until
  • was_banned_count
  • likelihood
  • staked_ratio
  • is_deleted

All this fields get from contracts' methods ( isValidator, validatorCounter, isValidatorBanned, bannedUntil, banCounter, isPoolActive, poolDelegators, stakeAmountTotalMinusOrderedWithdraw, stakeAmountMinusOrderedWithdraw)

staking_pools_delegators

  • delegator address_hash
  • pool_address_hash
  • stake_amount
  • ordered_withdraw
  • max_withdraw_allowed
  • max_ordered_withdraw_allowed
  • order_withdraw_epoch
  • is_active

This table will be filling, when pools fetched from the blockchain.
For every pool, there will fetch current list of delegators and replace the previous list from the DB by a new.

Modules

Fetchers

There is one fetcher Fetcher.StakingPools. It fetches current list of pools and list of delegators for every pool from the network on the per block and sends them to import runner.
It runs by block fetcher:
https://github.com/poanetwork/blockscout/blob/master/apps/indexer/lib/indexer/block/fetcher.ex#L285
It fetches pools by call Explorer.Staking.PoolsReader.get_pools/0
and fetches additional data by call Explorer.Staking.PoolsReader.pool_data/1

Modules

Explorer.Staking.PoolsReader is a module that calls contract methods. There are two base contracts: staking_contract and validator_contract.
The module has two base functions:

Importer

There is two importers Explorer.Chain.Import.Runner.StakingPools and Explorer.Chain.Import.Runner.StakingPoolsDelegators they just insert a list of entries to the database.

Config

To run blockscout with the POSDAO you need to set following envs:

  • POS_VALIDATORS_CONTRACT
  • POS_STAKING_CONTRACT
  • MIN_CANDIDATE_STAKE - the minimum of stake amount that candidate can make (Eth, just for view)
  • MIN_DELEGATOR_STAKE - the minimum of stake amount that delegator can make (Eth, just for view)

If there no POS_VALIDATOR_CONTRACT and POS_STAKING_CONTRACT fetchers are not run

What is added

  • Fetcher.StakingPools - fetches current list of pools from the network on the per block and send them to import runner.
  • Import.Runner.StakingPools - inserts new pools list to the database.
  • Explorer.Staking.PoolsReader - module to read the current list of pools and their data (at the moment data is fetching from different methods, but in the future will one contract's method for it)
  • Explorer.Staking.EpochCounter - Fetches current staking epoch number and the block number of epoch end at the startup and the end of an epoch. It subscribes to handle new blocks and conclude whether the epoch is over.

What is pending

  1. Fetching inactive delegators #2205
  2. Update templates and add a list of pools #2215
  3. Add async login and logout by MetaMask #2220
  4. Async updating of counters #2221
  5. Become a candidate #2251
  6. Remove my pool #2223
  7. Make a stake #2227
  8. Add functionality to move a stake #2240
  9. Add functionality to withdraw, order a withdraw and claim an order #2243
  10. Add modal window with a pool's information #2246

What is to be done

  • Optimization of fetching data by events, and remove long polling
  • Fix bug with batching repeated entries in the Fetcher

Test setup

To run the test setup you need to:

  1. install and set up https://github.com/poanetwork/posdao-test-setup (pull new changes if you already has the project).
  2. edit config/node1.toml to access websocket connection:
[websockets]
interface = "all"
origins = ["all"]
port = 9541
  1. set envs:
export ETHEREUM_JSONRPC_HTTP_URL=http://localhost:8541
export ETHEREUM_JSONRPC_TRACE_URL=http://localhost:8541
export ETHEREUM_JSONRPC_WS_URL=ws://localhost:9541
export POS_VALIDATORS_CONTRACT=0x1000000000000000000000000000000000000001
export POS_STAKING_CONTRACT=0x1100000000000000000000000000000000000001 
export ETHEREUM_JSONRPC_VARIANT=parity
export COIN=POA
export NETWORK=POA
export LOGO=/images/posdao_logo.png
export LOGO_FOOTER=/images/posdao_logo_footer.png
export MIN_CANDIDATE_STAKE=1
export MIN_DELEGATOR_STAKE=1
export STAKES_TOKEN_NAME=POSDAO
  1. run POSDAO npm run all
  2. run blockscout iex -S mix phx.server

You can use some test accounts from posdao-test-setup/accounts/keystore, the password is testnetpoa. Accounts with test coins are prefixed with UTC.

@ayrat555
Copy link
Contributor

@saneery can you please describe in more details what is Validators, Candidates, Delegators or attach link to it?

@saneery
Copy link
Contributor Author

saneery commented May 15, 2019

@saneery can you please describe in more details what is Validators, Candidates, Delegators or attach link to it?

@ayrat555 there is POSDAO white paper, but I think it's unnecessary to describe POSDAO essence in details here. For us, Validators and Candidates are just addresses with data and with pool (staking address).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Staking dApp
Projects
None yet
Development

No branches or pull requests

5 participants