Rewrite generation to use normal packets.

Now the network protocol doesn't insist on getting whole shards of
transactions, but can just take the hashes, we can simplify generate
to just give us standard packets when it finds a block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>