chaintope / bitcoinrb

The implementation of the bitcoin protocol for ruby.
MIT License
61 stars 19 forks source link

SpvChain#find_entry_by_height(height) returns wrong block for height below 16 #8

Closed Yamaguchi closed 6 years ago

Yamaguchi commented 6 years ago

chain.find_entry_by_height(1) returns 16th block chain.find_entry_by_height(2) returns 32th block ...

irb(main):001:0> c = Bitcoin::Node::Configuration.new(network: :regtest)
irb(main):003:0> spv = Bitcoin::Node::SPV.new(c)

irb(main):004:0> spv.chain.find_entry_by_height(1)
=> #<Bitcoin::Store::ChainEntry:0x007f8623194078 @header=#<Bitcoin::BlockHeader:0x007f86231940f0 @version=536870912, 
@prev_hash="17c43d59fd61f0285f714fef20d99123fb17b6113c5b1b0b7e9bf134b4a18553", 
@merkle_root="62cfba7a97a118e5f8dee1d3c2b61a911de8c16a91c03f89dc90c57a75be212a", 
@time=1508298370, @bits=545259519, @nonce=0>, @height=16>

irb(main):005:0> spv.chain.find_entry_by_height(15)
=> #<Bitcoin::Store::ChainEntry:0x007f8624123660 @header=#<Bitcoin::BlockHeader:0x007f8624123688 @version=805306371, 
@prev_hash="1f305cf6495386247a331caf06974f84778d5a60ec969cc81906cbf49a27fe5e", 
@merkle_root="b0575be6cb588bcce660b4095b1f38551def636f092ad3ff9882ae01bc8f5bcf", 
@time=1508298911, @bits=545259519, @nonce=0>, @height=240>

irb(main):006:0> spv.chain.find_entry_by_height(16)
=> #<Bitcoin::Store::ChainEntry:0x007f8622a4ccc0 @header=#<Bitcoin::BlockHeader:0x007f8622a4cce8 @version=536870912, 
@prev_hash="17c43d59fd61f0285f714fef20d99123fb17b6113c5b1b0b7e9bf134b4a18553", 
@merkle_root="62cfba7a97a118e5f8dee1d3c2b61a911de8c16a91c03f89dc90c57a75be212a", 
@time=1508298370, @bits=545259519, @nonce=0>, @height=16>
Yamaguchi commented 6 years ago

あとでPR投げます。

azuchi commented 6 years ago

thanks!