Skip to content

Commit dbd57a5

Browse files
committed
Merge commit '80f5a0ffdf363cfff27d550f9e38aa262667a7f1'
2 parents 07772e3 + 80f5a0f commit dbd57a5

File tree

182 files changed

+3036
-1245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+3036
-1245
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ coverage.txt
4545
btcec/coverage.txt
4646
ltcutil/coverage.txt
4747
ltcutil/psbt/coverage.txt
48+
49+
# vim
50+
*.swp

README.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
3. [Wallet](#Wallet)
2323
4. [Contact](#Contact)
2424
1. [Email](#ContactEmail)
25-
2. [Mailing Lists](#MailingLists)
2625
5. [Developer Resources](#DeveloperResources)
2726
1. [Code Contribution Guidelines](#ContributionGuidelines)
2827
2. [JSON-RPC Reference](#JSONRPCReference)
@@ -63,7 +62,7 @@ directly with ltcd. That functionality is provided by the
6362

6463
<a name="GettingStarted" />
6564

66-
### 2. Getting Started
65+
[Go](http://golang.org) 1.17 or newer.
6766

6867
<a name="Installation" />
6968

@@ -242,15 +241,6 @@ information.
242241

243242
- losh11@litecoin.net - maintainers email.
244243

245-
<a name="MailingLists" />
246-
247-
**4.2 Mailing Lists**
248-
249-
- <a href="mailto:ltcd+subscribe@opensource.conformal.com">btcd</a>: discussion
250-
of btcd and its packages.
251-
- <a href="mailto:ltcd-commits+subscribe@opensource.conformal.com">btcd-commits</a>:
252-
readonly mail-out of source code changes.
253-
254244
<a name="DeveloperResources" />
255245

256246
### 5. Developer Resources

addrmgr/addrmanager.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
// AddrManager provides a concurrency safe address manager for caching potential
31-
// peers on the bitcoin network.
31+
// peers on the litecoin network.
3232
type AddrManager struct {
3333
mtx sync.RWMutex
3434
peersFile string
@@ -244,7 +244,7 @@ func (a *AddrManager) updateAddress(netAddr, srcAddr *wire.NetAddressV2) {
244244
func (a *AddrManager) expireNew(bucket int) {
245245
// First see if there are any entries that are so bad we can just throw
246246
// them away. otherwise we throw away the oldest entry in the cache.
247-
// Bitcoind here chooses four random and just throws the oldest of
247+
// Litecoind here chooses four random and just throws the oldest of
248248
// those away, but we keep track of oldest in the initial traversal and
249249
// use that information instead.
250250
var oldest *KnownAddress
@@ -280,7 +280,7 @@ func (a *AddrManager) expireNew(bucket int) {
280280
}
281281

282282
// pickTried selects an address from the tried bucket to be evicted.
283-
// We just choose the eldest. Bitcoind selects 4 random entries and throws away
283+
// We just choose the eldest. Litecoind selects 4 random entries and throws away
284284
// the older of them.
285285
func (a *AddrManager) pickTried(bucket int) *list.Element {
286286
var oldest *KnownAddress
@@ -297,7 +297,7 @@ func (a *AddrManager) pickTried(bucket int) *list.Element {
297297
}
298298

299299
func (a *AddrManager) getNewBucket(netAddr, srcAddr *wire.NetAddressV2) int {
300-
// bitcoind:
300+
// litecoind:
301301
// doublesha256(key + sourcegroup + int64(doublesha256(key + group + sourcegroup))%bucket_per_source_group) % num_new_buckets
302302

303303
data1 := []byte{}
@@ -319,7 +319,7 @@ func (a *AddrManager) getNewBucket(netAddr, srcAddr *wire.NetAddressV2) int {
319319
}
320320

321321
func (a *AddrManager) getTriedBucket(netAddr *wire.NetAddressV2) int {
322-
// bitcoind hashes this as:
322+
// litecoind hashes this as:
323323
// doublesha256(key + group + truncate_to_64bits(doublesha256(key)) % buckets_per_group) % num_buckets
324324
data1 := []byte{}
325325
data1 = append(data1, a.key[:]...)
@@ -733,7 +733,7 @@ func (a *AddrManager) HostToNetAddress(host string, port uint16,
733733
// Tor v2 address is 16 char base32 + ".onion"
734734
if len(host) == wire.TorV2EncodedSize && host[wire.TorV2EncodedSize-6:] == ".onion" {
735735
// go base32 encoding uses capitals (as does the rfc
736-
// but Tor and bitcoind tend to user lowercase, so we switch
736+
// but Tor and litecoind tend to user lowercase, so we switch
737737
// case here.
738738
data, err := base32.StdEncoding.DecodeString(
739739
strings.ToUpper(host[:wire.TorV2EncodedSize-6]))
@@ -1202,7 +1202,7 @@ func (a *AddrManager) GetBestLocalAddress(remoteAddr *wire.NetAddressV2) *wire.N
12021202
return bestAddress
12031203
}
12041204

1205-
// New returns a new bitcoin address manager.
1205+
// New returns a new litecoin address manager.
12061206
// Use Start to begin processing asynchronous address updates.
12071207
func New(dataDir string, lookupFunc func(string) ([]net.IP, error)) *AddrManager {
12081208
am := AddrManager{

addrmgr/doc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// license that can be found in the LICENSE file.
44

55
/*
6-
Package addrmgr implements concurrency safe Bitcoin address manager.
6+
Package addrmgr implements concurrency safe Litecoin address manager.
77
8-
Address Manager Overview
8+
# Address Manager Overview
99
10-
In order maintain the peer-to-peer Bitcoin network, there needs to be a source
11-
of addresses to connect to as nodes come and go. The Bitcoin protocol provides
10+
In order maintain the peer-to-peer Litecoin network, there needs to be a source
11+
of addresses to connect to as nodes come and go. The Litecoin protocol provides
1212
the getaddr and addr messages to allow peers to communicate known addresses with
1313
each other. However, there needs to a mechanism to store those results and
1414
select peers from them. It is also important to note that remote peers can't

addrmgr/network.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
ipNet("192.168.0.0", 16, 32),
2121
}
2222

23-
// rfc2544Net specifies the the IPv4 block as defined by RFC2544
23+
// rfc2544Net specifies the IPv4 block as defined by RFC2544
2424
// (198.18.0.0/15)
2525
rfc2544Net = ipNet("198.18.0.0", 15, 32)
2626

@@ -72,7 +72,7 @@ var (
7272
rfc6598Net = ipNet("100.64.0.0", 10, 32)
7373

7474
// onionCatNet defines the IPv6 address block used to support Tor.
75-
// bitcoind encodes a .onion address as a 16 byte number by decoding the
75+
// litecoind encodes a .onion address as a 16 byte number by decoding the
7676
// address prior to the .onion (i.e. the key hash) base32 into a ten
7777
// byte number. It then stores the first 6 bytes of the address as
7878
// 0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43.
@@ -110,7 +110,7 @@ func IsLocal(na *wire.NetAddress) bool {
110110
}
111111

112112
// IsOnionCatTor returns whether or not the passed address is in the IPv6 range
113-
// used by bitcoin to support Tor (fd87:d87e:eb43::/48). Note that this range
113+
// used by litecoin to support Tor (fd87:d87e:eb43::/48). Note that this range
114114
// is the same range used by OnionCat, which is part of the RFC4193 unique local
115115
// IPv6 range.
116116
func IsOnionCatTor(na *wire.NetAddress) bool {
@@ -287,7 +287,7 @@ func GroupKey(na *wire.NetAddressV2) string {
287287
}
288288

289289
// OK, so now we know ourselves to be a IPv6 address.
290-
// bitcoind uses /32 for everything, except for Hurricane Electric's
290+
// litecoind uses /32 for everything, except for Hurricane Electric's
291291
// (he.net) IP range, which it uses /36 for.
292292
bits := 32
293293
if heNet.Contains(lna.IP) {

blockchain/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ blockchain
55
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
66
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/ltcsuite/ltcd/blockchain)
77

8-
Package blockchain implements bitcoin block handling and chain selection rules.
8+
Package blockchain implements litecoin block handling and chain selection rules.
99
The test coverage is currently only around 60%, but will be increasing over
1010
time. See `test_coverage.txt` for the gocov coverage report. Alternatively, if
1111
you are running a POSIX OS, you can run the `cov_report.sh` script for a
@@ -15,7 +15,7 @@ There is an associated blog post about the release of this package
1515
[here](https://blog.conformal.com/btcchain-the-bitcoin-chain-package-from-bctd/).
1616

1717
This package has intentionally been designed so it can be used as a standalone
18-
package for any projects needing to handle processing of blocks into the bitcoin
18+
package for any projects needing to handle processing of blocks into the litecoin
1919
block chain.
2020

2121
## Installation and Updating
@@ -24,7 +24,7 @@ block chain.
2424
$ go get -u github.com/ltcsuite/ltcd/blockchain
2525
```
2626

27-
## Bitcoin Chain Processing Overview
27+
## Litecoin Chain Processing Overview
2828

2929
Before a block is allowed into the block chain, it must go through an intensive
3030
series of validation rules. The following list serves as a general outline of

blockchain/bench_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/ltcsuite/ltcd/ltcutil"
11+
"github.com/ltcsuite/ltcd/wire"
1112
)
1213

1314
// BenchmarkIsCoinBase performs a simple benchmark against the IsCoinBase
@@ -29,3 +30,33 @@ func BenchmarkIsCoinBaseTx(b *testing.B) {
2930
IsCoinBaseTx(tx)
3031
}
3132
}
33+
34+
func BenchmarkUtxoFetchMap(b *testing.B) {
35+
block := Block100000
36+
transactions := block.Transactions
37+
b.ResetTimer()
38+
39+
for i := 0; i < b.N; i++ {
40+
needed := make(map[wire.OutPoint]struct{}, len(transactions))
41+
for _, tx := range transactions[1:] {
42+
for _, txIn := range tx.TxIn {
43+
needed[txIn.PreviousOutPoint] = struct{}{}
44+
}
45+
}
46+
}
47+
}
48+
49+
func BenchmarkUtxoFetchSlices(b *testing.B) {
50+
block := Block100000
51+
transactions := block.Transactions
52+
b.ResetTimer()
53+
54+
for i := 0; i < b.N; i++ {
55+
needed := make([]wire.OutPoint, 0, len(transactions))
56+
for _, tx := range transactions[1:] {
57+
for _, txIn := range tx.TxIn {
58+
needed = append(needed, txIn.PreviousOutPoint)
59+
}
60+
}
61+
}
62+
}

blockchain/blockindex.go

+61-3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,60 @@ func (node *blockNode) Ancestor(height int32) *blockNode {
169169
return n
170170
}
171171

172+
// Height returns the blockNode's height in the chain.
173+
//
174+
// NOTE: Part of the HeaderCtx interface.
175+
func (node *blockNode) Height() int32 {
176+
return node.height
177+
}
178+
179+
// Bits returns the blockNode's nBits.
180+
//
181+
// NOTE: Part of the HeaderCtx interface.
182+
func (node *blockNode) Bits() uint32 {
183+
return node.bits
184+
}
185+
186+
// Timestamp returns the blockNode's timestamp.
187+
//
188+
// NOTE: Part of the HeaderCtx interface.
189+
func (node *blockNode) Timestamp() int64 {
190+
return node.timestamp
191+
}
192+
193+
// Parent returns the blockNode's parent.
194+
//
195+
// NOTE: Part of the HeaderCtx interface.
196+
func (node *blockNode) Parent() HeaderCtx {
197+
if node.parent == nil {
198+
// This is required since node.parent is a *blockNode and if we
199+
// do not explicitly return nil here, the caller may fail when
200+
// nil-checking this.
201+
return nil
202+
}
203+
204+
return node.parent
205+
}
206+
207+
// RelativeAncestorCtx returns the blockNode's ancestor that is distance blocks
208+
// before it in the chain. This is equivalent to the RelativeAncestor function
209+
// below except that the return type is different.
210+
//
211+
// This function is safe for concurrent access.
212+
//
213+
// NOTE: Part of the HeaderCtx interface.
214+
func (node *blockNode) RelativeAncestorCtx(distance int32) HeaderCtx {
215+
ancestor := node.RelativeAncestor(distance)
216+
if ancestor == nil {
217+
// This is required since RelativeAncestor returns a *blockNode
218+
// and if we do not explicitly return nil here, the caller may
219+
// fail when nil-checking this.
220+
return nil
221+
}
222+
223+
return ancestor
224+
}
225+
172226
// RelativeAncestor returns the ancestor block node a relative 'distance' blocks
173227
// before this node. This is equivalent to calling Ancestor with the node's
174228
// height minus provided distance.
@@ -182,17 +236,17 @@ func (node *blockNode) RelativeAncestor(distance int32) *blockNode {
182236
// prior to, and including, the block node.
183237
//
184238
// This function is safe for concurrent access.
185-
func (node *blockNode) CalcPastMedianTime() time.Time {
239+
func CalcPastMedianTime(node HeaderCtx) time.Time {
186240
// Create a slice of the previous few block timestamps used to calculate
187241
// the median per the number defined by the constant medianTimeBlocks.
188242
timestamps := make([]int64, medianTimeBlocks)
189243
numNodes := 0
190244
iterNode := node
191245
for i := 0; i < medianTimeBlocks && iterNode != nil; i++ {
192-
timestamps[i] = iterNode.timestamp
246+
timestamps[i] = iterNode.Timestamp()
193247
numNodes++
194248

195-
iterNode = iterNode.parent
249+
iterNode = iterNode.Parent()
196250
}
197251

198252
// Prune the slice to the actual number of available timestamps which
@@ -217,6 +271,10 @@ func (node *blockNode) CalcPastMedianTime() time.Time {
217271
return time.Unix(medianTimestamp, 0)
218272
}
219273

274+
// A compile-time assertion to ensure blockNode implements the HeaderCtx
275+
// interface.
276+
var _ HeaderCtx = (*blockNode)(nil)
277+
220278
// blockIndex provides facilities for keeping track of an in-memory index of the
221279
// block chain. Although the name block chain suggests a single chain of
222280
// blocks, it is actually a tree-shaped structure where any node can have

0 commit comments

Comments
 (0)