Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ xcuserdata/
.vscode/
# mypy
.mypy_cache/

venv
1 change: 1 addition & 0 deletions contrib/build-wine/deterministic.spec
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ datas = [
(home+'electroncash/servers_testnet.json', 'electroncash'),
(home+'electroncash/servers_testnet4.json', 'electroncash'),
(home+'electroncash/servers_scalenet.json', 'electroncash'),
(home+'electroncash/servers_regtest.json', 'electroncash'),
(home+'electroncash/wordlist/english.txt', 'electroncash/wordlist'),
(home+'electroncash/locale', 'electroncash/locale'),
(home+'electroncash_gui/qt/data/ecsupplemental_win.ttf', 'electroncash_gui/qt/data'),
Expand Down
1 change: 1 addition & 0 deletions contrib/osx/osx.spec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ datas = [
(home+'electroncash/servers_testnet.json', PYPKG),
(home+'electroncash/servers_testnet4.json', PYPKG),
(home+'electroncash/servers_scalenet.json', PYPKG),
(home+'electroncash/servers_regtest.json', PYPKG),
(home+'electroncash/wordlist/english.txt', PYPKG + '/wordlist'),
(home+'electroncash/locale', PYPKG + '/locale'),
(home+'electroncash_plugins', PYPKG + '_plugins'),
Expand Down
10 changes: 8 additions & 2 deletions electron-radiant
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,22 @@ def process_config_options(args):
have_testnet = config_options.get("testnet", False)
have_testnet4 = config_options.get("testnet4", False)
have_scalenet = config_options.get("scalenet", False)
if have_testnet + have_testnet4 + have_scalenet > 1:
have_chipnet = config_options.get("chipnet", False)
have_regtest = config_options.get("regtest", False)
if have_testnet + have_testnet4 + have_scalenet + have_chipnet + have_regtest > 1:
sys.exit(
"Invalid combination of --testnet, --testnet4, and/or --scalenet"
"Invalid combination of --testnet, --testnet4, --scalenet, --chipnet and/or --regtest"
)
elif have_testnet:
networks.set_testnet()
elif have_testnet4:
networks.set_testnet4()
elif have_scalenet:
networks.set_scalenet()
elif have_chipnet:
networks.set_chipnet()
elif have_regtest:
networks.set_regtest()

# check uri
uri = config_options.get("url")
Expand Down
9 changes: 7 additions & 2 deletions electroncash/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class VerifyError(Exception):
# see https://gitlab.com/bitcoin-cash-node/bitcoin-cash-node/-/blob/v24.0.0/src/chainparams.cpp#L98
# Note: If we decide to support REGTEST this will need to come from regtest's networks.py params!
MAX_TARGET = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff # compact: 0x1d00ffff
MAX_BITS_REGTEST = 0x207fffff # FIXME: if it is always constant, move to network constants
# indicates no header in data file
NULL_HEADER = bytes([0]) * HEADER_SIZE
NULL_HASH_BYTES = bytes([0]) * 32
Expand Down Expand Up @@ -518,8 +519,10 @@ def get_bits(self, header, chunk=None):
prevheight = height - 1
daa_mtp = self.get_median_time_past(prevheight, chunk)

# ASERTi3-2d DAA activated on (1657404000) Sat Jul 09 2022 22:00:00 GMT+0000 ASERT DAA enabled
if daa_mtp >= networks.net.asert_daa.MTP_ACTIVATION_TIME:

# ASERTi3-2d DAA activated on Nov. 15th 2020 HF
# on regtest it is disabled as documented in BCHN code
if daa_mtp >= networks.net.asert_daa.MTP_ACTIVATION_TIME and not networks.net.REGTEST:
header_ts = header['timestamp']
prev_ts = prior['timestamp']
if networks.net.TESTNET:
Expand All @@ -544,6 +547,8 @@ def get_bits(self, header, chunk=None):
return MAX_BITS
# special case for a newly started testnet (such as testnet4)
if height < N_BLOCKS:
if networks.net.REGTEST:
return MAX_BITS_REGTEST
return MAX_BITS
return self.read_header(height // N_BLOCKS * N_BLOCKS, chunk)['bits']

Expand Down
2 changes: 2 additions & 0 deletions electroncash/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ def add_global_options(parser):
group.add_argument("--testnet", action="store_true", dest="testnet", default=False, help="Use Testnet")
group.add_argument("--testnet4", action="store_true", dest="testnet4", default=False, help="Use Testnet4")
group.add_argument("--scalenet", action="store_true", dest="scalenet", default=False, help="Use Scalenet")
group.add_argument("--chipnet", action="store_true", dest="chipnet", default=False, help="Use Chipnet")
group.add_argument("--regtest", action="store_true", dest="regtest", default=False, help="Use Regtest")

def get_parser():
# create main parser
Expand Down
12 changes: 10 additions & 2 deletions electroncash/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,12 @@ def on_block_headers(self, interface, request, response):
return

verification_top_height = self.checkpoint_servers_verified.get(interface.server, {}).get('height', None)
was_verification_request = verification_top_height and request_base_height == verification_top_height - 147 + 1 and actual_header_count == 147
was_verification_request = False
if verification_top_height is not None:
if not networks.net.REGTEST:
was_verification_request = request_base_height == verification_top_height - 147 + 1 and actual_header_count == 147
else:
was_verification_request = request_base_height == verification_top_height - 50 + 1 and actual_header_count == 50

initial_interface_mode = interface.mode
if interface.mode == Interface.MODE_VERIFICATION:
Expand Down Expand Up @@ -1696,7 +1701,10 @@ def request_initial_proof_and_headers(self, interface):
self.checkpoint_height = interface.tip - 100
self.checkpoint_servers_verified[interface.server] = { 'root': None, 'height': self.checkpoint_height }
# We need at least 147 headers before the post checkpoint headers for daa calculations.
self._request_headers(interface, self.checkpoint_height - 147 + 1, 147, self.checkpoint_height)
if not networks.net.REGTEST:
self._request_headers(interface, self.checkpoint_height - 147 + 1, 147, self.checkpoint_height)
else:
self._request_headers(interface, self.checkpoint_height - 50 + 1, 50, self.checkpoint_height)
else:
# We already have them verified, maybe we got disconnected.
interface.print_error("request_initial_proof_and_headers bypassed")
Expand Down
25 changes: 23 additions & 2 deletions electroncash/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def _read_json_dict(filename):

class AbstractNet:
TESTNET = False
REGTEST = False
LEGACY_POW_TARGET_TIMESPAN = 14 * 24 * 60 * 60 # 2 weeks
LEGACY_POW_TARGET_INTERVAL = 10 * 60 # 10 minutes
LEGACY_POW_RETARGET_BLOCKS = LEGACY_POW_TARGET_TIMESPAN // LEGACY_POW_TARGET_INTERVAL # 2016 blocks
Expand All @@ -49,10 +50,10 @@ class MainNet(AbstractNet):
WIF_PREFIX = 0x80
ADDRTYPE_P2PKH = 0
ADDRTYPE_P2SH = 5
CASHADDR_PREFIX = "bitcoincash"
CASHADDR_PREFIX = "radaddr"
RPA_PREFIX = "paycode"
HEADERS_URL = "http://bitcoincash.com/files/blockchain_headers" # Unused
GENESIS = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
GENESIS = "0000000065d8ed5d8be28d6876b3ffb660ac2a6c0ca59e437e1f7a6f4e003fb4"
DEFAULT_PORTS = {'t': '50001', 's': '50002'}
DEFAULT_SERVERS = _read_json_dict('servers.json') # DO NOT MODIFY IN CLIENT CODE
TITLE = 'Electron Radiant'
Expand Down Expand Up @@ -173,6 +174,21 @@ class ScaleNet(TestNet):
asert_daa = ASERTDaa(is_testnet=False) # Despite being a "testnet", ScaleNet uses 2d half-life
asert_daa.anchor = None # Intentionally not specified because it's after checkpoint; blockchain.py will calculate

class RegtestNet(TestNet):
GENESIS = "000000002008a2f4a76b850a838ae084994c200dc2fd354f73102298fe063a91"
TITLE = 'Electron Radiant Regtest'
CASHADDR_PREFIX = "radreg"
REGTEST = True

BITCOIN_CASH_FORK_BLOCK_HEIGHT = 0
BITCOIN_CASH_FORK_BLOCK_HASH = GENESIS

VERIFICATION_BLOCK_HEIGHT = 100
VERIFICATION_BLOCK_MERKLE_ROOT = None
asert_daa = ASERTDaa(is_testnet=True) # not used on regtest

DEFAULT_SERVERS = _read_json_dict('servers_regtest.json') # DO NOT MODIFY IN CLIENT CODE


# All new code should access this to get the current network config.
net = MainNet
Expand Down Expand Up @@ -208,6 +224,11 @@ def set_scalenet():
net = ScaleNet
_set_units()

def set_regtest():
global net
net = RegtestNet
_set_units()


# Compatibility
def _instancer(cls):
Expand Down
8 changes: 8 additions & 0 deletions electroncash/servers_regtest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"127.0.0.1": {
"pruning": "-",
"s": "50110",
"t": "50112",
"version": "1.4"
}
}
5 changes: 5 additions & 0 deletions electroncash/simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def electrum_path(self):
elif self.get('scalenet'):
path = os.path.join(path, 'scalenet')
make_dir(path)
elif self.get('chipnet'):
path = os.path.join(path, 'chipnet')
elif self.get('regtest'):
path = os.path.join(path, 'regtest')
make_dir(path)

obsolete_file = os.path.join(path, 'recent_servers')
if os.path.exists(obsolete_file):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def run(self):
'servers_testnet.json',
'servers_testnet4.json',
'servers_scalenet.json',
'servers_regtest.json',
'currencies.json',
'www/index.html',
'wordlist/*.txt',
Expand Down