Skip to content

Instantly share code, notes, and snippets.

@yyforyongyu
yyforyongyu / channel_test.go
Last active February 8, 2023 16:17
A test inside `channeldb/channel_test.go`
func TestBatchUpdate(t *testing.T) {
t.Parallel()
fullDB, err := MakeTestDB(t, OptionStoreFinalHtlcResolutions(true))
require.NoError(t, err, "unable to make test database")
cdb := fullDB.ChannelStateDB()
chanID := lnwire.ShortChannelID{
BlockHeight: 1,
@yyforyongyu
yyforyongyu / main_test.go
Created January 19, 2023 10:57
Benchmark on read and write for `atomic.Bool` and mutex `bool`
func BenchmarkBoolAmoticWrite(b *testing.B) {
type foo struct {
x atomic.Bool
}
f := &foo{}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
f.x.Store(true)
@yyforyongyu
yyforyongyu / main_test.go
Created January 18, 2023 21:49
Benchmark performance among sync map, mutex map and read-write mutex map.
package main
import (
"sync"
"sync/atomic"
"testing"
)
func BenchmarkReadMutexMap(b *testing.B) {
// Create a map with a mutex.
@yyforyongyu
yyforyongyu / main.go
Last active December 16, 2022 05:50
A draft script to clean itest logs for lnd
package main
import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
"time"
)
@yyforyongyu
yyforyongyu / eve.log
Created December 5, 2022 17:40
trimmed log
// Eve received messages from Carol.
2022-12-06 01:09:31.414 [DBG] PEER: Peer([carol]): Received ChannelAnnouncement(chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206, short_chan_id=[SID: carol=>Bob]) from [carol]@127.0.0.1:55297
2022-12-06 01:09:31.449 [DBG] PEER: Peer([carol]): Received ChannelUpdate(chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206, short_chan_id=[SID: carol=>Bob], mflags=00000001, cflags=00000000, update_time=2022-12-06 01:09:22 +0800 CST) from [carol]@127.0.0.1:55297
2022-12-06 01:09:31.543 [DBG] DISC: Processing ChannelAnnouncement: peer=[carol]@127.0.0.1:55297, short_chan_id=[SID: carol=>Bob]
2022-12-06 01:09:31.767 [DBG] PEER: Peer([carol]): Received ChannelUpdate(chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206, short_chan_id=[SID: carol=>Bob], mflags=00000001, cflags=00000001, update_time=2022-12-06 01:09:21 +0800 CST) from [carol]@127.0.0.1:55297
// Eve tries to add the edge info heard from Carol.
2022-

Pruned logs

Carol's log

# carol restarts
2022-10-17 11:56:31.967 [INF] LTND: Shutdown complete
...
2022-10-17 11:56:33.145 [INF] BTCN: Server listening on 127.0.0.1:8805

The issue

An entry with LogIndex: 1009, ID: 670, Type: Settle cannot be reloaded to localUpdateLog because its parent Add entry(htlcCounter=670) cannot be found in remoteUpdateLog.

This entry is loaded from db using bucket remoteUnsignedLocalUpdates, and it's used to settle an incoming HTLC sent by the remote. By looking at the remote's closing tx, our local commit, and the entries in remoteUnsignedLocalUpdates and unsignedAckedUpdates, this Settle entry was actually received by the remote, and we did remove it from our local commit, but failed to remove it in remoteUnsignedLocalUpdates.

Remote's force close tx.

@yyforyongyu
yyforyongyu / lnd_benchmark.go
Last active September 22, 2022 13:00
a naive benchmark
package itest
import (
"fmt"
"time"
"github.com/lightningnetwork/lnd/lntest"
)
// testNetworkConnectionTimeout checks that the connectiontimeout is taking
@yyforyongyu
yyforyongyu / btcd_ffldb_parser.go
Last active May 25, 2021 08:18
A simple golang script to parse the ffldb database files created by btcd.
package main
import (
"encoding/binary"
"flag"
"fmt"
_ "github.com/btcsuite/btcd/database/ffldb"
"github.com/btcsuite/btcd/chaincfg/chainhash"

Keybase proof

I hereby claim:

  • I am yyforyongyu on github.
  • I am yyforyongyu (https://keybase.io/yyforyongyu) on keybase.
  • I have a public key whose fingerprint is 3B3C 515E 3AB1 D2FD 970F DA70 DC77 66FD FF7A CA6C

To claim this, I am signing this object: