Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres crash fix #5513

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,41 @@ def test_funder_contribution_limits(node_factory, bitcoind):
assert l3.daemon.is_in_log(r'calling `signpsbt` .* 7 inputs')


@pytest.mark.openchannel('v2')
@pytest.mark.developer("requres 'dev-disconnect'")
def test_inflight_dbload(node_factory, bitcoind):
"""Bad db field access breaks Postgresql on startup with opening leases"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extremely minor nit: technically it only breaks if you try to load inflights from a postgres db, which happens in the case that a channel open isn't resolved at startup

disconnects = ["@WIRE_COMMITMENT_SIGNED"]
l1, l2 = node_factory.get_nodes(2, opts=[{'experimental-dual-fund': None,
'dev-no-reconnect': None,
'may_reconnect': True,
'disconnect': disconnects},
{'experimental-dual-fund': None,
'dev-no-reconnect': None,
'may_reconnect': True,
'funder-policy': 'match',
'funder-policy-mod': 100,
'lease-fee-base-sat': '100sat',
'lease-fee-basis': 100}])

feerate = 2000
amount = 500000
l1.fundwallet(20000000)
l2.fundwallet(20000000)

# l1 leases a channel from l2
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
wait_for(lambda: len(l1.rpc.listpeers(l2.info['id'])['peers']) == 0)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
feerate='{}perkw'.format(feerate),
compact_lease=rates['compact_lease'])
l1.daemon.wait_for_log(r'dev_disconnect: @WIRE_COMMITMENT_SIGNED')

l1.restart()


def test_zeroconf_mindepth(bitcoind, node_factory):
"""Check that funder/fundee can customize mindepth.

Expand Down
5 changes: 3 additions & 2 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,8 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
struct channel_inflight *inflight;

secp256k1_ecdsa_signature *lease_commit_sig;
u32 lease_chan_max_msat, lease_blockheight_start;
u32 lease_blockheight_start;
u64 lease_chan_max_msat;
u16 lease_chan_max_ppt;

db_col_txid(stmt, "funding_tx_id", &funding.txid);
Expand All @@ -1133,7 +1134,7 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
if (!db_col_is_null(stmt, "lease_commit_sig")) {
lease_commit_sig = tal(tmpctx, secp256k1_ecdsa_signature);
db_col_signature(stmt, "lease_commit_sig", lease_commit_sig);
lease_chan_max_msat = db_col_int(stmt, "lease_chan_max_msat");
lease_chan_max_msat = db_col_u64(stmt, "lease_chan_max_msat");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, I was wondering how this works on the sqlite site but it looks like sqlite integers are 8 bytes anyways...

lease_chan_max_ppt = db_col_int(stmt, "lease_chan_max_ppt");
lease_blockheight_start = db_col_int(stmt, "lease_blockheight_start");
db_col_amount_msat(stmt, "lease_fee", &lease_fee);
Expand Down