Proto: consensus key
This MR implements the consensus key TZIP draft. See the corresponding Tezosagora post for more general discussion about the proposed feature. See also a complete test report of the feature.
This is a rebase of the work from @g.b.fefe in !5456 (closed). It is currently on top of !5961 (merged) (which is a code quality/refactoring work effort prompted by this feature, currently being worked on by @eugenz).
This MR:
- adds the ability for delegates to register a custom consensus key which will be used, with some delays, to sign block and endorsement on behalf of the delegate key,
- implements a new operation
Drain_delegateand the associated command intezos-client, that lets the consensus key sign Drain, a transfer of the manager's balance to its own account.
This MR does not implement the Drain toggle vote, which can optionally be added later.
The MR can be reviewed in five distinct parts:
- the first part amends the low-level storage and allows delegates to register a consensus key but do not make any usage of this consensus key yet. The following properties are enforced:
- there is only one active consensus key per delegate and per cycle,
- a consensus key update is delayed by
preserved_cycles + 1, - two delegates can not share the same consensus key in the a same cycle.
- the second part is the critical part which make use of the new consensus for signing consensus operation. This part is split in three steps:
- introduce a new type
Consensus_key.pkfor snapshotting both the delegate public key and the consensus public key in the sampler state. - propagate this new type through the consensus code, while preserving the current behavior: the delegate public key is still used for signing consensus operations.
- remove the delegate public key from
Consensus_key.pkand do actually use the consensus key for signing consensus operations.
- introduce a new type
- the third part add small improvements in RPC and baker logging
- the fourth part add integration test for the new consensus key,
- the last part adds
Drain_delegate.
1. The storage part
The low-level storage
-
Proto/Delegate: rename
pubkeyintomanager_pubkey: a minor renaming to avoid confusion between the two keys associated to a delegate. -
Proto/Delegate: add
Storage.Contracts.Consensus_keyintroduce the low-level storage for consensus keys and their delayed updates. It also introduces the associated moduleDelegate_consensus_keyand the associated testsuite. - Proto/Delegate: forbid two delegates with the same consensus key
A new manager operation and the associated client commands.
- Proto/Operation: add manager operation
Update_consensus_key - Proto/Client: add
tezos-client set consensus key for <delagate> to <pk> - Proto/Client: add
tezos-client register key <pkh> as delegate with consensus key <pk>
Misc: RPC and activation
- Proto/RPC: add an RPC for querying a delegate's consensus key
- Proto/Bootstrap: allow to register a consensus key for bootstrap accounts
2. The critical consensus part
Snapshot the consensus key in sampler state
-
Proto: make room for more ghosts in
Storage_functors.: a minor patch to allow storage migration forIndexed_subcontext. - Proto/Delegate: capture the consensus key in the sampler state
Propagate the consensus key where needed
- Proto/Delegate: propagate
Consensus_key.pk(part 1) - Proto/Delegate: propagate
Consensus_key.pk(part 2) - Proto/Delegate: propagate
Consensus_key.pk(part 3) - Proto/Delegate: propagate
Consensus_key.pk(part 4)
Do actually use the new consensus key
- Proto/Delegate: use consensus_key for consensus operations
- Proto/Delegate: remove the delegate's public_key from sampler state
3. The baker part
- Proto/RPC: allow to filter baking/endorsing rights by consensus key
- Proto/Baker: display consensus key and delegate in logs
4. The testing part
- Proto: add a minimal
teztscenario for consensus key
5. Drain_delegate
- Proto: add operation
Drain_delegate - Proto/Plugin: prioritize
Drain_delegateover any manager op - Proto/Plugin: filter out
Drain_delegatewithout enough fees - Proto/Client: add
tezos-client drain delegate <del> to <pkh> - Proto: add a minimal
teztscenario forDrain_delegate
Edited by Eugen Zalinescu