I have some problem to understand your question. target is calculated every 2016 (using last 2016blocks-last timestamps)
all nodes calculates the same target from the chain with more accumulated pow(the longest)
a block to be valid must have hash(header)<=target.
header must contain:
https://bitcoin.org/en/developer-reference#block-headers here is where target is calculated in bitcoin core client:
https://github.com/bitcoin/bitcoin/blob/5961b23898ee7c0af2626c46d5d70e80136578d3/src/pow.cpp#L49thats the code used by electrum to check the target.
def get_target(self, index):
# compute target from chunk x, used in chunk x+1
if constants.net.TESTNET:
return 0
if index == -1:
return MAX_TARGET
if index < len(self.checkpoints):
h, t = self.checkpoints[index]
return t
# new target
first = self.read_header(index * 2016)
last = self.read_header(index * 2016 + 2015)
bits = last.get('bits')
target = self.bits_to_target(bits)
nActualTimespan = last.get('timestamp') - first.get('timestamp')
nTargetTimespan = 14 * 24 * 60 * 60
nActualTimespan = max(nActualTimespan, nTargetTimespan // 4)
nActualTimespan = min(nActualTimespan, nTargetTimespan * 4)
new_target = min(MAX_TARGET, (target * nActualTimespan) // nTargetTimespan)
return new_target
Would someone be able to create a block of exclusively transactions and information they have control over and have already generated a nonce for? Effectively solving an entirely self-created block (in advance) that would be accepted by the blockchain and allow you to reap the block reward. Is this prevented by accepting the "longest" valid chain? This may all be wrong, and foolish.
block header must contain merkle root for included transactions
and previous block hash to build the chain
the nonce itself is not the solution to pow, the solution is the whole header
thats the code used by electrum to check the header.
hash(header)<=target
def verify_header(self, header, prev_hash, target):
_hash = hash_header(header)
if prev_hash != header.get('prev_block_hash'):
raise Exception("prev hash mismatch: %s vs %s" % (prev_hash, header.get('prev_block_hash')))
if constants.net.TESTNET:
return
bits = self.target_to_bits(target)
if bits != header.get('bits'):
raise Exception("bits mismatch: %s vs %s" % (bits, header.get('bits')))
if int('0x' + _hash, 16) > target:
raise Exception("insufficient proof of work: %s vs target %s" % (int('0x' + _hash, 16), target))