Comments (17)
Your concerns are valid. However, use RPC API requires a lot of programming/testing effort. I need to see more demand before adding RPC based reward calculations.
I will leave this issue open to see if there will be more demand.
from tezos-reward-distributor.
Found it. Credit to @DefinitelyNotAGoat golang tezos library.
The pattern:
- get level for cycle X (cycle X * 4096 + 1)
- get block for level (/chains/main/blocks/" + headHash + "~" + (current level - level))
- get roll snapshot index for block (/chains/main/blocks/" + block.Hash + "/context/raw/json/cycle/" + strCycle)
- get snapshot block for payment cycle X (((cycleX - 7) * 4096) + (RollSnapShot+1)*256)
- get staking balance of delegate using snapshot block (/chains/main/blocks/" + snapshot block
hash + "/context/delegates/" + delegatePhk + "/staking_balance) - get delegates at cycle X (/chains/main/blocks/" + snapshot block hash + "/context/delegates/" + delegatePhk + "/delegated_contracts
- get rewards for delegate at cycle X (/chains/main/blocks/head/context/raw/json/contracts/index/" + delegatePhk + "/frozen_balance/" + X
- foreach delegates, get delegate balance at snapshot (/chains/main/blocks/" + snapshot block hash + "/context/contracts/" + delegate KT1 + "/balance"
-- calculate % of total staking per delegatee
-- calculate reward for delegatee
from tezos-reward-distributor.
Nope. I asked lead dev and Aurthor in bakers-slack. Waiting for response.
from tezos-reward-distributor.
+1
from tezos-reward-distributor.
What needs to be fetched from RPC?
- List of delegators
- list of 'active' delegators
- Balance of each delegator
- Staking balance of baker
- total balance of baker
The hardest thing I cannot find is for which cycle a delegator activates.
# Alphanet
$ ./tezos-client rpc get /chains/main/blocks/head/context/delegates/tz1LdZ6S8ScNMgaCLqrekDvbBWhLqtUebk23
{ "balance": "13594924319", "frozen_balance": "0",
"frozen_balance_by_cycle": [], "staking_balance": "32345701585",
"delegated_contracts":
[ "KT1WyMWHxGt8HLgWG9LZEqxG5u2kEpHNyE8D",
"KT1Ua68oUfTwykAC8MRh8JZm9Ekd8wp57rm9",
"KT1MTZGjAZo9ZYNU2y72vxwpg3iqGUWpZyfm",
"KT1Lg9R2b2UjJhJdhvRnNovdpaQF41o2jvgw" ],
"delegated_balance": "18750777266", "deactivated": false,
"grace_period": 7 }
You can see a list of all delegates but no info on their staked balance, nor any indication to which cycle their delegation amount unfreezes and becomes part of the staked balance. This is typically 7 cycles, but I was expecting there to be an RPC call to find out which specific block/level.
The staking balance noted above is incorrect. Each of those delegates were added in cycle 1 (alphanet reset on Nov 30th) and should not be considered part of the staked balance for 7 cycles.
from tezos-reward-distributor.
This RPC validates the KT1 is a delegate of our baker, tz1LdZ, and gives us the staked balance.
./tezos-client rpc get /chains/main/blocks/head/context/contracts/KT1XfTzTJWFMsEukKXXVoKbwsBFbZvYS3hkn
{ "manager": "tz1Sfe7Nm2MdmkCopA7DVBUHHEd8G73TWwfN",
"balance": "14378132380", "spendable": true,
"delegate":
{ "setable": false, "value": "tz1LdZ6S8ScNMgaCLqrekDvbBWhLqtUebk23" },
"counter": "0" }
from tezos-reward-distributor.
/chains/main/blocks/head/context/delegates/
balance + delegated_balance - rewars = staking_balance.
For a specific cycle/block we will need to use blockhash instead of 'head'. In order to get that we will need to find snapshot chosen for the cycle.
from tezos-reward-distributor.
Been looking for snapshot information in RPC. Not documented fully.
from tezos-reward-distributor.
Yeah, documentation is not great.
/chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/
returns selected snapshot index <sn_idx> for
block index for which snapshot taken can be calculated. Remember in each block there are 16 snapshot thus 256 blocks between snapshots. Eventually:
block_index = sn_idx*256 + * 4096 (roughly)
This block_index can be converted to block_hash. Once we have block hash we can query delegators/stake state for the specific block.
from tezos-reward-distributor.
So this gives me snapshots I can access:
$ ./tezos-client rpc get /chains/main/blocks/head/context/raw/json/rolls/owner/snapshot
[ 7, 6, 5, 4, 3, 2, 1, 0 ]
Then I can query a specific (the current) cycle:
$ ./tezos-client rpc get /chains/main/blocks/head | jq -r '.metadata.level.cycle'
2
$ ./tezos-client rpc get /chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/2/
[ 0 ]
What does that 0 mean here?
If I look at mainnet, current cycle 51:
https://rpc.tezrpc.me/chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/51/
"[1]"
Fetching that:
$ ./tezos-client rpc get /chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/2/0/
[ 2403, 2147, 1891, 1635, 1379, 1123, 867, 611, 2659, 355, 99, 2402, 2146,
1890, 1634, 1378, 1122, 866, 610, 2658, 354, 98, 2401, 2145, 1889, 1633,
...
Fetching one of these:
$ ./tezos-client rpc get /chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/2/0/596/
"p2pk66EmFoQS6b2mYLvCrwjXs7XT1A2znX26HcT9YMiGsyCHyDvsLaF"
And that is?
from tezos-reward-distributor.
How long does
./tezos-client rpc get /chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/2/
take on your mainnet node?
from tezos-reward-distributor.
https://rpc.tezrpc.me/chains/main/blocks/head/context/raw/json/rolls/owner/snapshot/55/
Takes about 10 seconds
from tezos-reward-distributor.
The block-snapshot calculation is different on alphanet (-1) vs mainnet (-2)
PRESERVED_CYCLES=3
BLOCKS_IN_CYCLE=2048
(cycle - PRESERVED_CYCLES - 1) * BLOCKS_IN_CYCLE) + (snapShotQuery.RollSnapShot + 1) * 256
from tezos-reward-distributor.
Any idea why it is different? Reserved cycles parameter is already different in alpha and mainnet e.g. 2 vs 5.
from tezos-reward-distributor.
+1 add dependance on the node
from tezos-reward-distributor.
@amzid implemented this feature.
from tezos-reward-distributor.
Work of @amzid is merged. Now RPC based calculations are supported.
from tezos-reward-distributor.
Related Issues (20)
- Dry run command not reading correctly
- Batch payer class is unmanageable.
- exit status is always 0 even when TRD fails (in single-shot mode)
- Don't require signer to know about baker address
- Problem with using the new addresses as owner and founder. HOT 10
- Smoke tests are stuck in an infinite loop on the CI only HOT 1
- payouts in failed/backtracked transactions are marked as paid
- Signer auth HOT 2
- re-running failed operations with TzKT backend is so slow, it hangs HOT 2
- use `simulate_operation` instead of `run_operation` HOT 1
- TRD exiting with status code 1, even when it succeeds HOT 2
- Payment to KT always fails on first try, it goes through in a second attempt. HOT 1
- TzStats "offline_losses" is not working HOT 4
- -M 4 seems to be broken, wrong status for backtracked transactions and ctez vaults are no longer avoided
- payment error. Cycle 669 HOT 4
- Error when using on new v19.0 node version HOT 4
- When running with switch -P tzkt no validation of payments is done
- Error: Failed to get network configuration constants from a local node (http://127.0.0.1:8732)
- Warn instead of exit when new protocol live date is exceeded HOT 1
- Paris support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tezos-reward-distributor.