Browse Source

Increased nPowTargetTimespan to 10 seconds for RegTest.

Checked fPowNoRetargeting in pow.cpp.
cn
Jianping Wu 6 years ago
parent
commit
3cf8093553
  1. 4
      src/chainparams.cpp
  2. 3
      src/pow.cpp
  3. 17
      test/functional/feature_block.py
  4. 2
      test/functional/interface_rest.py
  5. 6
      test/functional/p2p_invalid_block.py
  6. 4
      test/functional/test_framework/blocktools.py
  7. 14
      test/functional/test_framework/mininode.py
  8. 2
      test/functional/test_framework/util.py

4
src/chainparams.cpp

@ -260,8 +260,8 @@ public: @@ -260,8 +260,8 @@ public:
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 1; // 1 second
consensus.nPowTargetSpacing = 1; // 1 second
consensus.nPowTargetTimespan = 10; // 10 second
consensus.nPowTargetSpacing = 10; // 10 second
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains

3
src/pow.cpp

@ -15,6 +15,9 @@ @@ -15,6 +15,9 @@
// Copy and modified from CalculateDogecoinNextWorkRequired (dogecoin.cpp)
unsigned int CalculateDigishieldNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
{
if (params.fPowNoRetargeting)
return pindexLast->nBits;
const int64_t retargetTimespan = params.nPowTargetTimespan;
const int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
int64_t nModulatedTimespan = nActualTimespan;

17
test/functional/feature_block.py

@ -825,7 +825,7 @@ class FullBlockTest(ComparisonTestFramework): @@ -825,7 +825,7 @@ class FullBlockTest(ComparisonTestFramework):
# tx with output value > input value out of range
tip(57)
b59 = block(59)
tx = create_and_sign_tx(out[17].tx, out[17].n, 51*COIN)
tx = create_and_sign_tx(out[17].tx, out[17].n, 510*COIN)
b59 = update_block(59, [tx])
yield rejected(RejectResult(16, b'bad-txns-in-belowout'))
@ -844,13 +844,14 @@ class FullBlockTest(ComparisonTestFramework): @@ -844,13 +844,14 @@ class FullBlockTest(ComparisonTestFramework):
# not-fully-spent transaction in the same chain. To test, make identical coinbases;
# the second one should be rejected.
#
tip(60)
b61 = block(61, spend=out[18])
b61.vtx[0].vin[0].scriptSig = b60.vtx[0].vin[0].scriptSig #equalize the coinbases
b61.vtx[0].rehash()
b61 = update_block(61, [])
assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize())
yield rejected(RejectResult(16, b'bad-txns-BIP30'))
# Kevacoin - BIP34 is activated since beginning, no need for BIP30, test case skipped.
#tip(60)
#b61 = block(61, spend=out[18])
#b61.vtx[0].vin[0].scriptSig = b60.vtx[0].vin[0].scriptSig #equalize the coinbases
#b61.vtx[0].rehash()
#b61 = update_block(61, [])
#assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize())
#yield rejected(RejectResult(16, b'bad-txns-BIP30'))
# Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests)

2
test/functional/interface_rest.py

@ -60,7 +60,7 @@ class RESTTest (BitcoinTestFramework): @@ -60,7 +60,7 @@ class RESTTest (BitcoinTestFramework):
self.nodes[2].generate(100)
self.sync_all()
assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[0].getbalance(), 500)
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()

6
test/functional/p2p_invalid_block.py

