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

Delete ConsensusMode type #342

Merged
merged 37 commits into from
Nov 2, 2023
Merged

Conversation

newhoggy
Copy link
Collaborator

@newhoggy newhoggy commented Oct 25, 2023

Changelog

- description: |
    Delete `ByronMode` and `ShelleyMode`
    Delete `anyEraInModeToAnyEra`
    Delete `AnyEraInMode`
    Modify to use `CardanoMode` only:
      - `executeQueryAnyMode`
      - `connectToLocalNode`
      - `connectToLocalNodeWithVersion
      - `mkLocalNodeClientParams`
      - `queryNodeLocalState`
      - `submitTxToNodeLocal`
      - `queryTxMonitoringLocal`
      - `getLocalChainTip`
      - `executeLocalStateQueryExpr`
    Deparameterise `LocalNodeClientProtocolsInMode`
    Modify `LocalNodeClientProtocols` to only work in `CardanoMode`.
    Rename `LocalNodeClientProtocolsInMode` to `LocalNodeClientProtocolsInIO`
    Rename `TxValidationErrorInMode` to `TxValidationErrorInCardanoMode`
    Deparameterise `TxValidationErrorInMode`
    Modify to use `CardanoMode` only
    - `determineEra`
    Deparameterise `LocalNodeConnectInfo`
    Deparameterise `LocalTxMonitoringResult`
    Deparameterise `LocalTxMonitoringQuery`
    Deparameterise `TxInMode`
    Modify to use `CardanoMode` only
    - `fromConsensusBlock`
    - `toConsensusBlock`
    - `queryExpr`
    - `getProgress`
    - `getSlotForRelativeTime`
    - `toLedgerEpochInfo`
    - `slotToEpoch`
    - `queryCurrentEpochState`
    - `queryEpoch`
    - `queryDebugLedgerState`
    - `queryGenesisParameters`
    - `queryPoolDistribution`
    - `queryPoolState`
    - `queryProtocolParameters`
    - `queryConstitutionHash`
    - `queryProtocolParametersUpdate`
    - `queryProtocolState`
    - `queryStakeAddresses`
    - `queryStakeDelegDeposits`
    - `queryStakeDistribution`
    - `queryStakePoolParameters`
    - `queryStakePools`
    - `queryStakeSnapshot`
    - `queryUtxo`
    - `queryConstitution`
    - `queryGovState`
    - `queryDRepState`
    - `queryDRepStakeDistribution`
    - `queryCommitteeMembersState`
    Deparameterise `BlockInMode`
    Deparameterise `TxIdInMode`
    Remove `EraInMode` argument in `QueryInEra` constructor
    Delete `ConsensusBlockForMode`
    Modify `TxInMode` to carry `CardanoEra` instead of `EraInMode`
    Deparameterise `BlockInMode`
    Deparameterise `TxIdInMode`
    Deparameterise `EraHistory`
    Modify to not take `EraInMode` argument
    - `queryCurrentEpochState`
    - `queryEpoch`
    - `queryDebugLedgerState`
    - `queryGenesisParameters`
    - `queryPoolDistribution`
    - `queryPoolState`
    - `queryProtocolParameters`
    - `queryConstitutionHash`
    - `queryProtocolParametersUpdate`
    - `queryProtocolState`
    - `queryStakeAddresses`
    - `queryStakeDelegDeposits`
    - `queryStakeDistribution`
    - `queryStakePoolParameters`
    - `queryStakePools`
    - `queryStakeSnapshot`
    - `queryUtxo`
    - `queryConstitution`
    - `queryGovState`
    - `queryDRepState`
    - `queryDRepStakeDistribution`
    - `queryCommitteeMembersState`
    Modify `TxInMode` constructors to remove `EraInMode` arguments from constructors
    Remove `EraInMode` from `TxValidationErrorInCardanoMode` constructors
    Delete `EraInMode`, `eraInModeToEra` and `toEraInMode`
    Remove `ConsensusMode` argument from:
    - `fromConsensusBlock`
    - `fromConsensusTip`
    - `determineEra`
    Delete `determineEraExpr`.  Use `queryCurrentEra` instead.
    Deparameterise `QueryInMode`
    Delete `AnyConsensusModeParams`
    Deparametrise `ConsensusModeParams`
    Remove `ConsensusMode` argument from `EraHistory` constructor
    Delete `EraConsensusModeMismatch` constructor
    Delete `localConsensusMode`, `AnyConsensusMode` and `renderMode`
    Delete `EraConsensusModeMismatch`
    Delete `CardanoMode` and `ConsensusMode`.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

We neither use not need ConsensusMode anymore.

This PR makes all the necessary changes to remove ConsensusMode.

Type names and function names retain the word Mode in them because that can be postponed to a future PR.

Refactoring to simplify code enabled by the removal can also be postponed to a future PR.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

Sorry, something went wrong.

@newhoggy newhoggy force-pushed the newhoggy/delete-ConsensusMode-type branch from a23b983 to 8490c1c Compare October 27, 2023 09:24
@newhoggy newhoggy marked this pull request as ready for review October 27, 2023 09:30
@newhoggy newhoggy force-pushed the newhoggy/delete-ConsensusMode-type branch from e8a4f9c to 6ab9918 Compare October 27, 2023 10:52
@newhoggy newhoggy changed the title WIP Delete ConsensusMode type Delete ConsensusMode type Oct 27, 2023
@newhoggy newhoggy force-pushed the newhoggy/delete-ConsensusMode-type branch 2 times, most recently from 2d87f7d to e15de45 Compare October 27, 2023 11:48
@newhoggy newhoggy added this pull request to the merge queue Oct 27, 2023
@newhoggy newhoggy removed this pull request from the merge queue due to a manual request Oct 27, 2023
, localTxMonitoringClient
:: Maybe (LocalTxMonitorClient txid tx slot m ())
}
data LocalNodeClientProtocols point tip slot m = LocalNodeClientProtocols
Copy link
Contributor

@Jimbo4350 Jimbo4350 Oct 27, 2023

Choose a reason for hiding this comment

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

This should remain generic because we are now forcing consumers of cardano-api to use our types for block, tx, txid, txerr and query. We can instantiate the types we want with type LocalNodeClientProtocolsInIO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If these need to be parameterised, then we need to keep these types:

data BlockInMode mode where
  BlockInMode
    :: CardanoEra era
    -> Block era
    -> EraInMode era mode
    -> BlockInMode mode
data TxInMode mode where

     TxInMode :: Tx era -> EraInMode era mode -> TxInMode mode

     TxInByronSpecial :: Consensus.GenTx Consensus.ByronBlock
                      -> EraInMode ByronEra mode -> TxInMode mode
data TxIdInMode mode where
  TxIdInMode :: TxId -> EraInMode era mode -> TxIdInMode mode
data TxValidationErrorInMode mode where
     TxValidationErrorInMode :: TxValidationError era
                             -> EraInMode era mode
                             -> TxValidationErrorInMode mode

     TxValidationEraMismatch :: EraMismatch
                             -> TxValidationErrorInMode mode
data QueryInMode mode result where
  QueryCurrentEra
    :: QueryInMode mode AnyCardanoEra

  QueryInEra
    :: EraInMode era mode
    -> QueryInEra era result
    -> QueryInMode mode (Either EraMismatch result)

  QueryEraHistory
    :: QueryInMode mode (EraHistory mode)

  QuerySystemStart
    :: QueryInMode mode SystemStart

  QueryChainBlockNo
    :: QueryInMode mode (WithOrigin BlockNo)

  QueryChainPoint
    :: ConsensusMode mode
    -> QueryInMode mode ChainPoint

We can still convert EraInMode era mode to CardanoEra era so the mode type parameter disappears however.

It's not clear what the benefit of keeping these type parameters are if we only fix it to one type. Is there a known use case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The deleted parameters of LocalNodeClientProtocols have been restored.

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

tx' = Consensus.ByronTx (Consensus.byronIdTx tx) tx

toConsensusGenTx (TxInMode (ByronTx tx) ByronEraInCardanoMode) =
data TxInMode where
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary for this PR but we need to think of a better name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. I kept the name so the diff is easier to see. A separate PR can rename the type.

-- actually transactions. This covers: update proposals, votes and
-- delegation certs.
--
TxInByronSpecial
Copy link
Contributor

Choose a reason for hiding this comment

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

We may be able to get away with using data Tx era directly and removing TxInMode. If we can convert Byron.ATxAux ByteString -> Consensus.GenTx Consensus.ByronBlock then we should be able to. Not necessary for this PR.


-- | The Shelley-only consensus mode consists of only the Shelley era.
--
-- This was used for the early Shelley testnets prior to the use of the
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, so my memory served me correctly.

@newhoggy newhoggy force-pushed the newhoggy/delete-ConsensusMode-type branch 6 times, most recently from 6f81c9a to 7072909 Compare October 31, 2023 10:04
@newhoggy newhoggy requested a review from Jimbo4350 October 31, 2023 10:07
@newhoggy newhoggy dismissed Jimbo4350’s stale review October 31, 2023 10:08

Comments addresed

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

Almost there! I spotted an error.

, localTxMonitoringClient
:: Maybe (LocalTxMonitorClient txid tx slot m ())
}
LocalNodeClientProtocols
Copy link
Contributor

Choose a reason for hiding this comment

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

💪

consensusModeOnly ShelleyModeParams{} = ShelleyMode
consensusModeOnly CardanoModeParams{} = CardanoMode

type LocalNodeClientProtocolsInMode =
Copy link
Contributor

Choose a reason for hiding this comment

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

💪

Consensus.HardForkGenTx (Consensus.OneEraGenTx (S (Z tx'))) ->
let Consensus.ShelleyTx _txid shelleyEraTx = tx'
in TxInMode ShelleyEra (ShelleyTx ShelleyBasedEraShelley shelleyEraTx)
Consensus.HardForkGenTx (Consensus.OneEraGenTx (S (S (Z tx')))) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary for this PR but in consensus there are patterns we can use:

pattern TagByron   x =                   Z x
pattern TagShelley x =                S (Z x)
pattern TagAllegra x =             S (S (Z x))
pattern TagMary    x =          S (S (S (Z x)))
pattern TagAlonzo  x =       S (S (S (S (Z x))))
pattern TagBabbage x =    S (S (S (S (S (Z x)))))
pattern TagConway  x = S (S (S (S (S (S (Z x))))))

ConsensusBlockForEra,
EraInMode(..),
Copy link
Contributor

Choose a reason for hiding this comment

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

💪

@@ -47,10 +47,6 @@ module Cardano.Api.Byron

-- ** Low level protocol interaction with a Cardano node
LocalNodeConnectInfo(LocalNodeConnectInfo),
ByronMode,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* convLocalChainSyncClient
* convLocalChainSyncClientPipelined
* convLocalNodeClientProtocols
* convLocalTxMonitoringClient
* fromConsensusGenTx
* fromConsensusTip
@newhoggy newhoggy force-pushed the newhoggy/delete-ConsensusMode-type branch from 7072909 to b155e2d Compare November 1, 2023 10:53
@newhoggy newhoggy added this pull request to the merge queue Nov 2, 2023
Merged via the queue into main with commit 561bec4 Nov 2, 2023
@newhoggy newhoggy deleted the newhoggy/delete-ConsensusMode-type branch November 2, 2023 09:27
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.

None yet

3 participants