CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

CKB node, RPC and indexer

45 lessons found. All lessons

Page 4 of 4

Simulating a real CKB reorg with two devnet nodes over P2PAdvancedFrom one fix

To exercise genuine fork choice on a Dummy devnet, partition two nodes with set_network_active(false) plus remove_node, wait until get_peers is empty on both, then mine a longer competing branch on one node with generate_block. Reconnect with set_network_active(true) and add_node(node_id, /ip4/.../tcp/port), and wait until both nodes report the same get_tip_header hash and the same tx_pool_info tip_hash before checking reorg recovery.

#Testing and devnet #Network and RPC reliability · Sources (2) · 2026-10-10

Molecule table encoding of absent optional fieldsWorkingFrom one fix

A molecule table or dynvec (Script, CellOutput, WitnessArgs) is serialized as a u32 total size, then one u32 offset per field, then the fields. There is no separate count; readers derive it from the first offset. An absent Opt field takes zero bytes, so its offset equals the next offset, or the total size if it is last. A hand-rolled encoder that inserts a u32 count after the total size, as this commit's dyn_collection does, produces malformed molecule.

#Data encoding (molecule, hex, bigints) #Witnesses and signatures · Sources (1) · 2026-10-09

Reconstructing the live cell set at a past height from the CKB indexerAdvancedFrom one fix

The indexer's get_cells lists only cells live at its current tip. To get Nervos DAO deposits live at height H, read the indexer tip, list get_cells and keep those with block_number <= H, then read the indexer tip again as T. Then query get_transactions on the DAO type script with filter block_range [H+1, T+1) (the end is exclusive), keep io_type input, follow each input's previous_output to the creating tx and its header, and add back cells created at or below H. In both passes keep only real deposits (DAO type and 8 zero bytes of data), since withdrawing cells share the type script, and retry if either tip hash is no longer canonical per get_block_hash.

#Indexer queries and cell collection #Network and RPC reliability · Sources (1) · 2026-10-08

Verify a self indexed tip against the node's canonical block hash before serving itWorkingFrom one fix

A locally maintained index of CKB blocks can lag the node or still hold an orphaned block after a reorg, so before serving its tip as an anchor, fetch the node's tip number, wait briefly for the index to reach it, then ask the node for the canonical block hash at the indexed height and refuse (503 with NOT_SYNCED or REORGANIZING) unless it equals the indexed hash. The check narrows the window but is not atomic, so a client that signs over the anchor should also compare it with an independent source.

#Network and RPC reliability #Indexer queries and cell collection · Sources (1) · 2026-10-08

Wait for tx_pool_info tip to match chain tip before submitting on devnetWorkingFrom one fix

After generate_block, CKB's tx pool updates its snapshot asynchronously, so a transaction spending just-committed outputs can be rejected (e.g. "Resolve failed Unknown") even though get_live_cell sees them. Before send_transaction or send_test_transaction, poll tx_pool_info until its tip_hash and tip_number equal get_tip_header's hash and number.

#Testing and devnet #Network and RPC reliability · Sources (1) · 2026-10-08

Computing cell confirmations from get_transaction block_hash and tip headerWorkingFrom one fix

To get a cell's confirmation count over raw CKB JSON-RPC, read tx_status.block_hash from get_transaction, look up its number with get_header, then compute tip − included + 1 using get_tip_header; treat a missing block_hash as 0 confirmations. This commit's helper also retries get_transaction without the "0x2" verbosity param if the node rejects it, and treats get_live_cell as live only when status === "live".

#Network and RPC reliability #Indexer queries and cell collection · Sources (1) · 2026-09-22

Filter prefix get_cells results by data length before decodingWorkingFrom one fix

A get_cells query with script_search_mode "prefix" and args "0x" returns every live cell whose script has that code hash and hash_type, whatever its args, so it can include cells of the same script with a different data layout (for example a script that owns both a state cell and a ledger cell). Check output_data length, or catch the decode error, and skip the cell before calling a strict decoder. Otherwise one unexpected cell throws and the whole result list is lost.

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-09-18

Indexer RPC module must be listed in ckb.toml rpc modules for get_cells on devnetWorkingFrom one fix

CKB serves get_cells, get_indexer_tip and the other indexer RPC methods only when "Indexer" is listed in the [rpc] modules array of ckb.toml. The ckb.toml generated in the nervos/ckb 0.209.0 devnet image used here leaves Indexer out, so add it before relying on cell collection against a devnet node. Then confirm with a real indexer call such as get_cells after the node starts.

#Indexer queries and cell collection #Testing and devnet · Sources (1) · 2026-09-18

Never pass the terminal "0x" cursor back to indexer get_cellsWorkingFrom one fix

An exhausted indexer get_cells scan returns {objects: [], last_cursor: "0x"} (captured from a real node). The authors report that calling get_cells again with after = "0x" then returns nothing, even once matching cells exist, and a hand-written mock that never returned the real "0x" hid this for days. When paging, stop on an empty page before reading last_cursor, and never send or persist a "0x" cursor. Build paging tests from captured node responses, not hand-written mocks.

#Indexer queries and cell collection #Testing and devnet · Sources (1) · 2026-09-18

Page 4 of 4

Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. JSON · Want a lesson changed or removed? Open an issue.