Browse Source

breaking out view

master
Loki Verloren 6 months ago
parent
commit
b90b975202

+ 13
- 26
blockchain/chain.go View File

@@ -11,6 +11,9 @@ import (
11 11
 	"sync"
12 12
 	"time"
13 13
 
14
+	"git.parallelcoin.io/dev/btcd/blockchain/locator"
15
+	"git.parallelcoin.io/dev/btcd/blockchain/view"
16
+
14 17
 	"git.parallelcoin.io/dev/btcd/blockchain/spent"
15 18
 	"git.parallelcoin.io/dev/btcd/blockchain/utxo"
16 19
 
@@ -41,22 +44,6 @@ const (
41 44
 	MaxOrphanBlocks = 100
42 45
 )
43 46
 
44
-// BlockLocator is used to help locate a specific block.  The algorithm for
45
-// building the block locator is to add the hashes in reverse order until
46
-// the genesis block is reached.  In order to keep the list of locator hashes
47
-// to a reasonable number of entries, first the most recent previous 12 block
48
-// hashes are added, then the step is doubled each loop iteration to
49
-// exponentially decrease the number of hashes as a function of the distance
50
-// from the block being located.
51
-//
52
-// For example, assume a block chain with a side chain as depicted below:
53
-// 	genesis -> 1 -> 2 -> ... -> 15 -> 16  -> 17  -> 18
54
-// 	                              \-> 16a -> 17a
55
-//
56
-// The block locator for block 17a would be the hashes of blocks:
57
-// [17a 16a 15 14 13 12 11 10 9 8 7 6 4 genesis]
58
-type BlockLocator []*chainhash.Hash
59
-
60 47
 // OrphanBlock represents a block that we don't yet have the parent for.  It
61 48
 // is a normal block plus an expiration time to prevent caching the orphan
62 49
 // forever.
@@ -104,7 +91,7 @@ type BlockChain struct {
104 91
 	// bestChain tracks the current active chain by making use of an
105 92
 	// efficient chain view into the block Index.
106 93
 	Index     *index.Block
107
-	BestChain *ChainView
94
+	BestChain *view.Chain
108 95
 
109 96
 	// These fields are related to handling of orphan blocks.  They are
110 97
 	// protected by a combination of the chain lock and the orphan lock.
@@ -1258,14 +1245,14 @@ func (b *BlockChain) MainChainHasBlock(hash *chainhash.Hash) bool {
1258 1245
 }
1259 1246
 
1260 1247
 // BlockLocatorFromHash returns a block locator for the passed block hash.
1261
-// See BlockLocator for details on the algorithm used to create a block locator.
1248
+// See locator.Block for details on the algorithm used to create a block locator.
1262 1249
 //
1263 1250
 // In addition to the general algorithm referenced above, this function will
1264 1251
 // return the block locator for the latest known tip of the main (best) chain if
1265 1252
 // the passed hash is not currently known.
1266 1253
 //
1267 1254
 // This function is safe for concurrent access.
1268
-func (b *BlockChain) BlockLocatorFromHash(hash *chainhash.Hash) BlockLocator {
1255
+func (b *BlockChain) BlockLocatorFromHash(hash *chainhash.Hash) locator.Block {
1269 1256
 	b.ChainLock.RLock()
1270 1257
 	node := b.Index.LookupNode(hash)
1271 1258
 	locator := b.BestChain.UnsafeGetBlockLocator(node)
@@ -1277,7 +1264,7 @@ func (b *BlockChain) BlockLocatorFromHash(hash *chainhash.Hash) BlockLocator {
1277 1264
 // main (best) chain.
1278 1265
 //
1279 1266
 // This function is safe for concurrent access.
1280
-func (b *BlockChain) LatestBlockLocator() (BlockLocator, error) {
1267
+func (b *BlockChain) LatestBlockLocator() (locator.Block, error) {
1281 1268
 	b.ChainLock.RLock()
1282 1269
 	locator := b.BestChain.GetBlockLocator(nil)
1283 1270
 	b.ChainLock.RUnlock()
@@ -1458,7 +1445,7 @@ func (b *BlockChain) IntervalBlockHashes(endHash *chainhash.Hash, interval int,
1458 1445
 // functions.
1459 1446
 //
1460 1447
 // This function MUST be called with the chain state lock held (for reads).
1461
-func (b *BlockChain) UnsafeLocateInventory(locator BlockLocator, hashStop *chainhash.Hash, maxEntries uint32) (*node.Block, uint32) {
1448
+func (b *BlockChain) UnsafeLocateInventory(locator locator.Block, hashStop *chainhash.Hash, maxEntries uint32) (*node.Block, uint32) {
1462 1449
 	// There are no block locators so a specific block is being requested
1463 1450
 	// as identified by the stop hash.
1464 1451
 	stopNode := b.Index.LookupNode(hashStop)
@@ -1512,7 +1499,7 @@ func (b *BlockChain) UnsafeLocateInventory(locator BlockLocator, hashStop *chain
1512 1499
 // See the comment on the exported function for more details on special cases.
1513 1500
 //
1514 1501
 // This function MUST be called with the chain state lock held (for reads).
1515
-func (b *BlockChain) UnsafeLocateBlocks(locator BlockLocator, hashStop *chainhash.Hash, maxHashes uint32) []chainhash.Hash {
1502
+func (b *BlockChain) UnsafeLocateBlocks(locator locator.Block, hashStop *chainhash.Hash, maxHashes uint32) []chainhash.Hash {
1516 1503
 	// Find the node after the first known block in the locator and the
1517 1504
 	// total number of nodes after it needed while respecting the stop hash
1518 1505
 	// and max entries.
@@ -1543,7 +1530,7 @@ func (b *BlockChain) UnsafeLocateBlocks(locator BlockLocator, hashStop *chainhas
1543 1530
 //   after the genesis block will be returned
1544 1531
 //
1545 1532
 // This function is safe for concurrent access.
1546
-func (b *BlockChain) LocateBlocks(locator BlockLocator, hashStop *chainhash.Hash, maxHashes uint32) []chainhash.Hash {
1533
+func (b *BlockChain) LocateBlocks(locator locator.Block, hashStop *chainhash.Hash, maxHashes uint32) []chainhash.Hash {
1547 1534
 	b.ChainLock.RLock()
1548 1535
 	hashes := b.UnsafeLocateBlocks(locator, hashStop, maxHashes)
1549 1536
 	b.ChainLock.RUnlock()
@@ -1557,7 +1544,7 @@ func (b *BlockChain) LocateBlocks(locator BlockLocator, hashStop *chainhash.Hash
1557 1544
 // See the comment on the exported function for more details on special cases.
1558 1545
 //
1559 1546
 // This function MUST be called with the chain state lock held (for reads).
1560
-func (b *BlockChain) UnsafeLocateHeaders(locator BlockLocator, hashStop *chainhash.Hash, maxHeaders uint32) []msg.BlockHeader {
1547
+func (b *BlockChain) UnsafeLocateHeaders(locator locator.Block, hashStop *chainhash.Hash, maxHeaders uint32) []msg.BlockHeader {
1561 1548
 	// Find the node after the first known block in the locator and the
1562 1549
 	// total number of nodes after it needed while respecting the stop hash
1563 1550
 	// and max entries.
@@ -1588,7 +1575,7 @@ func (b *BlockChain) UnsafeLocateHeaders(locator BlockLocator, hashStop *chainha
1588 1575
 //   after the genesis block will be returned
1589 1576
 //
1590 1577
 // This function is safe for concurrent access.
1591
-func (b *BlockChain) LocateHeaders(locator BlockLocator, hashStop *chainhash.Hash) []msg.BlockHeader {
1578
+func (b *BlockChain) LocateHeaders(locator locator.Block, hashStop *chainhash.Hash) []msg.BlockHeader {
1592 1579
 	b.ChainLock.RLock()
1593 1580
 	headers := b.UnsafeLocateHeaders(locator, hashStop, msg.MaxBlockHeadersPerMsg)
1594 1581
 	b.ChainLock.RUnlock()
@@ -1731,7 +1718,7 @@ func New(config *Config) (*BlockChain, error) {
1731 1718
 		BlocksPerRetarget:   int32(targetTimespan / targetTimePerBlock),
1732 1719
 		Index:               index.NewBlock(config.DB, params),
1733 1720
 		HashCache:           config.HashCache,
1734
-		BestChain:           NewChainView(nil),
1721
+		BestChain:           view.NewChain(nil),
1735 1722
 		Orphans:             make(map[chainhash.Hash]*OrphanBlock),
1736 1723
 		PrevOrphans:         make(map[chainhash.Hash][]*OrphanBlock),
1737 1724
 		WarningCaches:       newThresholdCaches(vbNumBits),

+ 21
- 18
blockchain/chain_test.go View File

@@ -9,6 +9,9 @@ import (
9 9
 	"testing"
10 10
 	"time"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/blockchain/locator"
13
+	"git.parallelcoin.io/dev/btcd/blockchain/view"
14
+
12 15
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
13 16
 	"git.parallelcoin.io/dev/btcd/blockchain/status"
14 17
 	"git.parallelcoin.io/dev/btcd/blockchain/utxo"
@@ -473,10 +476,10 @@ func TestLocateInventory(t *testing.T) {
473 476
 	// the following structure.
474 477
 	// 	genesis -> 1 -> 2 -> ... -> 15 -> 16  -> 17  -> 18
475 478
 	// 	                              \-> 16a -> 17a
476
-	tip := TstTip
479
+	tip := view.TstTip
477 480
 	chain := NewFakeChain(&chaincfg.MainNetParams)
478
-	branch0Nodes := ChainedNodes(chain.BestChain.GetGenesis(), 18)
479
-	branch1Nodes := ChainedNodes(branch0Nodes[14], 2)
481
+	branch0Nodes := view.ChainedNodes(chain.BestChain.GetGenesis(), 18)
482
+	branch1Nodes := view.ChainedNodes(branch0Nodes[14], 2)
480 483
 	for _, node := range branch0Nodes {
481 484
 		chain.Index.AddNode(node)
482 485
 	}
@@ -487,17 +490,17 @@ func TestLocateInventory(t *testing.T) {
487 490
 
488 491
 	// Create chain views for different branches of the overall chain to
489 492
 	// simulate a local and remote node on different parts of the chain.
490
-	localView := NewChainView(tip(branch0Nodes))
491
-	remoteView := NewChainView(tip(branch1Nodes))
493
+	localView := view.NewChain(tip(branch0Nodes))
494
+	remoteView := view.NewChain(tip(branch1Nodes))
492 495
 
493 496
 	// Create a chain view for a completely unrelated block chain to
494 497
 	// simulate a remote node on a totally different chain.
495
-	unrelatedBranchNodes := ChainedNodes(nil, 5)
496
-	unrelatedView := NewChainView(tip(unrelatedBranchNodes))
498
+	unrelatedBranchNodes := view.ChainedNodes(nil, 5)
499
+	unrelatedView := view.NewChain(tip(unrelatedBranchNodes))
497 500
 
498 501
 	tests := []struct {
499 502
 		name       string
500
-		locator    BlockLocator      // locator for requested inventory
503
+		locator    locator.Block     // locator for requested inventory
501 504
 		hashStop   chainhash.Hash    // stop hash for locator
502 505
 		maxAllowed uint32            // max to locate, 0 = wire const
503 506
 		headers    []msg.BlockHeader // expected located headers
@@ -713,7 +716,7 @@ func TestLocateInventory(t *testing.T) {
713 716
 			// The expected result is the blocks after the second
714 717
 			// block limited by the max.
715 718
 			name:       "remote genesis",
716
-			locator:    LocatorHashes(branch0Nodes, 0),
719
+			locator:    view.LocatorHashes(branch0Nodes, 0),
717 720
 			hashStop:   chainhash.Hash{},
718 721
 			maxAllowed: 3,
719 722
 			headers:    NodeHeaders(branch0Nodes, 1, 2, 3),
@@ -729,7 +732,7 @@ func TestLocateInventory(t *testing.T) {
729 732
 			// a side chain and there are no more locators to find
730 733
 			// the fork point.
731 734
 			name:     "weak locator, single known side block",
732
-			locator:  LocatorHashes(branch1Nodes, 1),
735
+			locator:  view.LocatorHashes(branch1Nodes, 1),
733 736
 			hashStop: chainhash.Hash{},
734 737
 			headers: NodeHeaders(branch0Nodes, 0, 1, 2, 3, 4, 5, 6,
735 738
 				7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17),
@@ -746,7 +749,7 @@ func TestLocateInventory(t *testing.T) {
746 749
 			// blocks are known, they are all on a side chain and
747 750
 			// there are no more locators to find the fork point.
748 751
 			name:     "weak locator, multiple known side blocks",
749
-			locator:  LocatorHashes(branch1Nodes, 1),
752
+			locator:  view.LocatorHashes(branch1Nodes, 1),
750 753
 			hashStop: chainhash.Hash{},
751 754
 			headers: NodeHeaders(branch0Nodes, 0, 1, 2, 3, 4, 5, 6,
752 755
 				7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17),
@@ -765,7 +768,7 @@ func TestLocateInventory(t *testing.T) {
765 768
 			// side chain and there are no more locators to find the
766 769
 			// fork point.
767 770
 			name:     "weak locator, multiple known side blocks, stop in main",
768
-			locator:  LocatorHashes(branch1Nodes, 1),
771
+			locator:  view.LocatorHashes(branch1Nodes, 1),
769 772
 			hashStop: branch0Nodes[5].Hash,
770 773
 			headers:  NodeHeaders(branch0Nodes, 0, 1, 2, 3, 4, 5),
771 774
 			hashes:   NodeHashes(branch0Nodes, 0, 1, 2, 3, 4, 5),
@@ -813,10 +816,10 @@ func TestHeightToHashRange(t *testing.T) {
813 816
 	// the following structure.
814 817
 	// 	genesis -> 1 -> 2 -> ... -> 15 -> 16  -> 17  -> 18
815 818
 	// 	                              \-> 16a -> 17a -> 18a (unvalidated)
816
-	tip := TstTip
819
+	tip := view.TstTip
817 820
 	chain := NewFakeChain(&chaincfg.MainNetParams)
818
-	branch0Nodes := ChainedNodes(chain.BestChain.GetGenesis(), 18)
819
-	branch1Nodes := ChainedNodes(branch0Nodes[14], 3)
821
+	branch0Nodes := view.ChainedNodes(chain.BestChain.GetGenesis(), 18)
822
+	branch1Nodes := view.ChainedNodes(branch0Nodes[14], 3)
820 823
 	for _, nn := range branch0Nodes {
821 824
 		chain.Index.SetStatusFlags(nn, status.Valid)
822 825
 		chain.Index.AddNode(nn)
@@ -905,10 +908,10 @@ func TestIntervalBlockHashes(t *testing.T) {
905 908
 	// the following structure.
906 909
 	// 	genesis -> 1 -> 2 -> ... -> 15 -> 16  -> 17  -> 18
907 910
 	// 	                              \-> 16a -> 17a -> 18a (unvalidated)
908
-	tip := TstTip
911
+	tip := view.TstTip
909 912
 	chain := NewFakeChain(&chaincfg.MainNetParams)
910
-	branch0Nodes := ChainedNodes(chain.BestChain.GetGenesis(), 18)
911
-	branch1Nodes := ChainedNodes(branch0Nodes[14], 3)
913
+	branch0Nodes := view.ChainedNodes(chain.BestChain.GetGenesis(), 18)
914
+	branch1Nodes := view.ChainedNodes(branch0Nodes[14], 3)
912 915
 	for _, nn := range branch0Nodes {
913 916
 		chain.Index.SetStatusFlags(nn, status.Valid)
914 917
 		chain.Index.AddNode(nn)

+ 2
- 1
blockchain/common_test.go View File

@@ -18,6 +18,7 @@ import (
18 18
 	"git.parallelcoin.io/dev/btcd/blockchain/median"
19 19
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
20 20
 	"git.parallelcoin.io/dev/btcd/blockchain/utxo"
21
+	"git.parallelcoin.io/dev/btcd/blockchain/view"
21 22
 	"git.parallelcoin.io/dev/btcd/wire/msg"
22 23
 
23 24
 	"git.parallelcoin.io/dev/btcd/txscript/sig"
@@ -372,7 +373,7 @@ func NewFakeChain(params *chaincfg.Params) *BlockChain {
372 373
 		MaxRetargetTimespan: targetTimespan * adjustmentFactor,
373 374
 		BlocksPerRetarget:   int32(targetTimespan / targetTimePerBlock),
374 375
 		Index:               index,
375
-		BestChain:           NewChainView(node),
376
+		BestChain:           view.NewChain(node),
376 377
 		WarningCaches:       newThresholdCaches(vbNumBits),
377 378
 		DeploymentCaches:    newThresholdCaches(chaincfg.DefinedDeployments),
378 379
 	}

+ 19
- 0
blockchain/locator/blocklocator.go View File

@@ -0,0 +1,19 @@
1
+package locator
2
+
3
+import "git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
4
+
5
+// Block is used to help locate a specific block.  The algorithm for
6
+// building the block locator is to add the hashes in reverse order until
7
+// the genesis block is reached.  In order to keep the list of locator hashes
8
+// to a reasonable number of entries, first the most recent previous 12 block
9
+// hashes are added, then the step is doubled each loop iteration to
10
+// exponentially decrease the number of hashes as a function of the distance
11
+// from the block being located.
12
+//
13
+// For example, assume a block chain with a side chain as depicted below:
14
+// 	genesis -> 1 -> 2 -> ... -> 15 -> 16  -> 17  -> 18
15
+// 	                              \-> 16a -> 17a
16
+//
17
+// The block locator for block 17a would be the hashes of blocks:
18
+// [17a 16a 15 14 13 12 11 10 9 8 7 6 4 genesis]
19
+type Block []*chainhash.Hash

blockchain/chainview.go → blockchain/view/chainview.go View File

@@ -2,14 +2,21 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package blockchain
5
+package view
6 6
 
7 7
 import (
8
+	"math/rand"
8 9
 	"sync"
9 10
 
11
+	"git.parallelcoin.io/dev/btcd/blockchain/locator"
10 12
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
13
+	"git.parallelcoin.io/dev/btcd/wire/msg"
11 14
 )
12 15
 
16
+// TestNoncePrng provides a deterministic prng for the nonce in generated fake
17
+// nodes.  The ensures that the node have unique hashes.
18
+var TestNoncePrng = rand.New(rand.NewSource(0))
19
+
13 20
 // ApproxNodesPerWeek is an approximation of the number of new blocks there are
14 21
 // in a week on average.
15 22
 // TODO: this will become part of the consensus interface
@@ -34,7 +41,7 @@ func FastLog2Floor(n uint32) uint8 {
34 41
 	return rv
35 42
 }
36 43
 
37
-// ChainView provides a flat view of a specific branch of the block chain from
44
+// Chain provides a flat view of a specific branch of the block chain from
38 45
 // its tip back to the genesis block and provides various convenience functions
39 46
 // for comparing chains.
40 47
 //
@@ -44,17 +51,17 @@ func FastLog2Floor(n uint32) uint8 {
44 51
 //
45 52
 // The chain view for the branch ending in 6a consists of:
46 53
 //   genesis -> 1 -> 2 -> 3 -> 4a -> 5a -> 6a
47
-type ChainView struct {
54
+type Chain struct {
48 55
 	Mutex sync.Mutex
49 56
 	Nodes []*node.Block
50 57
 }
51 58
 
52
-// NewChainView returns a new chain view for the given tip block node.  Passing
59
+// NewChain returns a new chain view for the given tip block node.  Passing
53 60
 // nil as the tip will result in a chain view that is not initialized.  The tip
54 61
 // can be updated at any time via the setTip function.
55
-func NewChainView(tip *node.Block) *ChainView {
62
+func NewChain(tip *node.Block) *Chain {
56 63
 	// The mutex is intentionally not held since this is a constructor.
57
-	var c ChainView
64
+	var c Chain
58 65
 	c.UnsafeSetTip(tip)
59 66
 	return &c
60 67
 }
@@ -64,7 +71,7 @@ func NewChainView(tip *node.Block) *ChainView {
64 71
 // held.
65 72
 //
66 73
 // This function MUST be called with the view mutex locked (for reads).
67
-func (c *ChainView) UnsafeGetGenesis() *node.Block {
74
+func (c *Chain) UnsafeGetGenesis() *node.Block {
68 75
 	if len(c.Nodes) == 0 {
69 76
 		return nil
70 77
 	}
@@ -75,7 +82,7 @@ func (c *ChainView) UnsafeGetGenesis() *node.Block {
75 82
 // GetGenesis returns the genesis block for the chain view.
76 83
 //
77 84
 // This function is safe for concurrent access.
78
-func (c *ChainView) GetGenesis() *node.Block {
85
+func (c *Chain) GetGenesis() *node.Block {
79 86
 	c.Mutex.Lock()
80 87
 	genesis := c.UnsafeGetGenesis()
81 88
 	c.Mutex.Unlock()
@@ -87,7 +94,7 @@ func (c *ChainView) GetGenesis() *node.Block {
87 94
 // it is up to the caller to ensure the lock is held.
88 95
 //
89 96
 // This function MUST be called with the view mutex locked (for reads).
90
-func (c *ChainView) UnsafeGetTip() *node.Block {
97
+func (c *Chain) UnsafeGetTip() *node.Block {
91 98
 	if len(c.Nodes) == 0 {
92 99
 		return nil
93 100
 	}
@@ -99,7 +106,7 @@ func (c *ChainView) UnsafeGetTip() *node.Block {
99 106
 // nil if there is no tip.
100 107
 //
101 108
 // This function is safe for concurrent access.
102
-func (c *ChainView) GetTip() *node.Block {
109
+func (c *Chain) GetTip() *node.Block {
103 110
 	c.Mutex.Lock()
104 111
 	tip := c.UnsafeGetTip()
105 112
 	c.Mutex.Unlock()
@@ -114,7 +121,7 @@ func (c *ChainView) GetTip() *node.Block {
114 121
 // up to the caller to ensure the lock is held.
115 122
 //
116 123
 // This function MUST be called with the view mutex locked (for writes).
117
-func (c *ChainView) UnsafeSetTip(nn *node.Block) {
124
+func (c *Chain) UnsafeSetTip(nn *node.Block) {
118 125
 	if nn == nil {
119 126
 		// Keep the backing array around for potential future use.
120 127
 		c.Nodes = c.Nodes[:0]
@@ -155,7 +162,7 @@ func (c *ChainView) UnsafeSetTip(nn *node.Block) {
155 162
 // tips is efficient.
156 163
 //
157 164
 // This function is safe for concurrent access.
158
-func (c *ChainView) SetTip(nn *node.Block) {
165
+func (c *Chain) SetTip(nn *node.Block) {
159 166
 	c.Mutex.Lock()
160 167
 	c.UnsafeSetTip(nn)
161 168
 	c.Mutex.Unlock()
@@ -167,7 +174,7 @@ func (c *ChainView) SetTip(nn *node.Block) {
167 174
 // to the caller to ensure the lock is held.
168 175
 //
169 176
 // This function MUST be called with the view mutex locked (for reads).
170
-func (c *ChainView) UnsafeGetHeight() int32 {
177
+func (c *Chain) UnsafeGetHeight() int32 {
171 178
 	return int32(len(c.Nodes) - 1)
172 179
 }
173 180
 
@@ -176,7 +183,7 @@ func (c *ChainView) UnsafeGetHeight() int32 {
176 183
 // initialized).
177 184
 //
178 185
 // This function is safe for concurrent access.
179
-func (c *ChainView) GetHeight() int32 {
186
+func (c *Chain) GetHeight() int32 {
180 187
 	c.Mutex.Lock()
181 188
 	height := c.UnsafeGetHeight()
182 189
 	c.Mutex.Unlock()
@@ -188,7 +195,7 @@ func (c *ChainView) GetHeight() int32 {
188 195
 // version in that it is up to the caller to ensure the lock is held.
189 196
 //
190 197
 // This function MUST be called with the view mutex locked (for reads).
191
-func (c *ChainView) UnsafeGetNodeByHeight(height int32) *node.Block {
198
+func (c *Chain) UnsafeGetNodeByHeight(height int32) *node.Block {
192 199
 	if height < 0 || height >= int32(len(c.Nodes)) {
193 200
 		return nil
194 201
 	}
@@ -200,7 +207,7 @@ func (c *ChainView) UnsafeGetNodeByHeight(height int32) *node.Block {
200 207
 // returned if the height does not exist.
201 208
 //
202 209
 // This function is safe for concurrent access.
203
-func (c *ChainView) GetNodeByHeight(height int32) *node.Block {
210
+func (c *Chain) GetNodeByHeight(height int32) *node.Block {
204 211
 	c.Mutex.Lock()
205 212
 	node := c.UnsafeGetNodeByHeight(height)
206 213
 	c.Mutex.Unlock()
@@ -211,7 +218,7 @@ func (c *ChainView) GetNodeByHeight(height int32) *node.Block {
211 218
 // views (tip set to nil) are considered equal.
212 219
 //
213 220
 // This function is safe for concurrent access.
214
-func (c *ChainView) Equals(other *ChainView) bool {
221
+func (c *Chain) Equals(other *Chain) bool {
215 222
 	c.Mutex.Lock()
216 223
 	other.Mutex.Lock()
217 224
 	equals := len(c.Nodes) == len(other.Nodes) && c.UnsafeGetTip() == other.UnsafeGetTip()
@@ -225,7 +232,7 @@ func (c *ChainView) Equals(other *ChainView) bool {
225 232
 // caller to ensure the lock is held.
226 233
 //
227 234
 // This function MUST be called with the view mutex locked (for reads).
228
-func (c *ChainView) UnsafeContains(nn *node.Block) bool {
235
+func (c *Chain) UnsafeContains(nn *node.Block) bool {
229 236
 	return c.UnsafeGetNodeByHeight(nn.Height) == nn
230 237
 }
231 238
 
@@ -233,7 +240,7 @@ func (c *ChainView) UnsafeContains(nn *node.Block) bool {
233 240
 // node.
234 241
 //
235 242
 // This function is safe for concurrent access.
236
-func (c *ChainView) Contains(nn *node.Block) bool {
243
+func (c *Chain) Contains(nn *node.Block) bool {
237 244
 	c.Mutex.Lock()
238 245
 	contains := c.UnsafeContains(nn)
239 246
 	c.Mutex.Unlock()
@@ -248,7 +255,7 @@ func (c *ChainView) Contains(nn *node.Block) bool {
248 255
 // See the comment on the exported function for more details.
249 256
 //
250 257
 // This function MUST be called with the view mutex locked (for reads).
251
-func (c *ChainView) UnsafeGetNext(node *node.Block) *node.Block {
258
+func (c *Chain) UnsafeGetNext(node *node.Block) *node.Block {
252 259
 	if node == nil || !c.UnsafeContains(node) {
253 260
 		return nil
254 261
 	}
@@ -273,7 +280,7 @@ func (c *ChainView) UnsafeGetNext(node *node.Block) *node.Block {
273 280
 // of the view.
274 281
 //
275 282
 // This function is safe for concurrent access.
276
-func (c *ChainView) GetNext(node *node.Block) *node.Block {
283
+func (c *Chain) GetNext(node *node.Block) *node.Block {
277 284
 	c.Mutex.Lock()
278 285
 	next := c.UnsafeGetNext(node)
279 286
 	c.Mutex.Unlock()
@@ -288,7 +295,7 @@ func (c *ChainView) GetNext(node *node.Block) *node.Block {
288 295
 // See the exported FindFork comments for more details.
289 296
 //
290 297
 // This function MUST be called with the view mutex locked (for reads).
291
-func (c *ChainView) UnsafeFindFork(nn *node.Block) *node.Block {
298
+func (c *Chain) UnsafeFindFork(nn *node.Block) *node.Block {
292 299
 	// No fork point for node that doesn't exist.
293 300
 	if nn == nil {
294 301
 		return nil
@@ -336,7 +343,7 @@ func (c *ChainView) UnsafeFindFork(nn *node.Block) *node.Block {
336 343
 // the branch formed by the view.
337 344
 //
338 345
 // This function is safe for concurrent access.
339
-func (c *ChainView) FindFork(node *node.Block) *node.Block {
346
+func (c *Chain) FindFork(node *node.Block) *node.Block {
340 347
 	c.Mutex.Lock()
341 348
 	fork := c.UnsafeFindFork(node)
342 349
 	c.Mutex.Unlock()
@@ -348,10 +355,10 @@ func (c *ChainView) FindFork(node *node.Block) *node.Block {
348 355
 // associated with the view will be returned.  This only differs from the
349 356
 // exported version in that it is up to the caller to ensure the lock is held.
350 357
 //
351
-// See the exported BlockLocator function comments for more details.
358
+// See the exported locator.Block function comments for more details.
352 359
 //
353 360
 // This function MUST be called with the view mutex locked (for reads).
354
-func (c *ChainView) UnsafeGetBlockLocator(nn *node.Block) BlockLocator {
361
+func (c *Chain) UnsafeGetBlockLocator(nn *node.Block) locator.Block {
355 362
 	// Use the current tip if requested.
356 363
 	if nn == nil {
357 364
 		nn = c.UnsafeGetTip()
@@ -372,7 +379,7 @@ func (c *ChainView) UnsafeGetBlockLocator(nn *node.Block) BlockLocator {
372 379
 		adjustedHeight := uint32(nn.Height) - 10
373 380
 		maxEntries = 12 + FastLog2Floor(adjustedHeight)
374 381
 	}
375
-	locator := make(BlockLocator, 0, maxEntries)
382
+	locator := make(locator.Block, 0, maxEntries)
376 383
 
377 384
 	step := int32(1)
378 385
 	for nn != nil {
@@ -418,9 +425,55 @@ func (c *ChainView) UnsafeGetBlockLocator(nn *node.Block) BlockLocator {
418 425
 // locator.
419 426
 //
420 427
 // This function is safe for concurrent access.
421
-func (c *ChainView) GetBlockLocator(nn *node.Block) BlockLocator {
428
+func (c *Chain) GetBlockLocator(nn *node.Block) locator.Block {
422 429
 	c.Mutex.Lock()
423 430
 	locator := c.UnsafeGetBlockLocator(nn)
424 431
 	c.Mutex.Unlock()
425 432
 	return locator
426 433
 }
434
+
435
+// TstTip is a convenience function to grab the tip of a chain of block nodes
436
+// created via chainedNodes.
437
+func TstTip(nodes []*node.Block) *node.Block {
438
+	return nodes[len(nodes)-1]
439
+}
440
+
441
+// ChainedNodes returns the specified number of nodes constructed such that each
442
+// subsequent node points to the previous one to create a chain.  The first node
443
+// will point to the passed parent which can be nil if desired.
444
+func ChainedNodes(parent *node.Block, numNodes int) []*node.Block {
445
+	nodes := make([]*node.Block, numNodes)
446
+	tip := parent
447
+	for i := 0; i < numNodes; i++ {
448
+		// This is invalid, but all that is needed is enough to get the
449
+		// synthetic tests to work.
450
+		header := msg.BlockHeader{Nonce: TestNoncePrng.Uint32()}
451
+		if tip != nil {
452
+			header.PrevBlock = tip.Hash
453
+		}
454
+		nodes[i] = node.NewBlock(&header, tip)
455
+		tip = nodes[i]
456
+	}
457
+	return nodes
458
+}
459
+
460
+// LocatorHashes is a convenience function that returns the hashes for all of
461
+// the passed indexes of the provided nodes.  It is used to construct expected
462
+// block locators in the tests.
463
+func LocatorHashes(nodes []*node.Block, indexes ...int) locator.Block {
464
+	hashes := make(locator.Block, 0, len(indexes))
465
+	for _, idx := range indexes {
466
+		hashes = append(hashes, &nodes[idx].Hash)
467
+	}
468
+	return hashes
469
+}
470
+
471
+// ZipLocators is a convenience function that returns a single block locator
472
+// given a variable number of them and is used in the tests.
473
+func ZipLocators(locators ...locator.Block) locator.Block {
474
+	var hashes locator.Block
475
+	for _, locator := range locators {
476
+		hashes = append(hashes, locator...)
477
+	}
478
+	return hashes
479
+}

blockchain/chainview_test.go → blockchain/view/chainview_test.go View File

@@ -2,67 +2,16 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package blockchain
5
+package view
6 6
 
7 7
 import (
8
-	"math/rand"
9 8
 	"reflect"
10 9
 	"testing"
11 10
 
11
+	"git.parallelcoin.io/dev/btcd/blockchain/locator"
12 12
 	"git.parallelcoin.io/dev/btcd/blockchain/node"
13
-	"git.parallelcoin.io/dev/btcd/wire/msg"
14 13
 )
15 14
 
16
-// TestNoncePrng provides a deterministic prng for the nonce in generated fake
17
-// nodes.  The ensures that the node have unique hashes.
18
-var TestNoncePrng = rand.New(rand.NewSource(0))
19
-
20
-// ChainedNodes returns the specified number of nodes constructed such that each
21
-// subsequent node points to the previous one to create a chain.  The first node
22
-// will point to the passed parent which can be nil if desired.
23
-func ChainedNodes(parent *node.Block, numNodes int) []*node.Block {
24
-	nodes := make([]*node.Block, numNodes)
25
-	tip := parent
26
-	for i := 0; i < numNodes; i++ {
27
-		// This is invalid, but all that is needed is enough to get the
28
-		// synthetic tests to work.
29
-		header := msg.BlockHeader{Nonce: TestNoncePrng.Uint32()}
30
-		if tip != nil {
31
-			header.PrevBlock = tip.Hash
32
-		}
33
-		nodes[i] = node.NewBlock(&header, tip)
34
-		tip = nodes[i]
35
-	}
36
-	return nodes
37
-}
38
-
39
-// TstTip is a convenience function to grab the tip of a chain of block nodes
40
-// created via chainedNodes.
41
-func TstTip(nodes []*node.Block) *node.Block {
42
-	return nodes[len(nodes)-1]
43
-}
44
-
45
-// LocatorHashes is a convenience function that returns the hashes for all of
46
-// the passed indexes of the provided nodes.  It is used to construct expected
47
-// block locators in the tests.
48
-func LocatorHashes(nodes []*node.Block, indexes ...int) BlockLocator {
49
-	hashes := make(BlockLocator, 0, len(indexes))
50
-	for _, idx := range indexes {
51
-		hashes = append(hashes, &nodes[idx].Hash)
52
-	}
53
-	return hashes
54
-}
55
-
56
-// ZipLocators is a convenience function that returns a single block locator
57
-// given a variable number of them and is used in the tests.
58
-func ZipLocators(locators ...BlockLocator) BlockLocator {
59
-	var hashes BlockLocator
60
-	for _, locator := range locators {
61
-		hashes = append(hashes, locator...)
62
-	}
63
-	return hashes
64
-}
65
-
66 15
 // TestChainView ensures all of the exported functionality of chain views works
67 16
 // as intended with the exception of some special cases which are handled in
68 17
 // other tests.
@@ -79,48 +28,48 @@ func TestChainView(t *testing.T) {
79 28
 	tip := TstTip
80 29
 	tests := []struct {
81 30
 		name       string
82
-		view       *ChainView    // active view
31
+		view       *Chain        // active view
83 32
 		genesis    *node.Block   // expected genesis block of active view
84 33
 		tip        *node.Block   // expected tip of active view
85
-		side       *ChainView    // side chain view
34
+		side       *Chain        // side chain view
86 35
 		sideTip    *node.Block   // expected tip of side chain view
87 36
 		fork       *node.Block   // expected fork node
88 37
 		contains   []*node.Block // expected nodes in active view
89 38
 		noContains []*node.Block // expected nodes NOT in active view
90
-		equal      *ChainView    // view expected equal to active view
91
-		unequal    *ChainView    // view expected NOT equal to active
92
-		locator    BlockLocator  // expected locator for active view tip
39
+		equal      *Chain        // view expected equal to active view
40
+		unequal    *Chain        // view expected NOT equal to active
41
+		locator    locator.Block // expected locator for active view tip
93 42
 	}{
94 43
 		{
95 44
 			// Create a view for branch 0 as the active chain and
96 45
 			// another view for branch 1 as the side chain.
97 46
 			name:       "chain0-chain1",
98
-			view:       NewChainView(tip(branch0Nodes)),
47
+			view:       NewChain(tip(branch0Nodes)),
99 48
 			genesis:    branch0Nodes[0],
100 49
 			tip:        tip(branch0Nodes),
101
-			side:       NewChainView(tip(branch1Nodes)),
50
+			side:       NewChain(tip(branch1Nodes)),
102 51
 			sideTip:    tip(branch1Nodes),
103 52
 			fork:       branch0Nodes[1],
104 53
 			contains:   branch0Nodes,
105 54
 			noContains: branch1Nodes,
106
-			equal:      NewChainView(tip(branch0Nodes)),
107
-			unequal:    NewChainView(tip(branch1Nodes)),
55
+			equal:      NewChain(tip(branch0Nodes)),
56
+			unequal:    NewChain(tip(branch1Nodes)),
108 57
 			locator:    LocatorHashes(branch0Nodes, 4, 3, 2, 1, 0),
109 58
 		},
110 59
 		{
111 60
 			// Create a view for branch 1 as the active chain and
112 61
 			// another view for branch 2 as the side chain.
113 62
 			name:       "chain1-chain2",
114
-			view:       NewChainView(tip(branch1Nodes)),
63
+			view:       NewChain(tip(branch1Nodes)),
115 64
 			genesis:    branch0Nodes[0],
116 65
 			tip:        tip(branch1Nodes),
117
-			side:       NewChainView(tip(branch2Nodes)),
66
+			side:       NewChain(tip(branch2Nodes)),
118 67
 			sideTip:    tip(branch2Nodes),
119 68
 			fork:       branch1Nodes[0],
120 69
 			contains:   branch1Nodes,
121 70
 			noContains: branch2Nodes,
122
-			equal:      NewChainView(tip(branch1Nodes)),
123
-			unequal:    NewChainView(tip(branch2Nodes)),
71
+			equal:      NewChain(tip(branch1Nodes)),
72
+			unequal:    NewChain(tip(branch2Nodes)),
124 73
 			locator: ZipLocators(
125 74
 				LocatorHashes(branch1Nodes, 24, 23, 22, 21, 20,
126 75
 					19, 18, 17, 16, 15, 14, 13, 11, 7),
@@ -130,16 +79,16 @@ func TestChainView(t *testing.T) {
130 79
 			// Create a view for branch 2 as the active chain and
131 80
 			// another view for branch 0 as the side chain.
132 81
 			name:       "chain2-chain0",
133
-			view:       NewChainView(tip(branch2Nodes)),
82
+			view:       NewChain(tip(branch2Nodes)),
134 83
 			genesis:    branch0Nodes[0],
135 84
 			tip:        tip(branch2Nodes),
136
-			side:       NewChainView(tip(branch0Nodes)),
85
+			side:       NewChain(tip(branch0Nodes)),
137 86
 			sideTip:    tip(branch0Nodes),
138 87
 			fork:       branch0Nodes[1],
139 88
 			contains:   branch2Nodes,
140 89
 			noContains: branch0Nodes[2:],
141
-			equal:      NewChainView(tip(branch2Nodes)),
142
-			unequal:    NewChainView(tip(branch0Nodes)),
90
+			equal:      NewChain(tip(branch2Nodes)),
91
+			unequal:    NewChain(tip(branch0Nodes)),
143 92
 			locator: ZipLocators(
144 93
 				LocatorHashes(branch2Nodes, 2, 1, 0),
145 94
 				LocatorHashes(branch1Nodes, 0),
@@ -305,8 +254,8 @@ func TestChainViewForkCorners(t *testing.T) {
305 254
 	unrelatedBranchNodes := ChainedNodes(nil, 7)
306 255
 
307 256
 	// Create chain views for the two unrelated histories.
308
-	view1 := NewChainView(TstTip(branchNodes))
309
-	view2 := NewChainView(TstTip(unrelatedBranchNodes))
257
+	view1 := NewChain(TstTip(branchNodes))
258
+	view2 := NewChain(TstTip(unrelatedBranchNodes))
310 259
 
311 260
 	// Ensure attempting to find a fork point with a node that doesn't exist
312 261
 	// doesn't produce a node.
@@ -343,7 +292,7 @@ func TestChainViewSetTip(t *testing.T) {
343 292
 	tip := TstTip
344 293
 	tests := []struct {
345 294
 		name     string
346
-		view     *ChainView      // active view
295
+		view     *Chain          // active view
347 296
 		tips     []*node.Block   // tips to set
348 297
 		contains [][]*node.Block // expected nodes in view for each tip
349 298
 	}{
@@ -351,7 +300,7 @@ func TestChainViewSetTip(t *testing.T) {
351 300
 			// Create an empty view and set the tip to increasingly
352 301
 			// longer chains.
353 302
 			name:     "increasing",
354
-			view:     NewChainView(nil),
303
+			view:     NewChain(nil),
355 304
 			tips:     []*node.Block{tip(branch0Nodes), tip(branch1Nodes)},
356 305
 			contains: [][]*node.Block{branch0Nodes, branch1Nodes},
357 306
 		},
@@ -359,7 +308,7 @@ func TestChainViewSetTip(t *testing.T) {
359 308
 			// Create a view with a longer chain and set the tip to
360 309
 			// increasingly shorter chains.
361 310
 			name:     "decreasing",
362
-			view:     NewChainView(tip(branch1Nodes)),
311
+			view:     NewChain(tip(branch1Nodes)),
363 312
 			tips:     []*node.Block{tip(branch0Nodes), nil},
364 313
 			contains: [][]*node.Block{branch0Nodes, nil},
365 314
 		},
@@ -368,7 +317,7 @@ func TestChainViewSetTip(t *testing.T) {
368 317
 			// a longer chain followed by setting it back to the
369 318
 			// shorter chain.
370 319
 			name:     "small-large-small",
371
-			view:     NewChainView(tip(branch0Nodes)),
320
+			view:     NewChain(tip(branch0Nodes)),
372 321
 			tips:     []*node.Block{tip(branch1Nodes), tip(branch0Nodes)},
373 322
 			contains: [][]*node.Block{branch1Nodes, branch0Nodes},
374 323
 		},
@@ -377,7 +326,7 @@ func TestChainViewSetTip(t *testing.T) {
377 326
 			// a smaller chain followed by setting it back to the
378 327
 			// longer chain.
379 328
 			name:     "large-small-large",
380
-			view:     NewChainView(tip(branch1Nodes)),
329
+			view:     NewChain(tip(branch1Nodes)),
381 330
 			tips:     []*node.Block{tip(branch0Nodes), tip(branch1Nodes)},
382 331
 			contains: [][]*node.Block{branch0Nodes, branch1Nodes},
383 332
 		},
@@ -412,8 +361,8 @@ testLoop:
412 361
 // as expected.
413 362
 func TestChainViewNil(t *testing.T) {
414 363
 	// Ensure two unininitialized views are considered equal.
415
-	view := NewChainView(nil)
416
-	if !view.Equals(NewChainView(nil)) {
364
+	view := NewChain(nil)
365
+	if !view.Equals(NewChain(nil)) {
417 366
 		t.Fatal("uninitialized nil views unequal")
418 367
 	}
419 368
 
@@ -465,7 +414,7 @@ func TestChainViewNil(t *testing.T) {
465 414
 	// Ensure attempting to get a block locator for the tip doesn't produce
466 415
 	// one since the tip is nil.
467 416
 	if locator := view.GetBlockLocator(nil); locator != nil {
468
-		t.Fatalf("BlockLocator: unexpected locator -- got %v, want nil",
417
+		t.Fatalf("locator.Block: unexpected locator -- got %v, want nil",
469 418
 			locator)
470 419
 	}
471 420
 
@@ -476,7 +425,7 @@ func TestChainViewNil(t *testing.T) {
476 425
 		42, 41, 40, 39, 38, 36, 32, 24, 8, 0)
477 426
 	locator := view.GetBlockLocator(TstTip(branchNodes))
478 427
 	if !reflect.DeepEqual(locator, wantLocator) {
479
-		t.Fatalf("BlockLocator: unexpected locator -- got %v, want %v",
428
+		t.Fatalf("locator.Block: unexpected locator -- got %v, want %v",
480 429
 			locator, wantLocator)
481 430
 	}
482 431
 }

+ 5
- 4
netsync/manager/manager.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"time"
10 10
 
11 11
 	"git.parallelcoin.io/dev/btcd/blockchain/er"
12
+	"git.parallelcoin.io/dev/btcd/blockchain/locator"
12 13
 	"git.parallelcoin.io/dev/btcd/wire/msg"
13 14
 
14 15
 	"git.parallelcoin.io/dev/btcd/blockchain"
@@ -845,8 +846,8 @@ func (sm *Sync) HandleBlockMsg(bmsg *BlockMsg) {
845 846
 	prevHash := sm.NextCheckpoint.Hash
846 847
 	sm.NextCheckpoint = sm.FindNextHeaderCheckpoint(prevHeight)
847 848
 	if sm.NextCheckpoint != nil {
848
-		locator := blockchain.BlockLocator([]*chainhash.Hash{prevHash})
849
-		err := peer.PushGetHeadersMsg(locator, sm.NextCheckpoint.Hash)
849
+		l := locator.Block([]*chainhash.Hash{prevHash})
850
+		err := peer.PushGetHeadersMsg(l, sm.NextCheckpoint.Hash)
850 851
 		if err != nil {
851 852
 			netsync.Log.Warnf("Failed to send getheaders message to "+
852 853
 				"peer %s: %v", peer.GetAddr(), err)
@@ -864,7 +865,7 @@ func (sm *Sync) HandleBlockMsg(bmsg *BlockMsg) {
864 865
 	sm.HeadersFirstMode = false
865 866
 	sm.HeaderList.Init()
866 867
 	netsync.Log.Infof("Reached the final checkpoint -- switching to normal mode")
867
-	locator := blockchain.BlockLocator([]*chainhash.Hash{blockHash})
868
+	locator := locator.Block([]*chainhash.Hash{blockHash})
868 869
 	err = peer.PushGetBlocksMsg(locator, &ZeroHash)
869 870
 	if err != nil {
870 871
 		netsync.Log.Warnf("Failed to send getblocks message to peer %s: %v",
@@ -1026,7 +1027,7 @@ func (sm *Sync) HandleHeadersMsg(hmsg *HeadersMsg) {
1026 1027
 	// This header is not a checkpoint, so request the next batch of
1027 1028
 	// headers starting from the latest known header and ending with the
1028 1029
 	// next checkpoint.
1029
-	locator := blockchain.BlockLocator([]*chainhash.Hash{finalHash})
1030
+	locator := locator.Block([]*chainhash.Hash{finalHash})
1030 1031
 	err := peer.PushGetHeadersMsg(locator, sm.NextCheckpoint.Hash)
1031 1032
 	if err != nil {
1032 1033
 		netsync.Log.Warnf("Failed to send getheaders message to "+

+ 7
- 6
peer/peer.go View File

@@ -18,6 +18,8 @@ import (
18 18
 	"sync/atomic"
19 19
 	"time"
20 20
 
21
+	"git.parallelcoin.io/dev/btcd/blockchain/locator"
22
+
21 23
 	"git.parallelcoin.io/dev/btcd/wire/msg"
22 24
 	"git.parallelcoin.io/dev/btcd/wire/na"
23 25
 	"git.parallelcoin.io/dev/btcd/wire/reject"
@@ -27,7 +29,6 @@ import (
27 29
 
28 30
 	"git.parallelcoin.io/dev/btcd/wire/inv"
29 31
 
30
-	"git.parallelcoin.io/dev/btcd/blockchain"
31 32
 	"git.parallelcoin.io/dev/btcd/chaincfg"
32 33
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
33 34
 	"git.parallelcoin.io/dev/btcd/wire/service"
@@ -858,12 +859,12 @@ func (p *Peer) PushAddrMsg(addresses []*na.NetAddress) ([]*na.NetAddress, error)
858 859
 // and stop hash.  It will ignore back-to-back duplicate requests.
859 860
 //
860 861
 // This function is safe for concurrent access.
861
-func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
862
+func (p *Peer) PushGetBlocksMsg(l locator.Block, stopHash *chainhash.Hash) error {
862 863
 	// Extract the begin hash from the block locator, if one was specified,
863 864
 	// to use for filtering duplicate getblocks requests.
864 865
 	var beginHash *chainhash.Hash
865
-	if len(locator) > 0 {
866
-		beginHash = locator[0]
866
+	if len(l) > 0 {
867
+		beginHash = l[0]
867 868
 	}
868 869
 
869 870
 	// Filter duplicate getblocks requests.
@@ -881,7 +882,7 @@ func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chain
881 882
 
882 883
 	// Construct the getblocks request and queue it to be sent.
883 884
 	msg := msg.NewMsgGetBlocks(stopHash)
884
-	for _, hash := range locator {
885
+	for _, hash := range l {
885 886
 		err := msg.AddBlockLocatorHash(hash)
886 887
 		if err != nil {
887 888
 			return err
@@ -902,7 +903,7 @@ func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chain
902 903
 // and stop hash.  It will ignore back-to-back duplicate requests.
903 904
 //
904 905
 // This function is safe for concurrent access.
905
-func (p *Peer) PushGetHeadersMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
906
+func (p *Peer) PushGetHeadersMsg(locator locator.Block, stopHash *chainhash.Hash) error {
906 907
 	// Extract the begin hash from the block locator, if one was specified,
907 908
 	// to use for filtering duplicate getheaders requests.
908 909
 	var beginHash *chainhash.Hash

Loading…
Cancel
Save