From c0463a8a680c03fc150b11a50705883ad5f6919f Mon Sep 17 00:00:00 2001 From: Dan Aharoni Date: Wed, 22 Jan 2020 18:14:42 +0200 Subject: [PATCH] [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. --- peer/log.go | 4 +-- peer/peer.go | 24 ++++++------- rpcclient/dag.go | 12 +++---- rpcclient/net.go | 22 ++++++------ rpcmodel/rpc_commands.go | 6 ++-- rpcmodel/rpc_commands_test.go | 4 +-- server/rpc/handle_get_blocks.go | 16 ++++----- server/rpc/rpcserverhelp.go | 8 ++--- wire/bench_test.go | 4 +-- wire/msgblocklocator_test.go | 2 +- wire/msggetblockinvs.go | 4 +-- wire/msggetblockinvs_test.go | 56 ++++++++++++++--------------- wire/msggetblocklocator.go | 2 +- wire/msggetblocklocator_test.go | 62 ++++++++++++++++----------------- wire/msggetheaders.go | 24 ++++++------- wire/msggetheaders_test.go | 62 ++++++++++++++++----------------- 16 files changed, 156 insertions(+), 156 deletions(-) diff --git a/peer/log.go b/peer/log.go index f64cf3f80..0feb4f535 100644 --- a/peer/log.go +++ b/peer/log.go @@ -143,8 +143,8 @@ func messageSummary(msg wire.Message) string { msg.HighHash) case *wire.MsgGetHeaders: - return fmt.Sprintf("start hash %s, stop hash %s", msg.StartHash, - msg.StopHash) + return fmt.Sprintf("low hash %s, high hash %s", msg.LowHash, + msg.HighHash) case *wire.MsgGetBlockLocator: return fmt.Sprintf("high hash %s, low hash %s", msg.HighHash, diff --git a/peer/peer.go b/peer/peer.go index e49ef9d8d..a647c3579 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -426,8 +426,8 @@ type Peer struct { prevGetBlockInvsLow *daghash.Hash prevGetBlockInvsHigh *daghash.Hash prevGetHdrsMtx sync.Mutex - prevGetHdrsStart *daghash.Hash - prevGetHdrsStop *daghash.Hash + prevGetHdrsLow *daghash.Hash + prevGetHdrsHigh *daghash.Hash // These fields keep track of statistics for the peer and are protected // 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 -// 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. -func (p *Peer) PushGetHeadersMsg(startHash, stopHash *daghash.Hash) error { +func (p *Peer) PushGetHeadersMsg(lowHash, highHash *daghash.Hash) error { // Filter duplicate getheaders requests. p.prevGetHdrsMtx.Lock() - isDuplicate := p.prevGetHdrsStop != nil && p.prevGetHdrsStart != nil && - startHash != nil && stopHash.IsEqual(p.prevGetHdrsStop) && - startHash.IsEqual(p.prevGetHdrsStart) + isDuplicate := p.prevGetHdrsHigh != nil && p.prevGetHdrsLow != nil && + lowHash != nil && highHash.IsEqual(p.prevGetHdrsHigh) && + lowHash.IsEqual(p.prevGetHdrsLow) p.prevGetHdrsMtx.Unlock() if isDuplicate { - log.Tracef("Filtering duplicate [getheaders] with start hash %s", - startHash) + log.Tracef("Filtering duplicate [getheaders] with low hash %s", + lowHash) return nil } // Construct the getheaders request and queue it to be sent. - msg := wire.NewMsgGetHeaders(startHash, stopHash) + msg := wire.NewMsgGetHeaders(lowHash, highHash) p.QueueMessage(msg, nil) // Update the previous getheaders request information for filtering // duplicates. p.prevGetHdrsMtx.Lock() - p.prevGetHdrsStart = startHash - p.prevGetHdrsStop = stopHash + p.prevGetHdrsLow = lowHash + p.prevGetHdrsHigh = highHash p.prevGetHdrsMtx.Unlock() return nil } diff --git a/rpcclient/dag.go b/rpcclient/dag.go index 93a158176..4eeb25c5b 100644 --- a/rpcclient/dag.go +++ b/rpcclient/dag.go @@ -116,7 +116,7 @@ func (c *Client) GetBlock(blockHash *daghash.Hash, subnetworkID *string) (*wire. type FutureGetBlocksResult chan *response // 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) { res, err := receiveFuture(r) if err != nil { @@ -135,15 +135,15 @@ func (r FutureGetBlocksResult) Receive() (*rpcmodel.GetBlocksResult, error) { // returned instance. // // See GetBlocks for the blocking version and more details. -func (c *Client) GetBlocksAsync(includeRawBlockData bool, IncludeVerboseBlockData bool, startHash *string) FutureGetBlocksResult { - cmd := rpcmodel.NewGetBlocksCmd(includeRawBlockData, IncludeVerboseBlockData, startHash) +func (c *Client) GetBlocksAsync(includeRawBlockData bool, IncludeVerboseBlockData bool, lowHash *string) FutureGetBlocksResult { + cmd := rpcmodel.NewGetBlocksCmd(includeRawBlockData, IncludeVerboseBlockData, lowHash) 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. -func (c *Client) GetBlocks(includeRawBlockData bool, includeVerboseBlockData bool, startHash *string) (*rpcmodel.GetBlocksResult, error) { - return c.GetBlocksAsync(includeRawBlockData, includeVerboseBlockData, startHash).Receive() +func (c *Client) GetBlocks(includeRawBlockData bool, includeVerboseBlockData bool, lowHash *string) (*rpcmodel.GetBlocksResult, error) { + return c.GetBlocksAsync(includeRawBlockData, includeVerboseBlockData, lowHash).Receive() } // FutureGetBlockVerboseResult is a future promise to deliver the result of a diff --git a/rpcclient/net.go b/rpcclient/net.go index be311e06b..18abc8fa8 100644 --- a/rpcclient/net.go +++ b/rpcclient/net.go @@ -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. // // See GetHeaders for the blocking version and more details. -func (c *Client) GetHeadersAsync(startHash, stopHash *daghash.Hash) FutureGetHeadersResult { - startHashStr := "" - if startHash != nil { - startHashStr = startHash.String() +func (c *Client) GetHeadersAsync(lowHash, highHash *daghash.Hash) FutureGetHeadersResult { + lowHashStr := "" + if lowHash != nil { + lowHashStr = lowHash.String() } - stopHashStr := "" - if stopHash != nil { - stopHashStr = stopHash.String() + highHashStr := "" + if highHash != nil { + highHashStr = highHash.String() } - cmd := rpcmodel.NewGetHeadersCmd(startHashStr, stopHashStr) + cmd := rpcmodel.NewGetHeadersCmd(lowHashStr, highHashStr) return c.sendCmd(cmd) } // GetHeaders mimics the wire protocol getheaders and headers messages by // returning all headers in the DAG after the first known block in the -// locators, up until a block hash matches stopHash. -func (c *Client) GetHeaders(startHash, stopHash *daghash.Hash) ([]wire.BlockHeader, error) { - return c.GetHeadersAsync(startHash, stopHash).Receive() +// locators, up until a block hash matches highHash. +func (c *Client) GetHeaders(lowHash, highHash *daghash.Hash) ([]wire.BlockHeader, error) { + return c.GetHeadersAsync(lowHash, highHash).Receive() } // FutureSessionResult is a future promise to deliver the result of a diff --git a/rpcmodel/rpc_commands.go b/rpcmodel/rpc_commands.go index 348f1bffe..023f7c9d7 100644 --- a/rpcmodel/rpc_commands.go +++ b/rpcmodel/rpc_commands.go @@ -157,16 +157,16 @@ func NewGetBlockCmd(hash string, verbose, verboseTx *bool, subnetworkID *string) type GetBlocksCmd struct { IncludeRawBlockData bool `json:"includeRawBlockData"` IncludeVerboseBlockData bool `json:"includeVerboseBlockData"` - StartHash *string `json:"startHash"` + LowHash *string `json:"lowHash"` } // NewGetBlocksCmd returns a new instance which can be used to issue a // GetGetBlocks JSON-RPC command. -func NewGetBlocksCmd(includeRawBlockData bool, includeVerboseBlockData bool, startHash *string) *GetBlocksCmd { +func NewGetBlocksCmd(includeRawBlockData bool, includeVerboseBlockData bool, lowHash *string) *GetBlocksCmd { return &GetBlocksCmd{ IncludeRawBlockData: includeRawBlockData, IncludeVerboseBlockData: includeVerboseBlockData, - StartHash: startHash, + LowHash: lowHash, } } diff --git a/rpcmodel/rpc_commands_test.go b/rpcmodel/rpc_commands_test.go index 13039c765..d74c7698d 100644 --- a/rpcmodel/rpc_commands_test.go +++ b/rpcmodel/rpc_commands_test.go @@ -201,7 +201,7 @@ func TestRPCServerCommands(t *testing.T) { unmarshalled: &rpcmodel.GetBlocksCmd{ IncludeRawBlockData: true, IncludeVerboseBlockData: true, - StartHash: rpcmodel.String("123"), + LowHash: rpcmodel.String("123"), }, }, { @@ -987,7 +987,7 @@ func TestRPCServerCommands(t *testing.T) { unmarshalled: &rpcmodel.GetTopHeadersCmd{}, }, { - name: "getTopHeaders - with start hash", + name: "getTopHeaders - with high hash", newCmd: func() (interface{}, error) { return rpcmodel.NewCommand("getTopHeaders", "000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7") }, diff --git a/server/rpc/handle_get_blocks.go b/server/rpc/handle_get_blocks.go index 7a5e81713..59d740f19 100644 --- a/server/rpc/handle_get_blocks.go +++ b/server/rpc/handle_get_blocks.go @@ -16,20 +16,20 @@ const ( func handleGetBlocks(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { c := cmd.(*rpcmodel.GetBlocksCmd) - var startHash *daghash.Hash - if c.StartHash != nil { - startHash = &daghash.Hash{} - err := daghash.Decode(startHash, *c.StartHash) + var lowHash *daghash.Hash + if c.LowHash != nil { + lowHash = &daghash.Hash{} + err := daghash.Decode(lowHash, *c.LowHash) if err != nil { - return nil, rpcDecodeHexError(*c.StartHash) + return nil, rpcDecodeHexError(*c.LowHash) } } s.cfg.DAG.RLock() defer s.cfg.DAG.RUnlock() - // If startHash is not in the DAG, there's nothing to do; return an error. - if startHash != nil && !s.cfg.DAG.HaveBlock(startHash) { + // If lowHash is not in the DAG, there's nothing to do; return an error. + if lowHash != nil && !s.cfg.DAG.HaveBlock(lowHash) { return nil, &rpcmodel.RPCError{ Code: rpcmodel.ErrRPCBlockNotFound, Message: "Block not found", @@ -37,7 +37,7 @@ func handleGetBlocks(s *Server, cmd interface{}, closeChan <-chan struct{}) (int } // Retrieve the block hashes. - blockHashes, err := s.cfg.DAG.BlockHashesFrom(startHash, maxBlocksInGetBlocksResult) + blockHashes, err := s.cfg.DAG.BlockHashesFrom(lowHash, maxBlocksInGetBlocksResult) if err != nil { return nil, err } diff --git a/server/rpc/rpcserverhelp.go b/server/rpc/rpcserverhelp.go index 7bfea1184..e01b99e80 100644 --- a/server/rpc/rpcserverhelp.go +++ b/server/rpc/rpcserverhelp.go @@ -172,11 +172,11 @@ var helpDescsEnUS = map[string]string{ "getBlock--result0": "Hex-encoded bytes of the serialized block", // 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-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--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-lowHash": "Hash of the block with the bottom blue score. If this hash is unknown - returns an error.", + "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. "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", // 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--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)", diff --git a/wire/bench_test.go b/wire/bench_test.go index 552403e8d..ae3039070 100644 --- a/wire/bench_test.go +++ b/wire/bench_test.go @@ -379,8 +379,8 @@ func BenchmarkWriteBlockHeader(b *testing.B) { func BenchmarkDecodeGetHeaders(b *testing.B) { pver := ProtocolVersion var m MsgGetHeaders - m.StartHash = &daghash.Hash{1} - m.StopHash = &daghash.Hash{1} + m.LowHash = &daghash.Hash{1} + m.HighHash = &daghash.Hash{1} // Serialize it so the bytes are available to test the decode below. var bb bytes.Buffer diff --git a/wire/msgblocklocator_test.go b/wire/msgblocklocator_test.go index 66820dcd7..c3475ebee 100644 --- a/wire/msgblocklocator_test.go +++ b/wire/msgblocklocator_test.go @@ -175,7 +175,7 @@ func TestBlockLocatorWireErrors(t *testing.T) { 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.AddBlockLocatorHash(hashLocator2) baseGetBlocks.AddBlockLocatorHash(hashLocator) diff --git a/wire/msggetblockinvs.go b/wire/msggetblockinvs.go index 3e63035fc..5e6856504 100644 --- a/wire/msggetblockinvs.go +++ b/wire/msggetblockinvs.go @@ -12,7 +12,7 @@ import ( // MsgGetBlockInvs implements the Message interface and represents a kaspa // 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 { LowHash *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 // receiver. This is part of the Message interface implementation. func (msg *MsgGetBlockInvs) MaxPayloadLength(pver uint32) uint32 { - // start hash + stop hash. + // low hash + high hash. return 2 * daghash.HashSize } diff --git a/wire/msggetblockinvs_test.go b/wire/msggetblockinvs_test.go index 9e2b07289..c177e9125 100644 --- a/wire/msggetblockinvs_test.go +++ b/wire/msggetblockinvs_test.go @@ -19,22 +19,22 @@ func TestGetBlockInvs(t *testing.T) { pver := ProtocolVersion hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" - startHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } // Ensure we get the same data back out. - msg := NewMsgGetBlockInvs(startHash, stopHash) - if !msg.HighHash.IsEqual(stopHash) { - t.Errorf("NewMsgGetBlockInvs: wrong stop hash - got %v, want %v", - msg.HighHash, stopHash) + msg := NewMsgGetBlockInvs(lowHash, highHash) + if !msg.HighHash.IsEqual(highHash) { + t.Errorf("NewMsgGetBlockInvs: wrong high hash - got %v, want %v", + msg.HighHash, highHash) } // Ensure the command is expected value. @@ -44,7 +44,7 @@ func TestGetBlockInvs(t *testing.T) { 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) maxPayload := msg.MaxPayloadLength(pver) if maxPayload != wantPayload { @@ -58,41 +58,41 @@ func TestGetBlockInvs(t *testing.T) { // numbers of block locator hashes and protocol versions. func TestGetBlockInvsWire(t *testing.T) { hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" - startHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { 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{}) 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, // 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, // Stop hash + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash } - // MsgGetBlockInvs message with a start hash and a stop hash. - withStartAndStopHash := NewMsgGetBlockInvs(startHash, stopHash) - withStartAndStopHashEncoded := []byte{ + // MsgGetBlockInvs message with a low hash and a high hash. + withLowAndHighHash := NewMsgGetBlockInvs(lowHash, highHash) + withLowAndHighHashEncoded := []byte{ 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 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, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 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 { @@ -111,9 +111,9 @@ func TestGetBlockInvsWire(t *testing.T) { // Latest protocol version with multiple block locators. { - withStartAndStopHash, - withStartAndStopHash, - withStartAndStopHashEncoded, + withLowAndHighHash, + withLowAndHighHash, + withLowAndHighHashEncoded, ProtocolVersion, }, } @@ -156,28 +156,28 @@ func TestGetBlockInvsWireErrors(t *testing.T) { pver := ProtocolVersion hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" - startHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } - // MsgGetBlockInvs message with multiple block locators and a stop hash. - baseGetBlocks := NewMsgGetBlockInvs(startHash, stopHash) + // MsgGetBlockInvs message with multiple block locators and a high hash. + baseGetBlocks := NewMsgGetBlockInvs(lowHash, highHash) baseGetBlocksEncoded := []byte{ 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 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, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 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 { @@ -188,9 +188,9 @@ func TestGetBlockInvsWireErrors(t *testing.T) { writeErr error // Expected write error readErr error // Expected read error }{ - // Force error in start hash. + // Force error in low hash. {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}, } diff --git a/wire/msggetblocklocator.go b/wire/msggetblocklocator.go index f17522847..5ef3f48c5 100644 --- a/wire/msggetblocklocator.go +++ b/wire/msggetblocklocator.go @@ -7,7 +7,7 @@ import ( ) // 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). type MsgGetBlockLocator struct { HighHash *daghash.Hash diff --git a/wire/msggetblocklocator_test.go b/wire/msggetblocklocator_test.go index b18088740..b67ce3455 100644 --- a/wire/msggetblocklocator_test.go +++ b/wire/msggetblocklocator_test.go @@ -15,20 +15,20 @@ func TestGetBlockLocator(t *testing.T) { pver := ProtocolVersion hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" - startHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } // Ensure the command is expected value. wantCmd := "getlocator" - msg := NewMsgGetBlockLocator(startHash, &daghash.ZeroHash) + msg := NewMsgGetBlockLocator(highHash, &daghash.ZeroHash) if cmd := msg.Command(); cmd != wantCmd { t.Errorf("NewMsgGetBlockLocator: wrong command - got %v want %v", 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) maxPayload := msg.MaxPayloadLength(pver) if maxPayload != wantPayload { @@ -41,41 +41,41 @@ func TestGetBlockLocator(t *testing.T) { // TestGetBlockLocatorWire tests the MsgGetBlockLocator wire encode and decode. func TestGetBlockLocatorWire(t *testing.T) { hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" - startHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } - // MsgGetBlockLocator message with no block locators or stop hash. - noStartAndStopHash := NewMsgGetBlockLocator(&daghash.ZeroHash, &daghash.ZeroHash) - noStartAndStopHashEncoded := []byte{ + // MsgGetBlockLocator message with no block locators or high hash. + noLowAndHighHash := NewMsgGetBlockLocator(&daghash.ZeroHash, &daghash.ZeroHash) + 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, // 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, // Stop hash + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Low hash } - // MsgGetBlockLocator message with multiple block locators and a stop hash. - withStartAndStopHash := NewMsgGetBlockLocator(startHash, stopHash) - withStartAndStopHashEncoded := []byte{ + // MsgGetBlockLocator message with multiple block locators and a high hash. + withLowAndHighHash := NewMsgGetBlockLocator(highHash, lowHash) + withLowAndHighHashEncoded := []byte{ 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 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, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 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 { @@ -84,19 +84,19 @@ func TestGetBlockLocatorWire(t *testing.T) { buf []byte // 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, - noStartAndStopHash, - noStartAndStopHashEncoded, + noLowAndHighHash, + noLowAndHighHash, + noLowAndHighHashEncoded, ProtocolVersion, }, - // Message with start hash and stop hash. + // Message with low hash and high hash. { - withStartAndStopHash, - withStartAndStopHash, - withStartAndStopHashEncoded, + withLowAndHighHash, + withLowAndHighHash, + withLowAndHighHashEncoded, ProtocolVersion, }, } @@ -139,28 +139,28 @@ func TestGetBlockLocatorWireErrors(t *testing.T) { pver := ProtocolVersion hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" - startHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } - // MsgGetBlockLocator message with multiple block locators and a stop hash. - baseGetBlockLocator := NewMsgGetBlockLocator(startHash, stopHash) + // MsgGetBlockLocator message with multiple block locators and a high hash. + baseGetBlockLocator := NewMsgGetBlockLocator(highHash, lowHash) baseGetBlockLocatorEncoded := []byte{ 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 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, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 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 { @@ -171,9 +171,9 @@ func TestGetBlockLocatorWireErrors(t *testing.T) { writeErr error // Expected write error readErr error // Expected read error }{ - // Force error in start hash. + // Force error in low hash. {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}, } diff --git a/wire/msggetheaders.go b/wire/msggetheaders.go index d0e321151..933501d1c 100644 --- a/wire/msggetheaders.go +++ b/wire/msggetheaders.go @@ -27,32 +27,32 @@ import ( // exponentially decrease the number of hashes the further away from head and // closer to the genesis block you get. type MsgGetHeaders struct { - StartHash *daghash.Hash - StopHash *daghash.Hash + LowHash *daghash.Hash + HighHash *daghash.Hash } // KaspaDecode decodes r using the kaspa protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgGetHeaders) KaspaDecode(r io.Reader, pver uint32) error { - msg.StartHash = &daghash.Hash{} - err := ReadElement(r, msg.StartHash) + msg.LowHash = &daghash.Hash{} + err := ReadElement(r, msg.LowHash) if err != nil { return err } - msg.StopHash = &daghash.Hash{} - return ReadElement(r, msg.StopHash) + msg.HighHash = &daghash.Hash{} + return ReadElement(r, msg.HighHash) } // KaspaEncode encodes the receiver to w using the kaspa protocol encoding. // This is part of the Message interface implementation. func (msg *MsgGetHeaders) KaspaEncode(w io.Writer, pver uint32) error { - err := WriteElement(w, msg.StartHash) + err := WriteElement(w, msg.LowHash) if err != nil { return err } - return WriteElement(w, msg.StopHash) + return WriteElement(w, msg.HighHash) } // 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 // receiver. This is part of the Message interface implementation. func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32 { - // start hash + stop hash. + // low hash + high hash. return 2 * daghash.HashSize } // NewMsgGetHeaders returns a new kaspa getheaders message that conforms to // the Message interface. See MsgGetHeaders for details. -func NewMsgGetHeaders(startHash, stopHash *daghash.Hash) *MsgGetHeaders { +func NewMsgGetHeaders(lowHash, highHash *daghash.Hash) *MsgGetHeaders { return &MsgGetHeaders{ - StartHash: startHash, - StopHash: stopHash, + LowHash: lowHash, + HighHash: highHash, } } diff --git a/wire/msggetheaders_test.go b/wire/msggetheaders_test.go index ca6370129..e3700250c 100644 --- a/wire/msggetheaders_test.go +++ b/wire/msggetheaders_test.go @@ -20,20 +20,20 @@ func TestGetHeaders(t *testing.T) { // Block 99500 hash. hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" - startHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } // Ensure the command is expected value. wantCmd := "getheaders" - msg := NewMsgGetHeaders(startHash, &daghash.ZeroHash) + msg := NewMsgGetHeaders(lowHash, &daghash.ZeroHash) if cmd := msg.Command(); cmd != wantCmd { t.Errorf("NewMsgGetHeaders: wrong command - got %v want %v", 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) maxPayload := msg.MaxPayloadLength(pver) if maxPayload != wantPayload { @@ -46,41 +46,41 @@ func TestGetHeaders(t *testing.T) { // TestGetHeadersWire tests the MsgGetHeaders wire encode and decode. func TestGetHeadersWire(t *testing.T) { hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" - startHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } - // MsgGetHeaders message with no block locators or stop hash. - noStartAndStopHash := NewMsgGetHeaders(&daghash.ZeroHash, &daghash.ZeroHash) - noStartAndStopHashEncoded := []byte{ + // MsgGetHeaders message with no block locators or high hash. + noLowAndHighHash := NewMsgGetHeaders(&daghash.ZeroHash, &daghash.ZeroHash) + 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, // 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, // Stop hash + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // High hash } - // MsgGetHeaders message with multiple block locators and a stop hash. - withStartAndStopHash := NewMsgGetHeaders(startHash, stopHash) - withStartAndStopHashEncoded := []byte{ + // MsgGetHeaders message with multiple block locators and a high hash. + withLowAndHighHash := NewMsgGetHeaders(lowHash, highHash) + withLowAndHighHashEncoded := []byte{ 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 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, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 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 { @@ -89,19 +89,19 @@ func TestGetHeadersWire(t *testing.T) { buf []byte // 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, - noStartAndStopHash, - noStartAndStopHashEncoded, + noLowAndHighHash, + noLowAndHighHash, + noLowAndHighHashEncoded, ProtocolVersion, }, - // Message with start hash and stop hash. + // Message with low hash and high hash. { - withStartAndStopHash, - withStartAndStopHash, - withStartAndStopHashEncoded, + withLowAndHighHash, + withLowAndHighHash, + withLowAndHighHashEncoded, ProtocolVersion, }, } @@ -144,28 +144,28 @@ func TestGetHeadersWireErrors(t *testing.T) { pver := ProtocolVersion hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" - startHash, err := daghash.NewHashFromStr(hashStr) + lowHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - stopHash, err := daghash.NewHashFromStr(hashStr) + highHash, err := daghash.NewHashFromStr(hashStr) if err != nil { t.Errorf("NewHashFromStr: %v", err) } - // MsgGetHeaders message with multiple block locators and a stop hash. - baseGetHeaders := NewMsgGetHeaders(startHash, stopHash) + // MsgGetHeaders message with multiple block locators and a high hash. + baseGetHeaders := NewMsgGetHeaders(lowHash, highHash) baseGetHeadersEncoded := []byte{ 0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60, 0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9, 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, 0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2, 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 { @@ -176,9 +176,9 @@ func TestGetHeadersWireErrors(t *testing.T) { writeErr error // Expected write error readErr error // Expected read error }{ - // Force error in start hash. + // Force error in low hash. {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}, }