Skip to content

Commit c486747

Browse files
committed
Implement FetchBlock SyncService method via node kernel access
Adds in-process block fetching from ChainDB, bypassing N2C IPC. Response includes raw CBOR bytes and cardano block header (slot, hash, height).
1 parent ab2de02 commit c486747

19 files changed

Lines changed: 2944 additions & 20 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-api
2+
pr: 1232
3+
kind:
4+
- compatible
5+
description: |
6+
Re-export consensus types from Cardano.Api.Consensus for node kernel access: NodeKernel, ChainDB, BlockComponent, RealPoint, OneEraHash, HeaderHash, HasHeader, BlockType, StandardCrypto, CardanoBlock, blockNo.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-rpc
2+
pr: 1232
3+
kind:
4+
- feature
5+
description: |
6+
Implement FetchBlock SyncService method via node kernel access. Fetches blocks from ChainDB with raw CBOR bytes and cardano block header (slot, hash, height).

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ cardano-wasm/examples/*/main.js
8585
cardano-wasm/examples/*/cardano_node_grpc_web_pb.js
8686
.ghc-wasm/
8787

88+
.serena/

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,25 @@ module Cardano.Api.Consensus
4747
, ProtocolClientInfoArgs (..)
4848

4949
-- * Reexports from @ouroboros-consensus@
50+
, BlockComponent (..)
5051
, ByronBlock
52+
, CardanoBlock
53+
, ChainDB.ChainDB
54+
, ChainDB.getBlockComponent
5155
, ChainDepState
5256
, GenTx (..)
5357
, EraMismatch (..)
58+
, HasHeader
59+
, HeaderHash
60+
, NodeKernel (..)
61+
, OneEraHash (..)
5462
, PastHorizonException
5563
, PraosProtocolSupportsNode
5664
, PraosProtocolSupportsNodeCrypto
65+
, RealPoint (..)
5766
, ShelleyGenesisStaking (..)
67+
, StandardCrypto
68+
, blockNo
5869
, byronIdTx
5970
, condense
6071
, getOpCertCounters
@@ -68,3 +79,5 @@ import Cardano.Api.Consensus.Internal.InMode
6879
import Cardano.Api.Consensus.Internal.Mode
6980
import Cardano.Api.Consensus.Internal.Protocol
7081
import Cardano.Api.Consensus.Internal.Reexport
82+
83+
import Ouroboros.Consensus.Storage.ChainDB qualified as ChainDB
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
module Cardano.Api.Consensus.Internal.Reexport
2-
( ByronBlock
2+
( BlockComponent (..)
3+
, ByronBlock
4+
, CardanoBlock
35
, ChainDepState
46
, GenTx (..)
7+
, HasHeader
8+
, HeaderHash
59
, EraMismatch (..)
10+
, NodeKernel (..)
11+
, OneEraHash (..)
612
, PastHorizonException
713
, PraosProtocolSupportsNode
814
, PraosProtocolSupportsNodeCrypto
15+
, RealPoint (..)
916
, ShelleyGenesisStaking (..)
17+
, StandardCrypto
18+
, blockNo
1019
, byronIdTx
1120
, condense
1221
, getOpCertCounters
@@ -16,19 +25,24 @@ module Cardano.Api.Consensus.Internal.Reexport
1625
)
1726
where
1827

28+
import Cardano.Protocol.Crypto (StandardCrypto)
29+
import Ouroboros.Consensus.Block (HasHeader, HeaderHash, RealPoint (..), blockNo)
1930
import Ouroboros.Consensus.Byron.Ledger (ByronBlock, GenTx (..), byronIdTx)
20-
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
31+
import Ouroboros.Consensus.Cardano.Block (CardanoBlock, EraMismatch (..))
32+
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (OneEraHash (..))
2133
import Ouroboros.Consensus.HardFork.History.EpochInfo (interpreterToEpochInfo)
2234
import Ouroboros.Consensus.HardFork.History.Qry
2335
( PastHorizonException
2436
, unsafeExtendSafeZone
2537
)
2638
import Ouroboros.Consensus.Ledger.SupportsMempool (txId)
39+
import Ouroboros.Consensus.Node (NodeKernel (..))
2740
import Ouroboros.Consensus.Protocol.Abstract (ChainDepState)
2841
import Ouroboros.Consensus.Protocol.Praos.Common
2942
( PraosProtocolSupportsNode
3043
, PraosProtocolSupportsNodeCrypto
3144
, getOpCertCounters
3245
)
3346
import Ouroboros.Consensus.Shelley.Node (ShelleyGenesisStaking (..))
47+
import Ouroboros.Consensus.Storage.Common (BlockComponent (..))
3448
import Ouroboros.Consensus.Util.Condense (condense)

cardano-rpc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ It implements [UTxO RPC](https://utxorpc.org/introduction) protobuf communicatio
3333

3434
| Method | Status |
3535
|--------|--------|
36-
| [FetchBlock](https://utxorpc.org/sync/spec/#fetchblockrequest) | ⬜ Not supported |
36+
| [FetchBlock](https://utxorpc.org/sync/spec/#fetchblockrequest) | 🚧 In progress (missing: `Block.timestamp`, `Block.body.tx`) |
3737
| [DumpHistory](https://utxorpc.org/sync/spec/#dumphistoryrequest) | ⬜ Not supported |
3838
| [FollowTip](https://utxorpc.org/sync/spec/#followtiprequest) | ⬜ Not supported |
3939
| [ReadTip](https://utxorpc.org/sync/spec/#readtiprequest) | ⬜ Not supported |

cardano-rpc/cardano-rpc.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ library
5151
Cardano.Rpc.Proto.Api.Node
5252
Cardano.Rpc.Proto.Api.UtxoRpc.Query
5353
Cardano.Rpc.Proto.Api.UtxoRpc.Submit
54+
Cardano.Rpc.Proto.Api.UtxoRpc.Sync
5455
Cardano.Rpc.Server
5556
Cardano.Rpc.Server.Config
5657
Cardano.Rpc.Server.Internal.Env
@@ -62,7 +63,10 @@ library
6263
Cardano.Rpc.Server.Internal.UtxoRpc.Predicate
6364
Cardano.Rpc.Server.Internal.UtxoRpc.Query
6465
Cardano.Rpc.Server.Internal.UtxoRpc.Submit
66+
Cardano.Rpc.Server.Internal.UtxoRpc.Sync
6567
Cardano.Rpc.Server.Internal.UtxoRpc.Type
68+
Cardano.Rpc.Server.NodeKernelAccess
69+
Cardano.Rpc.Server.NodeKernelAccess.Internal
6670

6771
other-modules:
6872
Cardano.Rpc.Server.Internal.Orphans
@@ -111,6 +115,8 @@ library gen
111115
Proto.Utxorpc.V1beta.Query.Query_Fields
112116
Proto.Utxorpc.V1beta.Submit.Submit
113117
Proto.Utxorpc.V1beta.Submit.Submit_Fields
118+
Proto.Utxorpc.V1beta.Sync.Sync
119+
Proto.Utxorpc.V1beta.Sync.Sync_Fields
114120

115121
build-depends:
116122
proto-lens-protobuf-types,

0 commit comments

Comments
 (0)