Skip to content

Commit 015e30f

Browse files
feat: add onion_seeds to seed creation; do seed creation (#5866)
## Issue being fixed or feature implemented We did not previously ship any onion seeds. This results in people needing to use `addnode` in order to actually get connected ## What was done? Modified seed creation process to handle a list of onion seeds. ## How Has This Been Tested? Running with and without onlynet=onion and with dnsseed=0 and deleting peers.dat ## Breaking Changes None ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
1 parent 854bccd commit 015e30f

File tree

6 files changed

+384
-394
lines changed

6 files changed

+384
-394
lines changed

contrib/seeds/README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ Utility to generate the seeds.txt list that is compiled into the client
55

66
The seeds compiled into the release are created from the current protx list, like this:
77

8-
dash-cli protx list valid 1 1716101 > protx_list.json
9-
python3 makeseeds.py < protx_list.json > nodes_main.txt
10-
python3 generate-seeds.py . > ../../src/chainparamsseeds.h
8+
```bash
9+
dash-cli protx list valid 1 2018966 > protx_list.json
10+
11+
# Make sure the onion seeds still work!
12+
while IFS= read -r line
13+
do
14+
address=$(echo $line | cut -d':' -f1)
15+
port=$(echo $line | cut -d':' -f2)
16+
nc -v -x 127.0.0.1:9050 -z $address $port
17+
done < "onion_seeds.txt"
18+
19+
python3 makeseeds.py protx_list.json onion_seeds.txt > nodes_main.txt
20+
python3 generate-seeds.py . > ../../src/chainparamsseeds.h
21+
```
1122

1223
Make sure to use a recent block height in the "protx list" call. After updating, create a PR and
1324
specify which block height you used so that reviewers can re-run the same commands and verify

contrib/seeds/makeseeds.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
#
66
# Generate seeds.txt from "protx list valid 1"
7+
# then create onion_seeds.txt and add some active onion services to it; check tor.md for some
78
#
89

910
import re
@@ -25,16 +26,15 @@
2526

2627
PATTERN_IPV4 = re.compile(r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$")
2728
PATTERN_IPV6 = re.compile(r"^\[([0-9a-z:]+)\]:(\d+)$")
28-
PATTERN_ONION = re.compile(r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$")
29+
PATTERN_ONION = re.compile(r"^([a-z2-7]{56}\.onion):(\d+)$")
2930

30-
def parseip(ip):
31-
m = PATTERN_IPV4.match(ip)
32-
sortkey = None
31+
def parseip(ip_in):
32+
m = PATTERN_IPV4.match(ip_in)
3333
ip = None
3434
if m is None:
35-
m = PATTERN_IPV6.match(ip)
35+
m = PATTERN_IPV6.match(ip_in)
3636
if m is None:
37-
m = PATTERN_ONION.match(ip)
37+
m = PATTERN_ONION.match(ip_in)
3838
if m is None:
3939
return None
4040
else:
@@ -135,8 +135,8 @@ def filterbyasn(ips, max_per_asn, max_total):
135135
continue
136136
asn_count[asn] += 1
137137
result.append(ip)
138-
except:
139-
sys.stderr.write('ERR: Could not resolve ASN for "' + ip['ip'] + '"\n')
138+
except Exception as e:
139+
sys.stderr.write(f'ERR: Could not resolve ASN for {ip["ip"]}: {e}\n')
140140

141141
# Add back Onions
142142
result.extend(ips_onion)
@@ -150,6 +150,10 @@ def main():
150150
else:
151151
mns = json.load(sys.stdin)
152152

153+
if len(sys.argv) > 2:
154+
with open(sys.argv[2], 'r', encoding="utf8") as f:
155+
onions = f.read().split('\n')
156+
153157
# Skip PoSe banned MNs
154158
mns = [mn for mn in mns if mn['state']['PoSeBanHeight'] == -1]
155159
# Skip MNs with < 10000 confirmations
@@ -160,10 +164,14 @@ def main():
160164
mns = filtermultipayoutaddress(mns)
161165
# Extract IPs
162166
ips = [parseip(mn['state']['service']) for mn in mns]
167+
for onion in onions:
168+
parsed = parseip(onion)
169+
if parsed is not None:
170+
ips.append(parsed)
163171
# Look up ASNs and limit results, both per ASN and globally.
164172
ips = filterbyasn(ips, MAX_SEEDS_PER_ASN, NSEEDS)
165173
# Sort the results by IP address (for deterministic output).
166-
ips.sort(key=lambda x: (x['net'], x['sortkey']))
174+
ips.sort(key=lambda x: (x['net'], x['sortkey']), reverse=True)
167175

168176
for ip in ips:
169177
if ip['net'] == 'ipv6':

0 commit comments

Comments
 (0)