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

Implement leadership-schedule command for stake pool operators #3464

Merged
merged 7 commits into from Jan 11, 2022

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Dec 24, 2021

Resolves #1027

The leadership-schedule command can calculate a given stake pool's leadership schedule in the current epoch

Output:

> cardano-cli query leadership-schedule \
     --testnet-magic 42 \
     --genesis example/shelley/genesis.json \
     --stake-pool-id  pool12t0y7agkqct89pf00eeytkvfjlquv76tjy27duannan9w63ckxv \
     --vrf-signing-key-file example/node-pool1/shelley/vrf.skey
     --current
> 
     SlotNo                          UTC Time              
-------------------------------------------------------------
     4073                   2021-12-29 17:26:54.998001755 UTC
     4126                   2021-12-29 17:27:00.298001755 UTC
     4206                   2021-12-29 17:27:08.298001755 UTC
     4256                   2021-12-29 17:27:13.298001755 UTC
     4309                   2021-12-29 17:27:18.598001755 UTC
     4376                   2021-12-29 17:27:25.298001755 UTC
     4423                   2021-12-29 17:27:29.998001755 UTC
     4433                   2021-12-29 17:27:30.998001755 UTC
     

@Jimbo4350 Jimbo4350 force-pushed the jordan/cli-command-get-eligible-leadership-slots branch from 332b459 to 8ec6f66 Compare December 24, 2021 19:41
@Jimbo4350 Jimbo4350 changed the title cli command that returns eligible leadership slots Implement leadership-schedule command for stake pool operators Dec 24, 2021
@Jimbo4350 Jimbo4350 force-pushed the jordan/cli-command-get-eligible-leadership-slots branch 8 times, most recently from f9d7783 to 6a890e7 Compare December 30, 2021 15:35
@Jimbo4350 Jimbo4350 marked this pull request as ready for review December 30, 2021 15:37
@Jimbo4350 Jimbo4350 force-pushed the jordan/cli-command-get-eligible-leadership-slots branch 2 times, most recently from 9ebe265 to 4fcf994 Compare December 30, 2021 18:35
"Failed to successfully decode protocol state"

-- | Return the slots at which a particular stake pool operator is
-- expected to mint a block.
Copy link
Contributor

@newhoggy newhoggy Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document for which epoch(s) the function will report over.

Also similar functionality in cncli allows the operator to query for either the current epoch or the next epoch which helps them schedule downtime, so it would be nice if we can achieve something similar here.

& hoistMaybe (ShelleyQueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) anyE)

let pparamsQuery = QueryInEra eInMode $ QueryInShelleyBasedEra sbe QueryProtocolParameters
serDebugLedgerStateQuery = QueryInEra eInMode . QueryInShelleyBasedEra sbe $ QueryDebugLedgerState
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the ser prefix? Does it mean Shelly ERa?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serialised

@Jimbo4350 Jimbo4350 force-pushed the jordan/cli-command-get-eligible-leadership-slots branch 5 times, most recently from 20d10ff to c07e124 Compare January 6, 2022 20:51
@newhoggy
Copy link
Contributor

newhoggy commented Jan 8, 2022

This is the result of my testing:

$ rm -rf example; scripts/byron-to-alonzo/mkfiles.sh alonzo; bash -x example/run/all.sh

Wait a few minutes, then in another shell:

$ CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock cardano-cli query tip --testnet-magic 42
{
    "era": "Alonzo",
    "syncProgress": "100.00",
    "hash": "888adbca6d32b566e30decf5ef85fa0cdd967c616771dfe44f37251506df88c0",
    "epoch": 1,
    "slot": 714,
    "block": 50
}
$ pool_id=$(cardano-cli stake-pool id --cold-verification-key-file ./example/node-pool1/shelley/operator.vkey --output-format hex)
$ CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock cardano-cli query leadership-schedule --testnet-magic 42 --genesis example/shelley/genesis.json --signing-key-file example/node-pool1/shelley/vrf.skey --stake-pool-id "$pool_id" --current
     SlotNo                          UTC Time
-------------------------------------------------------------

Can you tell me where I'm going wrong?

@newhoggy
Copy link
Contributor

newhoggy commented Jan 8, 2022

This is what I get when trying the same on mainnet:

