Don't assert if asked to get refs/tx and it's a hash.

Surprising behaviour (that I hit): we handle the "shard isn't there"
case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Initialize peermap to zero.

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

This would have exploded, once we start sending txs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fix sending block we get from generator.

We obviously want to tell all peers about it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Change the way prev_merkles works.

We weren't doing it correctly since we changed the merkle functions
anyway.  The new method is simple: it's the double-sha of the payout
address followed by each transaction in the shard with its refs.

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

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Use a valid genesis block for testing.

And put it in a single file where we can share it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
More assertions on block & shard structure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Make put_tx_in_block take a struct txptr_with_refs by copy.

Makes usage a bit simpler, and we're about to use it in tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Remove unused fields form struct peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Remove unused routines now we've updated generator.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add merkle_some_txs for proof to use.

And remove the unused prefix args from merkle_txs.

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

Hasn't been updated since we started hashing in refs!

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

In order to generate a PROTOCOL_PKT_TX_IN_BLOCK reply when we don't
know the tx, we need to send a position without a proof, so
we also split struct protocol_tx_with_proof here.

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

Handling requests for a particular transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add err to PROTOCOL_PKT_TX.

This can happen once we start asking about specific txs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
num_txs_in_shard() helper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Split up check_tx() into check_tx() and check_tx_inputs().

This makes the code and error handling cleaner, and gets rid of many
private error codes.  It's a little less efficient, though, since we
need to re-lookup inputs to generate the error packet.

We also rename complain_about_input and complain_about_inputs because
the term "complain" means a problem with a block, rather than just
our feedback on a transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rename put_tx_in_block to put_tx_in_shard.

It actually applies to this shard, not necessarily the one currently
in the block (and copy_old_txs uses this fact!).

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

First we break them into separate functions for the different types
of complaints.

Then we fix them: they used tal_packet_append_proof() which implicitly
generated a proof for what was currently in the block.  But bad
transactions are not supposed to be in the block, so that would fail.

1) tal_packet_append_proof() now takes an explicit proof, so hopefully
   the caller will think about what proof to generate.
2) each complaint takes a proof pointer, as it can't generate
   a proof for a transaction which isn't in the block.
3) put_tx_in_shard() doesn't generate a complaint, add check_tx_ordering()
   and make the caller do it.
4) Remove almost all the now-unused private ecodes.

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