Skip to content

Commit 3b48ce1

Browse files
Nana-ECjsync-swirlds
authored andcommitted
Add communication protocol descriptions
Signed-off-by: Nana Essilfie-Conduah <nana@swirldslabs.com>
1 parent 4ec87c0 commit 3b48ce1

File tree

1 file changed

+138
-35
lines changed

1 file changed

+138
-35
lines changed

HIP/hip-1081.md

Lines changed: 138 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ performance streaming, use of protobufs (continued commitment to simple and clea
6464
flexibility with microservice pluggable options.
6565

6666
As such consumers will utilize gRPC clients to communicate.
67-
This matches the communication protocol with the CN but differs from other web3 nodes which often utilize JSON RPC APIs over HTTP.
68-
In the future it may be valuable to explore and add additional protocol such as WS and HTTP (REST API, graphQL) based on community needs.
69-
67+
This matches the communication protocol with the CN but differs from other web3 nodes which often utilize JSON RPC APIs
68+
over HTTP. In the future it may be valuable to explore and add additional protocol such as WS and HTTP (REST API,
69+
graphQL) based on community needs.
7070

7171

7272
<aside>
@@ -94,6 +94,16 @@ The block node will support semantic version values and will make it's current v
9494

9595
## User stories
9696

97+
### Terms
98+
- Block Node: A software system intended to store and process a Block Stream. The API for a Block Node is defined in
99+
HIP 1056, among others.
100+
- Block Number: A monotonically increasing number assigned by consensus to each block produced by the network.
101+
- Publisher: An entity publishing blocks to a Block Node via the `publishBlockStream` API. This is typically a
102+
Consensus Node or another Block Node.
103+
- Subscriber: An entity that subscribes to a verified or unverified Block Stream from a Block Node.
104+
- Verified Block: A verified block is a block for which a Block Proof is received and for which the TSS signature of
105+
the network ledger ID is valid.
106+
97107
### Personas
98108

99109
- Council consensus node operators
@@ -131,8 +141,8 @@ minimum possible latency.
131141
possible latency.
132142
15. As a custom dApp I want to receive the block stream starting at any historical block and continue forward from that
133143
point indefinitely.
134-
16. As a custom dApp I want an API to request a snapshot of the state, as of an arbitrary historical block, from a block
135-
node.
144+
16. As a custom dApp I want an API to request a snapshot of the state, as of an arbitrary historical block, from a
145+
block node.
136146
17. As a custom dApp I want an API to request a state proof for any item in state, as of an arbitrary historical block,
137147
from a block node.
138148
18. As a custom dApp I want an API to request a state proof for any item in state, as of the most recent block, from a
@@ -150,8 +160,8 @@ determine, in software, the best choice(s) of block node(s) to use.
150160

151161
## Specification
152162

153-
The block node at its simplest will be another node server that offers APIs to consumers to obtain needed network information and insights.
154-
Clean extendable schemas and easy to consume APIs are important to reach this goal
163+
The block node at its simplest will be another node server that offers APIs to consumers to obtain needed network
164+
information and insights. Clean extendable schemas and easy to consume APIs are important to reach this goal
155165

156166
### Block Stream Schema
157167

@@ -168,8 +178,10 @@ in the [hedera-protobuf repository](https://github.com/hashgraph/hedera-protobuf
168178
</aside>
169179

170180
### Services
171-
To achieve the above the block node will offer multiple pluggable modular services which can be enabled by node operators.
172-
Note: protobuf summaries are noted in this HIP doc. The full protobuf specification can be found under
181+
To achieve the above the block node will offer multiple pluggable modular services which can be enabled by node
182+
operators.
183+
184+
> Note: protobuf summaries are noted in this HIP doc. The full protobuf specification can be found under
173185
[block node protobuf](./../assets/hip-1081/protobuf)
174186

175187
#### Block Node Service
@@ -192,23 +204,11 @@ service BlockNodeService {
192204

193205
#### Block Stream Service
194206

195-
One of the primary goals of the Block Node will be to expose a public streaming endpoint of block information obtained
196-
from Consensus Node outputs.
207+
One of the primary goals of the Block Node will be to expose a public streaming endpoint of block information
208+
obtained from Consensus Node outputs.
197209

198-
There will be 2 types of stream services offered
199-
200-
- Unverified block stream for low latency
201-
- Verified block stream for high confidence
202-
203-
Depending on a user, consuming clients can optimize for requesting Block Items as fast as possible for their own
204-
optional verification or rely on confirmed blocks as confirmed by a Block Node following the Block Proof algorithm.
205-
206-
Both streams may also offer filtering capabilities based on user requests and Block Node functionality support.
207-
Filtering support is expanded upon in the Block Stream HIP 1056 and is charectorized buy the replacement of block items
208-
with hash values whiles maintian the ability to carry out block and state proofs on the block information.
209-
210-
Initially filtering will be at the Block Item level (e.g. a Mirror Node may want only Transaction input and outputs)
211-
but in the future block nodes could stream blockItems out based on the matching of state or transaction matches.
210+
The block node will support 2 modes of data flow connections from external clients: publishBlockStream (push) &
211+
subscribeBlockStream (pull)
212212

213213
```protobuf
214214
/**
@@ -227,8 +227,100 @@ service BlockStreamService {
227227
}
228228
```
229229

230-
Notably, a block node may consume a block stream from multiple sources e.g. multiple CNs.
231-
This approach can be used to increase the reliability and availability of network data
230+
#### publishBlockStream: Push mode
231+
232+
For multiple reasons including security and ease of data rate controls the consensus node will push block stream data
233+
to a block node. As such a block node must be ready and available to accept connections that push the block stream to
234+
the node as blocks are agreed upon by the network. In this mode the Consensus Node or other block stream clients act as
235+
the Producer feeding the block node data.
236+
237+
A summarized handshake of communication between a publisher and BN is as follows
238+
- A publisher will send a Block Header item on connection
239+
- A block node will accept the stream if it is the next block or the node has no cache of previous blocks.
240+
- If the block is less than the last known block, the block node will respond with a `DuplicateBlock` response
241+
including details of the last known block. In this case the Block Node itself may explore a backfill path from
242+
another block node to resolve gaps in blocks where applicable.
243+
- If the block is greater than the last known block, the block node will respond with a `Behind` response including
244+
details of the last known block. A publisher must send either an earlier block or an `EndOfStream` in response. If
245+
an an `EndOfStream` is sent by the publisher it must include its earliest known block to signal to the Block Node
246+
how large of a catchup range it must resolve. In this case the Block Node itself may explore a backfill path from
247+
another block node to resolve gaps in blocks where applicable.
248+
- During streaming errors may occur from either side.
249+
- If a Publisher detects an error it must send an `EndStream` response in the next BlockItem. A Block Node will
250+
drop unverified blocks from that Publisher.
251+
- If a Block Node detects an error it will send an `EndStream` response in the next BlockItem to all publishers.
252+
A publisher must respond with a a replay of the given block in sessions and will apply exponential
253+
backoff if the error repeats.
254+
255+
<aside>
256+
🚨 **Open Task:** Add sequence diagram to illustrate handshake
257+
</aside>
258+
259+
<aside>
260+
🚨 **Open Task:** Add sequence diagram to illustrate error handling modes
261+
</aside>
262+
263+
Additional response codes and their details are noted below
264+
265+
| Response code | Description |
266+
| --------------------- | ------------- |
267+
| STREAM_END_UNKNOWN | This status indicates the server software failed to set a status, and SHALL be considered
268+
a software defect. |
269+
270+
<aside>
271+
🚨 **Open Task:** Add all known response codes
272+
</aside>
273+
274+
> When the producer is a consensus node it is important to expose error cases that suggest a blocks node is falling
275+
behind or failing to store blocks when expected.
276+
277+
> Notably, a block node may consume a block stream from multiple sources e.g. multiple CNs.
278+
This approach can be used to increase the reliability and availability of network data.
279+
280+
#### subscribeBlockStream: Pull mode
281+
In addition to ingesting the block stream, teh block will also support the export of the block stream data in a similar
282+
manner to the consensus node.
283+
284+
There will be 2 types of stream services offered
285+
286+
- Unverified block stream for low latency
287+
- Verified block stream for high confidence
288+
289+
Depending on a user, consuming clients can optimize for requesting Block Items as fast as possible for their own
290+
optional verification or rely on confirmed blocks as confirmed by a Block Node following the Block Proof algorithm.
291+
292+
Both streams may also offer filtering capabilities based on user requests and Block Node functionality support.
293+
Filtering support is expanded upon in the Block Stream HIP 1056 and is characterized by the replacement of block items
294+
with hash values whiles maintain the ability to carry out block and state proofs on the block information.
295+
296+
Initially filtering will be at the Block Item level (e.g. a Mirror Node may want only Transaction input and outputs)
297+
but in the future block nodes could stream blockItems out based on the matching of state or transaction matches.
298+
299+
An overview of communication between a Block Node and a subscriber is as follows
300+
- A subscriber will send a desired block range and desired for verified or unverified streaming on connection
301+
- A block node will accept the stream if the desired block range is supported.
302+
- If the block is less than the last available block, the block node will respond with a
303+
`READ_STREAM_INVALID_START_BLOCK_NUMBER` response.
304+
- If the block is greater than the last available block, the block node will respond with a
305+
`READ_STREAM_INVALID_END_BLOCK_NUMBER` response.
306+
- During streaming errors may occur.
307+
- If a Block Node detects an error it will send an `EndStream` response in the next BlockItem to all subscribers.
308+
A subscriber may choose to retry or connect to a different block node.
309+
310+
<aside>
311+
🚨 **Open Task:** Complete communication overview
312+
</aside>
313+
314+
Additional response codes and their details are noted below
315+
316+
| Response code | Description |
317+
| --------------------- | ------------- |
318+
| READ_STREAM_UNKNOWN | This status indicates the server software failed to set a status and SHALL be considered a
319+
software defect. |
320+
321+
<aside>
322+
🚨 **Open Task:** Add all known response codes
323+
</aside>
232324

233325
#### Block Service
234326

@@ -248,6 +340,10 @@ service BlockAccessService {
248340
}
249341
```
250342

343+
<aside>
344+
🚨 **Open Task:** Add all known response codes for API
345+
</aside>
346+
251347
#### State Service
252348

253349
Live state, snapshot, changes and single entity state
@@ -267,13 +363,19 @@ service StateService {
267363

268364
<aside>
269365
🚨 **Open Task:** Flesh out 3 different state related query endpoints
270-
1. State snapshot - covering latest state and historical state. All cases represent verified state at the end of a block.
271-
2. State changes e.g. what state changes occurred in block x, this is a subset of the block query and avoid the transmission of extra block information beyond state
366+
1. State snapshot - covering latest state and historical state. All cases represent verified state at the end of a
367+
block.
368+
2. State changes e.g. what state changes occurred in block x, this is a subset of the block query and avoid the
369+
transmission of extra block information beyond state
272370
- Add new endpoint to proto
273371
3. Single entity state query e.g. return account 0.0.x
274372
- Add new endpoint to proto
275373
</aside>
276374

375+
<aside>
376+
🚨 **Open Task:** Add all known response codes for API
377+
</aside>
378+
277379
#### Reconnect Service
278380

279381
Today the network consensus node act as teachers to each other when a new node comes online and needs to ge the latest
@@ -294,8 +396,8 @@ consensus node or block node coming online and looking for latest network detail
294396
#### Proof Service
295397

296398
Consensus nodes provided proof of state APIs has long been desired, however, this would put additional work on the
297-
consensus node that could be better provided elsewhere. By maintaining live state and streaming block stream information
298-
a block node can finally fill this gap and provide users with proofs including that of state.
399+
consensus node that could be better provided elsewhere. By maintaining live state and streaming block stream
400+
information a block node can finally fill this gap and provide users with proofs including that of state.
299401

300402
<aside>
301403
🚨 **Open Task:** Flesh out response components
@@ -330,9 +432,9 @@ Block nodes will perform significant work by consuming the block stream, verifyi
330432
multiple API services to further users. To block node operators it is thus important to offer capabilities to cover
331433
the cost of work and encourage a vibrant economy.
332434

333-
To achieve this the Block Node will adopt a charge card comparable model with crypto transfers of hbar required prior to the
334-
consumption of APIs. The block node will initially manage an hbar ledger on node to track the remaining hbar balance
335-
that an account ID holds with the block node.
435+
To achieve this the Block Node will adopt a charge card comparable model with crypto transfers of hbar required prior
436+
to the consumption of APIs. The block node will initially manage an hbar ledger on node to track the remaining hbar
437+
balance that an account ID holds with the block node.
336438

337439
To achieve this it is required that a block node have it's own account Id that users can transfer hbar to.
338440

@@ -431,4 +533,5 @@ A collections of URLs used as references through the HIP.
431533

432534
## Copyright/license
433535

434-
This document is licensed under the Apache License, Version 2.0 -- see [LICENSE](../LICENSE) or (https://www.apache.org/licenses/LICENSE-2.0)
536+
This document is licensed under the Apache License, Version 2.0 -- see [LICENSE](../LICENSE) or
537+
(https://www.apache.org/licenses/LICENSE-2.0)

0 commit comments

Comments
 (0)