Skip to content

Commit

Permalink
feat: add onion_seeds to seed creation; do seed creation (#5866)
Browse files Browse the repository at this point in the history
## 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)_
  • Loading branch information
PastaPastaPasta committed Feb 15, 2024
1 parent 854bccd commit 015e30f
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 394 deletions.
17 changes: 14 additions & 3 deletions contrib/seeds/README.md
Expand Up @@ -5,9 +5,20 @@ Utility to generate the seeds.txt list that is compiled into the client

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

dash-cli protx list valid 1 1716101 > protx_list.json
python3 makeseeds.py < protx_list.json > nodes_main.txt
python3 generate-seeds.py . > ../../src/chainparamsseeds.h
```bash
dash-cli protx list valid 1 2018966 > protx_list.json

# Make sure the onion seeds still work!
while IFS= read -r line
do
address=$(echo $line | cut -d':' -f1)
port=$(echo $line | cut -d':' -f2)
nc -v -x 127.0.0.1:9050 -z $address $port
done < "onion_seeds.txt"

python3 makeseeds.py protx_list.json onion_seeds.txt > nodes_main.txt
python3 generate-seeds.py . > ../../src/chainparamsseeds.h
```

Make sure to use a recent block height in the "protx list" call. After updating, create a PR and
specify which block height you used so that reviewers can re-run the same commands and verify
Expand Down
26 changes: 17 additions & 9 deletions contrib/seeds/makeseeds.py
Expand Up @@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Generate seeds.txt from "protx list valid 1"
# then create onion_seeds.txt and add some active onion services to it; check tor.md for some
#

import re
Expand All @@ -25,16 +26,15 @@

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

def parseip(ip):
m = PATTERN_IPV4.match(ip)
sortkey = None
def parseip(ip_in):
m = PATTERN_IPV4.match(ip_in)
ip = None
if m is None:
m = PATTERN_IPV6.match(ip)
m = PATTERN_IPV6.match(ip_in)
if m is None:
m = PATTERN_ONION.match(ip)
m = PATTERN_ONION.match(ip_in)
if m is None:
return None
else:
Expand Down Expand Up @@ -135,8 +135,8 @@ def filterbyasn(ips, max_per_asn, max_total):
continue
asn_count[asn] += 1
result.append(ip)
except:
sys.stderr.write('ERR: Could not resolve ASN for "' + ip['ip'] + '"\n')
except Exception as e:
sys.stderr.write(f'ERR: Could not resolve ASN for {ip["ip"]}: {e}\n')

# Add back Onions
result.extend(ips_onion)
Expand All @@ -150,6 +150,10 @@ def main():
else:
mns = json.load(sys.stdin)

if len(sys.argv) > 2:
with open(sys.argv[2], 'r', encoding="utf8") as f:
onions = f.read().split('\n')

# Skip PoSe banned MNs
mns = [mn for mn in mns if mn['state']['PoSeBanHeight'] == -1]
# Skip MNs with < 10000 confirmations
Expand All @@ -160,10 +164,14 @@ def main():
mns = filtermultipayoutaddress(mns)
# Extract IPs
ips = [parseip(mn['state']['service']) for mn in mns]
for onion in onions:
parsed = parseip(onion)
if parsed is not None:
ips.append(parsed)
# Look up ASNs and limit results, both per ASN and globally.
ips = filterbyasn(ips, MAX_SEEDS_PER_ASN, NSEEDS)
# Sort the results by IP address (for deterministic output).
ips.sort(key=lambda x: (x['net'], x['sortkey']))
ips.sort(key=lambda x: (x['net'], x['sortkey']), reverse=True)

for ip in ips:
if ip['net'] == 'ipv6':
Expand Down

0 comments on commit 015e30f

Please sign in to comment.