yegor256/sibit

`Sibit::Blockchain#height` returns nil on missing `height` field while siblings raise

Open

#268 opened on Jun 23, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Ruby (6 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (27 stars)
PR merge metrics
 (PR metrics pending)

Description

Sibit::Blockchain#height at lib/sibit/blockchain.rb:46-53 returns nil whenever the blockchain.info/rawblock/<hash> response body lacks a height field, while every sibling implementation under the same contract raises Sibit::Error in that case:

  • Sibit::Btc#height (lib/sibit/btc.rb:70-79) raises "The block #{hash} found but the height is absent" when data['height'] is nil.
  • Sibit::Sochain#height (lib/sibit/sochain.rb:46-55) raises "The block #{hash} found but the height is absent" when data['block_no'] is nil.
  • Sibit::Bitcoinchain#height and Sibit::Cex#height raise Sibit::NotSupportedError outright.

The silent return is invisible to Sibit::FirstOf and Sibit::BestOf, which only fall back on Sibit::Error/Sibit::NotSupportedError. A nil height therefore short-circuits the consensus chain instead of escalating to the next provider, and downstream Integer(h) calls or arithmetic on the result crash later with a less informative TypeError.

The fix is one guard line: raise Sibit::Error, "The block #{hash} found but the height is absent" when h.nil?, mirroring the sibling adapters. A regression test under test/test_blockchain.rb stubbing a rawblock response without height and asserting the raise would lock the contract in place.

Contributor guide