@@ -6,29 +6,42 @@ SPDX-License-Identifier: Apache-2.0
66
77# Notification Service — Client Usage Guide
88
9- The Sidecar exposes a Notification Service that allows clients to subscribe to transaction status
10- updates and receive asynchronous notifications when transactions are committed, rejected, or aborted.
11- This is the primary mechanism for clients that submit transactions asynchronously to the Ordering
12- Service to learn the outcome of their transactions, without polling or scanning the entire block stream.
9+ The Sidecar exposes a Notification Service that provides two mechanisms for receiving transaction status updates:
1310
14- The Notification Service uses a bidirectional gRPC stream: clients send subscription requests
15- containing transaction IDs of interest, and the server pushes status responses as transactions
16- complete. Multiple subscription requests can be sent on the same stream.
11+ 1 . ** Transaction ID Subscription** — Allows clients to subscribe to transaction status
12+ updates and receive asynchronous notifications when transactions are committed, rejected, or aborted.
13+ This is the primary mechanism for clients that submit transactions asynchronously to the Ordering
14+ Service to learn the outcome of their transactions, without polling or scanning the entire block stream.
15+ It uses a bidirectional gRPC stream: clients send subscription requests
16+ containing transaction IDs of interest, and the server pushes status responses as transactions
17+ complete. Multiple subscription requests can be sent on the same stream.
18+
19+ 2 . ** All Transactions Stream** — Allows clients to subscribe to a stream of all committed transactions in block order,
20+ with optional filtering by namespace and status. This is useful for audit, monitoring, event-driven applications, and
21+ replication systems.
1722
1823For internal architecture details, see [ sidecar.md — Section 6] ( sidecar.md#6-notification-service ) .
1924
2025## 1. API Definition
2126
22- The Notification Service is defined as a bidirectional streaming RPC :
27+ The Notification Service provides two streaming RPCs :
2328
2429From [ fabric-x-common/api/committerpb] ( https://github.com/hyperledger/fabric-x-common )
2530
2631``` protobuf
2732service Notifier {
33+ // Subscribe to specific transaction IDs
2834 rpc OpenNotificationStream (stream NotificationRequest) returns (stream NotificationResponse);
35+
36+ // Subscribe to all committed transactions
37+ rpc StreamAllTransactions (StreamAllRequest) returns (stream TxBatch);
2938}
3039```
3140
41+ ## 2. Transaction ID Subscription API
42+
43+ ### 2.1. API Definition
44+
3245The client sends ` NotificationRequest ` messages, each containing a batch of transaction IDs to watch
3346and a timeout:
3447
@@ -70,7 +83,7 @@ message RejectedTxIds {
7083}
7184```
7285
73- ## 2. Subscribing to Transaction Status Updates
86+ ### 2. 2. Subscribing to Transaction Status Updates
7487
7588Create a gRPC connection to the Sidecar, open a notification stream, and send a
7689` NotificationRequest ` with the transaction IDs to watch:
@@ -103,7 +116,7 @@ err = stream.Send(&committerpb.NotificationRequest{
103116Multiple ` NotificationRequest ` messages can be sent on the same stream. Each request is
104117tracked independently with its own timeout.
105118
106- ## 3. Receiving Notifications
119+ ## 2. 3. Receiving Notifications
107120
108121The client receives ` NotificationResponse ` messages by calling ` Recv() ` on the stream.
109122Each response contains one of the following payloads:
@@ -156,7 +169,7 @@ Responses are batched per stream for efficiency — if multiple subscribed trans
156169complete in the same coordinator status update, they are grouped into a single
157170` NotificationResponse ` .
158171
159- ## 4. Recommended Client Pattern
172+ ### 2. 4. Recommended Client Pattern
160173
161174To avoid missing notifications, clients should follow this sequence:
162175
@@ -170,27 +183,119 @@ If the notification stream breaks (e.g., sidecar restart) or the timeout expires
170183the transaction completes, the client should fall back to the Block Query API to check
171184the transaction status.
172185
173- ## 5. Concurrency Limits
186+ ## 3. All Transactions Stream API
187+
188+ ### 3.1. API Definition
189+
190+ The ` StreamAllTransactions ` RPC provides a server-streaming interface that delivers all committed transactions in block
191+ order. Unlike the transaction ID subscription API, this stream does not require clients to know transaction IDs in
192+ advance.
193+
194+ ``` protobuf
195+ message StreamAllRequest {
196+ repeated string filter_namespaces = 1; // Optional: filter by namespace(s)
197+ repeated Status filter_status = 2; // Optional: filter by status
198+ bool include_read_write_sets = 3; // Optional: include read/write sets
199+ bool include_endorsements = 4; // Optional: include endorsements
200+ }
201+
202+ message TxBatch {
203+ repeated TxEvent events = 1;
204+ }
205+
206+ message TxEvent {
207+ TxRef ref = 1; // Transaction reference
208+ Status status = 2; // Transaction status
209+ repeated TxNamespace namespaces = 3; // Namespaces (if filtering enabled)
210+ repeated Endorsement endorsements = 4; // Endorsements (if requested)
211+ }
212+ ```
213+
214+ ### 3.2. Opening a Stream
215+
216+ Create a gRPC connection to the Sidecar and call ` StreamAllTransactions ` :
217+
218+ ``` go
219+ client := committerpb.NewNotifierClient (conn)
220+ stream , err := client.StreamAllTransactions (ctx, &committerpb.StreamAllRequest {
221+ FilterNamespaces : []string {" namespace-1" , " namespace-2" },
222+ FilterStatus : []committerpb.Status {committerpb.Status_COMMITTED },
223+ IncludeReadWriteSets : true ,
224+ IncludeEndorsements : false ,
225+ })
226+ ```
227+
228+ ** Request Parameters:**
229+
230+ - ** ` filter_namespaces ` ** (optional): If specified, only transactions touching these namespaces are included. Empty
231+ means all namespaces. Multiple namespaces use OR logic: a transaction is included if it touches any of the specified
232+ namespaces.
233+
234+ - ** ` filter_status ` ** (optional): If specified, only transactions with these status codes are included. Empty means all
235+ statuses.
236+
237+ - ** ` include_read_write_sets ` ** (optional): If true, the ` namespaces ` field in each ` TxEvent `
238+ includes the read/write sets for each namespace. Default: false.
239+
240+ - ** ` include_endorsements ` ** (optional): If true, the ` endorsements ` field in each ` TxEvent `
241+ includes the transaction endorsements. Default: false.
242+
243+ ### 3.3. Receiving Transaction Events
244+
245+ The server sends ` TxBatch ` messages containing one or more ` TxEvent ` entries. Transactions are batched by block. All
246+ transactions from the same block are delivered in a single ` TxBatch ` .
247+
248+ ``` go
249+ for {
250+ batch , err := stream.Recv ()
251+ ...
252+
253+ for _ , event := range batch.Events {
254+ ...
255+ }
256+ }
257+ ```
258+
259+ ### 3.4. Stream Behavior
260+
261+ ** Block Order Guarantee:**
262+ Transactions are streamed in deterministic block order. All transactions from block N are delivered before any
263+ transactions from block N+1.
264+
265+ ** Starting Point:**
266+ The stream starts from the currently processed block when the client connects. Historical transactions are not included.
267+
268+ ** No Recovery:**
269+ If the stream disconnects, the client must reconnect and will resume from the current block. Transactions from missed
270+ blocks are not replayed. For guaranteed delivery, use the Block Delivery API instead.
271+
272+ ** Backpressure:**
273+ If the client cannot keep up with the transaction rate, the server will block sending to that client. The server uses a
274+ configurable write timeout (default: 30 seconds) to prevent slow clients from blocking the system.
275+
276+ ## 4. Concurrency Limits
174277
175278The Notification Service shares the server's ` max-concurrent-streams ` limit (default: 10)
176279with the Block Delivery streams ([ Section 5 of sidecar.md] ( sidecar.md#5-block-delivery-service ) ).
177- Both stream types compete for the same pool of stream slots.
280+ All stream types compete for the same pool of stream slots.
178281
179282When the limit is reached, new stream requests are rejected with a gRPC ` ResourceExhausted `
180283status code. Clients should handle this error with appropriate backoff and retry logic.
181284
182- ## 6 . Configuration
285+ ## 5 . Configuration
183286
184287The following configuration options in ` sidecar.yaml ` control notification behavior:
185288
186- | Setting | Default | Description |
187- | ---------| ---------| -------------|
188- | ` notification.max-timeout ` | ` 1m ` | Upper limit on per-request timeout. Client timeouts are capped to this value. |
189- | ` server.max-concurrent-streams ` | ` 10 ` | Maximum concurrent streaming RPCs across all stream types (Deliver + Notification). |
289+ | Setting | Default | Description |
290+ | -------------------------------------| ---------| -------------------------------------------------------------------------------------------------|
291+ | ` notification.max-timeout ` | ` 1m ` | Upper limit on per-request timeout for transaction ID subscriptions. |
292+ | ` notification.stream-write-timeout ` | ` 30s ` | Write timeout for all transactions stream. Prevents slow clients from blocking. |
293+ | ` server.max-concurrent-streams ` | ` 10 ` | Maximum concurrent streaming RPCs across all stream types (Deliver + Notification + StreamAll). |
190294
191295Sample configuration:
192296
193297``` yaml
194298notification :
195299 max-timeout : 10m
300+ stream-write-timeout : 10s
196301` ` `
0 commit comments