Skip to content

Instantly share code, notes, and snippets.

@nicolasochem
Last active Oct 11, 2022
Embed
What would you like to do?
consensus key test

Build

These tests are done with tezos-k8s.

First build the tezos container (below are instructions with minikube or podman, but ymmv):

Start minikube with podman minikube start

Load podman-remote env vars eval $(minikube podman-env)

In tezos Makefile, replace docker or @docker commands with podman-remote in 4 places.

Build docker container with make docker-image

The containers will be built and accessible with minikube.

Checkout a recent version of tezos-k8s (I am using 6.9.1).

Use the values.yaml file provided with this gist (see bottom).

Test environment

3 tezos nodes: 1 baking for 3 addresses using 3 signature schemes (tz1, tz2, tz3), the other set up for 2 consensus keys, but unitialized at boot. The last one set for 1 consensus key.

Very short block times (1 sec) and cycles length (32 blocks).

The chain starts with kathmandu and updates to lima after 2 cycles; this checks proper initialization of variables during migration.

Test CLI

  1. observed the following help in cli for register as delegate
  register key <mgr> as delegate with consensus key <key> [--fee <amount>]
  set consensus key for <mgr> to <key> [--fee <amount>] [-D --dry-run]
  1. At first, the first node bakes for baker-0 to baker-2 and the second node bakes baker-0-consensus and baker-1-consensus. But, there are no consensus keys configured yet. Configure one by opening a shell on baking-node-0 and typing:
~ $  tezos-client set consensus key for baker-0 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Estimated gas: 1000 units (will add 100 for safety)
Estimated storage: no bytes added
Operation successfully injected in the node.
Operation hash is 'opDGy97PWUnwhZpK3QmiP5i8TNnaV2UnsQGnMQqUjo7xhMjHtW6'
Waiting for the operation to be included...
Operation found in block: BLRpn1etKaCTG5F48Fq6g3XtMohVeXDUqnHV1eTNJZfAYxLTe5i (pass: 3, offset: 0)
This sequence of operations was run:
  Manager signed operations:
    From: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
    Fee to the baker: ꜩ0.000368
    Expected counter: 1
    Gas limit: 1100
    Storage limit: 0 bytes
    Balance updates:
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ0.000368
      payload fees(the block proposer) ....... +ꜩ0.000368
    Update_consensus_key:
      Public key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
      This consensus key update was successfully applied
      Consumed gas: 1000

The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
  octez-client wait for opDGy97PWUnwhZpK3QmiP5i8TNnaV2UnsQGnMQqUjo7xhMjHtW6 to be included --confirmations 1 --branch BL14PxcJFiNkwykGLNZGeehZ65NYxBcRWSJ6CX5WikSSdjnhR8u
and/or an external block explorer.

Then create accounts test and test2, send 6000 tez to test and try register key test as delegate with consensus key test2. It sent both operations in a batch:

tezos-client gen keys test
tezos-client transfer 6000 from baker-0 to test --burn-cap 0.06425
tezos-client gen keys test2
tezos-client -l register key test as delegate with consensus key test2
>>>>9: http://localhost:8732/chains/main/blocks/head/helpers/scripts/simulate_operation?successor_level=true  
  { "operation":                                                                                              
      { "branch": "BMVraevbF1D2GtYKUVpGPv1FY7XXiVfEKNSCxd95kGPK311sHHC",                                      
        "contents":                                                                                           
          [ { "kind": "reveal",                                                                               
              "source": "tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa", "fee": "0",                                   
              "counter": "3", "gas_limit": "1000", "storage_limit": "60000",                                 
              "public_key":                                                                                  
                "edpkvaJ7U4548jECffkAPxFqWDMaSVAirqvWoNvG4hWhQhmoLwdSJ7" },                                  
            { "kind": "delegation",                                                                          
              "source": "tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa", "fee": "0",                                  
              "counter": "4", "gas_limit": "1040000",                                                        
              "storage_limit": "60000",                                                                      
              "delegate": "tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa" },                                          
            { "kind": "update_consensus_key",                                                                
              "source": "tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa", "fee": "0",                                  
              "counter": "5", "gas_limit": "1040000",                                                        
              "storage_limit": "60000",                                                                      
              "pk": "edpktjBjgFamLi3BJXxXXE7ENpkUHvQ2CuZYiTcPQvSoAC814GrRMN" } ],                            
        "signature":                                                                                        
          "edsigtXomBKi5CTRf5cjATJWSyaRvhfYNHqSUGrn4SdbYRcGwQrUGjzEfQDTuqHhuA8b2d8NarZjz8TRf65WkpQmo423BtomS8Q" },    
    "chain_id": "NetXjefMQvF7Wkm" }     

Note that consensus key is unitialized and with zero balance. That's OK.

And the CLI output is OK:

  Manager signed operations:
    From: tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa
    Fee to the baker: ꜩ0.000357
    Expected counter: 3
    Gas limit: 1000
    Storage limit: 0 bytes
    Balance updates:
      tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa ... -ꜩ0.000357
      payload fees(the block proposer) ....... +ꜩ0.000357
    Revelation of manager public key:
      Contract: tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa
      Key: edpkvaJ7U4548jECffkAPxFqWDMaSVAirqvWoNvG4hWhQhmoLwdSJ7
      This revelation was successfully applied
      Consumed gas: 1000
  Manager signed operations:
    From: tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa
    Fee to the baker: ꜩ0.00025
    Expected counter: 4
    Gas limit: 1000
    Storage limit: 0 bytes
    Balance updates:
      tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa ... -ꜩ0.00025
      payload fees(the block proposer) ....... +ꜩ0.00025
    Delegation:
      Contract: tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa
      To: tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa
      This delegation was successfully applied
      Consumed gas: 1000
  Manager signed operations:
    From: tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa
    Fee to the baker: ꜩ0.000271
    Expected counter: 5
    Gas limit: 1100
    Storage limit: 0 bytes
    Balance updates:
      tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa ... -ꜩ0.000271
      payload fees(the block proposer) ....... +ꜩ0.000271
    Update_consensus_key:
      Public key hash: tz1YJ2UNsTbXBVK5CHD7Q8wVCpbPHKG1ZtUD
      This consensus key update was successfully applied
      Consumed gas: 1000

