Skip to content

Instantly share code, notes, and snippets.

@yyforyongyu
yyforyongyu / .bashrc
Created November 25, 2015 05:35
Linux-Hadoop-Setup
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
run_mapreduce() {
hadoop jar /usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.1.1.jar -mapper $1 -reducer $2 -file $1 -file $2 -input $3 -output $4
MAX_TEST_MINE_ATTEMPTS = 1000
def mine_pow_nonce(block_number: int, mining_hash: Hash32, difficulty: int) -> Tuple[bytes, bytes]:
cache = get_cache(block_number)
for nonce in range(MAX_TEST_MINE_ATTEMPTS):
mining_output = hashimoto_light(block_number, cache, mining_hash, nonce)
result = big_endian_to_int(mining_output[b'result'])
result_cap = 2**256 // difficulty
if result <= result_cap:
{
"txid": "37e0ab41ada62a7eddac77d47d3ce9b089cc34a1ac2d0b66bc7e00f4f9946a76",
"hash": "37e0ab41ada62a7eddac77d47d3ce9b089cc34a1ac2d0b66bc7e00f4f9946a76",
"version": 1,
"size": 226,
"vsize": 226,
"weight": 904,
"locktime": 596173,
"vin": [
{
@yyforyongyu
yyforyongyu / lnd_log
Created October 15, 2019 22:03
A trimmed log on how Alice and Bob opened a channel in the lightning network
Alice's log
================================================================================================
2019-09-10 22:34:36.711 [DBG] PEER: Sending MsgOpenChannel(temp_chan_id=cfc031525216624c40d52d7c4add59d2f1b1ef8651d77089b685fe727a8dd368, chain=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206, csv=144, amt=0.01 BTC, push_amt=0 mSAT, reserve=0.0001 BTC, flags=1) to 021fb0e0d877ef5c4c8aeb7dc931a58ed1d15e402bfe60228135d5a5573a1438e1@172.19.0.6:9735
2019-09-10 22:34:36.741 [DBG] PEER: Received MsgAcceptChannel(temp_chan_id=cfc031525216624c40d52d7c4add59d2f1b1ef8651d77089b685fe727a8dd368, reserve=0.0001 BTC, csv=144, num_confs=3) from 021fb0e0d877ef5c4c8aeb7dc931a58ed1d15e402bfe60228135d5a5573a1438e1@172.19.0.6:9735
2019-09-10 22:34:36.741 [INF] FNDG: Recv'd fundingResponse for pendingID(cfc031525216624c40d52d7c4add59d2f1b1ef8651d77089b685fe727a8dd368)
2019-09-10 22:34:36.746 [DBG] LNWL: Funding tx for ChannelPoint(ed16bab420d4d45006ff1644a16c8c9b74d990d6efc3c512962388a13d81b8e6:0) generate
Alice's log(sends bitcoins to Bob)
========================================================================================================================
...
2019-10-21 12:38:20.476 [DBG] PEER: Sending Ping to 02d933bf399aadf537f78a48aa3d25a80fd87c3d0a861d7e35ffbcd06523313cf9@172.19.0.3:9735
2019-10-21 12:38:20.479 [DBG] PEER: Received Pong from 02d933bf399aadf537f78a48aa3d25a80fd87c3d0a861d7e35ffbcd06523313cf9@172.19.0.3:9735
2019-10-21 12:38:26.713 [DBG] CRTR: Found route: probability=0.6, hops=1, fee=0 mSAT
2019-10-21 12:38:26.740 [DBG] CRTR: Payment 83e1c34af5ea9b3f840f5c5d0f18985ff9f81958cd2c92fd2c62910c030ce032 (pid=1) successfully sent to switch
2019-10-21 12:38:26.740 [DBG] HSWC: ChannelLink(401:1:0) Queueing keystone of ADD open circuit: (Chan ID=0:0:0, HTLC ID=1)->(Chan ID=401:1:0, HTLC ID=0)
2019-10-21 12:38:26.741 [DBG] PEER: Sending UpdateAddHTLC(chan_id=3918d9d451fccc282250508991109007deecb6cafa73b6df9360a2bd589ec7c2, id=0, amt=10000000 mSAT, expiry=600, hash=83e1c34af5ea9b3f840f5c5d0f18985ff9

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:

@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"
@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

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.

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