memoriesadrift / tuw-cryptocurrencies-blockchain

Blockchain created for the Cryptocurrencies course at TU Wien
0 stars 0 forks source link

T3: Block Validation #19

Closed memoriesadrift closed 10 months ago

memoriesadrift commented 10 months ago

In this exercise, you will implement block validation for your Kerma node.

  1. Create the logic to represent a block, as defined in the protocol description.
  2. Check that the block contains all required fields and that they are of the correct format.
  3. Ensure that the target is the one required, i.e. "00000000abc00000000000000000000000000000000000000000000000000000"
  4. Check the proof-of-work.
  5. Check that for all the txids in the block, you have the corresponding transaction in your local object database. If not, then send a "getobject" message to your peers in order to get the transaction and leave the validation of the block pending. Resume validation once you received all transactions. Note: fail transactions if we can't get missing info within 5 seconds for each missing item
  6. For each transaction in the block, check that the transaction is valid, and update your UTXO set based on the transaction. More details on this in Section 5. If any transaction is invalid, the whole block must be considered invalid.
  7. Check for coinbase transactions. There can be at most one coinbase transaction in a block. If present, then the txid of the coinbase transaction must be at index 0 in txids. The coinbase transaction cannot be spent in another transaction in the same block (this is in order to make the law of conservation for the coinbase transaction easier to verify).
  8. Validate the coinbase transaction if there is one. (a) Check that the coinbase transaction has no inputs, exactly one output and a height. Check that the height and the public key are of the valid format. (b) Verify the law of conservation for the coinbase transaction. The output of the coin- base transaction can be at most the sum of transaction fees in the block plus the block reward. In our protocol, the block reward is a constant 50 × 1012 picaker. The fee of a transaction is the sum of its input values minus the sum of its output values.
  9. When you receive a block object from the network, validate it. If valid, then store the block in your local database and gossip the block to all of your peers as you did with transactions in the last task.