Skip to content

Instantly share code, notes, and snippets.

@ddustin
ddustin / SpliceSignOrder.md
Last active January 18, 2024 17:46
Splice Signing Order Woes

Imagine a three node network with two channels

A <-> B <-> C

Let's say B would like to perform two splices:

splice-out 10M sats from A <-> B
splice-out 10M sats from B <-> C

IMMEDIATELY AFTER RECEIVING CHANNEL_REESTABLISH

  • Do we have any active inflight splices?
    • Yes:
      • does latest splice inflight have commit and remote sig?
        • Yes: continue
        • No: send next_funding txid of latest inflight candidate, then, continue
      • peer sends next_funding value of:
        • None: Have I sent splice tx signatures?
          • Yes: Have I received splice tx signatures?
  • Yes: send nothing
@ddustin
ddustin / rebase_fix.c
Last active June 22, 2023 21:44
Go through rebase conflicts that don't delete any code and auto-fix them.
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
/*
* Often while rebasing, the git merge algorithm will leave these
splice_locked ->
<- splice_locked
(Whichever side has lower funding pubkey starts STFU)
STFU ->
<- STFU (ack)
splice_locked_ack ->
<- splice_locked_ack
Receiving splice_locked_ack ends STFU mode and
means we can atomically move to the new channel
confirmed state.
Legend:
Item -> means sent
Item <- means received
Chan X (implies a channel at block height X)
(Since these happen at different times)
Splice locked race condition example
Node A. Node B.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include "BTCUtil.h"
#include "../libraries/mnemonic/mnemonic.h"
#include "../libraries/mnemonic/wordlist.h"
static const char *answer = "bc1qh07vgylvs66k850vr5e7efxxemhdgczj8w72xq";
static int found = 0;
class CoreLightning < Formula
desc "Core Lightning — Lightning Network implementation focusing on spec compliance and performance"
homepage "https://github.com/ElementsProject/lightning"
url "https://github.com/ddustin/lightning.git",
using: :git,
tag: "99.99"
license "MIT"
depends_on "autoconf" => :build
depends_on "automake" => :build
2022-09-15T00:12:43.712Z DEBUG lightningd: Opened log file /tmp/l1-regtest/log
2022-09-15T00:12:43.697Z INFO lightningd: Creating configuration directory /tmp/l1-regtest/regtest
2022-09-15T00:12:43.712Z DEBUG lightningd: Opened log file /tmp/l1-regtest/log
2022-09-15T00:12:43.715Z DEBUG plugin-manager: started(62874) /Users/ddustin/Development/lightning3/plugins/autoclean
2022-09-15T00:12:43.717Z DEBUG plugin-manager: started(62876) /Users/ddustin/Development/lightning3/plugins/chanbackup
2022-09-15T00:12:43.719Z DEBUG plugin-manager: started(62877) /Users/ddustin/Development/lightning3/plugins/bcli
2022-09-15T00:12:43.720Z DEBUG plugin-manager: started(62878) /Users/ddustin/Development/lightning3/plugins/commando
2022-09-15T00:12:43.722Z DEBUG plugin-manager: started(62879) /Users/ddustin/Development/lightning3/plugins/fetchinvoice
2022-09-15T00:12:43.723Z DEBUG plugin-manager: started(62880) /Users/ddustin/Development/lightning3/plugins/funder
2022-09-15T00:12:43.725Z DEBUG plugin-manag
2022-09-15T00:12:43.845Z DEBUG lightningd: Opened log file /tmp/l2-regtest/log
2022-09-15T00:12:43.844Z INFO lightningd: Creating configuration directory /tmp/l2-regtest/regtest
2022-09-15T00:12:43.845Z DEBUG lightningd: Opened log file /tmp/l2-regtest/log
2022-09-15T00:12:43.847Z DEBUG plugin-manager: started(62912) /Users/ddustin/Development/lightning3/plugins/autoclean
2022-09-15T00:12:43.849Z DEBUG plugin-manager: started(62913) /Users/ddustin/Development/lightning3/plugins/chanbackup
2022-09-15T00:12:43.850Z DEBUG plugin-manager: started(62914) /Users/ddustin/Development/lightning3/plugins/bcli
2022-09-15T00:12:43.852Z DEBUG plugin-manager: started(62916) /Users/ddustin/Development/lightning3/plugins/commando
2022-09-15T00:12:43.853Z DEBUG plugin-manager: started(62917) /Users/ddustin/Development/lightning3/plugins/fetchinvoice
2022-09-15T00:12:43.855Z DEBUG plugin-manager: started(62918) /Users/ddustin/Development/lightning3/plugins/funder
2022-09-15T00:12:43.856Z DEBUG plugin-manag
2022-09-15T00:01:37.257Z DEBUG lightningd: Opened log file /tmp/l2-regtest/log
2022-09-15T00:01:37.257Z INFO lightningd: Creating configuration directory /tmp/l2-regtest/regtest
2022-09-15T00:01:37.257Z DEBUG lightningd: Opened log file /tmp/l2-regtest/log
2022-09-15T00:01:37.260Z DEBUG plugin-manager: started(58285) /Users/ddustin/Development/lightning3/plugins/autoclean
2022-09-15T00:01:37.261Z DEBUG plugin-manager: started(58286) /Users/ddustin/Development/lightning3/plugins/chanbackup
2022-09-15T00:01:37.263Z DEBUG plugin-manager: started(58287) /Users/ddustin/Development/lightning3/plugins/bcli
2022-09-15T00:01:37.265Z DEBUG plugin-manager: started(58288) /Users/ddustin/Development/lightning3/plugins/commando
2022-09-15T00:01:37.266Z DEBUG plugin-manager: started(58289) /Users/ddustin/Development/lightning3/plugins/fetchinvoice
2022-09-15T00:01:37.268Z DEBUG plugin-manager: started(58290) /Users/ddustin/Development/lightning3/plugins/funder
2022-09-15T00:01:37.270Z DEBUG plugin-manag