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

Fix qKesKesKeyExpiry to not always be null #4909

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Feb 22, 2023

Note that qKesKesKeyExpiry is only an estimate that is usually correct, but it could be wrong due to a hard fork that changes KES parameters.

The fix involves uses an unsafe query interpreter that ignores forecasting horizon. Therefore a new Unsafe newtype has been introduced to clearly show all the code that uses the unsafe query interpreter so that it doesn't accidentally get used where it shouldn't.

Resolves #4396

hoistEpochInfo (first (Text.pack . show) . runExcept)
$ Consensus.interpreterToEpochInfo (Consensus.unsafeExtendSafeZone interpreter)

newtype Unsafe a = Unsafe { unsafe :: a } deriving (Eq, Show)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this use of a newtype. I think Unsafe is a bit too scary/general of a name though. Perhaps AssumingNoUpcomingHardfork (or something like that)?

Copy link
Contributor

@Jimbo4350 Jimbo4350 Feb 24, 2023

Choose a reason for hiding this comment

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

What about newtype BeyondHorizonEpochInfo = BeyondHorizonEpochInfo (EpochInfo (Either Text))? And we can put a comment with a brief explanation behind the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've decided to replace the word Unsafe to Tentative because that captures the meaning I wanted to convey.


newtype Unsafe a = Unsafe { unsafe :: a } deriving (Eq, Show)

unsafeToEpochInfo :: EraHistory CardanoMode -> Unsafe (EpochInfo (Either Text))
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, I'd suggest naming this toEpochAssumingNoUpcomingHardFork or something like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

toBeyondHorizonEpochInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now toTentativeEpochInfo.

cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs Outdated Show resolved Hide resolved
@newhoggy newhoggy force-pushed the newhoggy/fix-qKesKesKeyExpiry branch 2 times, most recently from eacb364 to a7637c1 Compare March 3, 2023 12:51
@newhoggy newhoggy requested a review from nfrisby March 3, 2023 12:52
@newhoggy newhoggy force-pushed the newhoggy/fix-qKesKesKeyExpiry branch 2 times, most recently from 49d13e1 to 77d274f Compare March 7, 2023 05:08
-- | A value that is tentative or produces a tentative value if used. These values
-- are considered accurate only if some future event such as a hard fork does not
-- render them invalid.
newtype Tentative a = Tentative { tentative :: a } deriving (Eq, Show)
Copy link
Contributor

@Jimbo4350 Jimbo4350 Mar 7, 2023

Choose a reason for hiding this comment

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

What other values do we expect to be tentative besides EpochInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially anything derived from Tentative EpochInfo is a candidate.

@newhoggy newhoggy force-pushed the newhoggy/fix-qKesKesKeyExpiry branch from 77d274f to e5e4564 Compare March 29, 2023 00:24
-- tentative because it uses an interpreter that is extended past the horizon.
-- This interpreter will compute accurate values into the future as long as a
-- a hard fork does not happen in the intervening time. Those values are thus
-- "tentative" because they can change in the event of a hard fork.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify my understanding, they can change in the event of a hardfork occurring within the horizon?

Copy link
Contributor Author

@newhoggy newhoggy Mar 29, 2023

Choose a reason for hiding this comment

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

They can change in the event of a hardfork occurring after the horizon. Normally the interpreter refuses to give an answer beyond the horizon so we construct a different interpreter that ignores the horizon.

Values before the horizon still won't change.

However, because the type allows for values beyond the horizon to change, it is annotated as Tentative regardless of whether the value can change or not.

@newhoggy newhoggy added this pull request to the merge queue Mar 30, 2023
Merged via the queue into master with commit 541e7b9 Mar 30, 2023
@iohk-bors iohk-bors bot deleted the newhoggy/fix-qKesKesKeyExpiry branch March 30, 2023 02:19
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.

[BUG] - query kes-period-info returns null for qKesKesKeyExpiry metric
3 participants