[NOD-675] Replace start-hash/stop-hash with meaningful names (#597)

* [NOD-675] Rename startHash/stopHash to lowHigh/stopHash

* [NOD-675] Fix typo

* [NOD-675] Undo go.mod go.sum conflicts

* [NOD-675] revert back to startHash for getChainFromBlock.

* [NOD-675] Revet back to startHash in getChainFromBlock leftovers.

* [NOD-675] Fix test name.
This commit is contained in:
Dan Aharoni 2020-01-22 18:14:42 +02:00 committed by Svarog
parent 52e0a0967d
commit c0463a8a68
16 changed files with 156 additions and 156 deletions

View File

@ -143,8 +143,8 @@ func messageSummary(msg wire.Message) string {
msg.HighHash) msg.HighHash)
case *wire.MsgGetHeaders: case *wire.MsgGetHeaders:
return fmt.Sprintf("start hash %s, stop hash %s", msg.StartHash, return fmt.Sprintf("low hash %s, high hash %s", msg.LowHash,
msg.StopHash) msg.HighHash)
case *wire.MsgGetBlockLocator: case *wire.MsgGetBlockLocator:
return fmt.Sprintf("high hash %s, low hash %s", msg.HighHash, return fmt.Sprintf("high hash %s, low hash %s", msg.HighHash,

View File

@ -426,8 +426,8 @@ type Peer struct {
prevGetBlockInvsLow *daghash.Hash prevGetBlockInvsLow *daghash.Hash
prevGetBlockInvsHigh *daghash.Hash prevGetBlockInvsHigh *daghash.Hash
prevGetHdrsMtx sync.Mutex prevGetHdrsMtx sync.Mutex
prevGetHdrsStart *daghash.Hash prevGetHdrsLow *daghash.Hash
prevGetHdrsStop *daghash.Hash prevGetHdrsHigh *daghash.Hash
// These fields keep track of statistics for the peer and are protected // These fields keep track of statistics for the peer and are protected
// by the statsMtx mutex. // by the statsMtx mutex.
@ -879,32 +879,32 @@ func (p *Peer) PushBlockLocatorMsg(locator blockdag.BlockLocator) error {
} }
// PushGetHeadersMsg sends a getblockinvs message for the provided block locator // PushGetHeadersMsg sends a getblockinvs message for the provided block locator
// and stop hash. It will ignore back-to-back duplicate requests. // and low hash. It will ignore back-to-back duplicate requests.
// //
// This function is safe for concurrent access. // This function is safe for concurrent access.
func (p *Peer) PushGetHeadersMsg(startHash, stopHash *daghash.Hash) error { func (p *Peer) PushGetHeadersMsg(lowHash, highHash *daghash.Hash) error {
// Filter duplicate getheaders requests. // Filter duplicate getheaders requests.
p.prevGetHdrsMtx.Lock() p.prevGetHdrsMtx.Lock()
isDuplicate := p.prevGetHdrsStop != nil && p.prevGetHdrsStart != nil && isDuplicate := p.prevGetHdrsHigh != nil && p.prevGetHdrsLow != nil &&
startHash != nil && stopHash.IsEqual(p.prevGetHdrsStop) && lowHash != nil && highHash.IsEqual(p.prevGetHdrsHigh) &&
startHash.IsEqual(p.prevGetHdrsStart) lowHash.IsEqual(p.prevGetHdrsLow)
p.prevGetHdrsMtx.Unlock() p.prevGetHdrsMtx.Unlock()
if isDuplicate { if isDuplicate {
log.Tracef("Filtering duplicate [getheaders] with start hash %s", log.Tracef("Filtering duplicate [getheaders] with low hash %s",
startHash) lowHash)
return nil return nil
} }
// Construct the getheaders request and queue it to be sent. // Construct the getheaders request and queue it to be sent.
msg := wire.NewMsgGetHeaders(startHash, stopHash) msg := wire.NewMsgGetHeaders(lowHash, highHash)
p.QueueMessage(msg, nil) p.QueueMessage(msg, nil)
// Update the previous getheaders request information for filtering // Update the previous getheaders request information for filtering
// duplicates. // duplicates.
p.prevGetHdrsMtx.Lock() p.prevGetHdrsMtx.Lock()
p.prevGetHdrsStart = startHash p.prevGetHdrsLow = lowHash
p.prevGetHdrsStop = stopHash p.prevGetHdrsHigh = highHash
p.prevGetHdrsMtx.Unlock() p.prevGetHdrsMtx.Unlock()
return nil return nil
} }

View File

@ -116,7 +116,7 @@ func (c *Client) GetBlock(blockHash *daghash.Hash, subnetworkID *string) (*wire.
type FutureGetBlocksResult chan *response type FutureGetBlocksResult chan *response
// Receive waits for the response promised by the future and returns the blocks // Receive waits for the response promised by the future and returns the blocks
// starting from startHash up to the virtual ordered by blue score. // starting from lowHash up to the virtual ordered by blue score.
func (r FutureGetBlocksResult) Receive() (*rpcmodel.GetBlocksResult, error) { func (r FutureGetBlocksResult) Receive() (*rpcmodel.GetBlocksResult, error) {
res, err := receiveFuture(r) res, err := receiveFuture(r)
if err != nil { if err != nil {
@ -135,15 +135,15 @@ func (r FutureGetBlocksResult) Receive() (*rpcmodel.GetBlocksResult, error) {
// returned instance. // returned instance.
// //
// See GetBlocks for the blocking version and more details. // See GetBlocks for the blocking version and more details.
func (c *Client) GetBlocksAsync(includeRawBlockData bool, IncludeVerboseBlockData bool, startHash *string) FutureGetBlocksResult { func (c *Client) GetBlocksAsync(includeRawBlockData bool, IncludeVerboseBlockData bool, lowHash *string) FutureGetBlocksResult {
cmd := rpcmodel.NewGetBlocksCmd(includeRawBlockData, IncludeVerboseBlockData, startHash) cmd := rpcmodel.NewGetBlocksCmd(includeRawBlockData, IncludeVerboseBlockData, lowHash)
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
// GetBlocks returns the blocks starting from startHash up to the virtual ordered // GetBlocks returns the blocks starting from lowHash up to the virtual ordered
// by blue score. // by blue score.
func (c *Client) GetBlocks(includeRawBlockData bool, includeVerboseBlockData bool, startHash *string) (*rpcmodel.GetBlocksResult, error) { func (c *Client) GetBlocks(includeRawBlockData bool, includeVerboseBlockData bool, lowHash *string) (*rpcmodel.GetBlocksResult, error) {
return c.GetBlocksAsync(includeRawBlockData, includeVerboseBlockData, startHash).Receive() return c.GetBlocksAsync(includeRawBlockData, includeVerboseBlockData, lowHash).Receive()
} }
// FutureGetBlockVerboseResult is a future promise to deliver the result of a // FutureGetBlockVerboseResult is a future promise to deliver the result of a

View File

@ -482,24 +482,24 @@ func (c *Client) GetTopHeaders(highHash *daghash.Hash) ([]wire.BlockHeader, erro
// of the RPC at some future time by invoking the Receive function on the returned instance. // of the RPC at some future time by invoking the Receive function on the returned instance.
// //
// See GetHeaders for the blocking version and more details. // See GetHeaders for the blocking version and more details.
func (c *Client) GetHeadersAsync(startHash, stopHash *daghash.Hash) FutureGetHeadersResult { func (c *Client) GetHeadersAsync(lowHash, highHash *daghash.Hash) FutureGetHeadersResult {
startHashStr := "" lowHashStr := ""
if startHash != nil { if lowHash != nil {
startHashStr = startHash.String() lowHashStr = lowHash.String()
} }
stopHashStr := "" highHashStr := ""
if stopHash != nil { if highHash != nil {
stopHashStr = stopHash.String() highHashStr = highHash.String()
} }
cmd := rpcmodel.NewGetHeadersCmd(startHashStr, stopHashStr) cmd := rpcmodel.NewGetHeadersCmd(lowHashStr, highHashStr)
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
// GetHeaders mimics the wire protocol getheaders and headers messages by // GetHeaders mimics the wire protocol getheaders and headers messages by
// returning all headers in the DAG after the first known block in the // returning all headers in the DAG after the first known block in the
// locators, up until a block hash matches stopHash. // locators, up until a block hash matches highHash.
func (c *Client) GetHeaders(startHash, stopHash *daghash.Hash) ([]wire.BlockHeader, error) { func (c *Client) GetHeaders(lowHash, highHash *daghash.Hash) ([]wire.BlockHeader, error) {
return c.GetHeadersAsync(startHash, stopHash).Receive() return c.GetHeadersAsync(lowHash, highHash).Receive()
} }
// FutureSessionResult is a future promise to deliver the result of a // FutureSessionResult is a future promise to deliver the result of a

View File

@ -157,16 +157,16 @@ func NewGetBlockCmd(hash string, verbose, verboseTx *bool, subnetworkID *string)
type GetBlocksCmd struct { type GetBlocksCmd struct {
IncludeRawBlockData bool `json:"includeRawBlockData"` IncludeRawBlockData bool `json:"includeRawBlockData"`
IncludeVerboseBlockData bool `json:"includeVerboseBlockData"` IncludeVerboseBlockData bool `json:"includeVerboseBlockData"`
StartHash *string `json:"startHash"` LowHash *string `json:"lowHash"`
} }
// NewGetBlocksCmd returns a new instance which can be used to issue a // NewGetBlocksCmd returns a new instance which can be used to issue a
// GetGetBlocks JSON-RPC command. // GetGetBlocks JSON-RPC command.
func NewGetBlocksCmd(includeRawBlockData bool, includeVerboseBlockData bool, startHash *string) *GetBlocksCmd { func NewGetBlocksCmd(includeRawBlockData bool, includeVerboseBlockData bool, lowHash *string) *GetBlocksCmd {
return &GetBlocksCmd{ return &GetBlocksCmd{
IncludeRawBlockData: includeRawBlockData, IncludeRawBlockData: includeRawBlockData,
IncludeVerboseBlockData: includeVerboseBlockData, IncludeVerboseBlockData: includeVerboseBlockData,
StartHash: startHash, LowHash: lowHash,
} }
} }

View File

@ -201,7 +201,7 @@ func TestRPCServerCommands(t *testing.T) {
unmarshalled: &rpcmodel.GetBlocksCmd{ unmarshalled: &rpcmodel.GetBlocksCmd{
IncludeRawBlockData: true, IncludeRawBlockData: true,
IncludeVerboseBlockData: true, IncludeVerboseBlockData: true,
StartHash: rpcmodel.String("123"), LowHash: rpcmodel.String("123"),
}, },
}, },
{ {
@ -987,7 +987,7 @@ func TestRPCServerCommands(t *testing.T) {
unmarshalled: &rpcmodel.GetTopHeadersCmd{}, unmarshalled: &rpcmodel.GetTopHeadersCmd{},
}, },
{ {
name: "getTopHeaders - with start hash", name: "getTopHeaders - with high hash",
newCmd: func() (interface{}, error) { newCmd: func() (interface{}, error) {
return rpcmodel.NewCommand("getTopHeaders", "000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7") return rpcmodel.NewCommand("getTopHeaders", "000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7")
}, },

View File

@ -16,20 +16,20 @@ const (
func handleGetBlocks(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { func handleGetBlocks(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
c := cmd.(*rpcmodel.GetBlocksCmd) c := cmd.(*rpcmodel.GetBlocksCmd)
var startHash *daghash.Hash var lowHash *daghash.Hash
if c.StartHash != nil { if c.LowHash != nil {
startHash = &daghash.Hash{} lowHash = &daghash.Hash{}
err := daghash.Decode(startHash, *c.StartHash) err := daghash.Decode(lowHash, *c.LowHash)
if err != nil { if err != nil {
return nil, rpcDecodeHexError(*c.StartHash) return nil, rpcDecodeHexError(*c.LowHash)
} }
} }
s.cfg.DAG.RLock() s.cfg.DAG.RLock()
defer s.cfg.DAG.RUnlock() defer s.cfg.DAG.RUnlock()
// If startHash is not in the DAG, there's nothing to do; return an error. // If lowHash is not in the DAG, there's nothing to do; return an error.
if startHash != nil && !s.cfg.DAG.HaveBlock(startHash) { if lowHash != nil && !s.cfg.DAG.HaveBlock(lowHash) {
return nil, &rpcmodel.RPCError{ return nil, &rpcmodel.RPCError{
Code: rpcmodel.ErrRPCBlockNotFound, Code: rpcmodel.ErrRPCBlockNotFound,
Message: "Block not found", Message: "Block not found",
@ -37,7 +37,7 @@ func handleGetBlocks(s *Server, cmd interface{}, closeChan <-chan struct{}) (int
} }
// Retrieve the block hashes. // Retrieve the block hashes.
blockHashes, err := s.cfg.DAG.BlockHashesFrom(startHash, maxBlocksInGetBlocksResult) blockHashes, err := s.cfg.DAG.BlockHashesFrom(lowHash, maxBlocksInGetBlocksResult)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -172,11 +172,11 @@ var helpDescsEnUS = map[string]string{
"getBlock--result0": "Hex-encoded bytes of the serialized block", "getBlock--result0": "Hex-encoded bytes of the serialized block",
// GetBlocksCmd help. // GetBlocksCmd help.
"getBlocks--synopsis": "Return the blocks starting from startHash up to the virtual ordered by blue score.", "getBlocks--synopsis": "Return the blocks starting from lowHash up to the virtual ordered by blue score.",
"getBlocks-includeRawBlockData": "If set to true - the raw block data would be also included.", "getBlocks-includeRawBlockData": "If set to true - the raw block data would be also included.",
"getBlocks-includeVerboseBlockData": "If set to true - the verbose block data would also be included.", "getBlocks-includeVerboseBlockData": "If set to true - the verbose block data would also be included.",
"getBlocks-startHash": "Hash of the block with the bottom blue score. If this hash is unknown - returns an error.", "getBlocks-lowHash": "Hash of the block with the bottom blue score. If this hash is unknown - returns an error.",
"getBlocks--result0": "Blocks starting from startHash. The result may contains up to 1000 blocks. For the remainder, call the command again with the bluest block's hash.", "getBlocks--result0": "Blocks starting from lowHash. The result may contains up to 1000 blocks. For the remainder, call the command again with the bluest block's hash.",
// GetChainFromBlockResult help. // GetChainFromBlockResult help.
"getBlocksResult-hashes": "List of hashes from StartHash (excluding StartHash) ordered by smallest blue score to greatest.", "getBlocksResult-hashes": "List of hashes from StartHash (excluding StartHash) ordered by smallest blue score to greatest.",
@ -393,7 +393,7 @@ var helpDescsEnUS = map[string]string{
"infoDagResult-errors": "Any current errors", "infoDagResult-errors": "Any current errors",
// GetTopHeadersCmd help. // GetTopHeadersCmd help.
"getTopHeaders--synopsis": "Returns the top block headers starting with the provided start hash (not inclusive)", "getTopHeaders--synopsis": "Returns the top block headers starting with the provided high hash (not inclusive)",
"getTopHeaders-highHash": "Block hash to start including block headers from; if not found, it'll start from the virtual.", "getTopHeaders-highHash": "Block hash to start including block headers from; if not found, it'll start from the virtual.",
"getTopHeaders--result0": "Serialized block headers of all located blocks, limited to some arbitrary maximum number of hashes (currently 2000, which matches the wire protocol headers message, but this is not guaranteed)", "getTopHeaders--result0": "Serialized block headers of all located blocks, limited to some arbitrary maximum number of hashes (currently 2000, which matches the wire protocol headers message, but this is not guaranteed)",

View File

@ -379,8 +379,8 @@ func BenchmarkWriteBlockHeader(b *testing.B) {
func BenchmarkDecodeGetHeaders(b *testing.B) { func BenchmarkDecodeGetHeaders(b *testing.B) {
pver := ProtocolVersion pver := ProtocolVersion
var m MsgGetHeaders var m MsgGetHeaders
m.StartHash = &daghash.Hash{1} m.LowHash = &daghash.Hash{1}
m.StopHash = &daghash.Hash{1} m.HighHash = &daghash.Hash{1}
// Serialize it so the bytes are available to test the decode below. // Serialize it so the bytes are available to test the decode below.
var bb bytes.Buffer var bb bytes.Buffer

View File

@ -175,7 +175,7 @@ func TestBlockLocatorWireErrors(t *testing.T) {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgBlockLocator message with multiple block locators and a stop hash. // MsgBlockLocator message with multiple block locators and a low hash.
baseGetBlocks := NewMsgBlockLocator() baseGetBlocks := NewMsgBlockLocator()
baseGetBlocks.AddBlockLocatorHash(hashLocator2) baseGetBlocks.AddBlockLocatorHash(hashLocator2)
baseGetBlocks.AddBlockLocatorHash(hashLocator) baseGetBlocks.AddBlockLocatorHash(hashLocator)

View File

@ -12,7 +12,7 @@ import (
// MsgGetBlockInvs implements the Message interface and represents a kaspa // MsgGetBlockInvs implements the Message interface and represents a kaspa
// getblockinvs message. It is used to request a list of blocks starting after the // getblockinvs message. It is used to request a list of blocks starting after the
// start hash and until the stop hash. // low hash and until the high hash.
type MsgGetBlockInvs struct { type MsgGetBlockInvs struct {
LowHash *daghash.Hash LowHash *daghash.Hash
HighHash *daghash.Hash HighHash *daghash.Hash
@ -51,7 +51,7 @@ func (msg *MsgGetBlockInvs) Command() string {
// MaxPayloadLength returns the maximum length the payload can be for the // MaxPayloadLength returns the maximum length the payload can be for the
// receiver. This is part of the Message interface implementation. // receiver. This is part of the Message interface implementation.
func (msg *MsgGetBlockInvs) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgGetBlockInvs) MaxPayloadLength(pver uint32) uint32 {
// start hash + stop hash. // low hash + high hash.
return 2 * daghash.HashSize return 2 * daghash.HashSize
} }

View File

@ -19,22 +19,22 @@ func TestGetBlockInvs(t *testing.T) {
pver := ProtocolVersion pver := ProtocolVersion
hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
startHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// Ensure we get the same data back out. // Ensure we get the same data back out.
msg := NewMsgGetBlockInvs(startHash, stopHash) msg := NewMsgGetBlockInvs(lowHash, highHash)
if !msg.HighHash.IsEqual(stopHash) { if !msg.HighHash.IsEqual(highHash) {
t.Errorf("NewMsgGetBlockInvs: wrong stop hash - got %v, want %v", t.Errorf("NewMsgGetBlockInvs: wrong high hash - got %v, want %v",
msg.HighHash, stopHash) msg.HighHash, highHash)
} }
// Ensure the command is expected value. // Ensure the command is expected value.
@ -44,7 +44,7 @@ func TestGetBlockInvs(t *testing.T) {
cmd, wantCmd) cmd, wantCmd)
} }
// Ensure max payload is start hash (32 bytes) + stop hash (32 bytes). // Ensure max payload is low hash (32 bytes) + high hash (32 bytes).
wantPayload := uint32(64) wantPayload := uint32(64)
maxPayload := msg.MaxPayloadLength(pver) maxPayload := msg.MaxPayloadLength(pver)
if maxPayload != wantPayload { if maxPayload != wantPayload {
@ -58,41 +58,41 @@ func TestGetBlockInvs(t *testing.T) {
// numbers of block locator hashes and protocol versions. // numbers of block locator hashes and protocol versions.
func TestGetBlockInvsWire(t *testing.T) { func TestGetBlockInvsWire(t *testing.T) {
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
startHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgGetBlocks message with no start or stop hash. // MsgGetBlocks message with no start or high hash.
noStartOrStop := NewMsgGetBlockInvs(&daghash.Hash{}, &daghash.Hash{}) noStartOrStop := NewMsgGetBlockInvs(&daghash.Hash{}, &daghash.Hash{})
noStartOrStopEncoded := []byte{ noStartOrStopEncoded := []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
} }
// MsgGetBlockInvs message with a start hash and a stop hash. // MsgGetBlockInvs message with a low hash and a high hash.
withStartAndStopHash := NewMsgGetBlockInvs(startHash, stopHash) withLowAndHighHash := NewMsgGetBlockInvs(lowHash, highHash)
withStartAndStopHashEncoded := []byte{ withLowAndHighHashEncoded := []byte{
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40, 0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
} }
tests := []struct { tests := []struct {
@ -111,9 +111,9 @@ func TestGetBlockInvsWire(t *testing.T) {
// Latest protocol version with multiple block locators. // Latest protocol version with multiple block locators.
{ {
withStartAndStopHash, withLowAndHighHash,
withStartAndStopHash, withLowAndHighHash,
withStartAndStopHashEncoded, withLowAndHighHashEncoded,
ProtocolVersion, ProtocolVersion,
}, },
} }
@ -156,28 +156,28 @@ func TestGetBlockInvsWireErrors(t *testing.T) {
pver := ProtocolVersion pver := ProtocolVersion
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
startHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgGetBlockInvs message with multiple block locators and a stop hash. // MsgGetBlockInvs message with multiple block locators and a high hash.
baseGetBlocks := NewMsgGetBlockInvs(startHash, stopHash) baseGetBlocks := NewMsgGetBlockInvs(lowHash, highHash)
baseGetBlocksEncoded := []byte{ baseGetBlocksEncoded := []byte{
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40, 0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
} }
tests := []struct { tests := []struct {
@ -188,9 +188,9 @@ func TestGetBlockInvsWireErrors(t *testing.T) {
writeErr error // Expected write error writeErr error // Expected write error
readErr error // Expected read error readErr error // Expected read error
}{ }{
// Force error in start hash. // Force error in low hash.
{baseGetBlocks, baseGetBlocksEncoded, pver, 0, io.ErrShortWrite, io.EOF}, {baseGetBlocks, baseGetBlocksEncoded, pver, 0, io.ErrShortWrite, io.EOF},
// Force error in stop hash. // Force error in high hash.
{baseGetBlocks, baseGetBlocksEncoded, pver, 32, io.ErrShortWrite, io.EOF}, {baseGetBlocks, baseGetBlocksEncoded, pver, 32, io.ErrShortWrite, io.EOF},
} }

View File

@ -7,7 +7,7 @@ import (
) )
// MsgGetBlockLocator implements the Message interface and represents a kaspa // MsgGetBlockLocator implements the Message interface and represents a kaspa
// getlocator message. It is used to request a block locator between start and stop hash. // getlocator message. It is used to request a block locator between high and low hash.
// The locator is returned via a locator message (MsgBlockLocator). // The locator is returned via a locator message (MsgBlockLocator).
type MsgGetBlockLocator struct { type MsgGetBlockLocator struct {
HighHash *daghash.Hash HighHash *daghash.Hash

View File

@ -15,20 +15,20 @@ func TestGetBlockLocator(t *testing.T) {
pver := ProtocolVersion pver := ProtocolVersion
hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
startHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// Ensure the command is expected value. // Ensure the command is expected value.
wantCmd := "getlocator" wantCmd := "getlocator"
msg := NewMsgGetBlockLocator(startHash, &daghash.ZeroHash) msg := NewMsgGetBlockLocator(highHash, &daghash.ZeroHash)
if cmd := msg.Command(); cmd != wantCmd { if cmd := msg.Command(); cmd != wantCmd {
t.Errorf("NewMsgGetBlockLocator: wrong command - got %v want %v", t.Errorf("NewMsgGetBlockLocator: wrong command - got %v want %v",
cmd, wantCmd) cmd, wantCmd)
} }
// Ensure max payload is start hash (32 bytes) + stop hash (32 bytes).. // Ensure max payload is low hash (32 bytes) + high hash (32 bytes)..
wantPayload := uint32(64) wantPayload := uint32(64)
maxPayload := msg.MaxPayloadLength(pver) maxPayload := msg.MaxPayloadLength(pver)
if maxPayload != wantPayload { if maxPayload != wantPayload {
@ -41,41 +41,41 @@ func TestGetBlockLocator(t *testing.T) {
// TestGetBlockLocatorWire tests the MsgGetBlockLocator wire encode and decode. // TestGetBlockLocatorWire tests the MsgGetBlockLocator wire encode and decode.
func TestGetBlockLocatorWire(t *testing.T) { func TestGetBlockLocatorWire(t *testing.T) {
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
startHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgGetBlockLocator message with no block locators or stop hash. // MsgGetBlockLocator message with no block locators or high hash.
noStartAndStopHash := NewMsgGetBlockLocator(&daghash.ZeroHash, &daghash.ZeroHash) noLowAndHighHash := NewMsgGetBlockLocator(&daghash.ZeroHash, &daghash.ZeroHash)
noStartAndStopHashEncoded := []byte{ noLowAndHighHashEncoded := []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
} }
// MsgGetBlockLocator message with multiple block locators and a stop hash. // MsgGetBlockLocator message with multiple block locators and a high hash.
withStartAndStopHash := NewMsgGetBlockLocator(startHash, stopHash) withLowAndHighHash := NewMsgGetBlockLocator(highHash, lowHash)
withStartAndStopHashEncoded := []byte{ withLowAndHighHashEncoded := []byte{
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40, 0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
} }
tests := []struct { tests := []struct {
@ -84,19 +84,19 @@ func TestGetBlockLocatorWire(t *testing.T) {
buf []byte // Wire encoding buf []byte // Wire encoding
pver uint32 // Protocol version for wire encoding pver uint32 // Protocol version for wire encoding
}{ }{
// Message with no start hash and stop hash. // Message with no low hash and high hash.
{ {
noStartAndStopHash, noLowAndHighHash,
noStartAndStopHash, noLowAndHighHash,
noStartAndStopHashEncoded, noLowAndHighHashEncoded,
ProtocolVersion, ProtocolVersion,
}, },
// Message with start hash and stop hash. // Message with low hash and high hash.
{ {
withStartAndStopHash, withLowAndHighHash,
withStartAndStopHash, withLowAndHighHash,
withStartAndStopHashEncoded, withLowAndHighHashEncoded,
ProtocolVersion, ProtocolVersion,
}, },
} }
@ -139,28 +139,28 @@ func TestGetBlockLocatorWireErrors(t *testing.T) {
pver := ProtocolVersion pver := ProtocolVersion
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
startHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgGetBlockLocator message with multiple block locators and a stop hash. // MsgGetBlockLocator message with multiple block locators and a high hash.
baseGetBlockLocator := NewMsgGetBlockLocator(startHash, stopHash) baseGetBlockLocator := NewMsgGetBlockLocator(highHash, lowHash)
baseGetBlockLocatorEncoded := []byte{ baseGetBlockLocatorEncoded := []byte{
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40, 0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
} }
tests := []struct { tests := []struct {
@ -171,9 +171,9 @@ func TestGetBlockLocatorWireErrors(t *testing.T) {
writeErr error // Expected write error writeErr error // Expected write error
readErr error // Expected read error readErr error // Expected read error
}{ }{
// Force error in start hash. // Force error in low hash.
{baseGetBlockLocator, baseGetBlockLocatorEncoded, pver, 0, io.ErrShortWrite, io.EOF}, {baseGetBlockLocator, baseGetBlockLocatorEncoded, pver, 0, io.ErrShortWrite, io.EOF},
// Force error in stop hash. // Force error in high hash.
{baseGetBlockLocator, baseGetBlockLocatorEncoded, pver, 32, io.ErrShortWrite, io.EOF}, {baseGetBlockLocator, baseGetBlockLocatorEncoded, pver, 32, io.ErrShortWrite, io.EOF},
} }

View File

@ -27,32 +27,32 @@ import (
// exponentially decrease the number of hashes the further away from head and // exponentially decrease the number of hashes the further away from head and
// closer to the genesis block you get. // closer to the genesis block you get.
type MsgGetHeaders struct { type MsgGetHeaders struct {
StartHash *daghash.Hash LowHash *daghash.Hash
StopHash *daghash.Hash HighHash *daghash.Hash
} }
// KaspaDecode decodes r using the kaspa protocol encoding into the receiver. // KaspaDecode decodes r using the kaspa protocol encoding into the receiver.
// This is part of the Message interface implementation. // This is part of the Message interface implementation.
func (msg *MsgGetHeaders) KaspaDecode(r io.Reader, pver uint32) error { func (msg *MsgGetHeaders) KaspaDecode(r io.Reader, pver uint32) error {
msg.StartHash = &daghash.Hash{} msg.LowHash = &daghash.Hash{}
err := ReadElement(r, msg.StartHash) err := ReadElement(r, msg.LowHash)
if err != nil { if err != nil {
return err return err
} }
msg.StopHash = &daghash.Hash{} msg.HighHash = &daghash.Hash{}
return ReadElement(r, msg.StopHash) return ReadElement(r, msg.HighHash)
} }
// KaspaEncode encodes the receiver to w using the kaspa protocol encoding. // KaspaEncode encodes the receiver to w using the kaspa protocol encoding.
// This is part of the Message interface implementation. // This is part of the Message interface implementation.
func (msg *MsgGetHeaders) KaspaEncode(w io.Writer, pver uint32) error { func (msg *MsgGetHeaders) KaspaEncode(w io.Writer, pver uint32) error {
err := WriteElement(w, msg.StartHash) err := WriteElement(w, msg.LowHash)
if err != nil { if err != nil {
return err return err
} }
return WriteElement(w, msg.StopHash) return WriteElement(w, msg.HighHash)
} }
// Command returns the protocol command string for the message. This is part // Command returns the protocol command string for the message. This is part
@ -64,15 +64,15 @@ func (msg *MsgGetHeaders) Command() string {
// MaxPayloadLength returns the maximum length the payload can be for the // MaxPayloadLength returns the maximum length the payload can be for the
// receiver. This is part of the Message interface implementation. // receiver. This is part of the Message interface implementation.
func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32 { func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32 {
// start hash + stop hash. // low hash + high hash.
return 2 * daghash.HashSize return 2 * daghash.HashSize
} }
// NewMsgGetHeaders returns a new kaspa getheaders message that conforms to // NewMsgGetHeaders returns a new kaspa getheaders message that conforms to
// the Message interface. See MsgGetHeaders for details. // the Message interface. See MsgGetHeaders for details.
func NewMsgGetHeaders(startHash, stopHash *daghash.Hash) *MsgGetHeaders { func NewMsgGetHeaders(lowHash, highHash *daghash.Hash) *MsgGetHeaders {
return &MsgGetHeaders{ return &MsgGetHeaders{
StartHash: startHash, LowHash: lowHash,
StopHash: stopHash, HighHash: highHash,
} }
} }

View File

@ -20,20 +20,20 @@ func TestGetHeaders(t *testing.T) {
// Block 99500 hash. // Block 99500 hash.
hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
startHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// Ensure the command is expected value. // Ensure the command is expected value.
wantCmd := "getheaders" wantCmd := "getheaders"
msg := NewMsgGetHeaders(startHash, &daghash.ZeroHash) msg := NewMsgGetHeaders(lowHash, &daghash.ZeroHash)
if cmd := msg.Command(); cmd != wantCmd { if cmd := msg.Command(); cmd != wantCmd {
t.Errorf("NewMsgGetHeaders: wrong command - got %v want %v", t.Errorf("NewMsgGetHeaders: wrong command - got %v want %v",
cmd, wantCmd) cmd, wantCmd)
} }
// Ensure max payload is start hash (32 bytes) + stop hash (32 bytes).. // Ensure max payload is low hash (32 bytes) + high hash (32 bytes)..
wantPayload := uint32(64) wantPayload := uint32(64)
maxPayload := msg.MaxPayloadLength(pver) maxPayload := msg.MaxPayloadLength(pver)
if maxPayload != wantPayload { if maxPayload != wantPayload {
@ -46,41 +46,41 @@ func TestGetHeaders(t *testing.T) {
// TestGetHeadersWire tests the MsgGetHeaders wire encode and decode. // TestGetHeadersWire tests the MsgGetHeaders wire encode and decode.
func TestGetHeadersWire(t *testing.T) { func TestGetHeadersWire(t *testing.T) {
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
startHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgGetHeaders message with no block locators or stop hash. // MsgGetHeaders message with no block locators or high hash.
noStartAndStopHash := NewMsgGetHeaders(&daghash.ZeroHash, &daghash.ZeroHash) noLowAndHighHash := NewMsgGetHeaders(&daghash.ZeroHash, &daghash.ZeroHash)
noStartAndStopHashEncoded := []byte{ noLowAndHighHashEncoded := []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
} }
// MsgGetHeaders message with multiple block locators and a stop hash. // MsgGetHeaders message with multiple block locators and a high hash.
withStartAndStopHash := NewMsgGetHeaders(startHash, stopHash) withLowAndHighHash := NewMsgGetHeaders(lowHash, highHash)
withStartAndStopHashEncoded := []byte{ withLowAndHighHashEncoded := []byte{
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40, 0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
} }
tests := []struct { tests := []struct {
@ -89,19 +89,19 @@ func TestGetHeadersWire(t *testing.T) {
buf []byte // Wire encoding buf []byte // Wire encoding
pver uint32 // Protocol version for wire encoding pver uint32 // Protocol version for wire encoding
}{ }{
// Message with no start hash and stop hash. // Message with no low hash and high hash.
{ {
noStartAndStopHash, noLowAndHighHash,
noStartAndStopHash, noLowAndHighHash,
noStartAndStopHashEncoded, noLowAndHighHashEncoded,
ProtocolVersion, ProtocolVersion,
}, },
// Message with start hash and stop hash. // Message with low hash and high hash.
{ {
withStartAndStopHash, withLowAndHighHash,
withStartAndStopHash, withLowAndHighHash,
withStartAndStopHashEncoded, withLowAndHighHashEncoded,
ProtocolVersion, ProtocolVersion,
}, },
} }
@ -144,28 +144,28 @@ func TestGetHeadersWireErrors(t *testing.T) {
pver := ProtocolVersion pver := ProtocolVersion
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
startHash, err := daghash.NewHashFromStr(hashStr) lowHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
stopHash, err := daghash.NewHashFromStr(hashStr) highHash, err := daghash.NewHashFromStr(hashStr)
if err != nil { if err != nil {
t.Errorf("NewHashFromStr: %v", err) t.Errorf("NewHashFromStr: %v", err)
} }
// MsgGetHeaders message with multiple block locators and a stop hash. // MsgGetHeaders message with multiple block locators and a high hash.
baseGetHeaders := NewMsgGetHeaders(startHash, stopHash) baseGetHeaders := NewMsgGetHeaders(lowHash, highHash)
baseGetHeadersEncoded := []byte{ baseGetHeadersEncoded := []byte{
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40, 0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Start hash 0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39, 0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa, 0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Stop hash 0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash
} }
tests := []struct { tests := []struct {
@ -176,9 +176,9 @@ func TestGetHeadersWireErrors(t *testing.T) {
writeErr error // Expected write error writeErr error // Expected write error
readErr error // Expected read error readErr error // Expected read error
}{ }{
// Force error in start hash. // Force error in low hash.
{baseGetHeaders, baseGetHeadersEncoded, pver, 0, io.ErrShortWrite, io.EOF}, {baseGetHeaders, baseGetHeadersEncoded, pver, 0, io.ErrShortWrite, io.EOF},
// Force error in stop hash. // Force error in high hash.
{baseGetHeaders, baseGetHeadersEncoded, pver, 32, io.ErrShortWrite, io.EOF}, {baseGetHeaders, baseGetHeadersEncoded, pver, 32, io.ErrShortWrite, io.EOF},
} }