Fix pow, max block size, still need some adjust
Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
This commit is contained in:
parent
6697207ac1
commit
50f32d0e66
3 changed files with 20 additions and 8 deletions
0
test/functional/feature_block.py
Executable file → Normal file
0
test/functional/feature_block.py
Executable file → Normal file
|
@ -98,6 +98,12 @@ def serialize_script_num(value):
|
||||||
r[-1] |= 0x80
|
r[-1] |= 0x80
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def GetBlockSubsidy(height):
|
||||||
|
if height == 0:
|
||||||
|
return 400000000 * COIN
|
||||||
|
else:
|
||||||
|
return 1 * COIN
|
||||||
|
|
||||||
def create_coinbase(height, pubkey=None):
|
def create_coinbase(height, pubkey=None):
|
||||||
"""Create a coinbase transaction, assuming no miner fees.
|
"""Create a coinbase transaction, assuming no miner fees.
|
||||||
|
|
||||||
|
@ -107,9 +113,7 @@ def create_coinbase(height, pubkey=None):
|
||||||
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
|
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
|
||||||
ser_string(serialize_script_num(height)), 0xffffffff))
|
ser_string(serialize_script_num(height)), 0xffffffff))
|
||||||
coinbaseoutput = CTxOut()
|
coinbaseoutput = CTxOut()
|
||||||
coinbaseoutput.nValue = 50 * COIN
|
coinbaseoutput.nValue = GetBlockSubsidy(height)
|
||||||
halvings = int(height / 150) # regtest
|
|
||||||
coinbaseoutput.nValue >>= halvings
|
|
||||||
if (pubkey is not None):
|
if (pubkey is not None):
|
||||||
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG])
|
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG])
|
||||||
else:
|
else:
|
||||||
|
|
18
test/functional/test_framework/messages.py
Executable file → Normal file
18
test/functional/test_framework/messages.py
Executable file → Normal file
|
@ -33,7 +33,7 @@ MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version
|
||||||
|
|
||||||
MAX_INV_SZ = 50000
|
MAX_INV_SZ = 50000
|
||||||
MAX_LOCATOR_SZ = 101
|
MAX_LOCATOR_SZ = 101
|
||||||
MAX_BLOCK_BASE_SIZE = 1000000
|
MAX_BLOCK_BASE_SIZE = 2000000
|
||||||
|
|
||||||
COIN = 100000000 # 1 btc in satoshis
|
COIN = 100000000 # 1 btc in satoshis
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ def ripemd160(s):
|
||||||
def hash256(s):
|
def hash256(s):
|
||||||
return sha256(sha256(s))
|
return sha256(sha256(s))
|
||||||
|
|
||||||
|
def hash160(s):
|
||||||
|
return hashlib.new('ripemd160', sha256(s)).digest()
|
||||||
|
|
||||||
def ser_compact_size(l):
|
def ser_compact_size(l):
|
||||||
r = b""
|
r = b""
|
||||||
if l < 253:
|
if l < 253:
|
||||||
|
@ -128,6 +131,11 @@ def deser_vector(f, c):
|
||||||
r.append(t)
|
r.append(t)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def lbryPOW(i):
|
||||||
|
h512 = hashlib.new('sha512', ser_uint256(i)).digest()
|
||||||
|
m = len(h512) // 2
|
||||||
|
s = hash256(ripemd160(h512[:m]) + ripemd160(h512[m:]))
|
||||||
|
return uint256_from_str(s)
|
||||||
|
|
||||||
# ser_function_name: Allow for an alternate serialization function on the
|
# ser_function_name: Allow for an alternate serialization function on the
|
||||||
# entries in the vector (we use this for serializing the vector of transactions
|
# entries in the vector (we use this for serializing the vector of transactions
|
||||||
|
@ -619,7 +627,7 @@ class CBlock(CBlockHeader):
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
self.calc_sha256()
|
self.calc_sha256()
|
||||||
target = uint256_from_compact(self.nBits)
|
target = uint256_from_compact(self.nBits)
|
||||||
if self.sha256 > target:
|
if lbryPOW(self.sha256) > target:
|
||||||
return False
|
return False
|
||||||
for tx in self.vtx:
|
for tx in self.vtx:
|
||||||
if not tx.is_valid():
|
if not tx.is_valid():
|
||||||
|
@ -631,13 +639,13 @@ class CBlock(CBlockHeader):
|
||||||
def solve(self):
|
def solve(self):
|
||||||
self.rehash()
|
self.rehash()
|
||||||
target = uint256_from_compact(self.nBits)
|
target = uint256_from_compact(self.nBits)
|
||||||
while self.sha256 > target:
|
while lbryPOW(self.sha256) > target:
|
||||||
self.nNonce += 1
|
self.nNonce += 1
|
||||||
self.rehash()
|
self.rehash()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "CBlock(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%08x nNonce=%08x vtx=%s)" \
|
return "CBlock(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x hashClaimTrie=%064x nTime=%s nBits=%08x nNonce=%08x vtx=%s)" \
|
||||||
% (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot,
|
% (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, self.hashClaimTrie,
|
||||||
time.ctime(self.nTime), self.nBits, self.nNonce, repr(self.vtx))
|
time.ctime(self.nTime), self.nBits, self.nNonce, repr(self.vtx))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue