Skip to content

Commit 7bff85e

Browse files
Merge pull request dashpay#5574 from kwvg/auxports11
backport: merge bitcoin#19326, bitcoin#20464, bitcoin#23451, bitcoin#20852, bitcoin#20355, bitcoin#22050, bitcoin#23115, bitcoin#23409, bitcoin#18468, bitcoin#23413, partial bitcoin#21560, bitcoin#23438 (auxiliary backports: part 11)
2 parents ee31352 + 117083f commit 7bff85e

Some content is hidden

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

81 files changed

+1705
-1474
lines changed

contrib/seeds/generate-seeds.py

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2014-2017 Wladimir J. van der Laan
2+
# Copyright (c) 2014-2021 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
'''
@@ -13,44 +13,47 @@
1313
1414
These files must consist of lines in the format
1515
16-
<ip>
1716
<ip>:<port>
18-
[<ipv6>]
1917
[<ipv6>]:<port>
20-
<onion>.onion
21-
0xDDBBCCAA (IPv4 little-endian old pnSeeds format)
18+
<onion>.onion:<port>
2219
2320
The output will be two data structures with the peers in binary format:
2421
25-
static SeedSpec6 pnSeed6_main[]={
26-
...
27-
}
28-
static SeedSpec6 pnSeed6_test[]={
22+
static const uint8_t chainparams_seed_{main,test}[]={
2923
...
3024
}
3125
3226
These should be pasted into `src/chainparamsseeds.h`.
3327
'''
3428

3529
from base64 import b32decode
36-
from binascii import a2b_hex
30+
from enum import Enum
31+
import struct
3732
import sys
3833
import os
3934
import re
4035

41-
# ipv4 in ipv6 prefix
42-
pchIPv4 = bytearray([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff])
43-
# tor-specific ipv6 prefix
44-
pchOnionCat = bytearray([0xFD,0x87,0xD8,0x7E,0xEB,0x43])
45-
46-
def name_to_ipv6(addr):
47-
if len(addr)>6 and addr.endswith('.onion'):
36+
class BIP155Network(Enum):
37+
IPV4 = 1
38+
IPV6 = 2
39+
TORV2 = 3 # no longer supported
40+
TORV3 = 4
41+
I2P = 5
42+
CJDNS = 6
43+
44+
def name_to_bip155(addr):
45+
'''Convert address string to BIP155 (networkID, addr) tuple.'''
46+
if addr.endswith('.onion'):
4847
vchAddr = b32decode(addr[0:-6], True)
49-
if len(vchAddr) != 16-len(pchOnionCat):
48+
if len(vchAddr) == 35:
49+
assert vchAddr[34] == 3
50+
return (BIP155Network.TORV3, vchAddr[:32])
51+
elif len(vchAddr) == 10:
52+
return (BIP155Network.TORV2, vchAddr)
53+
else:
5054
raise ValueError('Invalid onion %s' % vchAddr)
51-
return pchOnionCat + vchAddr
5255
elif '.' in addr: # IPv4
53-
return pchIPv4 + bytearray((int(x) for x in addr.split('.')))
56+
return (BIP155Network.IPV4, bytes((int(x) for x in addr.split('.'))))
5457
elif ':' in addr: # IPv6
5558
sub = [[], []] # prefix, suffix
5659
x = 0
@@ -67,13 +70,12 @@ def name_to_ipv6(addr):
6770
sub[x].append(val & 0xff)
6871
nullbytes = 16 - len(sub[0]) - len(sub[1])
6972
assert((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0))
70-
return bytearray(sub[0] + ([0] * nullbytes) + sub[1])
71-
elif addr.startswith('0x'): # IPv4-in-little-endian
72-
return pchIPv4 + bytearray(reversed(a2b_hex(addr[2:])))
73+
return (BIP155Network.IPV6, bytes(sub[0] + ([0] * nullbytes) + sub[1]))
7374
else:
7475
raise ValueError('Could not parse address %s' % addr)
7576

76-
def parse_spec(s, defaultport):
77+
def parse_spec(s):
78+
'''Convert endpoint string to BIP155 (networkID, addr, port) tuple.'''
7779
match = re.match(r'\[([0-9a-fA-F:]+)\](?::([0-9]+))?$', s)
7880
if match: # ipv6
7981
host = match.group(1)
@@ -85,32 +87,57 @@ def parse_spec(s, defaultport):
8587
(host,_,port) = s.partition(':')
8688

8789
if not port:
88-
port = defaultport
90+
port = 0
8991
else:
9092
port = int(port)
9193

92-
host = name_to_ipv6(host)
93-
94-
return (host,port)
94+
host = name_to_bip155(host)
9595

96-
def process_nodes(g, f, structname, defaultport):
97-
g.write('static SeedSpec6 %s[] = {\n' % structname)
98-
first = True
96+
if host[0] == BIP155Network.TORV2:
97+
return None # TORV2 is no longer supported, so we ignore it
98+
else:
99+
return host + (port, )
100+
101+
def ser_compact_size(l):
102+
r = b""
103+
if l < 253:
104+
r = struct.pack("B", l)
105+
elif l < 0x10000:
106+
r = struct.pack("<BH", 253, l)
107+
elif l < 0x100000000:
108+
r = struct.pack("<BI", 254, l)
109+
else:
110+
r = struct.pack("<BQ", 255, l)
111+
return r
112+
113+
def bip155_serialize(spec):
114+
'''
115+
Serialize (networkID, addr, port) tuple to BIP155 binary format.
116+
'''
117+
r = b""
118+
r += struct.pack('B', spec[0].value)
119+
r += ser_compact_size(len(spec[1]))
120+
r += spec[1]
121+
r += struct.pack('>H', spec[2])
122+
return r
123+
124+
def process_nodes(g, f, structname):
125+
g.write('static const uint8_t %s[] = {\n' % structname)
99126
for line in f:
100127
comment = line.find('#')
101128
if comment != -1:
102129
line = line[0:comment]
103130
line = line.strip()
104131
if not line:
105132
continue
106-
if not first:
107-
g.write(',\n')
108-
first = False
109133