The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
  octez-client wait for ooMF2LE4Kx4is8HqbTwThFa7QetshC117msED6uw5SoJf121QBv to be included --confirmations 1 --branch BMVraevbF1D2GtYKUVpGPv1FY7XXiVfEKNSCxd95kGPK311sHHC
and/or an external block explorer.

Baking

3-4 cycles later after setting consensus key above, the output is visible on baking-node-1 baker output:

 Oct 10 22:43:55.196 - 015-PtLimaPt.baker.actions: injected preendorsement ontw8ZL7o2obJWXHWpJAuAokk6UX8jkR3uJK69fymvJCnobEVd4                                                                                    │
│ Oct 10 22:43:55.196 - 015-PtLimaPt.baker.actions:   for baker-0-consensus (tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx)                                                                                                 │
│ Oct 10 22:43:55.196 - 015-PtLimaPt.baker.actions:   on behalf of tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv                                                                                                            │
│ Oct 10 22:43:55.202 - 015-PtLimaPt.baker.actions: injected endorsement onqPAT1JqwvLramq5imWiixpwM5Rot1XuuoSpMXsaPUAQHDBosh for                                                                                   │
│ Oct 10 22:43:55.202 - 015-PtLimaPt.baker.actions:   baker-0-consensus (tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx)                                                                                                     │
│ Oct 10 22:43:55.202 - 015-PtLimaPt.baker.actions:   on behalf of tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv                                                                                                            │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker: reading per block vote file path:                                                                                                                                      │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker:   /etc/tezos/per-block-votes/PtLimaPt-per-block-votes.json                                                                                                             │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker: per block vote file found                                                                                                                                              │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker: per block vote file "JSON decoded"                                                                                                                                     │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker: reading liquidity baking toggle vote                                                                                                                                   │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker: liquidity baking toggle vote = pass                                                                                                                                    │
│ Oct 10 22:43:57.002 - 015-PtLimaPt.baker.actions: Voting pass for liquidity baking toggle vote                                                                                                                   │
│ Oct 10 22:43:57.063 - 015-PtLimaPt.baker.actions: block BLKREQYzuRJy1CrZdHg5DsRQ1A8dVuPksBqcsAJk1mTgsQCF4es at level 761, round                                                                                  │
│ Oct 10 22:43:57.063 - 015-PtLimaPt.baker.actions:   0 injected for baker-0-consensus (tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx)                                                                                      │
│ Oct 10 22:43:57.063 - 015-PtLimaPt.baker.actions:   on behalf of tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv                                                                                                            │
│ Oct 10 22:43:57.081 - 015-PtLimaPt.baker.transitions: received new head BLKREQYzuRJy1CrZdHg5DsRQ1A8dVuPksBqcsAJk1mTgsQCF4es at                                                                                   │
│ Oct 10 22:43:57.081 - 015-PtLimaPt.baker.transitions:   level 761, round 0                                                                                                                                       │
│ Oct 10 22:43:57.112 - 015-PtLimaPt.baker.actions: injected preendorsement oovpiG9BSTcBPSHiWWXKMqdZiDyGs84WsoYM4jtcpCaDqNEcx1Q                                                                                    │
│ Oct 10 22:43:57.112 - 015-PtLimaPt.baker.actions:   for baker-0-consensus (tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx)                                                                                                 │
│ Oct 10 22:43:57.112 - 015-PtLimaPt.baker.actions:   on behalf of tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv                                                                                                            │
│ Oct 10 22:43:57.309 - 015-PtLimaPt.baker.actions: injected endorsement ooCQqt4CUXLLhpgHvu3qUxFmDVhhhtkcHPmwVYUm6K2seGjDLLK for                                                                                   │
│ Oct 10 22:43:57.309 - 015-PtLimaPt.baker.actions:   baker-0-consensus (tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx)                                                                                                     │
│ Oct 10 22:43:57.309 - 015-PtLimaPt.baker.actions:   on behalf of tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv                                                                                                            │
│ Oct 10 22:43:59.176 - 015-PtLimaPt.baker.transitions: received new head BMRPg9qh4j29q6cyeEBDkB84L6uPCZvdx62SCzWd4HKnyy6KzKt at                                                                                   │
│ Oct 10 22:43:59.176 - 015-PtLimaPt.baker.transitions:   level 762, round 0                                                                                    

Indeed, the baker starts baking. The logs indicate on behalf of... and the delegate key is printed.

There are new fields in metadata for observing consensus keys of the block proposer and payload proposer:

~ $ curl -s http://localhost:8732/chains/main/blocks/780/metadata |jq .proposer
"tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
~ $ curl -s http://localhost:8732/chains/main/blocks/780/metadata |jq .proposer_consensus_key
"tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx"
~ $ curl -s http://localhost:8732/chains/main/blocks/780/metadata |jq .baker
"tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
~ $ curl -s http://localhost:8732/chains/main/blocks/780/metadata |jq .baker_consensus_key
"tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx"

