Skip to content

Reliability changes ​

The first reliability pass kept the bundled Bitcoin dependency unchanged. The current native upgrade pins a newer Bitcoin Core snapshot and adds header Merkle roots, witness stacks, wtxids, transaction validation state, custom signet challenges, database-cache configuration, and mock time.

Correctness fixes ​

AreaFailureCorrected behavior
Logging ABIIncorrect callback argument order and packed struct alignment could abort the process.Natural C alignment, correct argument order, and byte-length UTF-8 decoding.
Callback lifetimeLogging used a transient callback; notifications passed the wrapper instead of its payload; validation registrations leaked.Persistent registrations, correct payloads, and release when the last native owner is destroyed.
Header processingAn owned pointer return was declared as an integer with an extra output argument.Returns an owned BlockValidationState; invalid headers carry an invalid state.
Block serializationReturning 1 from the writer stopped serialization, while the wrapper treated the failure as success.Shared zero-on-success writer returns the complete block.
Null pointersChecks against only 0n missed Koffi's null, including map membership tests.Missing lookups return false or throw; genesis previous returns null.
ImportsNative zero-on-success result was inverted.importBlocks() returns true on success, including an empty batch.
OwnershipBorrowed descendants could access freed native memory, and disposed views remained usable.Parent-chain and handle checks reject stale access, copying, and detachment.
PrecomputationThe copy path called the transaction-only constructor with a pointer; spent-output marshalling was fragile.Pointer constructor overload and a native-width pointer buffer; input-count validation.
Input validationInvalid indices, flags, enums, and counts could reach native assertions. Unsafe amounts could be rounded.JavaScript exceptions before entering C.
Temporary resourcesBootstrap helpers and block stringification leaked owned intermediates.Deterministic cleanup on success and failure.
Logging utilitiesNested category scopes disabled outer scopes; fractional timestamps failed parsing.Scope reference counts and fractional timestamp support.

Ownership and compatibility ​

Use using in TypeScript or try/finally with dispose() for owned native objects. This library does not automatically reclaim owned pointers through JavaScript garbage collection. copy() returns an independent owned wrapper; detach() promotes a borrowed wrapper to ownership. Detaching a parent invalidates previously obtained descendants into its old storage; fetch those descendants again afterward.

Validation callback arguments now have an explicit callback lifetime. Copy a block or state inside the callback to retain it, and dispose the copy when finished. Store entry heights/hash bytes instead of retaining callback entries. See validation callbacks.

Other observable corrections:

  • BlockTreeEntry.previous is nullable at genesis.
  • importBlocks() reports successful completion as true.
  • NotificationInterfaceCallbacks, SynchronizationState, and callback option types are available from the package root.
  • Invalid numeric arguments fail early with RangeError.
  • ValidationInterfaceCallbacks remains an actual class instance.
  • Header validation failures are represented by the returned validation state, rather than an exception for an incorrectly interpreted pointer.

Verification ​

bash
npm test
npm run type-check
npm run lint
npm run build
npm run docs:build

The tests use Node's test runner, named cases, assertions, isolated temporary databases, and cleanup with using. Tests run in separate processes so global native logging state does not leak between files. Both source and tests are type-checked.

Regression coverage includes complete serialization, native logging, callback ownership and slot reclamation, invalid-input guards, all 206 regtest fixture blocks, spent-coin undo data, a locally mined competing-chain reorganization, nonempty UTF-8 block-file imports, database reopen, and signet genesis initialization. Signet coverage is local initialization, not a live-network sync.

Experimental software. Do not use for consensus-critical systems or funds handling.