Add backrefs to transaction inputs in blocks.

This allows a node to prove that an input is invalid, by showing
the transaction referred to by the input reference.  Otherwise
a node with partial knowledge has no way of knowing if a transaction
simply references a transaction it doesn't know about (OK) or one
which doesn't exist (not OK).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Standardize type for proving a transaction is in a block.

Simplifies the protocol and the code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add a horizon (1 month).

Pettycoin is not a store of value!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Prevent timejacking attack.

I talked about doing it, but didn't actually fix it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Feature support.

Features get voted in by having a whole difficulty block voted by 75% of
the blocks.  Then after another difficulty block, we expect the version
to increment to indicate an incompatible change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fix add_to_thash for batchnum > 0.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add rest of enums to log helper, and make sure gcc warns us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Move chain pointer update logic into chain.c

But to avoid pulling everything into generate, we make a difficulty
function inline (ick).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Prepare datastructures for multiple longest known/longest chain.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
block: link siblings.

Makes forward iteration more efficient (ie. for-each-child).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Keep track of multiple best chains.

This may be overkill, but it's not too bad.  We make the [0] entry
the preferred entry, so we always prefer tiebreak a known chain which
heads to a longest chain (and vice versa).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Note the issues with nagle.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Give each peer a unique number (so objects can enumerate peers).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
num_batches instead of num_merkles

We have one merkle per batch, it's true, but num_batches
is clearer since that's the root.  And add num_batches_for_block
for the common case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
New TODO system for information we want to know.

It's primitive, but it abstracts the chain topology more and
allows us to avoid asking the same peers over and over.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fix mkgenesis.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fix batch_full() being called with NULL.

This crash was in ask_about_block, but others could be the same.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fix address calculation.

It's actually the RIPEMD160 of the *SHA* of the pubkey.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add option to print out bitcoin-style addresses.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fix comment cut & paste error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>