Baker man page also explains that the consensus key alias should be passed:

Commands related to the baker daemon.:
  run with local node <node_data_path> [<baker>...] [-P --pidfile <filename>]
<snip>
    Launch the baker daemon.
    <node_data_path>: Path to the node data directory (e.g. $HOME/.tezos-node)
    <baker>: name of the delegate owning the endorsement/baking right or name of the consensus key signing on the delegate's behalf

Consensus key unicity

I verified that it's not possible to assign the same consensus key to 2 delegates. From baking-node-0:

~ $ tezos-client set consensus key for baker-1 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
This simulation failed:
  Manager signed operations:
    From: tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx
    Fee to the baker: ꜩ0
    Expected counter: 1
    Gas limit: 1040000
    Storage limit: 60000 bytes
    Update_consensus_key:
      Public key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
      This operation FAILED.

Error:
  The delegate consensus key is already used by another delegate

Revert to a unique key

I was able to run

tezos-client set consensus key for baker-0 to baker-0

And 3 cycles later, the baker was back to signing consensus messages with the delegate's key.

Set to already set consensus key

Fails as expected (simulation failure, nothing written on-chain) when setting the consensus key to the delegate key:

~ $  tezos-client set consensus key for baker-2 to baker-2
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
This simulation failed:
  Manager signed operations:
    From: tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz
    Fee to the baker: ꜩ0
    Expected counter: 1
    Gas limit: 1040000
    Storage limit: 60000 bytes
    Update_consensus_key:
      Public key hash: tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz
      This operation FAILED.

Error:
  Invalid key while updating a consensus key (already active since 71).

Also tried when delegate key != consensus key: same error, same output.

Set consensus key of non baker fails

Yes:

~ $ tezos-client set consensus key for baker-2-consensus to baker-2-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Error:
  Empty implicit contract (tz1XeAxFB7RophB2x7vD4ZYMAw5VRv78Yk8k)

Set consensus key to already active consensus key

OK:

~ $ tezos-client set consensus key for baker-0 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
This simulation failed:
  Manager signed operations:
    From: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
    Fee to the baker: ꜩ0
    Expected counter: 6
    Gas limit: 1040000
    Storage limit: 60000 bytes
    Update_consensus_key:
      Public key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
      This operation FAILED.

Error:
  Invalid key while updating a consensus key (already active since 149).
~ $ 

Set consensus key when not owning secret key of baker

Fails as expected:

~ $ tezos-client set consensus key for baker-0 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Error:
  Unknown secret key for tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv

Drain

There is a new CLI command:

  drain delegate <mgr> to <key> with <key> [-D --dry-run] [--verbose-signing]
    Drain all funds from a delegate.
    <mgr>: the delegate key
    <key>: the destination key
    <key>: the consensus key
    -D --dry-run: don't inject the operation, just display it
    --verbose-signing: display extra information before signing the operation
  drain delegate <mgr> to <key> [-D --dry-run] [--verbose-signing]
    Drain all funds from a delegate.
    <mgr>: the delegate key
    <key>: the consensus key
    -D --dry-run: don't inject the operation, just display it
    --verbose-signing: display extra information before signing the operation

Tried it:

 $ tezos-client get balance for baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

4000000 ꜩ
~ $ tezos-client get balance for baker-0
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

3612645.904157 ꜩ
~ $ tezos-client drain delegate baker-0 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Operation successfully injected in the node.
Operation hash is 'opapHCH4B1zEZV2WHnxRqZrwinaGDcgMJAn5tkXUaVDozs7Ljvn'
Waiting for the operation to be included...
Operation found in block: BKmVXHFE79pCXNaJxnEYzxXHYAzJ9yq1NiyA5eLZhcXjzQqKm2y (pass: 2, offset: 0)
This sequence of operations was run:
  Drain delegate:
    Consensus key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
    Delegate: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
    Destination: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
    Balance updates:
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ3576539.244362
      tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx ... +ꜩ3576539.244362
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ36126.659033
      tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx ... +ꜩ36126.659033

The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
  octez-client wait for opapHCH4B1zEZV2WHnxRqZrwinaGDcgMJAn5tkXUaVDozs7Ljvn to be included --confirmations 1 --branch BL4jhzzKjZ2uXbDdoVXszV1HyX1mUzVmWR46DuGvvZWpUnUhW5g
and/or an external block explorer.
~ $ tezos-client get balance for baker-0
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

146.524578 ꜩ
~ $ tezos-client get balance for baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

7576704.35044 ꜩ

It drained, and it gave 1% of the public balance to the baker.

When 1% of the public balance is less than 1 tez, it is giving 1 tez:

~ $ tezos-client drain delegate baker-0 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Operation successfully injected in the node.
Operation hash is 'opapxZke9egtvt2uyQRwkGGwFByGfEjzHYcAb5Gd96h3Kdk4UNt'
Waiting for the operation to be included...
Operation found in block: BL3Kw6saTMPUDSRiyj7Loc2ssBYrc4Ygj3wHexdmXGH1HEFTMwE (pass: 2, offset: 0)
This sequence of operations was run:
  Drain delegate:
    Consensus key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
    Delegate: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
    Destination: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
    Balance updates:
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ14.164956
      tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx ... +ꜩ14.164956
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ1
      tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz ... +ꜩ1

The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
  octez-client wait for opapxZke9egtvt2uyQRwkGGwFByGfEjzHYcAb5Gd96h3Kdk4UNt to be included --confirmations 1 --branch BMHudmUse9x1ht5won2r6DGeee5SGSPzcHEzkYnnj6rVLETXd7a
