Hi
So now you know what you have to do: write the code for mining a block.
Once you have performed the initialization steps, you can just start mining straightaway. The first thing that you need to do is pick up a set of transactions that you want to mine. If there are no pending transactions, then you should wait for one. In the miner (worker), this can be accomplished by putting up an empty (or maybe with sleep commands) while loop to keep running until there is at least one transaction. In normal cases, this loop will exit immediately.
So if you have some transactions, you can try to include as many as possible, and maintain an accumulator for the total size of the transaction data. This data should not exceed 10^6 bytes (1 MB). Since we have 116 bytes for the block header, this will ensure that the size of a block never exceeds 1000116 bytes.
You may use any method to choose transactions. It would be simple if you just pick out transactions linearly from your data structure. If you want, you may choose transactions that have higher fees (this would be pretty complex to implement, so this is not recommended, unless you think you're a pro :p )
Once you have chosen your set of transactions (i.e., the body of your block is ready), you can start finding the nonce. Remember that when you're mining a block, it might be possible that you're interrupted in between. So you must not delete any transaction from your list of pending transactions before you mine a block. Neither should you delete any unspent output. All these parts will be taken care of in the post-new-block steps.
If you receive a /newBlock request while you are mining, you must notify the worker to stop, and then start mining a new block.
Whenever a new block appears (either through /newBlock, or by mining), the post-new-block steps must be executed. For now, you can just make an simple function that prints the new block. We'll implement this function later.
Note that you should never have two workers running simultaneously. You should start mining the next block only after the previous worker has been stopped.
The deadline for this task is 11:59 AM IST on Monday, July 06 2020. React here when you have completed the task: dryairship/IITKBucks#7
Once this part is implemented, we'd almost be ready to deploy our programs.