110-
(host,port) = parse_spec(line, defaultport)
111-
hoststr = ','.join(('0x%02x' % b) for b in host)
112-
g.write(' {{%s}, %i}' % (hoststr, port))
113-
g.write('\n};\n')
134+
spec = parse_spec(line)
135+
if spec is None: # ignore this entry (e.g. no longer supported addresses like TORV2)
136+
continue
137+
blob = bip155_serialize(spec)
138+
hoststr = ','.join(('0x%02x' % b) for b in blob)
139+
g.write(f' {hoststr},\n')
140+
g.write('};\n')
114141

115142
def main():
116143
if len(sys.argv)<2:
@@ -124,14 +151,13 @@ def main():
124151
g.write(' * List of fixed seed nodes for the dash network\n')
125152
g.write(' * AUTOGENERATED by contrib/seeds/generate-seeds.py\n')
126153
g.write(' *\n')
127-
g.write(' * Each line contains a 16-byte IPv6 address and a port.\n')
128-
g.write(' * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly.\n')
154+
g.write(' * Each line contains a BIP155 serialized (networkID, addr, port) tuple.\n')
129155
g.write(' */\n')
130156
with open(os.path.join(indir,'nodes_main.txt'), 'r', encoding="utf8") as f:
131-
process_nodes(g, f, 'pnSeed6_main', 9999)
157+
process_nodes(g, f, 'chainparams_seed_main')
132158
g.write('\n')
133159
with open(os.path.join(indir,'nodes_test.txt'), 'r', encoding="utf8") as f:
134-
process_nodes(g, f, 'pnSeed6_test', 19999)
160+
process_nodes(g, f, 'chainparams_seed_test')
135161
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')
136162

137163
if __name__ == '__main__':

doc/files.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ Subdirectory | File(s) | Description
5353
`indexes/blockfilter/basic/db/` | LevelDB database | Blockfilter index LevelDB database for the basic filtertype; *optional*, used if `-blockfilterindex=basic`
5454
`indexes/blockfilter/basic/` | `fltrNNNNN.dat`<sup>[\[2\]](#note2)</sup> | Blockfilter index filters for the basic filtertype; *optional*, used if `-blockfilterindex=basic`
5555
`wallets/` | | [Contains wallets](#multi-wallet-environment); can be specified by `-walletdir` option; if `wallets/` subdirectory does not exist, a wallet resides in the data directory
56+
`./` | `anchors.dat` | Anchor IP address database, created on shutdown and deleted at startup. Anchors are last known outgoing block-relay-only peers that are tried to re-connect to on startup
5657
`evodb/` | |special txes and quorums database
5758
`llmq/` | |quorum signatures database
58-
`./` | `banlist.dat` | Stores the IPs/subnets of banned nodes
59+
`./` | `banlist.json` | Stores the addresses/subnets of banned nodes.
5960
`./` | `dash.conf` | User-defined [configuration settings](dash-conf.md) for `dashd` or `dash-qt`. File is not written to by the software and must be created manually. Path can be specified by `-conf` option
6061
`./` | `dashd.pid` | Stores the process ID (PID) of `dashd` or `dash-qt` while running; created at start and deleted on shutdown; can be specified by `-pid` option
6162
`./` | `debug.log` | Contains debug information and general logging generated by `dashd` or `dash-qt`; can be specified by `-debuglogfile` option
@@ -110,10 +111,11 @@ Subdirectory | File | Description
110111

111112
## Legacy subdirectories and files
112113

113-
These subdirectories and files are no longer used by the Dash Core:
114+
These subdirectories and files are no longer used by Dash Core:
114115

115116
Path | Description | Repository notes
116117
---------------|-------------|-----------------
118+
`banlist.dat` | Stores the addresses/subnets of banned nodes; completely ignored and superseded by `banlist.json` in 20.0 | [PR #5574](https://github.com/dashpay/dash/pull/5574)
117119
`blktree/` | Blockchain index; replaced by `blocks/index/` in [0.8.0](https://github.com/dash/dash/blob/master/doc/release-notes/release-notes-0.8.0.md#improvements) | [PR #2231](https://github.com/dash/dash/pull/2231), [`8fdc94cc`](https://github.com/dash/dash/commit/8fdc94cc8f0341e96b1edb3a5b56811c0b20bd15)
118120
`coins/` | Unspent transaction output database; replaced by `chainstate/` in 0.8.0 | [PR #2231](https://github.com/dash/dash/pull/2231), [`8fdc94cc`](https://github.com/dash/dash/commit/8fdc94cc8f0341e96b1edb3a5b56811c0b20bd15)
119121
`blkindex.dat` | Blockchain index BDB database; replaced by {`chainstate/`, `blocks/index/`, `blocks/revNNNNN.dat`<sup>[\[2\]](#note2)</sup>} in 0.8.0 | [PR #1677](https://github.com/dash/dash/pull/1677)

0 commit comments

Comments
 (0)