and/or an external block explorer.

Special case: drain when the baker is also the delegate being drained. It works:

 $ tezos-client drain delegate baker-0 to baker-0-consensus                                                                                                                         
Warning:                                                                                                                                                                             
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now                                                                               
  deprecated, and it will be removed in a future release. Please update                                                                                                              
  your scripts to use the new name.                                                                                                                                                  
                                                                                                                                                                                     
Warning:                                                                                                                                                                             
                                                                                                                                                                                     
                 This is NOT the Tezos Mainnet.                                                                                                                                      
                                                                                                                                                                                     
           Do NOT use your fundraiser keys on this network.                                                                                                                          
                                                                                                                                                                                     
Node is bootstrapped.                                                                                                                                                                
Operation successfully injected in the node.                                                                                                                                         
Operation hash is 'opCGHnDat259FbUHsP6yRMjewx9Qu6vx6Ld4viy1i2YNgacsstE'                                                                                                              
Waiting for the operation to be included...                                                                                                                                          
Operation found in block: BLLtforEZqHN2PdBeb6Q5SQKrAYgKrzje6KbKukqZwo6irb4g1u (pass: 2, offset: 0)                                                                                   
This sequence of operations was run:                                                                                                                                                 
  Drain delegate:                                                                                                                                                                    
    Consensus key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx                                                                                                                         
    Delegate: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv                                                                                                                                   
    Destination: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx                                                                                                                                
    Balance updates:                                                                                                                                                                 
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ6930000                                                                                                                             
      tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx ... +ꜩ6930000                                                                                                                             
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ70000                                                                                                                               
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... +ꜩ70000                                                                                                                               
                                                                                                                                                                                     
The operation has only been included 0 blocks ago.                                                                                                                                   
We recommend to wait more.                                                                                                                                                           
Use command                                                                                                                                                                          
  octez-client wait for opCGHnDat259FbUHsP6yRMjewx9Qu6vx6Ld4viy1i2YNgacsstE to be included --confirmations 1 --branch BMbP378egF8URU4Dv121AoHEeoDVMyjmdiwcuGewY44MEjz84P2         

** Drain to third address**

There is a new CLI.

drain delegate <mgr> to <key> with <key> [-D --dry-run] [--verbose-signing]
  Drain all funds from a delegate.
  <mgr>: the delegate key
  <key>: the detination key
  <key>: the consensus key
  -D --dry-run: don't inject the operation, just display it
  --verbose-signing: display extra information before signing the operation

Here is the result:

~ $ tezos-client drain delegate baker-0 to baker-1-consensus with baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Operation successfully injected in the node.
Operation hash is 'oo1pGVewSb6QYbBiBWVEGTbGaogGnj66UsL3nwB2vw6gT3jYBrc'
Waiting for the operation to be included...
Operation found in block: BLyCRbmhuv43QQELyCqnEa7Zo27UMbM2NbA6mhJTN8KLUE2wAgM (pass: 2, offset: 0)
This sequence of operations was run:
  Drain delegate:
    Consensus key hash: tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx
    Delegate: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
    Destination: tz3T2DJPrdCB4AvTgeAPHb1FpfYvt7foAF45 (allocated)
    Balance updates:
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ0.06425
      storage fees ........................... +ꜩ0.06425
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ664255.216818
      tz3T2DJPrdCB4AvTgeAPHb1FpfYvt7foAF45 ... +ꜩ664255.216818
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ6709.648654
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... +ꜩ6709.648654

The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
  octez-client wait for oo1pGVewSb6QYbBiBWVEGTbGaogGnj66UsL3nwB2vw6gT3jYBrc to be included --confirmations 1 --branch BMeLg522xqJXQD4wV7dXbSniiwhGaAtkWU3JpmLZn66EeLvCX7u
and/or an external block explorer.

We also see that allocation works, when third account is not funded

Drain to wrong account

As expected:

~ $ octez-client drain delegate baker-0 to baker-1-consensus 
Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Error:
  Consensus key tz3T2DJPrdCB4AvTgeAPHb1FpfYvt7foAF45 is not the active consensus key for delegate tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv. The active consensus key is tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx.

Drain operation in the block

