Skip to content

Commit 2281836

Browse files
committed
blocktx wip
1 parent bc14885 commit 2281836

18 files changed

Lines changed: 270 additions & 717 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-api
2+
pr: 1247
3+
kind:
4+
- compatible
5+
description: |
6+
Add `caseShelleyToBabbageOrConwayOrDijkstra` to Cardano.Api.Era: a total variant of `caseShelleyToBabbageOrConwayEraOnwards` which passes the bare `ConwayEraOnwards` witness to the second arm instead of erroring for Dijkstra.

cardano-api/src/Cardano/Api/Era.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module Cardano.Api.Era
7373
, caseShelleyToMaryOrAlonzoEraOnwards
7474
, caseShelleyToAlonzoOrBabbageEraOnwards
7575
, caseShelleyToBabbageOrConwayEraOnwards
76+
, caseShelleyToBabbageOrConwayOrDijkstra
7677
)
7778
where
7879

cardano-api/src/Cardano/Api/Era/Internal/Case.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Cardano.Api.Era.Internal.Case
1212
, caseShelleyToMaryOrAlonzoEraOnwards
1313
, caseShelleyToAlonzoOrBabbageEraOnwards
1414
, caseShelleyToBabbageOrConwayEraOnwards
15+
, caseShelleyToBabbageOrConwayOrDijkstra
1516
)
1617
where
1718

@@ -131,3 +132,27 @@ caseShelleyToBabbageOrConwayEraOnwards l r = \case
131132
ShelleyBasedEraBabbage -> l ShelleyToBabbageEraBabbage
132133
ShelleyBasedEraConway -> r ConwayEraOnwardsConway
133134
ShelleyBasedEraDijkstra -> error "TODO Dijkstra: caseShelleyToBabbageOrConwayEraOnwards: era not supported"
135+
136+
-- | @caseShelleyToBabbageOrConwayOrDijkstra f g era@ applies @f@ to eras before conway;
137+
-- and applies @g@ to conway and later eras.
138+
--
139+
-- Unlike 'caseShelleyToBabbageOrConwayEraOnwards' this dispatcher is total: the
140+
-- second arm receives the bare 'ConwayEraOnwards' witness without
141+
-- 'ConwayEraOnwardsConstraints', whose bundle requires
142+
-- @TxCert ~ ConwayTxCert@ and therefore cannot be satisfied by dijkstra.
143+
-- Pattern match on the witness constructors in the second arm to get
144+
-- concrete-era instance resolution.
145+
caseShelleyToBabbageOrConwayOrDijkstra
146+
:: ()
147+
=> (ShelleyToBabbageEraConstraints era => ShelleyToBabbageEra era -> a)
148+
-> (ConwayEraOnwards era -> a)
149+
-> ShelleyBasedEra era
150+
-> a
151+
caseShelleyToBabbageOrConwayOrDijkstra l r = \case
152+
ShelleyBasedEraShelley -> l ShelleyToBabbageEraShelley
153+
ShelleyBasedEraAllegra -> l ShelleyToBabbageEraAllegra
154+
ShelleyBasedEraMary -> l ShelleyToBabbageEraMary
155+
ShelleyBasedEraAlonzo -> l ShelleyToBabbageEraAlonzo
156+
ShelleyBasedEraBabbage -> l ShelleyToBabbageEraBabbage
157+
ShelleyBasedEraConway -> r ConwayEraOnwardsConway
158+
ShelleyBasedEraDijkstra -> r ConwayEraOnwardsDijkstra

cardano-rpc/cardano-rpc.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ library
9999
cardano-crypto,
100100
cardano-crypto-class,
101101
cardano-crypto-wrapper,
102+
cardano-ledger-alonzo,
102103
cardano-ledger-api,
103104
cardano-ledger-binary,
104105
cardano-ledger-byron,

cardano-rpc/docs/node-kernel-access/01-node-access-types.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Piece 1: NodeKernelAccess types and cardano-rpc plumbing
22

3+
## Status: as built
4+
5+
Piece 1 shipped a deliberately thin `NodeKernelAccess`, not the snapshot record described below.
6+
As built, the module is `Cardano.Rpc.Server.NodeKernelAccess`, and the record itself lives in `Cardano.Rpc.Server.NodeKernelAccess.Type`.
7+
The module exports `mkNodeKernelAccess`, `fetchBlock` and `grabNodeKernelAccess`; there is no `withNodeKernelAccess`, no `LedgerSnapshot` and no `nkaWithSnapshot` / `nkaSubmitTx`.
8+
The record has three fields - `chainDb`, `systemStart` and `readEraHistory` - because direct `chainDb` access was enough to serve FetchBlock (pieces 2 and 3), so the snapshot interface was deferred.
9+
10+
Everything from "## Acceptance criteria" onwards describes the originally-planned snapshot design.
11+
That design is the target that pieces 4-7 grow into as they migrate the query, submit and eval methods off N2C; it is not current code.
12+
313
## Problem
414

