Check if we are the fundee of this channel, the channel * funding transaction is still not yet seen onchain, and * it has been too long since the channel was first opened. * If so, we should forget the channel. */
| 2016 | * it has been too long since the channel was first opened. |
| 2017 | * If so, we should forget the channel. */ |
| 2018 | static bool |
| 2019 | is_fundee_should_forget(struct lightningd *ld, |
| 2020 | struct channel *channel) |
| 2021 | { |
| 2022 | u32 block_height = get_block_height(ld->topology); |
| 2023 | /* 2016 by default */ |
| 2024 | u32 max_funding_unconfirmed = ld->dev_max_funding_unconfirmed; |
| 2025 | |
| 2026 | /* Only applies if we are fundee. */ |
| 2027 | if (channel->opener == LOCAL) |
| 2028 | return false; |
| 2029 | |
| 2030 | /* Does not apply if we already saw the funding tx. */ |
| 2031 | if (channel->scid) |
| 2032 | return false; |
| 2033 | |
| 2034 | /* Not even reached previous starting blocknum. |
| 2035 | * (e.g. if --rescan option is used) */ |
| 2036 | if (block_height < channel->first_blocknum) |
| 2037 | return false; |
| 2038 | |
| 2039 | /* Timeout in blocks not yet reached. */ |
| 2040 | if (block_height - channel->first_blocknum < max_funding_unconfirmed) |
| 2041 | return false; |
| 2042 | |
| 2043 | /* If we've got funds in the channel initially, don't forget it */ |
| 2044 | if (!amount_sat_is_zero(channel->our_funds)) |
| 2045 | return false; |
| 2046 | |
| 2047 | /* If we ever had a stake in the channel, don't forget it. */ |
| 2048 | if (!amount_msat_is_zero(channel->msat_to_us_max)) |
| 2049 | return false; |
| 2050 | |
| 2051 | /* Ah forget it! */ |
| 2052 | return true; |
| 2053 | } |
| 2054 | |
| 2055 | /* We want in ascending order, so oldest channels first */ |
| 2056 | static int cmp_channel_start(struct channel *const *a, struct channel *const *b, void *unused) |
no test coverage detected