Open sebeec opened 3 years ago
This should be the case. I can write an integration test around this to verify/fix.
@sebeec /baking_rights? rpc does not accept 'max_priority' as a parameter. You have to fetch all rights and filter manually.
The Tezos node rpc accepts a parameter "max_priority": https://tezos.gitlab.io/007/rpc.html#get-block-id-helpers-baking-rights.
When no parameter is provided then the max_priority is 64. If I only want to know priority 0 bakings, I will set this parameter to value '0'. When only querying 0 priority the RPC response is also much faster than querying all priorities up to 64.
However, the tezos go library allows to set a max_priority, but not priority 0 due to a mistake in the programming. If max_priority parameter in tezos go library is set to 0, then the Tezos rpc node is called without a "max_priority" parameter and thus defaults to 64.
@sebeec Interesting. A clear documentation issue as the CLI does not mention max_priority at all:
$ /opt/tezos_mainnet/tezos/tezos-client rpc list /chains/main/blocks/head/helpers/baking_rights
Available services:
- GET /chains/main/blocks/head/helpers/baking_rights
Retrieves the list of delegates allowed to bake a block.
By default, it
gives the best baking priorities for bakers that have at least one
opportunity below the 64th priority for the next block.
Parameters
`level` and `cycle` can be used to specify the (valid) level(s) in the
past or future at which the baking rights have to be returned.
Parameter `delegate` can be used to restrict the results to the given
delegates. If parameter `all` is set, all the baking opportunities for
each baker at each level are returned, instead of just the first
one.
Returns the list of baking slots. Also returns the minimal
timestamps that correspond to these slots. The timestamps are omitted
for levels in the past, and are only estimates for levels later that
the next block, based on the hypothesis that all predecessor blocks
were baked at the first priority.
But it certainly does work:
$ curl "http://127.0.0.1:18732/chains/main/blocks/head/helpers/baking_rights?delegate=tz1RMmSzPSWPSSaKU193Voh4PosWSZx1C7Hs&cycle=198&max_priority=0" | jq 'length'
31
$ curl "http://127.0.0.1:18732/chains/main/blocks/head/helpers/baking_rights?delegate=tz1RMmSzPSWPSSaKU193Voh4PosWSZx1C7Hs&cycle=198&max_priority=20" | jq 'length'
519
Can't get baking rights with 0 priority only:
https://github.com/goat-systems/go-tezos/blob/bdff4cf282eebbe51da452dc0d21bfb3f56c6012/rpc/delegate.go#L518
if "b.MaxPriority == 0" then the parameter "max_priority=0" should be appended to the request /../baking_rights?"