515
cardano-rpc currently threads `LocalNodeConnectInfo` through its environment and `MonadRpc` constraint.
@@ -18,6 +28,8 @@ As a cardano-rpc developer, I want the `NodeKernelAccess` abstraction and enviro
1828

1929
## Acceptance criteria
2030

31+
These criteria describe the originally-planned snapshot design (see "Status: as built" above), which is the target for pieces 4-7 rather than what piece 1 shipped.
32+
2133
1. **AC1: NodeKernelAccess module** - A new module `Cardano.Rpc.Server.Internal.NodeKernelAccess` exists at `src/Cardano/Rpc/Server/Internal/NodeKernelAccess.hs`, exporting `NodeKernelAccess(..)`, `LedgerSnapshot(..)`, and `withNodeKernelAccess`.
2234
`NodeKernelAccess` is a record with three fields: `nkaWithSnapshot :: forall a. (LedgerSnapshot -> IO a) -> IO a`, `nkaSubmitTx :: TxInMode -> IO (SubmitResult TxValidationErrorInCardanoMode)`, and `nkaFetchBlock :: SlotNo -> ByteString -> IO (Maybe ByteString)`.
2335
`LedgerSnapshot` is a newtype wrapping `runQuery :: forall result. QueryInMode result -> IO result`.

cardano-rpc/docs/node-kernel-access/analysis-consensus-protocol.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,5 @@ newtype LedgerSnapshot = LedgerSnapshot
186186

187187
`nkaWithSnapshot` acquires a single `ReadOnlyForker` and wraps it.
188188
All queries within one `nkaWithSnapshot` call share the same forker and therefore the same ledger state.
189+
190+
Note: this snapshot design is forward-looking - it is the target interface for pieces 4-7, not current code (as built, `NodeKernelAccess` is the thinner `chainDb` / `systemStart` / `readEraHistory` record; see `01-node-access-types.md`).

cardano-rpc/docs/node-kernel-access/implementation-plan.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ The N2C error is wrapped in `Submit.hs` via `tryAny` + `first TraceRpcSubmitN2cC
8585

8686
## File summary
8787

88-
### New files (2)
88+
### New files (as built)
8989

9090
| File | Purpose |
9191
|------|---------|
92-
| `cardano-api/cardano-rpc/src/Cardano/Rpc/Server/Internal/NodeKernelAccess.hs` | `NodeKernelAccess` record + `withNodeKernelAccess` |
93-
| `cardano-node/cardano-node/src/Cardano/Node/Rpc/NodeKernelAccess.hs` | `mkNodeKernelAccess` from `NodeKernel` |
92+
| `cardano-api/cardano-rpc/src/Cardano/Rpc/Server/NodeKernelAccess.hs` | `mkNodeKernelAccess`, `fetchBlock` and `grabNodeKernelAccess`; the `NodeKernelAccess` record itself lives in `Cardano/Rpc/Server/NodeKernelAccess/Type.hs`. No `withNodeKernelAccess` was built. |
93+
| `cardano-node/cardano-node/src/Cardano/Node/Run.hs` (modified, not new) | `mkNodeKernelAccess` is called inline here; no dedicated cardano-node module was created. |
9494

9595
### Modified files (12)
9696

@@ -114,7 +114,7 @@ The N2C error is wrapped in `Submit.hs` via `tryAny` + `first TraceRpcSubmitN2cC
114114
| File | Why |
115115
|------|-----|
116116
| `cardano-rpc/src/Cardano/Rpc/Server/Config.hs` | `nodeSocketPath` still needed for socket path derivation |
117-
| `cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Type.hs` | Conversion code untouched |
117+
| `cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Type.*` | The N2C-to-node-kernel migration does not touch the type conversions (now split across `Type.hs` and the `Type/*.hs` submodules). |
118118
| `cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Predicate.hs` | Filtering untouched |
119119
| Testnet test files | gRPC client API unchanged |
120120

cardano-rpc/docs/node-kernel-access/plan-fetchblock-byron.md

Lines changed: 0 additions & 121 deletions
This file was deleted.

cardano-rpc/docs/node-kernel-access/plan-fetchblock-phases.md

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)