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

Make STS rules above UTXO era-independent. #1922

Merged
merged 2 commits into from
Oct 20, 2020
Merged

Make STS rules above UTXO era-independent. #1922

merged 2 commits into from
Oct 20, 2020

Conversation

nc6
Copy link
Contributor

@nc6 nc6 commented Oct 19, 2020

Honestly it's embarassing that I failed to notice that this worked. We
carry a few more constraints in the STS instances and Embed instances.
But the payoff is that we only have to override the specific rules we
want to change in each era, and not re-plumb everything.

Obviously this means that, in the future, if we make a change in a
different rule then we have to go back and turn the era-independent one
into an era-dependent version (and add instances for all intermediate
eras). But still, this feels like a definite improvement.

Copy link
Contributor

@mrBliss mrBliss left a comment

Choose a reason for hiding this comment

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

Great! I'll try to update the consensus integration to see the full effect.

@@ -108,9 +113,6 @@ applyTxs ::
forall era m.
( STS (LEDGERS era),
BaseM (LEDGERS era) ~ ShelleyBase,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
BaseM (LEDGERS era) ~ ShelleyBase,

We can remove the line above, it compiles for me without it.

Or am I missing something? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, interesting. I wonder why I didn't see an "unneeded" warning.

@@ -127,9 +126,6 @@ applyBlockTransition ::
forall era m.
( STS (STS.BBODY era),
BaseM (STS.BBODY era) ~ ShelleyBase,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Environment (STS.BBODY era) ~ STS.BbodyEnv era,
State (STS.BBODY era) ~ STS.BbodyState era,
Signal (STS.BBODY era) ~ Block era
BaseM (STS.BBODY era) ~ ShelleyBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@@ -310,9 +321,28 @@ utxoWitnessed =
TRC (UtxoEnv slot pp stakepools genDelegs, u, tx)

instance
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that each constraint on the STS instance of UTXOW is needed here too. I haven't look at Embed closely, but it's kind of strange that we really need all of these constraints just to embed one error into another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Embed has a superclass constraint of STS

Comment on lines 181 to 183
DSignable c (Hash c EraIndependentTxBody),
ShelleyBased era,
DSignable c (Hash c EraIndependentTxBody),
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicates

@nc6 nc6 force-pushed the nc/era-indep branch 2 times, most recently from 2e15914 to a33914f Compare October 19, 2020 09:39
@mrBliss mrBliss self-requested a review October 19, 2020 10:44
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.

this is good news! thanks @nc6

Honestly it's embarassing that I failed to notice that this worked. We
carry a few more constraints in the STS instances and Embed instances.
But the payoff is that we only have to override the specific rules we
want to change in each era, and not re-plumb everything.

Obviously this means that, in the future, if we make a change in a
different rule then we have to go back and turn the era-independent one
into an era-dependent version (and add instances for all intermediate
eras). But still, this feels like a definite improvement.
@mrBliss
Copy link
Contributor

mrBliss commented Oct 20, 2020

Huh, Haskell CI / build (8.10.2, ubuntu-latest) (push) failed because of a failure in the cardano-prelude-test testsuite. That testsuite should be disabled, IMO 🙂

@mrBliss
Copy link
Contributor

mrBliss commented Oct 20, 2020

bors merge

iohk-bors bot added a commit that referenced this pull request Oct 20, 2020
1922: Make STS rules above UTXO era-independent. r=mrBliss a=nc6

Honestly it's embarassing that I failed to notice that this worked. We
carry a few more constraints in the STS instances and Embed instances.
But the payoff is that we only have to override the specific rules we
want to change in each era, and not re-plumb everything.

Obviously this means that, in the future, if we make a change in a
different rule then we have to go back and turn the era-independent one
into an era-dependent version (and add instances for all intermediate
eras). But still, this feels like a definite improvement.

Co-authored-by: Nicholas Clarke <nicholas.clarke@iohk.io>
DSignable c (Hash c EraIndependentTxBody)
( Era era,
ShelleyBased era,
STS (UTXOW era),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this constraint is causing CI to time out in https://hydra.iohk.io/build/4513046/nixlog/1.
The test case in question:

testCase "don't spend from a bootstrap address" testBootstrapNotSpending

Comment on lines 374 to 377
STS (CHAIN era),
STS (BBODY era)
) =>
Embed (BBODY (ShelleyEra c)) (CHAIN (ShelleyEra c))
Embed (BBODY era) (CHAIN era)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this right?

Note that the STS (CHAIN era) instance above has a Embed (BBODY era) (CHAIN era) constraint, i.e., this instance. Since this instance has a STS (CHAIN era) constraint, there is a cycle.

Embed (BBODY era) (CHAIN era),

Copy link
Contributor

@mrBliss mrBliss left a comment

Choose a reason for hiding this comment

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

I think there are still some cycles in the instances (STS vs. Embed), right?

VRF.Signable (VRF c) Seed
( Era era,
ShelleyBased era,
STS (CHAIN era)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same?

VRF.Signable (VRF c) Seed
( Era era,
ShelleyBased era,
STS (CHAIN era),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same?

( Era era,
c ~ Crypto era,
ShelleyBased era,
STS (CHAIN era),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same?

@mrBliss
Copy link
Contributor

mrBliss commented Oct 20, 2020

I think there are still some cycles in the instances (STS vs. Embed), right?

Hmm, I'm not sure whether these cycles are problematic. I'm just suspicious because of the tests timing out.

`Embed sub super` has the `STS super` super-class constraint, but `Embed sub
super` is almost always used as a super-class constraint of `Embed sub super`
itself. This is a cycle. My hypothesis is that these cycles are fine, *until*
you start relying on constraints that are implied by them, because the
corresponding dictionaries will be recursive too. I believe this is what caused
some tests to hang.

To remedy this, remove the `STS super` super-class constraint from the `Embed`
class. Next, remove the new redundant constraints and add the constraints that
are now missing.

Finally, remove the cycle between each pair of `Embed` and `STS` instances. For
example:

```diff
instance
  ( ..
    Embed (UTXO era) (UTXOW era),
    ..
  ) =>
  STS (UTXOW era)
  where
  ..

instance
  ( ..
-   STS (UTXOW era),
    ..
  ) =>
  Embed (UTXO era) (UTXOW era)
  where
  ..
```
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 20, 2020

Canceled.

@mrBliss
Copy link
Contributor

mrBliss commented Oct 20, 2020

I just pushed a commit removing – what I think – are cycles between Embed and STS instances that could be causing the timeouts in the tests. It at least fixed the don't spend from a bootstrap address test locally. Let's see whether CI agrees.

@mrBliss
Copy link
Contributor

mrBliss commented Oct 20, 2020

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 20, 2020

Build succeeded:

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.

3 participants