CKB Pulse
Lições

O que a CKB aprendeu

Começa aqui · Glossário · Testa-te · Feed

As lições estão escritas em inglês, por isso pesquise em inglês.

Prático

174 lições encontradas. Todas as lições

Página 7 de 15

Confirm a committed transaction is on the canonical chain via get_header and get_block_hashPráticoDe uma correção

Before recording a transaction as committed, you can cross-check get_transaction's tx_status.block_hash. Call get_header on that hash and require get_block_hash(header.number) to return the same hash. If the header is missing or the hashes differ, keep the transaction marked uncertain and reconcile it later rather than building new transactions on its outputs.

#Network and RPC reliability · Fontes (1) · 2026-11-05

Filtering get_cells for plain, typeless, empty funding cellsPráticoVista outra vez

To collect plain funding cells of a lock with the indexer get_cells (or get_cells_capacity) RPC, search with script_type "lock" and add filter output_data_len_range ["0x0","0x1"] and script_len_range ["0x0","0x1"]. Ranges are half-open [start, end), so this keeps only cells with empty data, and since the search is by lock, script_len_range applies to the type script, so only cells with no type script come back. Sorting by capacity on the client only sees the page returned (limit), so page through the results if the lock may own more cells than the limit.

#Indexer queries and cell collection · Fontes (2) · 2026-11-05

Indexer free cell discovery by block scan plus get_live_cell on a local chainPráticoDe uma correção

Without an indexer on a small local chain, cells for a lock can be found by walking get_block_by_number from 0 to the tip, matching output locks, and confirming each hit with get_live_cell (with_data true). The commit also checks get_block_hash per height and at the end, then rechecks each match, so the result is treated as a snapshot that a reorg or spend can invalidate.

#Indexer queries and cell collection #Testing and devnet · Fontes (2) · 2026-11-05

Assert the specific script error code in ckb-testtool rejection testsPráticoDe uma correção

In ckb-testtool tests, checking only that `context.verify_tx(&tx, MAX_CYCLES)` returns an error lets a test keep passing even if the targeted check is deleted from the script, because a badly built transaction usually fails for several reasons. This commit matches the script's exit code in the error string instead (`err.contains("error code {code} ")`), one constant per error discriminant of the script.

#Testing and devnet · Fontes (1) · 2026-11-05

One placeholder witness per input when all inputs share one lockPráticoDe uma correção

In this deploy builder, several funding inputs all share the owner's lock. The signing witness (WitnessArgs) goes at index 0, and every other input gets an empty "0x" witness, so the witnesses list stays as long as the inputs list. That matches the secp256k1 sighash script group layout, where the first witness of the group carries the signature and covers the rest.

#Witnesses and signatures #Transaction building and fees · Fontes (1) · 2026-11-05

completeFeeBy adds change instead of shrinking outputs, breaking output bound proofsPráticoDe uma correção

When a lock script commits to output 0's exact bytes (capacity included), the capacity must be decided before proving and must equal what the transaction ships. In CCC, tx.completeFeeBy(signer) pays the fee by pulling in the signer's cells and adding a change output, so output 0 keeps its capacity and the fee is then paid from extra inputs, which breaks the binding if the proof assumed inputCapacity minus fee. Instead compute the fee from tx.toBytes().length with the witness already at its final length, build output 0 at inputCapacity minus that fee, and check before sending that the fee recomputed on the real transaction equals the planned one.

#Transaction building and fees #Witnesses and signatures #Capacity and cell size · Fontes (1) · 2026-11-04

Reuse one CkbRpcClient across a loop instead of building one per itemPráticoDe uma correção

Constructing a ckb_sdk CkbRpcClient (CkbRpcClient::with_builder) loads the TLS root store, about 6 ms of CPU each time. In Fiber's watchtower, building one per watched channel made a round over 11,496 channels take 93 to 115 s; building one client before the loop and passing &CkbRpcClient cut it to 5 to 7 s.

#Network and RPC reliability · Fontes (1) · 2026-11-03

Reconcile a lost send_transaction response by pinned hash, not by rebuildingPráticoDe uma correção

When a send_transaction response is lost (the node may already have accepted the transaction), this commit pins the signed transaction hash and its input outpoints, and recovers by querying get_transaction for that exact hash and get_live_cell for each input instead of building a new payment. Only a 'committed' status ends the intent; rejected, unknown or spent inputs stay 'uncertain' for operator review, because a fresh rebuild from refreshed cells was shown to let a second payment to the same recipient commit.

#Network and RPC reliability #Transaction building and fees #Indexer queries and cell collection · Fontes (1) · 2026-11-02

ckb-std C shim needs a RISC-V C toolchain (clang) in CIPráticoVerificada pelo dono

ckb-std compiles a C shim for riscv64imac-unknown-none-elf via cc-rs, which by default looks for riscv64-unknown-elf-gcc and fails with ToolNotFound when that toolchain is missing in CI. Pointing cc-rs at clang and llvm-ar (which can target RISC-V) lets the contract build without the GCC cross toolchain.

#Testing and devnet · Fontes (1) · 2026-11-02

ckb-testtool runs scripts only, so node transaction verifiers must be added in testsPráticoDe uma correção

ckb-testtool's Context::verify_tx runs scripts only, so a test can pass with a transaction the node rejects. Build a Consensus from the bundled mainnet chain spec and run ckb-verification's NonContextualTransactionVerifier, CapacityVerifier and DaoScriptSizeVerifier, plus DaoCalculator::transaction_fee for DAO withdraw balance, and add your own checks for inputs below occupied capacity, a cell spent twice and a malformed since (time-dependent maturity can be skipped). Run these on rejected transactions too, so a rejection test fails only for the script rule it targets, or explicitly names the node rule it overlaps.

#Testing and devnet #Capacity and cell size · Fontes (1) · 2026-11-02

Count only empty, typeless lock cells as spendable balancePráticoDe uma correção

When computing a wallet's spendable balance from indexer cells under a lock, count only cells with empty output data and no type script as available. A cell with data or any type script (UDT, DOB, profile or attachment cells, not just your own type) holds state, so its capacity stays in the total but is reported as reserved, because spending it would destroy that state. In cemp-mobile this is `const hasData = cell.data !== "0x" && cell.data !== ""; const isProtocol = hasData || type !== null;`.

#Indexer queries and cell collection #Capacity and cell size · Fontes (1) · 2026-10-31

Dry run a transaction with test_tx_pool_accept before send_transactionPráticoDe uma correção

The CKB node RPC test_tx_pool_accept takes the same params as send_transaction (the snake_case tx JSON without its hash, plus an outputs validator such as "passthrough"). It returns the cycles and fee the pool would accept without broadcasting, so a tool can check a pasted transaction before sending it for real.

#Transaction building and fees #Network and RPC reliability · Fontes (1) · 2026-10-30

Página 7 de 15

Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. JSON · Queres que uma lição seja mudada ou retirada? Abre um issue.