[NOD-263] Rename all instances of hashStop to stopHash. (#360)

This commit is contained in:
stasatdaglabs 2019-08-11 11:20:21 +03:00 committed by Svarog
parent 9981ce7adb
commit 594a209f83
15 changed files with 66 additions and 66 deletions

View File

@ -1675,10 +1675,10 @@ func (dag *BlockDAG) IntervalBlockHashes(endHash *daghash.Hash, interval uint64,
// functions.
//
// This function MUST be called with the DAG state lock held (for reads).
func (dag *BlockDAG) locateInventory(locator BlockLocator, hashStop *daghash.Hash, maxEntries uint32) (*blockNode, uint32) {
func (dag *BlockDAG) locateInventory(locator BlockLocator, stopHash *daghash.Hash, maxEntries uint32) (*blockNode, uint32) {
// There are no block locators so a specific block is being requested
// as identified by the stop hash.
stopNode := dag.index.LookupNode(hashStop)
stopNode := dag.index.LookupNode(stopHash)
if len(locator) == 0 {
if stopNode == nil {
// No blocks with the stop hash were found so there is
@ -1718,8 +1718,8 @@ func (dag *BlockDAG) locateInventory(locator BlockLocator, hashStop *daghash.Has
// See the comment on the exported function for more details on special cases.
//
// This function MUST be called with the DAG state lock held (for reads).
func (dag *BlockDAG) locateBlocks(locator BlockLocator, hashStop *daghash.Hash, maxHashes uint32) []*daghash.Hash {
nodes := dag.locateBlockNodes(locator, hashStop, maxHashes)
func (dag *BlockDAG) locateBlocks(locator BlockLocator, stopHash *daghash.Hash, maxHashes uint32) []*daghash.Hash {
nodes := dag.locateBlockNodes(locator, stopHash, maxHashes)
hashes := make([]*daghash.Hash, len(nodes))
for i, node := range nodes {
hashes[i] = node.hash
@ -1727,14 +1727,14 @@ func (dag *BlockDAG) locateBlocks(locator BlockLocator, hashStop *daghash.Hash,
return hashes
}
func (dag *BlockDAG) locateBlockNodes(locator BlockLocator, hashStop *daghash.Hash, maxEntries uint32) []*blockNode {
func (dag *BlockDAG) locateBlockNodes(locator BlockLocator, stopHash *daghash.Hash, maxEntries uint32) []*blockNode {
// Find the first known block in the locator and the estimated number of
// nodes after it needed while respecting the stop hash and max entries.
node, estimatedEntries := dag.locateInventory(locator, hashStop, maxEntries)
node, estimatedEntries := dag.locateInventory(locator, stopHash, maxEntries)
if estimatedEntries == 0 {
return nil
}
stopNode := dag.index.LookupNode(hashStop)
stopNode := dag.index.LookupNode(stopHash)
// Populate and return the found nodes.
nodes := make([]*blockNode, 0, estimatedEntries)
@ -1748,7 +1748,7 @@ func (dag *BlockDAG) locateBlockNodes(locator BlockLocator, hashStop *daghash.Ha
if !visited.contains(current) {
visited.add(current)
isBeforeStop := (stopNode == nil) || (current.height < stopNode.height)
if isBeforeStop || current.hash.IsEqual(hashStop) {
if isBeforeStop || current.hash.IsEqual(stopHash) {
nodes = append(nodes, current)
}
if isBeforeStop {
@ -1772,9 +1772,9 @@ func (dag *BlockDAG) locateBlockNodes(locator BlockLocator, hashStop *daghash.Ha
// after the genesis block will be returned
//
// This function is safe for concurrent access.
func (dag *BlockDAG) LocateBlocks(locator BlockLocator, hashStop *daghash.Hash, maxHashes uint32) []*daghash.Hash {
func (dag *BlockDAG) LocateBlocks(locator BlockLocator, stopHash *daghash.Hash, maxHashes uint32) []*daghash.Hash {
dag.dagLock.RLock()
hashes := dag.locateBlocks(locator, hashStop, maxHashes)
hashes := dag.locateBlocks(locator, stopHash, maxHashes)
dag.dagLock.RUnlock()
return hashes
}
@ -1786,8 +1786,8 @@ func (dag *BlockDAG) LocateBlocks(locator BlockLocator, hashStop *daghash.Hash,
// See the comment on the exported function for more details on special cases.
//
// This function MUST be called with the DAG state lock held (for reads).
func (dag *BlockDAG) locateHeaders(locator BlockLocator, hashStop *daghash.Hash, maxHeaders uint32) []*wire.BlockHeader {
nodes := dag.locateBlockNodes(locator, hashStop, maxHeaders)
func (dag *BlockDAG) locateHeaders(locator BlockLocator, stopHash *daghash.Hash, maxHeaders uint32) []*wire.BlockHeader {
nodes := dag.locateBlockNodes(locator, stopHash, maxHeaders)
headers := make([]*wire.BlockHeader, len(nodes))
for i, node := range nodes {
headers[i] = node.Header()
@ -1844,9 +1844,9 @@ func (dag *BlockDAG) RUnlock() {
// after the genesis block will be returned
//
// This function is safe for concurrent access.
func (dag *BlockDAG) LocateHeaders(locator BlockLocator, hashStop *daghash.Hash) []*wire.BlockHeader {
func (dag *BlockDAG) LocateHeaders(locator BlockLocator, stopHash *daghash.Hash) []*wire.BlockHeader {
dag.dagLock.RLock()
headers := dag.locateHeaders(locator, hashStop, wire.MaxBlockHeadersPerMsg)
headers := dag.locateHeaders(locator, stopHash, wire.MaxBlockHeadersPerMsg)
dag.dagLock.RUnlock()
return headers
}

View File

@ -109,7 +109,7 @@ func NewGetTopHeadersCmd(startHash *string) *GetTopHeadersCmd {
// github.com/decred/dcrd/dcrjson.
type GetHeadersCmd struct {
BlockLocators []string `json:"blockLocators"`
HashStop string `json:"hashStop"`
StopHash string `json:"stopHash"`
}
// NewGetHeadersCmd returns a new instance which can be used to issue a
@ -117,10 +117,10 @@ type GetHeadersCmd struct {
//
// NOTE: This is a btcsuite extension ported from
// github.com/decred/dcrd/dcrjson.
func NewGetHeadersCmd(blockLocators []string, hashStop string) *GetHeadersCmd {
func NewGetHeadersCmd(blockLocators []string, stopHash string) *GetHeadersCmd {
return &GetHeadersCmd{
BlockLocators: blockLocators,
HashStop: hashStop,
StopHash: stopHash,
}
}

View File

@ -150,7 +150,7 @@ func TestBtcdExtCmds(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getHeaders","params":[[],""],"id":1}`,
unmarshalled: &btcjson.GetHeadersCmd{
BlockLocators: []string{},
HashStop: "",
StopHash: "",
},
},
{
@ -173,7 +173,7 @@ func TestBtcdExtCmds(t *testing.T) {
"000000000000000001f1739002418e2f9a84c47a4fd2a0eb7a787a6b7dc12f16",
"0000000000000000026f4b7f56eef057b32167eb5ad9ff62006f1807b7336d10",
},
HashStop: "000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7",
StopHash: "000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7",
},
},
{

View File

@ -681,7 +681,7 @@ The following is an overview of the RPC methods which are implemented by btcd, b
| | |
|---|---|
|Method|getheaders|
|Parameters|1. Block Locators (JSON array, required)<br />&nbsp;`[ (json array of strings)`<br />&nbsp;&nbsp;`"blocklocator", (string) the known block hash`<br />&nbsp;&nbsp;`...`<br />&nbsp;`]`<br />2. hashstop (string) - last desired block's hash|
|Parameters|1. Block Locators (JSON array, required)<br />&nbsp;`[ (json array of strings)`<br />&nbsp;&nbsp;`"blocklocator", (string) the known block hash`<br />&nbsp;&nbsp;`...`<br />&nbsp;`]`<br />2. stophash (string) - last desired block's hash|
|Description|Returns block headers starting with the first known block hash from the request.|
|Returns|`[ (json array of strings)`<br />&nbsp;&nbsp;`"blockheader",`<br />&nbsp;&nbsp;`...`<br />`]`|
|Example Return|`[`<br />&nbsp;&nbsp;`"0000002099417930b2ae09feda10e38b58c0f6bb44b4d60fa33f0e000000000000000000d53...",`<br />&nbsp;&nbsp;`"000000203ba25a173bfd24d09e0c76002a910b685ca297bd09a17b020000000000000000702..."`<br />`]`|

View File

@ -179,10 +179,10 @@ func messageSummary(msg wire.Message) string {
return invSummary(msg.InvList)
case *wire.MsgGetBlocks:
return locatorSummary(msg.BlockLocatorHashes, msg.HashStop)
return locatorSummary(msg.BlockLocatorHashes, msg.StopHash)
case *wire.MsgGetHeaders:
return locatorSummary(msg.BlockLocatorHashes, msg.HashStop)
return locatorSummary(msg.BlockLocatorHashes, msg.StopHash)
case *wire.MsgHeaders:
return fmt.Sprintf("num %d", len(msg.Headers))

View File

@ -929,7 +929,7 @@ func (p *Peer) PushGetHeadersMsg(locator blockdag.BlockLocator, stopHash *daghas
// Construct the getheaders request and queue it to be sent.
msg := wire.NewMsgGetHeaders()
msg.HashStop = stopHash
msg.StopHash = stopHash
for _, hash := range locator {
err := msg.AddBlockLocatorHash(hash)
if err != nil {

View File

@ -300,14 +300,14 @@ func (c *Client) GetTopHeaders(startHash *daghash.Hash) ([]wire.BlockHeader, err
//
// NOTE: This is a btcsuite extension ported from
// github.com/decred/dcrrpcclient.
func (c *Client) GetHeadersAsync(blockLocators []*daghash.Hash, hashStop *daghash.Hash) FutureGetHeadersResult {
func (c *Client) GetHeadersAsync(blockLocators []*daghash.Hash, stopHash *daghash.Hash) FutureGetHeadersResult {
locators := make([]string, len(blockLocators))
for i := range blockLocators {
locators[i] = blockLocators[i].String()
}
hash := ""
if hashStop != nil {
hash = hashStop.String()
if stopHash != nil {
hash = stopHash.String()
}
cmd := btcjson.NewGetHeadersCmd(locators, hash)
return c.sendCmd(cmd)
@ -315,12 +315,12 @@ func (c *Client) GetHeadersAsync(blockLocators []*daghash.Hash, hashStop *daghas
// GetHeaders mimics the wire protocol getheaders and headers messages by
// returning all headers on the main chain after the first known block in the
// locators, up until a block hash matches hashStop.
// locators, up until a block hash matches stopHash.
//
// NOTE: This is a btcsuite extension ported from
// github.com/decred/dcrrpcclient.
func (c *Client) GetHeaders(blockLocators []*daghash.Hash, hashStop *daghash.Hash) ([]wire.BlockHeader, error) {
return c.GetHeadersAsync(blockLocators, hashStop).Receive()
func (c *Client) GetHeaders(blockLocators []*daghash.Hash, stopHash *daghash.Hash) ([]wire.BlockHeader, error) {
return c.GetHeadersAsync(blockLocators, stopHash).Receive()
}
// FutureExportWatchingWalletResult is a future promise to deliver the result of

View File

@ -696,7 +696,7 @@ func (sp *Peer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks) {
//
// This mirrors the behavior in the reference implementation.
dag := sp.server.DAG
hashList := dag.LocateBlocks(msg.BlockLocatorHashes, msg.HashStop,
hashList := dag.LocateBlocks(msg.BlockLocatorHashes, msg.StopHash,
wire.MaxInvPerMsg)
// Generate inventory message.
@ -731,7 +731,7 @@ func (sp *Peer) OnGetHeaders(_ *peer.Peer, msg *wire.MsgGetHeaders) {
//
// This mirrors the behavior in the reference implementation.
dag := sp.server.DAG
headers := dag.LocateHeaders(msg.BlockLocatorHashes, msg.HashStop)
headers := dag.LocateHeaders(msg.BlockLocatorHashes, msg.StopHash)
// Send found headers to the requesting peer.
blockHeaders := make([]*wire.BlockHeader, len(headers))

View File

@ -275,6 +275,6 @@ func (b *rpcSyncMgr) SyncPeerID() int32 {
//
// This function is safe for concurrent access and is part of the
// rpcserverSyncManager interface implementation.
func (b *rpcSyncMgr) LocateHeaders(locators []*daghash.Hash, hashStop *daghash.Hash) []*wire.BlockHeader {
return b.server.DAG.LocateHeaders(locators, hashStop)
func (b *rpcSyncMgr) LocateHeaders(locators []*daghash.Hash, stopHash *daghash.Hash) []*wire.BlockHeader {
return b.server.DAG.LocateHeaders(locators, stopHash)
}

View File

@ -2330,14 +2330,14 @@ func handleGetHeaders(s *Server, cmd interface{}, closeChan <-chan struct{}) (in
}
blockLocators[i] = blockLocator
}
var hashStop daghash.Hash
if c.HashStop != "" {
err := daghash.Decode(&hashStop, c.HashStop)
var stopHash daghash.Hash
if c.StopHash != "" {
err := daghash.Decode(&stopHash, c.StopHash)
if err != nil {
return nil, rpcDecodeHexError(c.HashStop)
return nil, rpcDecodeHexError(c.StopHash)
}
}
headers := s.cfg.SyncMgr.LocateHeaders(blockLocators, &hashStop)
headers := s.cfg.SyncMgr.LocateHeaders(blockLocators, &stopHash)
// Return the serialized block headers as hex-encoded strings.
hexBlockHeaders := make([]string, len(headers))
@ -4184,7 +4184,7 @@ type rpcserverSyncManager interface {
// block in the provided locators until the provided stop hash or the
// current tip is reached, up to a max of wire.MaxBlockHeadersPerMsg
// hashes.
LocateHeaders(locators []*daghash.Hash, hashStop *daghash.Hash) []*wire.BlockHeader
LocateHeaders(locators []*daghash.Hash, stopHash *daghash.Hash) []*wire.BlockHeader
}
// rpcserverConfig is a descriptor containing the RPC server configuration.

View File

@ -409,7 +409,7 @@ var helpDescsEnUS = map[string]string{
// GetHeadersCmd help.
"getHeaders--synopsis": "Returns block headers starting with the first known block hash from the request",
"getHeaders-blockLocators": "JSON array of hex-encoded hashes of blocks. Headers are returned starting from the first known hash in this list",
"getHeaders-hashStop": "Block hash to stop including block headers for; if not found, all headers to the latest known block are returned.",
"getHeaders-stopHash": "Block hash to stop including block headers for; if not found, all headers to the latest known block are returned.",
"getHeaders--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)",
// GetInfoCmd help.

View File

@ -21,7 +21,7 @@ const MaxBlockLocatorsPerMsg = 500
// via an inv message (MsgInv) and is limited by a specific hash to stop at or
// the maximum number of blocks per message, which is currently 500.
//
// Set the HashStop field to the hash at which to stop and use
// Set the StopHash field to the hash at which to stop and use
// AddBlockLocatorHash to build up the list of block locator hashes.
//
// The algorithm for building the block locator hashes should be to add the
@ -33,7 +33,7 @@ const MaxBlockLocatorsPerMsg = 500
type MsgGetBlocks struct {
ProtocolVersion uint32
BlockLocatorHashes []*daghash.Hash
HashStop *daghash.Hash
StopHash *daghash.Hash
}
// AddBlockLocatorHash adds a new block locator hash to the message.
@ -80,8 +80,8 @@ func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
msg.AddBlockLocatorHash(hash)
}
msg.HashStop = &daghash.Hash{}
return ReadElement(r, msg.HashStop)
msg.StopHash = &daghash.Hash{}
return ReadElement(r, msg.StopHash)
}
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
@ -111,7 +111,7 @@ func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error {
}
}
return WriteElement(w, msg.HashStop)
return WriteElement(w, msg.StopHash)
}
// Command returns the protocol command string for the message. This is part
@ -131,10 +131,10 @@ func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32 {
// NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the
// Message interface using the passed parameters and defaults for the remaining
// fields.
func NewMsgGetBlocks(hashStop *daghash.Hash) *MsgGetBlocks {
func NewMsgGetBlocks(stopHash *daghash.Hash) *MsgGetBlocks {
return &MsgGetBlocks{
ProtocolVersion: ProtocolVersion,
BlockLocatorHashes: make([]*daghash.Hash, 0, MaxBlockLocatorsPerMsg),
HashStop: hashStop,
StopHash: stopHash,
}
}

View File

@ -27,16 +27,16 @@ func TestGetBlocks(t *testing.T) {
// Block 100000 hash.
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
hashStop, err := daghash.NewHashFromStr(hashStr)
stopHash, err := daghash.NewHashFromStr(hashStr)
if err != nil {
t.Errorf("NewHashFromStr: %v", err)
}
// Ensure we get the same data back out.
msg := NewMsgGetBlocks(hashStop)
if !msg.HashStop.IsEqual(hashStop) {
msg := NewMsgGetBlocks(stopHash)
if !msg.StopHash.IsEqual(stopHash) {
t.Errorf("NewMsgGetBlocks: wrong stop hash - got %v, want %v",
msg.HashStop, hashStop)
msg.StopHash, stopHash)
}
// Ensure the command is expected value.
@ -102,7 +102,7 @@ func TestGetBlocksWire(t *testing.T) {
// Block 100000 hash.
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
hashStop, err := daghash.NewHashFromStr(hashStr)
stopHash, err := daghash.NewHashFromStr(hashStr)
if err != nil {
t.Errorf("NewHashFromStr: %v", err)
}
@ -120,7 +120,7 @@ func TestGetBlocksWire(t *testing.T) {
}
// MsgGetBlocks message with multiple block locators and a stop hash.
multiLocators := NewMsgGetBlocks(hashStop)
multiLocators := NewMsgGetBlocks(stopHash)
multiLocators.AddBlockLocatorHash(hashLocator2)
multiLocators.AddBlockLocatorHash(hashLocator)
multiLocators.ProtocolVersion = pver
@ -220,13 +220,13 @@ func TestGetBlocksWireErrors(t *testing.T) {
// Block 100000 hash.
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
hashStop, err := daghash.NewHashFromStr(hashStr)
stopHash, err := daghash.NewHashFromStr(hashStr)
if err != nil {
t.Errorf("NewHashFromStr: %v", err)
}
// MsgGetBlocks message with multiple block locators and a stop hash.
baseGetBlocks := NewMsgGetBlocks(hashStop)
baseGetBlocks := NewMsgGetBlocks(stopHash)
baseGetBlocks.ProtocolVersion = pver
baseGetBlocks.AddBlockLocatorHash(hashLocator2)
baseGetBlocks.AddBlockLocatorHash(hashLocator)
@ -249,7 +249,7 @@ func TestGetBlocksWireErrors(t *testing.T) {
// Message that forces an error by having more than the max allowed
// block locator hashes.
maxGetBlocks := NewMsgGetBlocks(hashStop)
maxGetBlocks := NewMsgGetBlocks(stopHash)
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
maxGetBlocks.AddBlockLocatorHash(mainNetGenesisHash)
}

View File

@ -18,7 +18,7 @@ import (
// limited by a specific hash to stop at or the maximum number of block headers
// per message, which is currently 2000.
//
// Set the HashStop field to the hash at which to stop and use
// Set the StopHash field to the hash at which to stop and use
// AddBlockLocatorHash to build up the list of block locator hashes.
//
// The algorithm for building the block locator hashes should be to add the
@ -30,7 +30,7 @@ import (
type MsgGetHeaders struct {
ProtocolVersion uint32
BlockLocatorHashes []*daghash.Hash
HashStop *daghash.Hash
StopHash *daghash.Hash
}
// AddBlockLocatorHash adds a new block locator hash to the message.
@ -77,8 +77,8 @@ func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32) error {
msg.AddBlockLocatorHash(hash)
}
msg.HashStop = &daghash.Hash{}
return ReadElement(r, msg.HashStop)
msg.StopHash = &daghash.Hash{}
return ReadElement(r, msg.StopHash)
}
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
@ -109,7 +109,7 @@ func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32) error {
}
}
return WriteElement(w, msg.HashStop)
return WriteElement(w, msg.StopHash)
}
// Command returns the protocol command string for the message. This is part
@ -133,6 +133,6 @@ func NewMsgGetHeaders() *MsgGetHeaders {
return &MsgGetHeaders{
BlockLocatorHashes: make([]*daghash.Hash, 0,
MaxBlockLocatorsPerMsg),
HashStop: &daghash.ZeroHash,
StopHash: &daghash.ZeroHash,
}
}

View File

@ -91,7 +91,7 @@ func TestGetHeadersWire(t *testing.T) {
// Block 100000 hash.
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
hashStop, err := daghash.NewHashFromStr(hashStr)
stopHash, err := daghash.NewHashFromStr(hashStr)
if err != nil {
t.Errorf("NewHashFromStr: %v", err)
}
@ -111,7 +111,7 @@ func TestGetHeadersWire(t *testing.T) {
// MsgGetHeaders message with multiple block locators and a stop hash.
multiLocators := NewMsgGetHeaders()
multiLocators.ProtocolVersion = pver
multiLocators.HashStop = hashStop
multiLocators.StopHash = stopHash
multiLocators.AddBlockLocatorHash(hashLocator2)
multiLocators.AddBlockLocatorHash(hashLocator)
multiLocatorsEncoded := []byte{
@ -210,7 +210,7 @@ func TestGetHeadersWireErrors(t *testing.T) {
// Block 100000 hash.
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
hashStop, err := daghash.NewHashFromStr(hashStr)
stopHash, err := daghash.NewHashFromStr(hashStr)
if err != nil {
t.Errorf("NewHashFromStr: %v", err)
}
@ -218,7 +218,7 @@ func TestGetHeadersWireErrors(t *testing.T) {
// MsgGetHeaders message with multiple block locators and a stop hash.
baseGetHeaders := NewMsgGetHeaders()
baseGetHeaders.ProtocolVersion = pver
baseGetHeaders.HashStop = hashStop
baseGetHeaders.StopHash = stopHash
baseGetHeaders.AddBlockLocatorHash(hashLocator2)
baseGetHeaders.AddBlockLocatorHash(hashLocator)
baseGetHeadersEncoded := []byte{