$ CARDANO_NODE_SOCKET_PATH=... cardano-cli query leadership-schedule --mainnet --genesis genesis-shelley.json --signing-key-file vrf.skey --stake-pool-id $(cardano-cli stake-pool id --cold-verification-key-file node.vkey --current
Command failed: query leadership-schedule  Error: Failed to successfully decode ledger state

For this, I queried against the node that comes with Daedalus. The node was fully synced when I did this.

This was the cardano-node version I used:

$ cardano-node-mainnet --version
cardano-node 1.30.1 - darwin-x86_64 - ghc-8.10
git rev 0fb43f4e3da8b225f4f86557aed90a183981a64f

@Jimbo4350
Copy link
Contributor Author

Jimbo4350 commented Jan 10, 2022

This is the result of my testing:

$ rm -rf example; scripts/byron-to-alonzo/mkfiles.sh alonzo; bash -x example/run/all.sh

Wait a few minutes, then in another shell:

$ CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock cardano-cli query tip --testnet-magic 42
{
    "era": "Alonzo",
    "syncProgress": "100.00",
    "hash": "888adbca6d32b566e30decf5ef85fa0cdd967c616771dfe44f37251506df88c0",
    "epoch": 1,
    "slot": 714,
    "block": 50
}
$ pool_id=$(cardano-cli stake-pool id --cold-verification-key-file ./example/node-pool1/shelley/operator.vkey --output-format hex)
$ CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock cardano-cli query leadership-schedule --testnet-magic 42 --genesis example/shelley/genesis.json --signing-key-file example/node-pool1/shelley/vrf.skey --stake-pool-id "$pool_id" --current
     SlotNo                          UTC Time
-------------------------------------------------------------

Can you tell me where I'm going wrong?

So you need have a stake pool running. I would use scripts/plutus/staking-example/register-stake-pool.sh and then try again. Also trying to predict the leadership schedule in the first epoch would involve getting the stake distribution from genesis. I didn't bother to do this as it would be additional work without much benefit to the user.

@Jimbo4350
Copy link
Contributor Author

This is what I get when trying the same on mainnet:

$ CARDANO_NODE_SOCKET_PATH=... cardano-cli query leadership-schedule --mainnet --genesis genesis-shelley.json --signing-key-file vrf.skey --stake-pool-id $(cardano-cli stake-pool id --cold-verification-key-file node.vkey --current
Command failed: query leadership-schedule  Error: Failed to successfully decode ledger state

For this, I queried against the node that comes with Daedalus. The node was fully synced when I did this.

This was the cardano-node version I used:

$ cardano-node-mainnet --version
cardano-node 1.30.1 - darwin-x86_64 - ghc-8.10
git rev 0fb43f4e3da8b225f4f86557aed90a183981a64f

I need to update the version mismatch error as it currently gives no information.

@Jimbo4350 Jimbo4350 force-pushed the jordan/cli-command-get-eligible-leadership-slots branch 4 times, most recently from b43fbce to c799dc3 Compare January 11, 2022 15:27
@disassembler
Copy link
Contributor

@newhoggy you should test CLI with node built from same branch. Ledger state format has changed from 1.30 to here.

Copy link
Contributor

@disassembler disassembler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a functionality perspective, this works great! Tested against a couple pools. Got leadership schedule for last epoch (using --current before the boundary) and then compared to db-sync slot leader from block table. 💯 from my perspective. So happy to have this done!

@Jimbo4350
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 11, 2022
3464: Implement leadership-schedule command for stake pool operators r=Jimbo4350 a=Jimbo4350

Resolves #1027

The `leadership-schedule` command can calculate a given stake pool's leadership schedule in the current epoch 

Output:
```
> cardano-cli query leadership-schedule \
     --testnet-magic 42 \
     --genesis example/shelley/genesis.json \
     --stake-pool-id  pool12t0y7agkqct89pf00eeytkvfjlquv76tjy27duannan9w63ckxv \
     --vrf-signing-key-file example/node-pool1/shelley/vrf.skey
     --current
> 
     SlotNo                          UTC Time              
-------------------------------------------------------------
     4073                   2021-12-29 17:26:54.998001755 UTC
     4126                   2021-12-29 17:27:00.298001755 UTC
     4206                   2021-12-29 17:27:08.298001755 UTC
     4256                   2021-12-29 17:27:13.298001755 UTC
     4309                   2021-12-29 17:27:18.598001755 UTC
     4376                   2021-12-29 17:27:25.298001755 UTC
     4423                   2021-12-29 17:27:29.998001755 UTC
     4433                   2021-12-29 17:27:30.998001755 UTC
     
```

Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
@Jimbo4350 Jimbo4350 force-pushed the jordan/cli-command-get-eligible-leadership-slots branch from c799dc3 to f4be627 Compare January 11, 2022 15:59
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 11, 2022

Canceled.

@Jimbo4350
Copy link
Contributor Author

bors r+

Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 11, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 54c3adf into master Jan 11, 2022
@iohk-bors iohk-bors bot deleted the jordan/cli-command-get-eligible-leadership-slots branch January 11, 2022 16:31
@Jimbo4350 Jimbo4350 restored the jordan/cli-command-get-eligible-leadership-slots branch January 11, 2022 16:52
@Jimbo4350 Jimbo4350 deleted the jordan/cli-command-get-eligible-leadership-slots branch January 13, 2022 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] - Add CLI command to display the leadership schedule
4 participants