We have to sign the commit at this stage, so easiest if peer isn't const
so we can sign it in-place.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This tell us to disarm the INPUT_CLOSE_COMPLETE_TIMEOUT: either we hit
an error and are going to unilateral close, or we received their signature
successfully.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Actually generating the anchor transaction in my implementation
requires interaction with bitcoind, which we want to be async. So add
a callback and a new state to wait for it.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We use both union fields idata->btc and idata->htlc, which is clearly
wrong. Have peer_tx_revealed_r_value return the HTLC it's talking
about.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This lets us eliminate struct state_effect altogether (the next patch
removes the now-unused arguments).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We only have one htlc in flight at a time, but sometimes it changes:
particularly when we are lowpriority and a highpriority request comes
in. Handle this using a set of callbacks for htlc handling.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Now we're covered by the opening command anyway, and the rule that you
can't have two commands at once.
There are two more defers:
1) In state STATE_WAIT_FOR_UPDATE_SIG_LOWPRIO/HIGHPRIO we are waiting for
their signature because they started an HTLC, we defer any new HTLC
creation, and
2) We defer PKT_OPEN_COMPLETE when we're waiting for anchor depth.
The first can be solved by a flag indicating whether we are accepting new
commands at all, the second by a pair of new states.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This is conceptually cleaner, especially since it means we're running
a command until we're set up (which prevents other commands, so no
special case needed).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
All the members of the transaction should be allocated off the
transaction, as they have the same lifetime.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We could probably just use Openssl's RAND_pseudo_bytes, but this gives
a nice interface to get a number between 1 and N.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This enforces the include order implemented by the previous patch, and
also make sure we haven't missed any headers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
A halfway house between the horror of dynamic generation and the fail of
making everything depend on every header.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>