@ -22,7 +22,7 @@ import time @@ -22,7 +22,7 @@ import time
# Use the ComparisonTestFramework with 1 node: only use --testbinary.
class InvalidBlockRequestTest(ComparisonTestFramework):
''' Can either run this test as 1 node with expected answers, or two and compare them.
''' Can either run this test as 1 node with expected answers, or two and compare them.
Change the "outcome" variable from each TestInstance object to only do the comparison. '''
def set_test_params(self):
self.num_nodes = 1
@ -73,7 +73,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework): @@ -73,7 +73,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework):
Now we use merkle-root malleability to generate an invalid block with
same blockheader.
Manufacture a block with 3 transactions (coinbase, spend of prior
coinbase, spend of that spend). Duplicate the 3rd transaction to
coinbase, spend of that spend). Duplicate the 3rd transaction to
leave merkle root and blockheader unchanged but invalidate the block.
'''
block2 = create_block(self.tip, create_coinbase(height), self.block_time)
@ -118,7 +118,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework): @@ -118,7 +118,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework):
block3 = create_block(self.tip, create_coinbase(height), self.block_time)
block3.nVersion = 0x20000000
self.block_time += 1
block3.vtx[0].vout[0].nValue = 100 * COIN # Too high!
block3.vtx[0].vout[0].nValue = 1000 * COIN # Too high!
block3.vtx[0].sha256=None
block3.vtx[0].calc_sha256()
block3.hashMerkleRoot = block3.calc_merkle_root()

4
test/functional/test_framework/blocktools.py

@ -86,10 +86,10 @@ def serialize_script_num(value): @@ -86,10 +86,10 @@ def serialize_script_num(value):
# otherwise an anyone-can-spend output.
def create_coinbase(height, pubkey = None):
coinbase = CTransaction()
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
ser_string(serialize_script_num(height)), 0xffffffff))
coinbaseoutput = CTxOut()
coinbaseoutput.nValue = 50 * COIN
coinbaseoutput.nValue = 500 * COIN
halvings = int(height/150) # regtest
coinbaseoutput.nValue >>= halvings
if (pubkey != None):

14
test/functional/test_framework/mininode.py

@ -345,25 +345,25 @@ class P2PInterface(P2PConnection): @@ -345,25 +345,25 @@ class P2PInterface(P2PConnection):
# Connection helper methods
def wait_for_disconnect(self, timeout=60):
def wait_for_disconnect(self, timeout=360):
test_function = lambda: self.state != "connected"
wait_until(test_function, timeout=timeout, lock=mininode_lock)
# Message receiving helper methods
def wait_for_block(self, blockhash, timeout=60):
def wait_for_block(self, blockhash, timeout=360):
test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
wait_until(test_function, timeout=timeout, lock=mininode_lock)
def wait_for_getdata(self, timeout=60):
def wait_for_getdata(self, timeout=360):
test_function = lambda: self.last_message.get("getdata")
wait_until(test_function, timeout=timeout, lock=mininode_lock)
def wait_for_getheaders(self, timeout=60):
def wait_for_getheaders(self, timeout=360):
test_function = lambda: self.last_message.get("getheaders")
wait_until(test_function, timeout=timeout, lock=mininode_lock)
def wait_for_inv(self, expected_inv, timeout=60):
def wait_for_inv(self, expected_inv, timeout=360):
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
if len(expected_inv) > 1:
raise NotImplementedError("wait_for_inv() will only verify the first inv object")
@ -372,7 +372,7 @@ class P2PInterface(P2PConnection): @@ -372,7 +372,7 @@ class P2PInterface(P2PConnection):
self.last_message["inv"].inv[0].hash == expected_inv[0].hash
wait_until(test_function, timeout=timeout, lock=mininode_lock)
def wait_for_verack(self, timeout=60):
def wait_for_verack(self, timeout=360):
test_function = lambda: self.message_count["verack"]
wait_until(test_function, timeout=timeout, lock=mininode_lock)
@ -383,7 +383,7 @@ class P2PInterface(P2PConnection): @@ -383,7 +383,7 @@ class P2PInterface(P2PConnection):
self.sync_with_ping()
# Sync up with the node
def sync_with_ping(self, timeout=60):
def sync_with_ping(self, timeout=360):
self.send_message(msg_ping(nonce=self.ping_counter))
test_function = lambda: self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter
wait_until(test_function, timeout=timeout, lock=mininode_lock)

2
test/functional/test_framework/util.py

@ -202,7 +202,7 @@ def satoshi_round(amount): @@ -202,7 +202,7 @@ def satoshi_round(amount):
def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None):
if attempts == float('inf') and timeout == float('inf'):
timeout = 60
timeout = 600
attempt = 0
timeout += time.time()

Loading…
Cancel
Save