Description
The chainHead
subscription implementation is not fully compliant with the JSON-RPC specification, as messages occasionally arrive out of order. This can cause inconsistencies in the event handling process. Below is an example demonstrating this issue:
{"jsonrpc":"2.0","method":"chainHead_v1_followEvent","params":{"subscription":"w2bkfzBzOuXeldcS","result":{"event":"newBlock","blockHash":"0xb2499db97650a723e2e3adeac3393cd395827db5aeef4512f4ab8c6a925a278a","parentBlockHash":"0xd0a64ca092b6ae44620ae99b3d6cf66664f2eaab8da5d8637304516fd29822f0","newRuntime":null}}}
{"jsonrpc":"2.0","method":"chainHead_v1_followEvent","params":{"subscription":"w2bkfzBzOuXeldcS","result":{"event":"bestBlockChanged","bestBlockHash":"0xb2499db97650a723e2e3adeac3393cd395827db5aeef4512f4ab8c6a925a278a"}}}
{"jsonrpc":"2.0","method":"chainHead_v1_followEvent","params":{"subscription":"w2bkfzBzOuXeldcS","result":{"event":"bestBlockChanged","bestBlockHash":"0xa5770d656f360a3cb1aa8be285ecec748e7063b1317eddc9f36db3dc8a78573d"}}}
{"jsonrpc":"2.0","method":"chainHead_v1_followEvent","params":{"subscription":"w2bkfzBzOuXeldcS","result":{"event":"finalized","finalizedBlockHashes":["0xb1796a1e2d6ef0d4ea4ae8c8a6126689389c336f2ee460356b47de5515559ca3"],"prunedBlockHashes":[]}}}
{"jsonrpc":"2.0","method":"chainHead_v1_followEvent","params":{"subscription":"w2bkfzBzOuXeldcS","result":{"event":"newBlock","blockHash":"0xa5770d656f360a3cb1aa8be285ecec748e7063b1317eddc9f36db3dc8a78573d","parentBlockHash":"0xb2499db97650a723e2e3adeac3393cd395827db5aeef4512f4ab8c6a925a278a","newRuntime":null}}}
In this sequence, the third message (bestBlockChanged
with bestBlockHash
0xa5770d656f360a3cb1aa8be285ecec748e7063b1317eddc9f36db3dc8a78573d
) should logically be the last one, as it refers to a block that has not yet been received via the newBlock
event.
This issue was identified by @ryanleecode while working with the RPC endpoint wss://westend-people-rpc.polkadot.io
, which is believed to be running the latest version of the node. The issue was originally reported in this Polkadot-API issue.
According to the JSON-RPC spec, the order of these messages is critical to ensure correct event processing.
Activity