jimmysong / programmingbitcoin

Repository for the book
Other
1.75k stars 656 forks source link

mainnet.programmingbitcoin.com not responding for getheaders message #258

Closed fedetaladriz closed 2 years ago

fedetaladriz commented 2 years ago

Hello! I'm in chapter 10 of the book. Now I'm trying to connect my node to the node with URL mainnet.programmingbitcoin.com.

I managed to handshake the node (I sent a version message and I got back a verack message). Until then, everything is going well. But when I send a getheaders message, I don't receive anything back. What am I doing wrong? Or there is something bad with the node?

This is part of my getHeaders class (implementation in ruby):

def initialize(version: 70015, num_hashes: 1, start_block: nil, end_block: nil)
  @version = version
  @num_hashes = num_hashes

  raise 'a start block is required' if start_block.nil?

  @start_block = start_block
  @end_block = end_block.nil? ? "\x00" * 32 : end_block
end

def serialize
  result = int_to_little_endian(@version, 4)
  result << encode_varint(@num_hashes)
  result << @start_block.reverse
  result << @end_block.reverse

  result
end
fedetaladriz commented 2 years ago

Never mind, my mistake 😄 I was sending a version message instead of a verack when i received a version. 🤦 Thanks!