Assignment 3
Assignment 3
In this assignment you will implement a node that’s part of a block-chain-based distributed consensus
protocol. Specifically, your code will receive incoming transactions and blocks and maintain an
updated block chain.
Files provided:
Block.java Stores the block data structure.
ByteArrayWrapper.java A utility file which creates a wrapper for byte arrays such that it
could be used as a key in hash functions. (See
TransactionPool.java)
Create a public function getUTXOPool() in the TxHandler.java file you have created for
assignment 1 and copy the file to your code for assignment 3.
When grading your code, we will run it with our reference TxHandler.java.
File to be modified:
BlockChain.java
// Block Chain should maintain only limited block nodes to satisfy the functions
// You should not have all the blocks added to the block chain in memory
// as it would cause a memory overflow.
/**
* create an empty block chain with just a genesis block. Assume {@code genesisBlock} is
* a valid block
*/
public BlockChain(Block genesisBlock) {
// IMPLEMENT THIS
}
/** Get the UTXOPool for mining a new block on top of max height block */
public UTXOPool getMaxHeightUTXOPool() {
// IMPLEMENT THIS
}
/**
* Add {@code block} to the block chain if it is valid. For validity, all transactions
* should be valid and block should be at {@code height > (maxHeight - CUT_OFF_AGE)}.
* For example, you can try creating a new block over the genesis block (block height 2)
* if the block chain height is {@code <= CUT_OFF_AGE + 1}. As soon as {@code height >
* CUT_OFF_AGE + 1}, you cannot create a new block at height 2.
* @return true if block is successfully added
*/
public boolean addBlock(Block block) {
// IMPLEMENT THIS
}
Since there can be (multiple) forks, blocks form a tree rather than a list. Your design should take this
into account. You have to maintain a UTXO pool corresponding to every block on top of which a new
block might be created.