I'm building a basic Bitcoin client in c# to better understand the mining protocol. I need help understanding Getblocktemplate. I have read the Getblocktemplate wiki, but I'm still having an issue understanding the protocol. The wiki states "Since you're making all the blocks yourself, you really don't ever need to get another template... until it's invalid". When is the template considered invalid? How often do I need to call Getblocktemplate? If a new block is mined every 10 minutes, with some coins that is every 1 minute, do I need to call Getblocktemplate every 10 minutes (1 minute depending on the coin) so that I have the latest "previousblockhash"?
The steps I'm using:
Make a rpc call to bicoind server for Getblocktemplate.
Parse data and build a merkle root.
Build a block header (version, previousblockhash, merkleroot, curtime, bits, nonce).
Get a header hash. headerHash = Hash(version, previousblockhash, merkleroot, curtime, bits, nonce).
Repeat step 4 by 2^32 increments of nonce.
I understand I can then increment "curtime", (which doesn't have to be precise?), so increment curtime and then repeat step 5.
Is this correct?
How long can I keep incrementing "curtime" before I need to call getblocktemplate again?
At what point do I need a new block (i.e. new previousblockhash and new merkle root)?