Skip to content

Commit

Permalink
Merge e650574 into 054b593
Browse files Browse the repository at this point in the history
  • Loading branch information
cculianu committed Aug 25, 2020
2 parents 054b593 + e650574 commit c22ed4d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
7 changes: 7 additions & 0 deletions electron-cash
Expand Up @@ -384,7 +384,14 @@ if __name__ == '__main__':

set_verbosity(config_options.get('verbose'))

have_testnet4 = False
if config_options.get('testnet4'):
networks.set_testnet4()
have_testnet4 = True

if config_options.get('testnet'):
if have_testnet4:
sys.exit("Cannot specify both --testnet and --testnet4")
networks.set_testnet()

# check uri
Expand Down
18 changes: 11 additions & 7 deletions lib/blockchain.py
Expand Up @@ -491,7 +491,7 @@ def get_bits(self, header, chunk=None):


# Mon Nov 13 19:06:40 2017 DAA HF
if daa_mtp >= 1510600000:
if prevheight >= networks.net.CW144_HEIGHT:

if networks.net.TESTNET:
# testnet 20 minute rule
Expand Down Expand Up @@ -527,15 +527,18 @@ def get_bits(self, header, chunk=None):
return daa_retval

#END OF NOV-2017 DAA

if height % 2016 == 0:
N_BLOCKS = networks.net.LEGACY_POW_RETARGET_BLOCKS # Normally 2016
if height % N_BLOCKS == 0:
return self.get_new_bits(height, chunk)

if networks.net.TESTNET:
# testnet 20 minute rule
if header['timestamp'] - prior['timestamp'] > 20*60:
return MAX_BITS
return self.read_header(height // 2016 * 2016, chunk)['bits']
# special case for a newly started testnet (such as testnet4)
if height < N_BLOCKS:
return MAX_BITS
return self.read_header(height // N_BLOCKS * N_BLOCKS, chunk)['bits']

# bitcoin cash EDA
# Can't go below minimum, so early bail
Expand All @@ -553,15 +556,16 @@ def get_bits(self, header, chunk=None):
return target_to_bits(target)

def get_new_bits(self, height, chunk=None):
assert height % 2016 == 0
N_BLOCKS = networks.net.LEGACY_POW_RETARGET_BLOCKS
assert height % N_BLOCKS == 0
# Genesis
if height == 0:
return MAX_BITS
first = self.read_header(height - 2016, chunk)
first = self.read_header(height - N_BLOCKS, chunk)
prior = self.read_header(height - 1, chunk)
prior_target = bits_to_target(prior['bits'])

target_span = 14 * 24 * 60 * 60
target_span = networks.net.LEGACY_POW_TARGET_TIMESPAN # usually: 14 * 24 * 60 * 60 = 2 weeks
span = prior['timestamp'] - first['timestamp']
span = min(max(span, target_span // 4), target_span * 4)
new_target = (prior_target * span) // target_span
Expand Down
1 change: 1 addition & 0 deletions lib/commands.py
Expand Up @@ -985,6 +985,7 @@ def add_global_options(parser):
group.add_argument("-w", "--wallet", dest="wallet_path", help="wallet path")
group.add_argument("-wp", "--walletpassword", dest="wallet_password", default=None, help="Supply wallet password")
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")

def get_parser():
# create main parser
Expand Down
27 changes: 27 additions & 0 deletions lib/networks.py
Expand Up @@ -37,6 +37,9 @@ def _read_json_dict(filename):
class AbstractNet:
TESTNET = False
asert_daa = ASERTDaa()
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


class MainNet(AbstractNet):
Expand All @@ -57,6 +60,9 @@ class MainNet(AbstractNet):
BITCOIN_CASH_FORK_BLOCK_HEIGHT = 478559
BITCOIN_CASH_FORK_BLOCK_HASH = "000000000000000000651ef99cb9fcbe0dadde1d424bd9f15ff20136191a5eec"

# Nov 13. 2017 HF to CW144 DAA height (height of last block mined on old DAA)
CW144_HEIGHT = 504031

# Note: this is not the Merkle root of the verification block itself , but a Merkle root of
# all blockchain headers up until and including this block. To get this value you need to
# connect to an ElectrumX server you trust and issue it a protocol command. This can be
Expand Down Expand Up @@ -94,6 +100,9 @@ class TestNet(AbstractNet):
DEFAULT_SERVERS = _read_json_dict('servers_testnet.json') # DO NOT MODIFY IN CLIENT CODE
TITLE = 'Electron Cash Testnet'

# Nov 13. 2017 HF to CW144 DAA height (height of last block mined on old DAA)
CW144_HEIGHT = 1155875

# Bitcoin Cash fork block specification
BITCOIN_CASH_FORK_BLOCK_HEIGHT = 1155876
BITCOIN_CASH_FORK_BLOCK_HASH = "00000000000e38fef93ed9582a7df43815d5c2ba9fd37ef70c9a0ea4a285b8f5"
Expand All @@ -112,6 +121,20 @@ class TestNet(AbstractNet):
}


class TestNet4(TestNet):
GENESIS = "000000001dd410c49a788668ce26751718cc797474d3152a5fc073dd44fd9f7b"
TITLE = 'Electron Cash Testnet4'

VERIFICATION_BLOCK_MERKLE_ROOT = "cfb7f86cf574ffc765f1531c9474c4aa74573c8acf085ab239a366570ad57f9d"
VERIFICATION_BLOCK_HEIGHT = 2016

BITCOIN_CASH_FORK_BLOCK_HEIGHT = 6
BITCOIN_CASH_FORK_BLOCK_HASH = "00000000d71b9b1f7e13b0c9b218a12df6526c1bcd1b667764b8693ae9a413cb"

# Nov 13. 2017 HF to CW144 DAA height (height of last block mined on old DAA)
CW144_HEIGHT = 3000


# All new code should access this to get the current network config.
net = MainNet

Expand All @@ -123,6 +146,10 @@ def set_testnet():
global net
net = TestNet

def set_testnet4():
global net
net = TestNet4


# Compatibility
def _instancer(cls):
Expand Down
5 changes: 4 additions & 1 deletion lib/simple_config.py
Expand Up @@ -93,7 +93,10 @@ def electrum_path(self):
path = self.user_dir()

make_dir(path)
if self.get('testnet'):
if self.get('testnet4'):
path = os.path.join(path, 'testnet4')
make_dir(path)
elif self.get('testnet'):
path = os.path.join(path, 'testnet')
make_dir(path)

Expand Down

0 comments on commit c22ed4d

Please sign in to comment.