Skip to content

JSON-RPC messages arrive out of order #5512

Closed
@josepot

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.

cc @jsdw @lexnv @bkchr

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions