| 35 | } |
| 36 | |
| 37 | struct uncommitted_channel * |
| 38 | new_uncommitted_channel(struct peer *peer) |
| 39 | { |
| 40 | struct lightningd *ld = peer->ld; |
| 41 | struct uncommitted_channel *uc = tal(ld, struct uncommitted_channel); |
| 42 | u8 *new_channel_msg; |
| 43 | |
| 44 | uc->peer = peer; |
| 45 | assert(!peer->uncommitted_channel); |
| 46 | |
| 47 | uc->transient_billboard = NULL; |
| 48 | uc->dbid = wallet_get_channel_dbid(ld->wallet); |
| 49 | |
| 50 | uc->log = new_log(uc, ld->log_book, &uc->peer->id, |
| 51 | "chan#%"PRIu64, uc->dbid); |
| 52 | |
| 53 | uc->fc = NULL; |
| 54 | uc->our_config.id = 0; |
| 55 | /* BOLT #2: |
| 56 | * |
| 57 | * The sender: |
| 58 | * - if `channel_type` includes `option_zeroconf`: |
| 59 | * - MUST set `minimum_depth` to zero. |
| 60 | * - otherwise: |
| 61 | * - SHOULD set `minimum_depth` to a number of blocks it |
| 62 | * considers reasonable to avoid double-spending of the |
| 63 | * funding transaction. |
| 64 | */ |
| 65 | /* We override this in openchannel hook if we want zeroconf */ |
| 66 | uc->minimum_depth = ld->config.anchor_confirms; |
| 67 | |
| 68 | /* Use default 1% reserve if not otherwise specified. If this |
| 69 | * is not-NULL it will be used by openingd as absolute value |
| 70 | * (clamped to dust limit). */ |
| 71 | uc->reserve = NULL; |
| 72 | |
| 73 | memset(&uc->cid, 0xFF, sizeof(uc->cid)); |
| 74 | |
| 75 | /* Declare the new channel to the HSM. */ |
| 76 | new_channel_msg = towire_hsmd_new_channel(NULL, &uc->peer->id, uc->dbid); |
| 77 | if (!wire_sync_write(ld->hsm_fd, take(new_channel_msg))) |
| 78 | fatal("Could not write to HSM: %s", strerror(errno)); |
| 79 | new_channel_msg = wire_sync_read(tmpctx, ld->hsm_fd); |
| 80 | if (!fromwire_hsmd_new_channel_reply(new_channel_msg)) |
| 81 | fatal("HSM gave bad hsm_new_channel_reply %s", |
| 82 | tal_hex(new_channel_msg, new_channel_msg)); |
| 83 | |
| 84 | get_channel_basepoints(ld, &uc->peer->id, uc->dbid, |
| 85 | &uc->local_basepoints, &uc->local_funding_pubkey); |
| 86 | |
| 87 | uc->peer->uncommitted_channel = uc; |
| 88 | tal_add_destructor(uc, destroy_uncommitted_channel); |
| 89 | |
| 90 | uc->got_offer = false; |
| 91 | uc->open_daemon = NULL; |
| 92 | |
| 93 | return uc; |
| 94 | } |
no test coverage detected