Looks good:

   [            
      {                              
        "protocol": "PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW",
        "chain_id": "NetXjefMQvF7Wkm",      
        "hash": "ooEEVFrktPDBMP74JuXHZXNJgmYZVqHhvXY5qTrPEqky3pyVDJ3",                                                                                         
        "branch": "BLbaKendcj2nqnLqYrU7TrqtyG42pwuEpTQzPGecve1RY4ejLS4",                                                                                       
        "contents": [
          {                          
            "kind": "drain_delegate",                                                     
            "consensus_key": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx",                                                                                           
            "delegate": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv",                                                                                                
            "destination": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx",                                                                                             
            "metadata": {
              "balance_updates": [   
                {                                                                         
                  "kind": "contract",     
                  "contract": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv",                                                                                          
                  "change": "-1220954446333",
                  "origin": "block"
                },                                                             
                {                                                              
                  "kind": "contract",                                          
                  "contract": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx",                                                                                          
                  "change": "1220954446333",                                   
                  "origin": "block"                                            
                },                                                             
                {                                                              
                  "kind": "contract",                                          
                  "contract": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv",                                                                                          
                  "change": "-12332873195",                                    
                  "origin": "block"                                            
                },                                                             
                {                                                              
                  "kind": "contract",                                          
                  "contract": "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz",                                                                                          
                  "change": "12332873195",                                     
                  "origin": "block"                                            
                }                                                              
              ]                                                                
            }                                                                  
          }                                                                    
        ],                                                                     
        "signature": "sigQtfLiLv2eeN9zencayEAai4omCJmLra8CyuChUoNRLCFkfZrY5xCGULEQYjiGPCzYZUT8APRJENYZ4enRoYrirurBYMCm"      

More drain testing

Drain when there is nothing to drain

It fails.

~ $ tezos-client drain delegate baker-0 to baker-0-consensus
Warning:
  The executable with name tezos-client has been renamed to octez-client. The name tezos-client is now
  deprecated, and it will be removed in a future release. Please update
  your scripts to use the new name.

Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Error:
  Cannot drain delegate from tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv to tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx: not enough funds for the drain fees in the delegate account (minimum balance required: 1).

Drain when consensus key == delegate key

It fails.

~ $ octez-client drain delegate baker-0 to baker-0
Warning:
  
                 This is NOT the Tezos Mainnet.
  
           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.
Error:
  Consensus key tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv is not the active consensus key for delegate tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv. The active consensus key is tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx.

Concurrent drain and withdraw

In baking-node-1, run the following:

# Note - this assumes a fresh helm deployment
tezos-client gen keys test
# do transfers to make sure every address is revealed
tezos-client import secret key baker-0 unencrypted:edsk4X99zYzn5TLCbARNqggTxaCpJTma6k5j9VTXddwCktytV2q24R -f
tezos-client transfer 1 from baker-0 to test --burn-cap 0.1
tezos-client transfer 0.5 from test to baker-0
tezos-client transfer 1 from baker-0-consensus to baker-0
sudo apk add python3 curl jq
# import secret key of baker-0 to baking-node-1
# set consensus key
tezos-client set consensus key for baker-0 to baker-0-consensus
# wait 3 cycles

Then we issue two concurrent commands to drain the free balance of baker-0 to baker-0-consensus and transfer it to test at the same time.

 balance=$(python3 -c "print(round($(tezos-client get balance for baker-0 2>/dev/null | sed 's/ ꜩ//') - 0.5,6))") && echo $balance && tezos-client transfer $balance from baker-0 to test --fee 0.5 & tezos-client drain delegate baker-0 to baker-0-consensus

Drain is executed immediately and the transfer is put in branch_delayed. After a few blocks, it is included and failing in the block because of low balance. I tried in a topology with just one node baking every block, and also in a topology with a third node that was not related to baker-0 and baker-0-consensus to prove both operations got propagated.

~ $ curl 'localhost:8732/chains/main/mempool/pending_operations?applied=false&outdated=false' | jq                                                                                                                  
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                                                                                                                     
                                 Dload  Upload   Total   Spent    Left  Speed                                                                                                                                       
100   886  100   886    0     0   271k      0 --:--:-- --:--:-- --:--:--  432k                                                                                                                                      
{                                                                                                                                                                                                                   
  "applied": [],                                                                                                                                                                                                    
  "refused": [],                                                                                                                                                                                                    
  "outdated": [],                                                                                                                                                                                                   
  "branch_refused": [],                                                                                                                                                                                             
  "branch_delayed": [                                                                                                                                                                                               
    [                                                                                                                                                                                                               
      "onmVACz1w8xabhXgxVqqqtUY8Q4Ck2ybjzoMV4d2KCfrutcEL9x",                                                                                                                                                        
      {                                                                                                                                                                                                             
        "protocol": "PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW",                                                                                                                                          
        "branch": "BKoyPvFuX3p9Eoy8isNTExEVqtoR1QVqYFLTCkYZ2BwANcZTfio",                                                                                                                                            
        "contents": [                                                                                                                                                                                               
          {                                                                                                                                                                                                         
            "kind": "transaction",                                                                                                                                                                                  
            "source": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv",                                                                                                                                                       
            "fee": "500000",                                                                                                                                                                                        
            "counter": "11",                                                                                                                                                                                        
            "gas_limit": "1001",                                                                                                                                                                                    
            "storage_limit": "0",                    
            "amount": "36618713019",                 
            "destination": "tz1ZZwSyEV5hLPSbQgaZCmMUVSuReZWF8AdR"                                         
          }                                          
        ],                                           
        "signature": "siggajgkHGZnbKG2NNp33vBrSGNYtUPjpEzP96iCDY4VCi6aMTnfcDFsrJt3ffW1k3Csp3ysGe2pUMwin56juaT9BcADUHCC",                                                                                            
        "error": [                                   
          {                                          
            "kind": "temporary",                     
            "id": "proto.015-PtLimaPt.contract.balance_too_low",                                          
            "contract": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv",                                           
            "balance": "0",                          
            "amount": "500000"                       
          },                                         
          {                                          
            "kind": "temporary",                     
            "id": "proto.015-PtLimaPt.tez.subtraction_underflow",                                         
            "amounts": [                             
              "0",                                   
              "500000"                               
            ]                                        
          }                                          
        ]                                            
      }                                              
    ]                                                
  ],                                                 
  "unprocessed": []                                  

~ $ Operation found in block: BKzu3W6a2UkF2NThZv67kQzRWWoyfwLrLc3ZGN9CgX2oLYCbHaD (pass: 3, offset: 0)
This sequence of operations was run:
  Manager signed operations:
    From: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
    Fee to the baker: ꜩ0.5
    Expected counter: 11
    Gas limit: 1001
    Storage limit: 0 bytes
    Balance updates:
      tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv ... -ꜩ0.5
      payload fees(the block proposer) ....... +ꜩ0.5
    Transaction:
      Amount: ꜩ36618.713019
      From: tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv
      To: tz1ZZwSyEV5hLPSbQgaZCmMUVSuReZWF8AdR
      This operation FAILED.

Balance of contract tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv too low (1.051351) to spend 36618.713019
Underflowing subtraction of 1.051351 tez and 36618.713019 tez
Fatal error:
  transfer simulation failed

[1]+  Done(1)                     && echo ${balance} && tezos-client transfer ${balance} from baker-0 to test --fee 0.5

RPC tests

context/delegates shows only delegate keys, not consensus keys, as expected:

~ $ curl -s http://localhost:8732/chains/main/blocks/head/context/delegates | jq
[
  "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz",
  "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
  "tz1djaW23ZSzait1uZfrNCbkcTw8quX5DfDa",
  "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
]

Query per delegate shows the consensus key hash:

~ $ curl -s http://localhost:8732/chains/main/blocks/head/context/delegates/tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz | jq
{
  "full_balance": "4125338236918",
  "current_frozen_deposits": "412503990301",
  "frozen_deposits": "412503990301",
  "staking_balance": "4125338236918",
  "delegated_contracts": [
    "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz"
  ],
  "delegated_balance": "0",
  "deactivated": false,
  "grace_period": 183,
  "voting_power": "4124879659110",
  "remaining_proposals": 20,
  "active_consensus_key": "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz"
}

The consensus key is here.

And for a delegate that has its consensus key set to itself, it shows the same key as expected:

~ $ curl -s http://localhost:8732/chains/main/blocks/head/context/delegates/tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx | jq .active_consensus_key
"tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
~ $ curl -s localhost:8732/chains/main/blocks/head/helpers/baking_rights?cycle=189  | jq                                                                                                                            
[                                                                                                                                                                                                                   
  {                                                                                                                                                                                                                 
    "level": 3025,                                                                                                                                                                                                  
    "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",                                                                                                                                                             
    "round": 0,                                                                                                                                                                                                     
    "estimated_time": "2022-10-10T23:59:25Z",                                                                                                                                                                       
    "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"                                                                                                                                                         
  },                                                                                                                                                                                                                
  {                                                                                                                                                                                                                 
    "level": 3025,                                                                                                                                                                                                  
    "delegate": "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz",                                                                                                                                                             
    "round": 1,                                                                                                                                                                                                     
    "estimated_time": "2022-10-10T23:59:27Z",                                                                                                                                                                       
    "consensus_key": "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz"                                                                                                                                                         
  },                                                                                                                                                                                                                
  {                                                                                                                                                                                                                 
    "level": 3026,                                                                                                                                                                                                  
    "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
    "round": 0,
    "estimated_time": "2022-10-10T23:59:27Z",
    "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
  },

And I can query by consensus key:

 $ curl -s 'localhost:8732/chains/main/blocks/head/helpers/baking_rights?cycle=191&consensus_key=tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx'  | jq                                                                       
[                                                                                                                                                                                                                   
  {                                                                                                                                                                                                                 
    "level": 3057,                                                                                                                                                                                                  
    "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",                                                                                                                                                             
    "round": 7,                                                                                                                                                                                                     
    "estimated_time": "2022-10-11T00:01:25Z",                                                                                                                                                                       
    "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"                                                                                                                                                         
  },                                                                                                                                                                                                                
  {                                                                                                                                                                                                                 
    "level": 3058,                                                                                                                                                                                                  
    "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",                                                                                                                                                             
    "round": 0,                                                                                                                                                                                                     
    "estimated_time": "2022-10-11T00:00:31Z",                                                                                                                                                                       
    "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"                                                                                                                                                         
  },                                                                                                                                                                                                                
  {                                                                                                                                                                                                                 
    "level": 3059,                                                                                                                                                                                                  
    "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",                                                                                                                                                             
    "round": 4,                                                                                                                                                                                                     
    "estimated_time": "2022-10-11T00:00:53Z",                                                                                                                                                                       
    "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"                                                                                                                                                         
  },                                                                                                    

Same for endorsing rights:

 $ curl -s localhost:8732/chains/main/blocks/head/helpers/endorsing_rights?cycle=192  | jq | head -30
[
  {
    "level": 3073,
    "delegates": [
      {
        "delegate": "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz",
        "first_slot": 5,
        "endorsing_power": 3408,
        "consensus_key": "tz2KbFzJa32HcHs5AKNxHjDqf5ws8fKnmwtz"
      },
      {
        "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
        "first_slot": 0,
        "endorsing_power": 3592,
        "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
      }
    ],
    "estimated_time": "2022-10-11T00:01:01Z"
  },
  {
    "level": 3074,
    "delegates": [
      {
        "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
        "first_slot": 1,
        "endorsing_power": 3484,
        "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
      },

I can query endorsing rights as well by consensus key:

~ $ curl -s 'localhost:8732/chains/main/blocks/head/helpers/endorsing_rights?cycle=191&consensus_key=tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx'  | jq | head -30
[
  {
    "level": 3057,
    "delegates": [
      {
        "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
        "first_slot": 7,
        "endorsing_power": 3492,
        "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
      }
    ],
    "estimated_time": "2022-10-11T00:00:29Z"
  },
  {
    "level": 3058,
    "delegates": [
      {
        "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
        "first_slot": 0,
        "endorsing_power": 3541,
        "consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
      }
    ],
    "estimated_time": "2022-10-11T00:00:31Z"
  },
  {
    "level": 3059,
    "delegates": [
      {
        "delegate": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx",
~ $ 

Pending

After setting a consensus key, it is visible as pending:

~ $  curl -s http://localhost:8732/chains/main/blocks/head/context/delegates/tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv | jq
{
  "full_balance": "4094333349",
  "current_frozen_deposits": "0",
  "frozen_deposits": "0",
  "staking_balance": "4094333349",
  "delegated_contracts": [
    "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
  ],
  "delegated_balance": "0",
  "deactivated": true,
  "grace_period": 180,
  "active_consensus_key": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx",
  "pending_consensus_keys": [
    {
      "cycle": 197,
      "pkh": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
    }
  ]
}

It is possible to have several pending consensus keys:

 $  curl -s http://localhost:8732/chains/main/blocks/head/context/delegates/tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv | jq
{
  "full_balance": "4094332981",
  "current_frozen_deposits": "0",
  "frozen_deposits": "0",
  "staking_balance": "4094332981",
  "delegated_contracts": [
    "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
  ],
  "delegated_balance": "0",
  "deactivated": true,
  "grace_period": 180,
  "active_consensus_key": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx",
  "pending_consensus_keys": [
    {
      "cycle": 197,
      "pkh": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
    },
    {
      "cycle": 199,
      "pkh": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx"
    }
  ]
}

Note: when setting a consensus key, then setting it again to its previous pending value, the pending field is still present, which has no effect:

~ $  curl -s http://localhost:8732/chains/main/blocks/head/context/delegates/tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv | jq
{
  "full_balance": "4094331879",
  "current_frozen_deposits": "0",
  "frozen_deposits": "0",
  "staking_balance": "4094331879",
  "delegated_contracts": [
    "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
  ],
  "delegated_balance": "0",
  "deactivated": true,
  "grace_period": 180,
  "active_consensus_key": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv",
  "pending_consensus_keys": [
    {
      "cycle": 199,
      "pkh": "tz2Jn36ZVn99RqqJZZ2ckLrdZ9XJVQCARxJx"
    },
    {
      "cycle": 200,
      "pkh": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
    },
    {
      "cycle": 201,
      "pkh": "tz1TAFTxbfhdxmMbQcoVPDekr5rqPmoREncv"
    }
  ]
}

Verify that change takes effect in PRESERVED_CYCLES + 1

Print current cycle and change consensus key:

~ $ curl -s localhost:8732/chains/main/blocks/head/metadata | jq .level_info.cycle && tezos-client set consensus key for baker-1 to baker-1
367
Warning:

                 This is NOT the Tezos Mainnet.

           Do NOT use your fundraiser keys on this network.

Node is bootstrapped.

Check pending consensus key

~ $ curl localhost:8732/chains/main/blocks/head/context/delegates/tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx  | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   446  100   446    0     0  51035      0 --:--:-- --:--:-- --:--:-- 55750
{
  "full_balance": "4079198145401",
  "current_frozen_deposits": "407901147949",
  "frozen_deposits": "407901147949",
  "staking_balance": "4079198145401",
  "delegated_contracts": [
    "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
  ],
  "delegated_balance": "0",
  "deactivated": false,
  "grace_period": 372,
  "voting_power": "4078991480259",
  "active_consensus_key": "tz3T2DJPrdCB4AvTgeAPHb1FpfYvt7foAF45",
  "pending_consensus_keys": [
    {
      "cycle": 371,
      "pkh": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
    }
  ]
}

Change pushed during cycle 367 will be effective at cycle 371. On our private test network, PRESERVED_CYCLES=3 so it works as expected.

At cycle 372 check again. Indeed, the change has been applied:

~ $ curl -s localhost:8732/chains/main/blocks/head/metadata | jq .level_info.cycle
372
~ $ curl localhost:8732/chains/main/blocks/head/context/delegates/tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx  | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   360  100   360    0     0   170k      0 --:--:-- --:--:-- --:--:--  351k
{
  "full_balance": "4080025067397",
  "current_frozen_deposits": "407983839863",
  "frozen_deposits": "407983839863",
  "staking_balance": "4080025067397",
  "delegated_contracts": [
    "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
  ],
  "delegated_balance": "0",
  "deactivated": false,
  "grace_period": 377,
  "voting_power": "4078991480259",
  "active_consensus_key": "tz3ZJEBEPEkG1av8yykQC4mp6uieU3ghjdfx"
}
counts:
baker-0:
bootstrap_balance: '4000000000000'
is_bootstrap_baker_account: true
key: edsk4X99zYzn5TLCbARNqggTxaCpJTma6k5j9VTXddwCktytV2q24R
baker-1:
bootstrap_balance: '4000000000000'
is_bootstrap_baker_account: true
key: p2sk3AGwvKpXmK2nj5PNR8E4mSVy22daMo3tYM36jqUAnrrwu968ZQ
baker-2:
bootstrap_balance: '4000000000000'
is_bootstrap_baker_account: true
key: spsk27obC8bnjSAgzzVbTFBftTFvqw79CfMBmSm7HU4DeRKevrffxq
baker-0-consensus:
bootstrap_balance: '4000000000000'
is_bootstrap_baker_account: false
key: spsk2qnbLv55GQcU2bvtU7TZVqbDeGcUzXxsEo19QQ6nMtRc7b13rn
baker-1-consensus:
bootstrap_balance: '0'
is_bootstrap_baker_account: false
key: p2sk3YaQojXBXPLLbd2yjWjp6mSpPPiiiaVCNxsfTNsD1fiFt6PkA4
baker-2-consensus:
bootstrap_balance: '0'
is_bootstrap_baker_account: false
key: edsk4Nzk9UFDHgfE5zR5mHHgYcEHvj6UzFHx3MmcN3oNiTVvzMby4Y
activation:
protocol_hash: "PtKathmankSpLLDALzWw7CGD2j2MtyveTwboEYokqUCP4a1LxMg"
protocol_parameters:
preserved_cycles: 3
blocks_per_cycle: 16
blocks_per_commitment: 8
blocks_per_stake_snapshot: 8
cycles_per_voting_period: 2
hard_gas_limit_per_operation: '1040000'
hard_gas_limit_per_block: '5200000'
proof_of_work_threshold: '-1'
tokens_per_roll: '8000000000'
seed_nonce_revelation_tip: '125000'
baking_reward_fixed_portion: '10000000'
baking_reward_bonus_per_slot: '4286'
endorsing_reward_per_slot: '2857'
hard_storage_limit_per_operation: '60000'
origination_size: 257
cost_per_byte: '250'
quorum_max: 7000
quorum_min: 2000
min_proposal_quorum: 500
liquidity_baking_subsidy: '2500000'
liquidity_baking_sunset_level: 10000000
liquidity_baking_toggle_ema_threshold: 100000
max_operations_time_to_live: 120
minimal_block_delay: "2"
delay_increment_per_round: "2"
consensus_committee_size: 7000
consensus_threshold: 4667
minimal_participation_ratio:
numerator: 2
denominator: 3
max_slashing_period: 2
frozen_deposits_percentage: 10
double_baking_punishment: "640000000"
ratio_of_frozen_deposits_slashed_per_double_endorsement:
numerator: 1
denominator: 2
cache_script_size: 100000000
cache_stake_distribution_cycles: 8
cache_sampler_state_cycles: 8
nonce_revelation_threshold: 4
vdf_difficulty: '10000'
tx_rollup_enable: true
tx_rollup_origination_size: 4000
tx_rollup_hard_size_limit_per_inbox: 500000
tx_rollup_hard_size_limit_per_message: 5000
tx_rollup_commitment_bond: "10000000000"
tx_rollup_finality_period: 10
tx_rollup_max_inboxes_count: 15
tx_rollup_withdraw_period: 10
tx_rollup_max_messages_per_inbox: 1010
tx_rollup_max_commitments_count: 30
tx_rollup_cost_per_byte_ema_factor: 120
tx_rollup_max_withdrawals_per_batch: 15
tx_rollup_max_ticket_payload_size: 2048
tx_rollup_rejection_max_proof_size: 30000
tx_rollup_sunset_level: 10000000
dal_parametric:
feature_enable: true
number_of_slots: 256
number_of_shards: 2048
endorsement_lag: 2
availability_threshold: 50
slot_size: 1048576
redundancy_factor: 16
page_size: 4096
sc_rollup_enable: true
sc_rollup_origination_size: 6314
sc_rollup_challenge_window_in_blocks: 40
sc_rollup_max_number_of_messages_per_commitment_period: 32765
sc_rollup_stake_amount: "32000000"
sc_rollup_commitment_period_in_blocks: 20
sc_rollup_max_lookahead_in_blocks: 30000
sc_rollup_max_active_outbox_levels: 20160
sc_rollup_max_outbox_messages_per_level: 100
sc_rollup_number_of_sections_in_dissection: 32
sc_rollup_timeout_period_in_blocks: 500
sc_rollup_max_number_of_cemented_commitments: 5
zk_rollup_enable: true
zk_rollup_origination_size: 4000
zk_rollup_min_pending_to_process: 10
archive_tarball_url: null
bootstrap_peers: []
expected_proof_of_work: 0
full_snapshot_url: null
tezos_k8s_images:
utils: oxheadalpha/tezos-k8s-utils:6.9.1
images:
#octez: localhost/tezos:latest
octez: tezos/tezos:master_ff82b221_20221010174757
is_invitation: false
node_config_network:
activation_account_name: baker-0
chain_name: nico
genesis:
block: BL3YCVQat6LT58pPqksa1vRE5ux8MgSHEjVnXKT1DgXXeznQWeP
protocol: Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P
timestamp: '2022-02-18T00:46:30.511911+00:00'
user_activated_upgrades:
- level: 32
replacement_protocol: "PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW"
nodes:
baking-node:
instances:
- bake_using_accounts:
- baker-0
- baker-1
- baker-2
config:
shell:
history_mode: archive
is_bootstrap_node: true
- bake_using_accounts:
- baker-0-consensus
- baker-1-consensus
config:
shell:
history_mode: archive
is_bootstrap_node: true
# identity:
# peer_id: idtHfozBsuCyYFrAhSu9MnDzcj4kHC
# public_key: 04ace2cd862bcd8f3d5da8f768f757fe79b43b859f40fa012942844a42bfc216
# secret_key: 51007841a2ffb943a9de807773149fe395a685eaf84fcd9a68e5d20a2114a5dd
# proof_of_work_stamp: 6482e775ecf93ac9cf6c9a3f86b873bfb5ce2c6997a104ec
- bake_using_accounts:
- baker-2-consensus
config:
shell:
history_mode: archive
is_bootstrap_node: true
runs:
- octez_node
- baker
storage_size: 15Gi
rolling-node: null
rolling_snapshot_url: null
rolling_tarball_url: null
should_generate_unsafe_deterministic_data: false
zerotier_config:
zerotier_network: null
zerotier_token: null
protocols:
- command: PtLimaPt
vote:
liquidity_baking_toggle_vote: "pass"
- command: PtKathma
vote:
liquidity_baking_toggle_vote: "pass"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment