70 changes: 70 additions & 0 deletions docs/call_scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# call scripts

## abstruct

ptarmd call `install/<NODE DIR>/scripts/*.sh` on event happens.

1. [started.sh](#startedsh)
2. [connected.sh](#connectedsh)
3. [disconnected.sh](#disconnectedsh)
4. [established.sh](#establishedsh)
5. [payment.sh](#paymentsh)
6. [addfinal.sh](#addfinalsh)
7. [fulfill.sh](#fulfillsh)
8. [fail.sh](#failsh)
9. [htlcchanged.sh](#htlcchangedsh)
10. [closed.sh](#closedsh)
11. [dbclosed.sh](#dbclosedsh)
12. [error.sh](#errorsh)

### started.sh

ptarmd started.

### connected.sh

connected peer node.

### disconnected.sh

disconnected peer node.

### established.sh

channel established.

### payment.sh

* receive payment request from JSON-RPC(including `ptarmcli`)
* routing success

### addfinal.sh

* `update_add_htlc` received and the preimage is mine.
* `revoke_and_ack` message exchanged.

This is useful for faster receiving action.

### fulfill.sh

.

### fail.sh

.

### htlcchanged.sh

`revoke_and_ack` message exchanged.

### closed.sh

channel closed.

### dbclosed.sh

channel closed and remove channel from database.

### error.sh

`error` message received.
21 changes: 3 additions & 18 deletions docs/howtopay_starblocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,12 @@ You should wait untill finishing log output.
`ptarmcli` shows current connection information.
Connected node `status` is `"connected"` in the log.

10. Generate funding transactionn related command file

First, send testnet bitcoin to segwit address, then send testnet bitcoinn payment channnel.

```bash
../pay_fundin.py 1000000 500000
```

These command generate a file `fund_yyyymmddhhmmss.conf`.
File contents means the following:

1. create 10mBTC segwit transaction
2. send the transaction
3. fund channel 10mBTC (give 500000msat for peer node)

Note that unit is satoshi.

11. Fund payment channel

fund channel 10mBTC, and give 500000msat for peer node.

```bash
../ptarmcli -c [peer node_id] -f fund_yyyymmddhhmmss.conf
../ptarmcli -c [peer node_id] -f 1000000,500000
```

12. Wait until funding transaction get into bitcoin testnet block (it will take time)
Expand Down
15 changes: 1 addition & 14 deletions docs/howtouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,12 @@ If you have channels, `ptarmd` try connect the peers automatically.
After connecting, you can open channel with connection node.

```bash
# create funding file
../pay_fundin.py AMOUNT_SAT
(create fund_xxxx.conf)

../ptarmcli -c NODE_ID -f fund_xxxx.conf
../ptarmcli -c NODE_ID -f AMOUNT_SAT
```

Establishing channel need some blocks.
You can check channel status with `ptarmcli --getinfo`.

#### memo

`pay_fundin.py` only support P2PKH / native P2WPKH / P2WPKH nested in BIP16 P2SH.
If using "regtest", you send to `bitcoin-cli getnewaddress`.

```bash
bitcoin-cli sendtoaddress `bitcoin-cli getnewaddress` 0.1
```

### request payment

* "request payment" means:
Expand Down
28 changes: 24 additions & 4 deletions docs/howtouse_rest_api.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# ptarmigan-api
# How to use Ptarmigan REST API

[ptarmigan rest-api](../ptarmapi) Lightning Network implementation ptarmigan REST-API
[Ptarmigan REST API](../ptarmapi) Lightning Network implementation Ptarmigan REST API

## Configration


```
# copy .env file
$ cd $INSTALL_DIR/ptarmigan/ptarmapi/
$ cp.env-sample .env
$ cp .env-sample .env
# edit .env change to your environment
$ vi .env
Expand All @@ -23,18 +23,38 @@ $ sudo apt-get install npm
$ npm install
```

If use `invoice notifications api`, please install this.

[What's invoice notifications api](./about_invoice_notifications.md)

```bash
$ sudo apt install -y curl
```


## Running the app

```bash
# start development mode
$ npm run start
```

Not use invoice notifications.

```bash
$ npm run start:not-use-invoices-notification
```


## Example

Default API token is `ptarmigan`.

```
$ curl -X POST "http://localhost:3000/getinfo" -H "accept: application/json"
$ curl -X POST "http://localhost:3000/getinfo" -H "accept: application/json/" -H "Authorization: Bearer ptarmigan"
```


## Browser of local PC

Use this rest-api in a closed network.
Expand Down
65 changes: 0 additions & 65 deletions docs/ptarm_event_script_ja.md

This file was deleted.

61 changes: 22 additions & 39 deletions docs/ptarmcli.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ ptarmcli [options] [JSON-RPC port number]
* `--getinfo` : get information

* funding
* `-f FUND_CONFIG_FILE` : open channel(need `-c` option)
* FUND_CONFIG_FILE can create by `pay_fundin.py`
* `-f FUNDING_SATOSHI[,PUSH_MSAT[,FEERATE_PER_KW]]` : open channel(need `-c` option)
* start open channel

* invoice
* `--addinvoice=AMOUNT_MSAT` : add invoice
* `--addinvoice=AMOUNT_MSAT[,MIN_FINAL_CLTV_EXPIRY[,DESCRIPTION]]` : add invoice
* `--listinvoice` : list invoices
* `--removeinvoice=PAYMENT_HASH` : erase a payment_hash
* `--removeinvoice=ALL` : erase all payment_hashs
Expand Down Expand Up @@ -63,18 +63,6 @@ ptarmcli [options] [JSON-RPC port number]
Control `ptarmd`.
`ptarmcli` and `ptarmd` are connect with TCP JSON-RPC(not HTTP).

### Configuration File Format

* fund config file format (`-f`)

```text
txid=[fund-in txid]
txindex=[fund-in outpoint index]
funding_sat=[funding satoshis in txid amount]
push_sat=[push satoshis for peer node]
feerate_per_kw=[feerate_per_kw for `open_channel`]
```

### Command and JSON-RPC command

#### connect
Expand All @@ -94,31 +82,11 @@ ptarmcli -c 02f5fa009cbf9774960d5f5591a37fd931fe4a22563b7cfbf57d3f9a98b0e11882@1
```

#### funding
For funding, it needs a config file.

```bash
../pay_fundin.py 1000000 50000

[FeeRate] 0.00001000
[Size] 167 bytes
[Send] 0.01000227 btc
[Address] 2NCvy3cefpVHBGrjC6RgAJPCZZEeLpvvYcE
[TXID] 04c7fe01a3721ebb0ab417dad804b22ad7aebd812bd81c5141ede9ff8645cd17
[LOCK] True
[CREATE] fund_20190415053538.conf
fund 10 mBTC(1000000 satoshi), and give 5000 satoshi.

----
cat fund_20190415053538.conf

txid=04c7fe01a3721ebb0ab417dad804b22ad7aebd812bd81c5141ede9ff8645cd17
txindex=0
signaddr=2NCvy3cefpVHBGrjC6RgAJPCZZEeLpvvYcE
funding_sat=1000000
push_msat=50000
feerate_per_kw=0
----

ptarmcli -c 028df7753f0802ec2b781ffd44da838b7b57baebe2930132411fded4399e33bf58 -f fund_20190415053538.conf
```bash
ptarmcli -c 028df7753f0802ec2b781ffd44da838b7b57baebe2930132411fded4399e33bf58 -f 1000000,50000

```

Expand All @@ -129,7 +97,7 @@ ptarmcli -c 028df7753f0802ec2b781ffd44da838b7b57baebe2930132411fded4399e33bf58 -
"028df7753f0802ec2b781ffd44da838b7b57baebe2930132411fded4399e33bf58",
"0.0.0.0",
0,
"04c7fe01a3721ebb0ab417dad804b22ad7aebd812bd81c5141ede9ff8645cd17",
"",
0,
1000000,
50000,
Expand All @@ -155,6 +123,21 @@ ptarmcli -i 123000
}
```

```bash
ptarmcli -i 123000,2000,"nayuta lightning"
```

```json
{
"method":"invoice",
"params":[
123000,
2000,
"nayuta lightning"
]
}
```

#### getinfo

```bash
Expand Down
16 changes: 15 additions & 1 deletion docs/ptarmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,21 @@ ptarmd [--network=NETWORK] [-p PORT] [-n ALIAS NAME] [-a IPv4 ADDRESS] [-c BITCO

* --conf=BITCOIN.CONF
* current bitcoin.conf
* default: ~/.bitcoin/bitcoin.conf
* read `rpcuser`, `rpcpassword` and `rpcport`.
* if no `rpcuser` or `rpcpassword`, read from ~/.bitcoin/bitcoin.conf
* if no `rpcport`, use default rpc port number(mainnet=8332, testnet=18332, regtest=18443)

* --bitcoinrpcuser=USERNAME
* bitcoin RPC username
* default: read from bitcoin.conf

* --bitcoinrpcpassword=PASSWORD
* bitcoin RPC password
* default: read from bitcoin.conf

* --bitcoinrpcport=PORT
* bitcoin RPC port
* default: read from bitcoin.conf

* --datadir=DATA_DIR
* working directory
Expand Down
14 changes: 1 addition & 13 deletions docs/testnet_2nodes_clightning.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,11 @@ rm -rf ~/.lightning
./cli/lightning-cli getinfo
```

8. [ptarmigan] Creating fund-in transaction

```bash
../pay_fundin.py 1000000 0
```

* Create a channel that sends you 10mBTC and the other person 0.
* 1000000 (fund-in satoshi) is the amount of money that is sent to an adress before sending payment to the channel.
* 1000000 (channel satoshi) is the amount of sending payment to the channel.
* 0 (push msatoshi) is the amount out of channel satoshi to be sent to the other person.
* `pay_fundin.py` will create a file in `fund_yyyymmddhhmmss.conf` format.

9. [ptarmigan] Starting Channel Establishment

```bash
../ptarmcli -c [PEER NODE_ID]@[IPv4 ADDR]:[PORT]
../ptarmcli -c [PEER NODE_ID] -f fund_yyyymmddhhmmss.conf
../ptarmcli -c [PEER NODE_ID] -f 1000000
```

10. [btc] Waiting for generating a block
Expand Down
14 changes: 1 addition & 13 deletions docs/testnet_2nodes_eclair.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,14 @@ chmod u+x eclair-cli
./eclair-cli getinfo
```

8. [ptarmigan] Creating fund-in transaction

```bash
../pay_fundin.py 1000000 0
```

* Create a channel that sends you 10mBTC and the other person 0.
* 1000000 (fund-in satoshi) is the amount of money that is sent to an adress before sending payment to the channel.
* 1000000 (channel satoshi) is the amount of sending payment to the channel.
* 0 (push msatoshi) is the amount out of channel satoshi to be sent to the other person.
* `pay_fundin.py` will create a file in `fund_yyyymmddhhmmss.conf` format.

9. [ptarmigan] Starting Channel Establishment

* If you get an error that feerate_per_kw is wrong, change fund_yyyymmddhhmmss.conf.
* Add `feerate_per_kw=zzzzz`(zzzzz is an approximate value to an error message `localFeeratePerKw`) in the last line.

```bash
../ptarmcli -c [PEER NODE_ID]@[IPv4 ADDR]:[PORT]
../ptarmcli -c [PEER NODE_ID] -f fund_yyyymmddhhmmss.conf
../ptarmcli -c [PEER NODE_ID] -f 1000000
```

10. [btc] Waiting for generating a block
Expand Down
14 changes: 1 addition & 13 deletions docs/testnet_2nodes_lnd.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,11 @@ lncli --no-macaroons create
lncli --no-macaroons getinfo
```

8. [ptarmigan] Creating fund-in transaction

```bash
../pay_fundin.py 1000000 0
```

* Create a channel that sends you 10mBTC and the other person 0.
* 1000000 (fund-in satoshi) is the amount of money that is sent to an adress before sending payment to the channel.
* 1000000 (channel satoshi) is the amount of sending payment to the channel.
* 0 (push msatoshi) is the amount out of channel satoshi to be sent to the other person.
* `pay_fundin.py` will create a file in `fund_yyyymmddhhmmss.conf` format.

9. [ptarmigan] Starting Channel Establishment

```bash
../ptarmcli -c [PEER NODE_ID]@[IPv4 ADDR]:[PORT]
../ptarmcli -c [PEER NODE_ID] -f fund_yyyymmddhhmmss.conf
../ptarmcli -c [PEER NODE_ID] -f 1000000
```

10. [btc] Waiting for generating a block
Expand Down
12 changes: 3 additions & 9 deletions docs/testnet_4nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,17 @@ lncli --no-macaroons getinfo
* Following results are for `feerate_per_kw = 10000`.

```bash
../pay_fundin.py 800000 300000000
../ptarmcli -c [c-lightning NODE_ID] -f fund_yyyymmddhhddss.conf
../ptarmcli -c [c-lightning NODE_ID] -f 800000,300000000
../ptarmcli -l
(wait... status: "wait_minimum_depth")
rm fund_yyyymmddhhddss.conf

../pay_fundin.py 800000 400000000
../ptarmcli -c [eclair NODE_ID] -f fund_yyyymmddhhddss.conf
../ptarmcli -c [eclair NODE_ID] -f 800000,400000000
../ptarmcli -l
(wait... status: "wait_minimum_depth")
rm fund_yyyymmddhhddss.conf

../pay_fundin.py 800000 500000000
../ptarmcli -c [lnd NODE_ID] -f fund_yyyymmddhhddss.conf
../ptarmcli -c [lnd NODE_ID] -f 800000,500000000
../ptarmcli -l
(wait... status: "wait_minimum_depth")
rm fund_yyyymmddhhddss.conf
```

## Waiting for opening channels
Expand Down
16 changes: 0 additions & 16 deletions install/create_knownpeer.sh

This file was deleted.

13 changes: 3 additions & 10 deletions install/jdk.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
#!/bin/sh

TARGET=x86_64
#TARGET=RASPI
#TARGET=RASPI_ARM11
#TARGET=ARM_RASPI

if [ "$TARGET" = "x86_64" ]; then
#JDK for x86_64
export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JDK_CPU=amd64/server
echo $TARGET

elif [ "$TARGET" = "RASPI" ]; then
#JDK for Raspberry-Pi 2/3
export JDK_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt
export JDK_CPU=arm/server
echo $TARGET

elif [ "$TARGET" = "RASPI_ARM11" ]; then
#JDK for Raspberry-Pi 1/Zero
elif [ "$TARGET" = "ARM_RASPI" ]; then
#JDK for openjdk-8-jdk (Raspberry-Pi)
export JDK_HOME=/usr/lib/jvm/java-8-openjdk-armhf
export JDK_CPU=arm/client
echo $TARGET
Expand Down
65 changes: 0 additions & 65 deletions install/pay_fundin.sh

This file was deleted.

21 changes: 21 additions & 0 deletions install/script/addfinal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -eu

# method: addfinal
# $1: short_channel_id
# $2: node_id
# $3: payment_hash
# $4: amount_msat
# $5: local_msat
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{
"method":"addfinal",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"payment_hash":"$3",
"amount_msat":$4,
"local_msat":$5
}
EOS
8 changes: 7 additions & 1 deletion install/script/closed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ set -eu
# $3: closing_txid
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"closed", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "closing_txid":"$3" }
{
"method":"closed",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"closing_txid":"$3"
}
EOS
9 changes: 8 additions & 1 deletion install/script/connected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ set -eu
# $4: received localfeatures
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"connected", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "peer_id":"$3", "localfeatures":$4 }
{
"method":"connected",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"peer_id":"$3",
"localfeatures":$4
}
EOS
8 changes: 7 additions & 1 deletion install/script/dbclosed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ set -eu
# $3: channel_id
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"dbclosed", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "channel_id":"$3" }
{
"method":"dbclosed",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"channel_id":"$3"
}
EOS
8 changes: 7 additions & 1 deletion install/script/disconnected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ set -eu
# $3: peer_id
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"disconnected", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "peer_id":"$3" }
{
"method":"disconnected",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"peer_id":"$3"
}
EOS
8 changes: 7 additions & 1 deletion install/script/error.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ set -eu
# $3: err_str
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"error", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "err_str":"$3" }
{
"method":"error",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"err_str":"$3"
}
EOS
9 changes: 8 additions & 1 deletion install/script/established.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ set -eu
# $4: funding_txid
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"established", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "local_msat":$3, "funding_txid":"$4" }
{
"method":"established",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"local_msat":$3,
"funding_txid":"$4"
}
EOS
8 changes: 7 additions & 1 deletion install/script/fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ set -eu
# $3: info
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"fail", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "info":"$3" }
{
"method":"fail",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"info":"$3"
}
EOS
12 changes: 0 additions & 12 deletions install/script/forward.sh

This file was deleted.

9 changes: 8 additions & 1 deletion install/script/fulfill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ set -eu
# $4: payment_preimage
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"fulfill", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "payment_hash":"$3", "payment_preimage":"$4" }
{
"method":"fulfill",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"payment_hash":"$3",
"payment_preimage":"$4"
}
EOS
8 changes: 7 additions & 1 deletion install/script/htlcchanged.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ set -eu
# $3: local_msat
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"htlc_changed", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "local_msat":$3 }
{
"method":"htlc_changed",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"local_msat":$3
}
EOS
10 changes: 9 additions & 1 deletion install/script/payment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ set -eu
# $5: payment_id
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"payment", "short_channel_id":"$1", "node_id":"$2", "date":"$DATE", "amt_to_forward":$3, "outgoing_cltv_value":$4, "payment_id":"$5" }
{
"method":"payment",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2",
"amt_to_forward":$3,
"outgoing_cltv_value":$4,
"payment_id":$5
}
EOS
7 changes: 6 additions & 1 deletion install/script/started.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ set -eu
# $2: node_id
DATE=`date -u +"%Y-%m-%dT%H:%M:%S.%N"`
cat << EOS | jq -e '.'
{ "method":"started", "short_channel_id":"$1", "node_id":"$2" }
{
"method":"started",
"date":"$DATE",
"short_channel_id":"$1",
"node_id":"$2"
}
EOS
25 changes: 15 additions & 10 deletions libs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ clean_mbedtls:
mbedtls_all: clean_mbedtls mk_mbedtls

mk_boost:
ifeq ("$(wildcard $(BOOST_VER_FILE).tar.gz)","")
rm -rf boost $(BOOST_VER_FILE) $(BOOST_VER_FILE).tar.gz
wget https://dl.bintray.com/boostorg/release/$(BOOST_VER)/source/$(BOOST_VER_FILE).tar.gz
endif
ifeq ("$(wildcard boost)","")
rm -rf $(BOOST_VER_FILE)
tar zxf $(BOOST_VER_FILE).tar.gz
ln -s $(BOOST_VER_FILE) boost
endif
-@if [ ! -f $(BOOST_VER_FILE).tar.gz ]; then\
rm -rf boost $(BOOST_VER_FILE) $(BOOST_VER_FILE).tar.gz ;\
wget -O boost.tgz https://dl.bintray.com/boostorg/release/$(BOOST_VER)/source/$(BOOST_VER_FILE).tar.gz &&\
mv boost.tgz $(BOOST_VER_FILE).tar.gz ;\
fi
@if [ ! -f $(BOOST_VER_FILE).tar.gz ]; then\
wget -O boost.tgz https://sourceforge.net/projects/boost/files/boost/$(BOOST_VER)/$(BOOST_VER_FILE).tar.gz/download &&\
mv boost.tgz $(BOOST_VER_FILE).tar.gz ;\
fi
if [ ! -d boost ]; then\
rm -rf $(BOOST_VER_FILE) ;\
tar zxf $(BOOST_VER_FILE).tar.gz ;\
ln -s $(BOOST_VER_FILE) boost ;\
fi
cd boost; \
./bootstrap.sh; \
./b2 tools/bcp; \
Expand Down Expand Up @@ -123,5 +128,5 @@ clean:
-$(MAKE) -C jansson clean
-$(MAKE) -C curl clean
-$(MAKE) -C zlib clean
-$(RM) -rf $(INSTALL_DIR) bech32 boost $(BOOST_VER_FILE)
-$(RM) -rf $(INSTALL_DIR) bech32 boost $(BOOST_VER_FILE) $(BOOST_VER_FILE).tar.gz

Empty file added libs/jre/lib/client/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion libs/mbedtls
2 changes: 1 addition & 1 deletion ln/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ CFLAGS_C += -std=gnu99
#C++ only
######################################

CFLAGS_CPP +=
CFLAGS_CPP += -std=gnu++11


######################################
Expand Down
35 changes: 25 additions & 10 deletions ln/ln.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ bool ln_init(
pChannel->commit_info_remote.p_funding_info =
&pChannel->funding_info;

#ifdef USE_GOSSIP_QUERY
SLIST_INIT(&pChannel->gossip_query.request.send_encoded_ids);
#endif

LOGD("END\n");

return true;
Expand Down Expand Up @@ -334,8 +338,6 @@ bool ln_establish_alloc(ln_channel_t *pChannel, const ln_establish_param_t *pPar
LOGD("BEGIN\n");

if (pParam) {
pChannel->establish.p_fundin = NULL; //open_channel送信側が設定する

memcpy(&pChannel->establish.param, pParam, sizeof(ln_establish_param_t));
LOGD("dust_limit_sat= %" PRIu64 "\n", pChannel->establish.param.dust_limit_sat);
LOGD("max_htlc_value_in_flight_msat= %" PRIu64 "\n", pChannel->establish.param.max_htlc_value_in_flight_msat);
Expand All @@ -354,11 +356,6 @@ bool ln_establish_alloc(ln_channel_t *pChannel, const ln_establish_param_t *pPar

void ln_establish_free(ln_channel_t *pChannel)
{
if (pChannel->establish.p_fundin != NULL) {
LOGD("pChannel->establish.p_fundin=%p\n", pChannel->establish.p_fundin);
UTL_DBG_FREE(pChannel->establish.p_fundin);
LOGD("free\n");
}
pChannel->funding_info.state = (ln_funding_state_t)((pChannel->funding_info.state & ~LN_FUNDING_STATE_STATE_FUNDING) | LN_FUNDING_STATE_STATE_OPENED);
}

Expand Down Expand Up @@ -390,7 +387,6 @@ void ln_short_channel_id_get_param(uint32_t *pHeight, uint32_t *pBIndex, uint32_
}



const uint8_t *ln_funding_blockhash(const ln_channel_t *pChannel)
{
return pChannel->funding_blockhash;
Expand Down Expand Up @@ -865,7 +861,8 @@ bool ln_revokedhtlc_create_spenttx(const ln_channel_t *pChannel, btc_tx_t *pTx,
uint64_t fee = (pChannel->p_revoked_type[WitIndex] == LN_COMMIT_TX_OUTPUT_TYPE_OFFERED) ? fee_info.htlc_timeout_fee : fee_info.htlc_success_fee;
LOGD("Value=%" PRIu64 ", fee=%" PRIu64 "\n", Value, fee);

ln_htlc_tx_create(pTx, Value - fee, &pChannel->shutdown_scriptpk_local, pChannel->p_revoked_type[WitIndex], 0, pTxid, Index);
ln_htlc_tx_create(pTx, Value - fee, NULL, pChannel->p_revoked_type[WitIndex], 0, pTxid, Index);
btc_tx_add_vout_spk(pTx, Value - fee, &pChannel->shutdown_scriptpk_local);
M_DBG_PRINT_TX2(pTx);

btc_keys_t signkey;
Expand Down Expand Up @@ -1083,7 +1080,15 @@ bool ln_is_announced(const ln_channel_t *pChannel)

uint32_t ln_feerate_per_kw_calc(uint64_t feerate_kb)
{
return (uint32_t)(feerate_kb / 4);
uint64_t feerate_kw = (uint32_t)(feerate_kb / 4);
if (feerate_kw < LN_FEERATE_PER_KW_MIN) {
// estimatesmartfeeは1000satoshisが下限のようだが、c-lightningは1000/4=250ではなく253を下限としている。
// https://github.com/ElementsProject/lightning/issues/1443
// https://github.com/ElementsProject/lightning/issues/1391
//LOGD("FIX: calc feerate_per_kw(%" PRIu32 ") < MIN\n", feerate_kw);
feerate_kw = LN_FEERATE_PER_KW_MIN;
}
return feerate_kw;
}


Expand Down Expand Up @@ -1439,6 +1444,16 @@ static void channel_clear(ln_channel_t *pChannel)
pChannel->anno_flag = 0;
pChannel->shutdown_flag = 0;

#ifdef USE_GOSSIP_QUERY
ln_anno_encoded_ids_t *p = SLIST_FIRST(&pChannel->gossip_query.request.send_encoded_ids);
while (p) {
ln_anno_encoded_ids_t *p_bak = p;
p = SLIST_NEXT(p, list);
utl_buf_free(&p_bak->encoded_short_ids);
UTL_DBG_FREE(p_bak);
}
#endif

ln_establish_free(pChannel);
}

Expand Down
98 changes: 58 additions & 40 deletions ln/ln.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <stdint.h>
#include <stdbool.h>
#include <sys/queue.h>

#include "utl_common.h"

Expand Down Expand Up @@ -82,6 +83,7 @@ extern "C" {
#define LN_BLK_FEEESTIMATE (6) ///< estimatefeeのブロック数(2以上)
#define LN_MIN_FINAL_CLTV_EXPIRY (9) ///< min_final_cltv_expiryのデフォルト値
#define LN_INVOICE_EXPIRY (3600) ///< invoice expiryのデフォルト値
#define LN_INVOICE_EXPIRY_MIN (60) ///< invoice expiry minimum

#define LN_FEE_COMMIT_BASE_WEIGHT (724ULL) ///< commit_tx base weight for the fee calculation

Expand Down Expand Up @@ -210,19 +212,6 @@ typedef enum {
* typedefs : HTLC
**************************************************************************/

/** @struct ln_fundin_t
* @brief open_channelでのfund_in情報
* @note
* - open_channelする方が #ln_establish_t .p_fundinに設定して使う
*/
typedef struct {
uint8_t txid[BTC_SZ_TXID]; ///< 2-of-2へ入金するTXID
int32_t index; ///< 未設定時(channelを開かれる方)は-1
uint64_t amount; ///< 2-of-2へ入金するtxのvout amount
utl_buf_t change_spk; ///< 2-of-2へ入金したお釣りの送金先ScriptPubkey
} ln_fundin_t;


/** @struct ln_establish_param_t
* @brief Establish関連のパラメータ
* @note
Expand All @@ -243,7 +232,6 @@ typedef struct {
* @brief [Establish]ワーク領域
*/
typedef struct {
ln_fundin_t *p_fundin; ///< 非NULL:open_channel側
ln_establish_param_t param; ///< channel establish parameter
} ln_establish_t;

Expand All @@ -262,9 +250,12 @@ typedef struct {
* @note
* - p_tx, p_htlc_idxsの添字
* - commit_tx: LN_CLOSE_IDX_COMMIT
* - to_local output: LN_CLOSE_IDX_TO_LOCAL
* - to_remote output: LN_CLOSE_IDX_TO_REMOTE
* - HTLC: LN_CLOSE_IDX_HTLC~
* - spending from to_local output tx: LN_CLOSE_IDX_TO_LOCAL
* - spending from to_remote output tx: LN_CLOSE_IDX_TO_REMOTE
* - HTLC_tx: LN_CLOSE_IDX_HTLC~
*
* - tx_buf.buf = btc_tx_t pointer array(len = tx_buf.size / sizeof(btc_tx_t*)
* - spending from HTLC_tx tx
*/
typedef struct {
int num; ///< p_txのtransaction数
Expand Down Expand Up @@ -299,24 +290,53 @@ typedef struct {
} ln_anno_param_t;


/** @typedef ln_gquery_t
#ifdef USE_GOSSIP_QUERY
/** @struct ln_anno_encoded_ids_t
* @brief encided_short_ids list
*/
typedef struct ln_anno_encoded_ids_t {
SLIST_ENTRY(ln_anno_encoded_ids_t) list;
utl_buf_t encoded_short_ids;
} ln_anno_encoded_ids_t;

SLIST_HEAD(ln_anno_encoded_ids_head_t, ln_anno_encoded_ids_t);


/** @typedef ln_gossip_query_t
* @brief
*/
typedef struct {
struct {
//for sending query_channel_range
uint32_t first_blocknum;

/**
* 0の場合、query_channel_rangeの送信可
* BOLT#07:
* MUST NOT send this if it has sent a previous query_channel_range to this peer and not received all reply_channel_range replies.
*/
uint32_t rest_blocks;

//for sending query_short_channel_ids
// 1. 受信したreply_channel_rangeのencoded_short_idsを展開する
// 2. 展開したencoded_short_idsを、1回に受信できるサイズにしてsend_encoded_idsに積む
struct ln_anno_encoded_ids_head_t send_encoded_ids;

/**
* for sending query_short_channel_ids
* BOLT#07:
* MUST NOT send query_short_channel_ids if it has sent a previous query_short_channel_ids to this peer and not received reply_short_channel_ids_end.
*/
bool wait_query_short_channel_ids_end; //true:reply_short_channel_ids_end待ち
// == can't send query_short_channel_ids
} request;

//for receiving query_channel_range
// query_channel_rangeを1回受信すると、その範囲のreply_channel_rangeを返す。
// reply_channel_rangeは複数回に分ける可能性がある(サイズ次第)。
// ここでは、query_channel_range受信時にp_reply_rangeを全部準備する想定。
// sent_reply_range_numは送信ごとにインクリメントし、reply_range_numと等しくなれば全送信完了。
//
// だが。
// reply_channel_rangeで返すべきデータがBOLT messageの最大長になるとしよう。
// encoded_short_idsはきっとzlib圧縮されているだろう。
// BOLTの考察で、zlib圧縮して65,535byteだった場合、short_channel_idsであれば
// 展開後のサイズは3,669,960byteくらいが最大になる、とのことであった。
// https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#query-messages
// short_channel_id数にすると46万程度。
// 現状では46万ものチャネル情報はないため、複数回のreply_channel_range返信は後回しとする。
// uint32_t sent_reply_range_num; ///< sent reply_channel_range count
// uint32_t reply_range_num; ///< p_reply_range count
// struct {
Expand All @@ -330,19 +350,12 @@ typedef struct {
// 可能性として、query_short_channel_idsで要求された個数よりも
// 現状の数が少ないことがありうる(closeされた場合など)。
// その場合はsent_reply_anno_numを進めて続けるので、どちらかといえばindexか?
uint32_t sent_reply_anno_num; ///< sent announcment count
uint32_t reply_anno_num; ///< p_reply_short_ids count
uint64_t *p_reply_short_ids; ///< decoded short_channel_ids

//for sending query_short_channel_ids
// query_short_channel_idsを1回送信すると、reply_short_channel_ids_endを
// 受信するまではquery_short_channel_idsを送信できない。
// node接続後に問い合わせて、それ以降問い合わせたいことがあるかどうかはわからないが、
// 一応管理しておく。
bool wait_query_short_channel_ids_end; //true:reply_short_channel_ids_end待ち
// == can't send query_short_channel_ids
} ln_gquery_t;
// uint32_t sent_reply_anno_num; ///< sent announcment count
// uint32_t reply_anno_num; ///< p_reply_short_ids count
// uint64_t *p_reply_short_ids; ///< decoded short_channel_ids

} ln_gossip_query_t;
#endif

/// @}

Expand Down Expand Up @@ -372,7 +385,8 @@ struct ln_channel_t {
ln_funding_info_t funding_info; ///< [FUND_01]funding info
ln_establish_t establish; ///< [FUND_02]Establishワーク領域
uint8_t funding_blockhash[BTC_SZ_HASH256]; ///< [FUNDSPV_01]funding_txがマイニングされたblock hash
uint32_t funding_last_confirm; ///< [FUNDSPV_02]confirmation at calling btcrpc_set_channel()
uint32_t funding_last_confirm; ///< [FUNDSPV_02]last unspent funding_tx confirmation
// update: funding_unspent()

//msg:announce
uint8_t anno_flag; ///< [ANNO_01]announcement_signaturesなど
Expand Down Expand Up @@ -413,8 +427,10 @@ struct ln_channel_t {
uint8_t prev_remote_commit_txid[BTC_SZ_TXID];
///< [COMM_03]previous remote commit tx's txid (for second last remote unilateral close)

#ifdef USE_GOSSIP_QUERY
//gossip_queries
ln_gquery_t gquery; ///< [GQRY_01]gossip_queries
ln_gossip_query_t gossip_query; ///< [GQRY_01]gossip_queries
#endif

//last error
int err; ///< [ERRO_01]error code(ln_err.h)
Expand Down Expand Up @@ -906,6 +922,8 @@ bool ln_is_announced(const ln_channel_t *pChannel);
*
* @param[in] feerate_kb bitcoindから取得したfeerate/KB
* @return feerate_per_kw
* @note
* - #LN_FEERATE_PER_KW_MIN未満になる場合、#LN_FEERATE_PER_KW_MINを返す
*/
uint32_t ln_feerate_per_kw_calc(uint64_t feerate_kb);

Expand Down
258 changes: 205 additions & 53 deletions ln/ln_anno.c

Large diffs are not rendered by default.

24 changes: 8 additions & 16 deletions ln/ln_cb.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef enum {
LN_CB_TYPE_WAIT_FUNDING_TX, ///< funding_tx安定待ち要求
LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV, ///< funding_locked受信通知
LN_CB_TYPE_NOTIFY_ANNODB_UPDATE, ///< announcement DB更新通知
LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV, ///< update_add_htlc受信通知
LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV, ///< update_add_htlc受信通知(final node only)
LN_CB_TYPE_START_BWD_DEL_HTLC, ///< HTLC削除処理開始
LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV, ///< update_fulfill_htlc受信通知
LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE, ///< revoke_and_ack交換通知
Expand Down Expand Up @@ -82,9 +82,9 @@ typedef void (*ln_callback_t)(ln_cb_type_t Type, void *pCommonParam, void *pType
*/
typedef struct {
btc_tx_t *p_tx;
utl_buf_t buf_tx; //
uint64_t fundin_amount; //(SPV未使用)fund-inするamount[satoshi]
bool ret; //署名結果
const utl_buf_t *p_buf_scriptpk; //funding scriputPubKey
uint64_t amount; //amount[satoshi]
bool ret; //署名結果
} ln_cb_param_sign_funding_tx_t;


Expand All @@ -100,20 +100,12 @@ typedef struct {
} ln_cb_param_wait_funding_tx_t;


/** @struct ln_cb_param_nofity_add_htlc_recv_t
* @brief update_add_htlc受信通知(#LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV)
/** @struct ln_cb_param_nofity_final_add_htlc_recv_t
* @brief update_add_htlc受信通知(#LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV)
*/
typedef struct {
bool ret; ///< callback処理結果
uint64_t next_short_channel_id;
uint64_t prev_htlc_id; ///< HTLC id
const uint8_t *p_payment_hash; ///< payment_hash
const ln_msg_x_update_add_htlc_t *p_forward_param;
uint64_t amount_msat; ///<
uint32_t cltv_expiry; ///<
utl_buf_t *p_onion_reason; ///< 変換後onionパケット(ok==true) or fail reason(ok==false)
const utl_buf_t *p_shared_secret; ///< onion shared secret
} ln_cb_param_nofity_add_htlc_recv_t;
ln_msg_x_update_add_htlc_t *p_add_htlc;
} ln_cb_param_nofity_final_add_htlc_recv_t;


typedef struct {
Expand Down
10 changes: 2 additions & 8 deletions ln/ln_commit_tx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ uint64_t HIDDEN ln_commit_tx_calc_obscured_commit_num_mask(const uint8_t *pOpenP
{
uint64_t obs = 0;
uint8_t base[32];
mbedtls_sha256_context ctx;

mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pOpenPayBasePt, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pAcceptPayBasePt, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, base);
mbedtls_sha256_free(&ctx);

btc_md_sha256cat(base, pOpenPayBasePt, BTC_SZ_PUBKEY, pAcceptPayBasePt, BTC_SZ_PUBKEY);

for (int lp = 0; lp < M_SZ_OBSCURED_COMMIT_NUM; lp++) {
obs <<= 8;
Expand Down
74 changes: 27 additions & 47 deletions ln/ln_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
#define LN_DB_WALLET_TYPE_TO_REMOTE ((uint8_t)2)
#define LN_DB_WALLET_TYPE_HTLC_OUTPUT ((uint8_t)3)

#define LN_DB_WALLET_INIT(t) { t/*type*/, NULL/*p_txid*/, 0/*index*/, 0/*amount*/, 0/*sequence*/, 0/*locktime*/, 0/*wit_item_cnt*/, NULL/*p_wit_items*/ }
#define LN_DB_WALLET_INIT(t) { t/*type*/, NULL/*p_txid*/, 0/*index*/, 0/*amount*/, 0/*sequence*/, 0/*locktime*/, 0/*wit_item_cnt*/, NULL/*p_wit_items*/, 0/*mined_height*/ }


/**************************************************************************
Expand Down Expand Up @@ -78,6 +78,17 @@ typedef enum {
} ln_db_cur_t;


/** @typedef ln_db_preimage_state_t
* @brief created preimage status
*/
typedef enum {
LN_DB_PREIMAGE_STATE_UNUSED = 0, ///< unused(including outdated)
LN_DB_PREIMAGE_STATE_USED = 1, ///< used(already received)
LN_DB_PREIMAGE_STATE_EXPIRE = 2, ///< unused and expire(not save DB)
LN_DB_PREIMAGE_STATE_UNKNOWN = UINT8_MAX
} ln_db_preimage_state_t;


/** @typedef ln_db_preimage_t
* @brief preimage/invoice
*/
Expand All @@ -86,6 +97,7 @@ typedef struct {
uint64_t amount_msat;
uint64_t creation_time;
uint32_t expiry;
ln_db_preimage_state_t state;
} ln_db_preimage_t;


Expand All @@ -106,6 +118,7 @@ typedef struct {
uint32_t locktime; ///< <locktime>
uint32_t wit_item_cnt;
utl_buf_t *p_wit_items; ///< p_wit_items[wit_item_cnt]
uint32_t mined_height; ///< outpointがminingされたblockcount
} ln_db_wallet_t;


Expand Down Expand Up @@ -172,10 +185,11 @@ typedef bool (*ln_db_func_wallet_t)(const ln_db_wallet_t *pWallet, void *pParam)
* @param[in,out] pWif ノードの秘密鍵
* @param[in,out] pNodeName ノード名
* @param[in,out] pPort ポート番号
* @param[in] bAutoUpdate true:auto version update(if it can)
* @param[in] bStdErr エラーをstderrに出力
* @retval true 初期化成功
*/
bool ln_db_init(char *pWif, char *pNodeName, uint16_t *pPort, bool bStdErr);
bool ln_db_init(char *pWif, char *pNodeName, uint16_t *pPort, bool bAutoUpdate, bool bStdErr);


/** db終了
Expand Down Expand Up @@ -622,55 +636,18 @@ ln_db_route_skip_t ln_db_route_skip_search(uint64_t ShortChannelId);
bool ln_db_route_skip_drop(bool bTemp);


/********************************************************************
* invoice
********************************************************************/

#if 0 //XXX: deprecated
/** "routepay" invoice保存
*
*/
bool ln_db_invoice_save(const char *pInvoice, uint64_t AddAmountMsat, const uint8_t *pPaymentHash);


/** "routepay" invoice取得
*
*/
bool ln_db_invoice_load(char **ppInvoice, uint64_t *pAddAmountMsat, const uint8_t *pPaymentHash);


/** "routepay" 全payment_hash取得
*
* @attention
* - 内部で UTL_DBG_REALLOC()するため、使用後に UTL_DBG_FREE()すること
*/
int ln_db_invoice_load_payment_hashs(uint8_t **ppPaymentHash);


/** "routepay" invoice削除
*
*/
bool ln_db_invoice_del(const uint8_t *pPaymentHash);


/** "routepay" DB削除
*
*/
bool ln_db_invoice_drop(void);
#endif


/********************************************************************
* payment preimage
********************************************************************/

/** preimage保存
*
* @param[in,out] pPreimage creation_timeのみoutput
* @param[in,out] pDb
* @param[in] pPreimage preimage information
* @param[in] pBolt11 BOLT11 format invoice
* @param[in,out] pDb (nullable)
* @retval true
*/
bool ln_db_preimage_save(ln_db_preimage_t *pPreimage, void *pDb);
bool ln_db_preimage_save(const ln_db_preimage_t *pPreimage, const char *pBolt11, void *pDb);


/** preimage削除
Expand Down Expand Up @@ -722,15 +699,18 @@ void ln_db_preimage_cur_close(void *pCur, bool bCommit);
* @param[in] pCur
* @param[out] pDetect true:取得成功
* @param[out] pPreimage
* @param[out] ppBolt11 (not NULL)BOLT11 invoice string
* @retval true エラーでは無い
*/
bool ln_db_preimage_cur_get(void *pCur, bool *pDetect, ln_db_preimage_t *pPreimage);
bool ln_db_preimage_cur_get(void *pCur, bool *pDetect, ln_db_preimage_t *pPreimage, const char **ppBolt11);


/** preimage expiry更新
/** preimage使用済み
*
* @param[in] pPreimage
* @retval true
*/
bool ln_db_preimage_set_expiry(void *pCur, uint32_t Expiry);
bool ln_db_preimage_used(const uint8_t *pPreimage);


/********************************************************************
Expand Down Expand Up @@ -794,7 +774,7 @@ bool ln_db_revoked_tx_save(const ln_channel_t *pChannel, bool bUpdate, void *pDb
* @param[in] Index
* @retval true 読み込み成功
*/
bool ln_db_wallet_load(utl_buf_t *pBuf, const uint8_t *pTxid, uint32_t Index);
//bool ln_db_wallet_load(utl_buf_t *pBuf, const uint8_t *pTxid, uint32_t Index);


/** 送金可能なINPUTを登録
Expand Down
600 changes: 315 additions & 285 deletions ln/ln_db_lmdb.c

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ln/ln_db_lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ typedef enum {
LN_LMDB_DB_TYPE_CNLANNO_INFO,
LN_LMDB_DB_TYPE_NODEANNO_INFO,
LN_LMDB_DB_TYPE_ROUTE_SKIP,
LN_LMDB_DB_TYPE_INVOICE,
LN_LMDB_DB_TYPE_PREIMAGE,
LN_LMDB_DB_TYPE_PAYMENT_HASH,
LN_LMDB_DB_TYPE_VERSION,
Expand Down
46 changes: 6 additions & 40 deletions ln/ln_derkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,8 @@ bool HIDDEN ln_derkey_pubkey(uint8_t *pPubKey,
int ret;

//sha256(per-commitment-point || basepoint)
mbedtls_sha256_context ctx;
uint8_t hash[BTC_SZ_HASH256];
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pPerCommitPoint, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pBasePoint, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, hash);
mbedtls_sha256_free(&ctx);
btc_md_sha256cat(hash, pPerCommitPoint, BTC_SZ_PUBKEY, pBasePoint, BTC_SZ_PUBKEY);

mbedtls_mpi h;
mbedtls_mpi_init(&h);
Expand Down Expand Up @@ -92,13 +86,7 @@ bool HIDDEN ln_derkey_privkey(uint8_t *pPrivKey,
int ret;

//sha256(per-commitment-point || basepoint)
mbedtls_sha256_context ctx;
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pPerCommitPoint, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pBasePoint, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, pPrivKey);
mbedtls_sha256_free(&ctx);
btc_md_sha256cat(pPrivKey, pPerCommitPoint, BTC_SZ_PUBKEY, pBasePoint, BTC_SZ_PUBKEY);

mbedtls_mpi a;
mbedtls_mpi b;
Expand Down Expand Up @@ -143,24 +131,13 @@ bool HIDDEN ln_derkey_revocation_pubkey(uint8_t *PubKey,
int ret;
uint8_t hash1[BTC_SZ_HASH256];
uint8_t hash2[BTC_SZ_HASH256];
mbedtls_sha256_context ctx;
mbedtls_ecp_keypair keypair;

//sha256(revocation-basepoint || per-commitment-point)
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pBasePoint, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pPerCommitPoint, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, hash1);
mbedtls_sha256_free(&ctx);
btc_md_sha256cat(hash1, pBasePoint, BTC_SZ_PUBKEY, pPerCommitPoint, BTC_SZ_PUBKEY);

//sha256(per-commitment-point || revocation-basepoint)
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pPerCommitPoint, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pBasePoint, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, hash2);
mbedtls_sha256_free(&ctx);
btc_md_sha256cat(hash2, pPerCommitPoint, BTC_SZ_PUBKEY, pBasePoint, BTC_SZ_PUBKEY);

size_t sz;
mbedtls_mpi h1;
Expand Down Expand Up @@ -218,16 +195,10 @@ bool HIDDEN ln_derkey_revocation_privkey(uint8_t *pPrivKey,
int ret;
uint8_t hash1[BTC_SZ_HASH256];
uint8_t hash2[BTC_SZ_HASH256];
mbedtls_sha256_context ctx;
mbedtls_ecp_keypair keypair;

//sha256(revocation-basepoint || per-commitment-point)
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pBasePoint, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pPerCommitPoint, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, hash1);
mbedtls_sha256_free(&ctx);
btc_md_sha256cat(hash1, pBasePoint, BTC_SZ_PUBKEY, pPerCommitPoint, BTC_SZ_PUBKEY);

mbedtls_mpi a;
mbedtls_mpi b;
Expand All @@ -243,12 +214,7 @@ bool HIDDEN ln_derkey_revocation_privkey(uint8_t *pPrivKey,
if (ret) goto LABEL_EXIT;

//sha256(per-commitment-point || revocation-basepoint)
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
mbedtls_sha256_update(&ctx, pPerCommitPoint, BTC_SZ_PUBKEY);
mbedtls_sha256_update(&ctx, pBasePoint, BTC_SZ_PUBKEY);
mbedtls_sha256_finish(&ctx, hash2);
mbedtls_sha256_free(&ctx);
btc_md_sha256cat(hash2, pPerCommitPoint, BTC_SZ_PUBKEY, pBasePoint, BTC_SZ_PUBKEY);

mbedtls_mpi_read_binary(&b, hash2, BTC_SZ_PRIVKEY);
mbedtls_mpi_read_binary(&c, pPerCommitSecret, BTC_SZ_PRIVKEY);
Expand Down
150 changes: 53 additions & 97 deletions ln/ln_establish.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static bool create_funding_tx(ln_channel_t *pChannel, bool bSign);
**************************************************************************/

bool /*HIDDEN*/ ln_open_channel_send(
ln_channel_t *pChannel, const ln_fundin_t *pFundin, uint64_t FundingSat, uint64_t PushMSat, uint32_t FeeRate,
ln_channel_t *pChannel, uint64_t FundingSat, uint64_t PushMSat, uint32_t FeeRate,
uint8_t PrivChannel)
{
if (!M_INIT_FLAG_EXCHNAGED(pChannel->init_flag)) {
Expand All @@ -102,17 +102,21 @@ bool /*HIDDEN*/ ln_open_channel_send(
M_SET_ERR(pChannel, LNERR_INV_VALUE, "feerate_per_kw too low");
return false;
}
if (FundingSat < LN_FUNDING_SATOSHIS_MIN) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "funding_satoshis too low");
return false;
} else if (FundingSat > LN_FUNDING_SATOSHIS_MAX) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "funding_satoshis too high");
return false;
}
if (LN_SATOSHI2MSAT(FundingSat) < PushMSat) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "push_msat too high");
return false;
}

//temporary_channel_id
btc_rng_rand(pChannel->channel_id, LN_SZ_CHANNEL_ID);

#if defined(USE_BITCOIND)
pChannel->establish.p_fundin = (ln_fundin_t *)UTL_DBG_MALLOC(sizeof(ln_fundin_t));
memcpy(pChannel->establish.p_fundin, pFundin, sizeof(ln_fundin_t));
#else
(void)pFundin;
#endif

//open_channel
ln_msg_open_channel_t msg;
msg.p_chain_hash = ln_genesishash_get();
Expand Down Expand Up @@ -181,20 +185,30 @@ bool HIDDEN ln_open_channel_recv(ln_channel_t *pChannel, const uint8_t *pData, u
M_SET_ERR(pChannel, LNERR_INV_SIDE, "not fundee");
return false;
}
if (ln_funding_info_funding_now(&pChannel->funding_info)) {
M_SET_ERR(pChannel, LNERR_ALREADY_FUNDING, "already funding");
return false;
}
if (pChannel->short_channel_id != 0) {
M_SET_ERR(pChannel, LNERR_ALREADY_FUNDING, "already established");
return false;
}

ln_msg_open_channel_t msg;
if (!ln_msg_open_channel_read(&msg, pData, Len)) {
M_SET_ERR(pChannel, LNERR_MSG_READ, "read message");
return false;
}

if (ln_funding_info_funding_now(&pChannel->funding_info) || (pChannel->short_channel_id != 0)) {
//NOTE:
// lnd return RPC Error code 177 receiving this message.
// "Multiple"=177, "Hello Multiple"=172, "multiple"=209, ...
// Please be careful if you change this message.
const char *p_err_msg = "Multiple channels unsupported";
ln_msg_error_t errmsg;
errmsg.p_channel_id = msg.p_temporary_channel_id;
errmsg.p_data = (const uint8_t *)p_err_msg;
errmsg.len = strlen(p_err_msg);
utl_buf_t buf = UTL_BUF_INIT;
ln_msg_error_write(&buf, &errmsg);
ln_callback(pChannel, LN_CB_TYPE_SEND_MESSAGE, &buf);
utl_buf_free(&buf);
return true;
}

memcpy(pChannel->channel_id, msg.p_temporary_channel_id, LN_SZ_CHANNEL_ID);
memcpy(pChannel->keys_remote.basepoints[LN_BASEPOINT_IDX_FUNDING], msg.p_funding_pubkey, BTC_SZ_PUBKEY);
memcpy(pChannel->keys_remote.basepoints[LN_BASEPOINT_IDX_REVOCATION], msg.p_revocation_basepoint, BTC_SZ_PUBKEY);
Expand All @@ -221,14 +235,23 @@ bool HIDDEN ln_open_channel_recv(ln_channel_t *pChannel, const uint8_t *pData, u
return false;
}

uint64_t fee = ln_estimate_initcommittx_fee(msg.feerate_per_kw);
if (msg.funding_satoshis < fee + BTC_DUST_LIMIT + LN_FUNDING_SATOSHIS_MIN) {
if (msg.funding_satoshis < LN_FUNDING_SATOSHIS_MIN) {
char str[256];
snprintf(str, sizeof(str), "funding_satoshis too low(<%d)",
LN_FUNDING_SATOSHIS_MIN);
M_SEND_ERR(pChannel, LNERR_INV_VALUE, "%s", str);
return false;
} else if (msg.funding_satoshis > LN_FUNDING_SATOSHIS_MAX) {
char str[256];
sprintf(str, "funding_satoshis too low(%" PRIu64 " < %" PRIu64 ")",
msg.funding_satoshis, fee + BTC_DUST_LIMIT + LN_FUNDING_SATOSHIS_MIN);
snprintf(str, sizeof(str), "funding_satoshis too high(>%d)",
LN_FUNDING_SATOSHIS_MAX);
M_SEND_ERR(pChannel, LNERR_INV_VALUE, "%s", str);
return false;
}
if (LN_SATOSHI2MSAT(msg.funding_satoshis) < msg.push_msat) {
M_SEND_ERR(pChannel, LNERR_INV_VALUE, "push_msat too high");
return false;
}

//BOLT02
// The sender:
Expand Down Expand Up @@ -460,7 +483,7 @@ bool HIDDEN ln_funding_created_recv(ln_channel_t *pChannel, const uint8_t *pData
return false;
}

ln_funding_info_set_txindex(&pChannel->funding_info, msg.funding_output_index);
pChannel->funding_info.txindex = msg.funding_output_index;

//署名チェック用
btc_tx_free(&pChannel->funding_info.tx_data);
Expand Down Expand Up @@ -611,9 +634,6 @@ bool HIDDEN ln_funding_locked_recv(ln_channel_t *pChannel, const uint8_t *pData,
//pubkeys.prev_per_commitment_pointはrevoke_and_ackでのみ更新する
memcpy(pChannel->keys_remote.per_commitment_point, msg.p_next_per_commitment_point, BTC_SZ_PUBKEY);

//funding中終了
ln_establish_free(pChannel);

ln_derkey_update_script_pubkeys(&pChannel->keys_local, &pChannel->keys_remote);
ln_print_keys(pChannel);
M_DB_CHANNEL_SAVE(pChannel);
Expand Down Expand Up @@ -859,85 +879,21 @@ static bool create_funding_tx(ln_channel_t *pChannel, bool bSign)
&pChannel->funding_info.wit_script, &pChannel->funding_info.key_order,
pChannel->keys_local.basepoints[LN_BASEPOINT_IDX_FUNDING],
pChannel->keys_remote.basepoints[LN_BASEPOINT_IDX_FUNDING]);

if (pChannel->establish.p_fundin != NULL) {
//output
ln_funding_info_set_txindex(&pChannel->funding_info, M_FUNDING_INDEX); //TODO: vout#0は2-of-2、vout#1はchangeにしている
//vout#0:P2WSH - 2-of-2 : M_FUNDING_INDEX
btc_sw_add_vout_p2wsh_wit(
&pChannel->funding_info.tx_data, pChannel->funding_info.funding_satoshis, &pChannel->funding_info.wit_script);

//vout#1:P2WPKH - change(amountは後で代入)
btc_tx_add_vout_spk(&pChannel->funding_info.tx_data, (uint64_t)-1, &pChannel->establish.p_fundin->change_spk);

//input
//vin#0
btc_tx_add_vin(
&pChannel->funding_info.tx_data, pChannel->establish.p_fundin->txid, pChannel->establish.p_fundin->index);

//FEE計算
// LEN+署名(72) + LEN+公開鍵(33)
// この時点では、pChannel->funding_info.tx_data に scriptSig(23byte)とwitness(1+72+1+33)が入っていない。
//
// (length)
// version:4
// flag:1
// mark:1
// vin_cnt: 1
// txid+index: 36
// scriptSig: 1+23
// sequence: 4
// vout_cnt: 2
// amount: 8
// scriptPubKey: 1+34
// amount: 8
// scriptPubKey: 1+23
// wit_item_cnt: 2
// sig: 1+72
// pub: 1+33
// locktime: 4
//ToDo: issue #344: nested in BIP16 size
uint64_t fee = ln_calc_fee(
LN_SZ_FUNDINGTX_VSIZE,
ln_update_info_get_feerate_per_kw_committed(&pChannel->update_info, true));
LOGD("fee=%" PRIu64 "\n", fee);
if (pChannel->establish.p_fundin->amount >= pChannel->funding_info.funding_satoshis + fee) {
pChannel->funding_info.tx_data.vout[1].value =
pChannel->establish.p_fundin->amount - pChannel->funding_info.funding_satoshis - fee;
} else {
LOGE("fail: amount too short:\n");
LOGD(" amount=%" PRIu64 "\n", pChannel->establish.p_fundin->amount);
LOGD(" funding_satoshis=%" PRIu64 "\n", pChannel->funding_info.funding_satoshis);
LOGD(" fee=%" PRIu64 "\n", fee);
return false;
}
} else {
//for SPV
//fee計算と署名はSPVに任せる(LN_CB_TYPE_SIGN_FUNDING_TXで吸収する)

//funding address(vout[0])
btc_sw_add_vout_p2wsh_wit(
&pChannel->funding_info.tx_data, pChannel->funding_info.funding_satoshis, &pChannel->funding_info.wit_script);
btc_tx_add_vin(&pChannel->funding_info.tx_data, ln_funding_info_txid(&pChannel->funding_info), 0); //dummy
}

//sign
if (!bSign) return true; //not sign

utl_buf_t two_of_two = UTL_BUF_INIT;
btc_script_p2wsh_create_scriptpk(&two_of_two, &pChannel->funding_info.wit_script);

ln_cb_param_sign_funding_tx_t param;
param.p_tx = &pChannel->funding_info.tx_data;
utl_buf_init(&param.buf_tx);
if (pChannel->establish.p_fundin != NULL) {
btc_tx_write(param.p_tx, &param.buf_tx);
param.fundin_amount = pChannel->establish.p_fundin->amount;
} else {
param.fundin_amount = 0;
}
param.p_buf_scriptpk = &two_of_two;
param.amount = pChannel->funding_info.funding_satoshis;
ln_callback(pChannel, LN_CB_TYPE_SIGN_FUNDING_TX, &param);
utl_buf_free(&param.buf_tx);
if (!param.ret) {
LOGE("fail: signature\n");
btc_tx_free(&pChannel->funding_info.tx_data);
utl_buf_free(&two_of_two);
return false;
}

Expand All @@ -948,19 +904,19 @@ static bool create_funding_tx(ln_channel_t *pChannel, bool bSign)
M_DBG_PRINT_TX(&pChannel->funding_info.tx_data);

//search funding vout
utl_buf_t two_of_two = UTL_BUF_INIT;
btc_script_p2wsh_create_scriptpk(&two_of_two, &pChannel->funding_info.wit_script);
uint32_t lp;
for (lp = 0; lp < pChannel->funding_info.tx_data.vout_cnt; lp++) {
if (utl_buf_equal(&pChannel->funding_info.tx_data.vout[lp].script, &two_of_two)) break;
}
utl_buf_free(&two_of_two);
if (lp == pChannel->funding_info.tx_data.vout_cnt) {
//not found
LOGE("fail: vout not found\n");
btc_tx_free(&pChannel->funding_info.tx_data);
return false;
}
ln_funding_info_set_txindex(&pChannel->funding_info, lp);
pChannel->funding_info.txindex = lp;

LOGD("funding_txindex=%d\n", ln_funding_info_txindex(&pChannel->funding_info));
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions ln/ln_establish.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@
/** send open_channel
*
* @param[in,out] pChannel channel info
* @param[in] pFundin fund-in情報
* @param[in] FundingSat fundingするamount[satoshi]
* @param[in] PushMSat push_msatするamount[msat]
* @param[in] FeeRate feerate_per_kw
* @param[in] PrivChannel !=0: private channel
* retval true 成功
*/
bool /*HIDDEN*/ ln_open_channel_send(
ln_channel_t *pChannel, const ln_fundin_t *pFundin, uint64_t FundingSat, uint64_t PushMSat, uint32_t FeeRate,
ln_channel_t *pChannel, uint64_t FundingSat, uint64_t PushMSat, uint32_t FeeRate,
uint8_t PrivChannel);
bool HIDDEN ln_open_channel_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len);
bool HIDDEN ln_accept_channel_send(ln_channel_t *pChannel);
Expand Down
6 changes: 0 additions & 6 deletions ln/ln_funding_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ const uint8_t *ln_funding_info_txid(const ln_funding_info_t *pFundingInfo)
}


void ln_funding_info_set_txindex(ln_funding_info_t *pFundingInfo, uint32_t Txindex)
{
pFundingInfo->txindex = Txindex;
}


uint32_t ln_funding_info_txindex(const ln_funding_info_t *pFundingInfo)
{
return pFundingInfo->txindex;
Expand Down
5 changes: 1 addition & 4 deletions ln/ln_funding_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* macros
**************************************************************************/

#define LN_FUNDING_SATOSHIS_MIN (1000) ///< minimum funding_sat(BOLTに規定はない)
#define LN_FUNDING_SATOSHIS_MIN (100000) ///< minimum funding_sat(BOLTに規定はない)
#define LN_FUNDING_SATOSHIS_MAX (0x1000000 - 1) //2^24-1


Expand Down Expand Up @@ -90,9 +90,6 @@ void ln_funding_info_set_txid(ln_funding_info_t *pFundingInfo, const uint8_t *pT
const uint8_t *ln_funding_info_txid(const ln_funding_info_t *pFundingInfo);


void ln_funding_info_set_txindex(ln_funding_info_t *pFundingInfo, uint32_t Txindex);


/** funding_txのTXINDEX取得
*
* @param[in] pFundingInfo funding info
Expand Down
6 changes: 4 additions & 2 deletions ln/ln_htlc_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ bool HIDDEN ln_htlc_tx_create(
int Index)
{
//vout
if (!btc_sw_add_vout_p2wsh_wit(pTx, Value, pWitScript)) return false;
pTx->vout[0].opt = (uint16_t)Type;
if (pWitScript != NULL) {
if (!btc_sw_add_vout_p2wsh_wit(pTx, Value, pWitScript)) return false;
pTx->vout[0].opt = (uint16_t)Type;
}
switch (Type) {
case LN_COMMIT_TX_OUTPUT_TYPE_RECEIVED:
LOGD("HTLC Success\n");
Expand Down
2 changes: 2 additions & 0 deletions ln/ln_invoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define LN_INVOICE_TESTNET ((uint8_t)5)
#define LN_INVOICE_REGTEST ((uint8_t)6)

#define LN_INVOICE_DESC_MAX (32)

#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
Expand Down
20 changes: 20 additions & 0 deletions ln/ln_msg_anno.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ static void announcement_signatures_print(const ln_msg_announcement_signatures_t
LOGD("bitcoin_signature: ");
DUMPD(pMsg->p_bitcoin_signature, LN_SZ_SIGNATURE);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}
#endif
Expand Down Expand Up @@ -281,6 +283,8 @@ static void channel_announcement_print(const ln_msg_channel_announcement_t *pMsg
LOGD("bitcoin_key_2: ");
DUMPD(pMsg->p_bitcoin_key_2, BTC_SZ_PUBKEY);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -452,6 +456,8 @@ static void node_announcement_print(const ln_msg_node_announcement_t *pMsg)
LOGD("addresses: ");
DUMPD(pMsg->p_addresses, pMsg->addrlen);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif
}
#endif
Expand Down Expand Up @@ -541,6 +547,8 @@ static void node_announcement_addresses_print(const ln_msg_node_announcement_add
LOGD("port: %u\n", addr_desc->port);
}
LOGD("--------------------------------\n");
#else
(void)pAddrs;
#endif
}
#endif
Expand Down Expand Up @@ -665,6 +673,8 @@ static void channel_update_print(const ln_msg_channel_update_t *pMsg)
LOGD("htlc_maximum_msat: %" PRIu64 "\n", pMsg->htlc_maximum_msat);
}
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -764,6 +774,8 @@ static void query_short_channel_ids_print(const ln_msg_query_short_channel_ids_t
}
DUMPD(pMsg->p_encoded_short_ids, len);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -822,6 +834,8 @@ static void reply_short_channel_ids_end_print(const ln_msg_reply_short_channel_i
DUMPD(pMsg->p_chain_hash, BTC_SZ_HASH256);
LOGD("complete: %02x\n", pMsg->complete);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -883,6 +897,8 @@ static void query_channel_range_print(const ln_msg_query_channel_range_t *pMsg)
LOGD("first_blocknum: %" PRIu32 "\n", pMsg->first_blocknum);
LOGD("number_of_blocks: %" PRIu32 "\n", pMsg->number_of_blocks);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -958,6 +974,8 @@ static void reply_channel_range_print(const ln_msg_reply_channel_range_t *pMsg)
}
DUMPD(pMsg->p_encoded_short_ids, len);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -1021,6 +1039,8 @@ static void gossip_timestamp_filter_print(const ln_msg_gossip_timestamp_filter_t
LOGD("first_timestamp: %" PRIu32 "(%s)\n", pMsg->first_timestamp, str_time);
LOGD("timestamp_range: %" PRIu32 "\n", pMsg->timestamp_range);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down
4 changes: 4 additions & 0 deletions ln/ln_msg_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ static void shutdown_print(const ln_msg_shutdown_t *pMsg)
LOGD("scriptpubkey: ");
DUMPD(pMsg->p_scriptpubkey, pMsg->len);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -180,5 +182,7 @@ static void closing_signed_print(const ln_msg_closing_signed_t *pMsg)
LOGD("signature: ");
DUMPD(pMsg->p_signature, LN_SZ_SIGNATURE);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}
12 changes: 12 additions & 0 deletions ln/ln_msg_establish.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ static void open_channel_print(const ln_msg_open_channel_t *pMsg)
LOGD("shutdown_scriptpubkey: ");
DUMPD(pMsg->p_shutdown_scriptpubkey, pMsg->shutdown_len);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -374,6 +376,8 @@ static void accept_channel_print(const ln_msg_accept_channel_t *pMsg)
LOGD("shutdown_scriptpubkey: ");
DUMPD(pMsg->p_shutdown_scriptpubkey, pMsg->shutdown_len);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -444,6 +448,8 @@ static void funding_created_print(const ln_msg_funding_created_t *pMsg)
LOGD("signature: ");
DUMPD(pMsg->p_signature, LN_SZ_SIGNATURE);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -507,6 +513,8 @@ static void funding_signed_print(const ln_msg_funding_signed_t *pMsg)
LOGD("signature: ");
DUMPD(pMsg->p_signature, LN_SZ_SIGNATURE);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -570,6 +578,8 @@ static void funding_locked_print(const ln_msg_funding_locked_t *pMsg)
LOGD("next_per_commitment_point: ");
DUMPD(pMsg->p_next_per_commitment_point, BTC_SZ_PUBKEY);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -654,5 +664,7 @@ static void channel_reestablish_print(const ln_msg_channel_reestablish_t *pMsg,
DUMPD(pMsg->p_my_current_per_commitment_point, BTC_SZ_PUBKEY);
}
LOGD("--------------------------------\n");
#else
(void)pMsg; (void)bOptionDataLossProtect;
#endif //PTARM_DEBUG
}
14 changes: 14 additions & 0 deletions ln/ln_msg_normalope.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ static void update_add_htlc_print(const ln_msg_update_add_htlc_t *pMsg)
LOGD("onion_routing_packet(top 34bytes only): ");
DUMPD(pMsg->p_onion_routing_packet, 34);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -201,6 +203,8 @@ static void update_fulfill_htlc_print(const ln_msg_update_fulfill_htlc_t *pMsg)
//DUMPD(pMsg->p_payment_preimage, BTC_SZ_PRIVKEY);
LOGD("p_payment_preimage: ???\n");
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -269,6 +273,8 @@ static void update_fail_htlc_print(const ln_msg_update_fail_htlc_t *pMsg)
LOGD("reason: ");
DUMPD(pMsg->p_reason, pMsg->len);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -338,6 +344,8 @@ static void update_fail_malformed_htlc_print(const ln_msg_update_fail_malformed_
DUMPD(pMsg->p_sha256_of_onion, BTC_SZ_HASH256);
LOGD("failure_code: %04x\n", pMsg->failure_code);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -410,6 +418,8 @@ static void commitment_signed_print(const ln_msg_commitment_signed_t *pMsg)
DUMPD(pMsg->p_htlc_signature + lp * LN_SZ_SIGNATURE, LN_SZ_SIGNATURE);
}
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -478,6 +488,8 @@ static void revoke_and_ack_print(const ln_msg_revoke_and_ack_t *pMsg)
LOGD("next_per_commitment_point: ");
DUMPD(pMsg->p_next_per_commitment_point, BTC_SZ_PUBKEY);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -540,5 +552,7 @@ static void update_fee_print(const ln_msg_update_fee_t *pMsg)
DUMPD(pMsg->p_channel_id, LN_SZ_CHANNEL_ID);
LOGD("feerate_per_kw: %u\n", pMsg->feerate_per_kw);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}
4 changes: 4 additions & 0 deletions ln/ln_msg_setupctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ static void init_print(const ln_msg_init_t *pMsg)
LOGD(" option_upfront_shutdown_script: %d\n", (pMsg->p_localfeatures[0] & 0x30) >> 4);
LOGD(" gossip_queries: %d\n", (pMsg->p_localfeatures[0] & 0xc0) >> 6);
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down Expand Up @@ -207,6 +209,8 @@ static void error_print(const ln_msg_error_t *pMsg)
}
LOGD2("\n");
LOGD("--------------------------------\n");
#else
(void)pMsg;
#endif //PTARM_DEBUG
}

Expand Down
57 changes: 40 additions & 17 deletions ln/ln_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool ln_node_init(const ln_node_t *pNode)
LOGD("port: %d\n", pNode->addr.port);

memcpy(&mNode, pNode, sizeof(ln_node_t));
if (!ln_db_init(wif, mNode.alias, &mNode.addr.port, true)) {
if (!ln_db_init(wif, mNode.alias, &mNode.addr.port, true, true)) {
LOGE("fail: db init\n");
goto LABEL_EXIT;
}
Expand All @@ -138,15 +138,11 @@ bool ln_node_init(const ln_node_t *pNode)
strncpy((char *)alias, mNode.alias, LN_SZ_ALIAS_STR);

if (mNode.addr.type == LN_ADDR_DESC_TYPE_IPV4) {
if (utl_net_ipv4_addr_is_routable(mNode.addr.addr)) {
addrs.addresses[0].type = mNode.addr.type;
addrs.addresses[0].p_addr = mNode.addr.addr;
addrs.addresses[0].port = mNode.addr.port;
addrs.num = 1;
} else {
LOGE("fail: not routable address\n");
return false;
}
// BTCPayServer unittest may use local address.
addrs.addresses[0].type = mNode.addr.type;
addrs.addresses[0].p_addr = mNode.addr.addr;
addrs.addresses[0].port = mNode.addr.port;
addrs.num = 1;
} else {
LOGD("no IP address\n");
addrs.num = 0;
Expand Down Expand Up @@ -270,6 +266,22 @@ bool ln_node_addr_dec(ln_node_conn_t *pNodeConn, const char *pConnStr)
}


bool ln_node_get_announceip(char *pIpStr)
{
bool ret = false;
if (mNode.addr.type == LN_ADDR_DESC_TYPE_IPV4) {
sprintf(pIpStr, "%d.%d.%d.%d:%d",
mNode.addr.addr[0],
mNode.addr.addr[1],
mNode.addr.addr[2],
mNode.addr.addr[3],
mNode.addr.port);
ret = true;
}
return ret;
}


/********************************************************************
* HIDDEN
********************************************************************/
Expand Down Expand Up @@ -426,16 +438,27 @@ static void print_node(void)
utl_dbg_dump(stdout, mNode.keys.pub, BTC_SZ_PUBKEY, true);
printf("alias= %s\n", mNode.alias);
printf("addr.type=%d\n", mNode.addr.type);
if (mNode.addr.type == LN_ADDR_DESC_TYPE_IPV4) {
printf("ipv4=%d.%d.%d.%d:%d\n",
mNode.addr.addr[0],
mNode.addr.addr[1],
mNode.addr.addr[2],
mNode.addr.addr[3],
mNode.addr.port);
char anno_ip[128];
if (ln_node_get_announceip(anno_ip)) {
printf("announce ipv4=%s\n", anno_ip);
} else {
printf("port=%d\n", mNode.addr.port);
}
printf("chain: ");
switch (btc_block_get_chain(ln_genesishash_get())) {
case BTC_BLOCK_CHAIN_BTCMAIN:
printf("bitcoin mainnet\n");
break;
case BTC_BLOCK_CHAIN_BTCTEST:
printf("bitcoin testnet\n");
break;
case BTC_BLOCK_CHAIN_BTCREGTEST:
printf("bitcoin regtest\n");
break;
default:
printf("unknown chain\n");
break;
}
printf("=============================================\n");
}

Expand Down
11 changes: 11 additions & 0 deletions ln/ln_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define LN_NODE_ADDR_INIT { LN_ADDR_DESC_TYPE_NONE, "", 0}
#define LN_NODE_INIT { {{0},{0}}, "", {0}, LN_NODE_ADDR_INIT }

#define LN_SZ_ADDRESS (250)
#define LN_SZ_ADDRESS_STR "250"


/********************************************************************
* typedefs
Expand Down Expand Up @@ -112,4 +115,12 @@ bool HIDDEN ln_node_search_node_id(uint8_t *pNodeId, uint64_t ShortChannelId);
*/
bool ln_node_addr_dec(ln_node_conn_t *pNodeConn, const char *pConnStr);


/** get announcement IP address string
*
* @param[out] pIpStr `ptarmd --announceip`
* @retval true success
*/
bool ln_node_get_announceip(char *pIpStr);

#endif /* LN_NODE_H__ */
37 changes: 26 additions & 11 deletions ln/ln_normalope.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ bool HIDDEN ln_update_fee_recv(ln_channel_t *pChannel, const uint8_t *pData, uin
LOGD("BEGIN\n");

ln_msg_update_fee_t msg;
uint32_t rate;
uint32_t old_fee;

if (!ln_msg_update_fee_read(&msg, pData, Len)) {
Expand All @@ -540,14 +539,20 @@ bool HIDDEN ln_update_fee_recv(ln_channel_t *pChannel, const uint8_t *pData, uin
return false;
}

ln_callback(pChannel, LN_CB_TYPE_GET_LATEST_FEERATE, &rate);
if (!M_UPDATEFEE_CHK_MIN_OK(msg.feerate_per_kw, rate)) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "too low feerate_per_kw from current");
return false;
}
if (!M_UPDATEFEE_CHK_MAX_OK(msg.feerate_per_kw, rate)) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "too large feerate_per_kw from current");
return false;
btc_block_chain_t gtype = btc_block_get_chain(ln_genesishash_get());
if (gtype == BTC_BLOCK_CHAIN_BTCMAIN) {
uint32_t rate;
ln_callback(pChannel, LN_CB_TYPE_GET_LATEST_FEERATE, &rate);
if (!M_UPDATEFEE_CHK_MIN_OK(msg.feerate_per_kw, rate)) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "too low feerate_per_kw from current");
return false;
}
if (!M_UPDATEFEE_CHK_MAX_OK(msg.feerate_per_kw, rate)) {
M_SET_ERR(pChannel, LNERR_INV_VALUE, "too large feerate_per_kw from current");
return false;
}
} else {
LOGD("skip: feerate range check\n");
}

uint16_t update_idx;
Expand Down Expand Up @@ -930,6 +935,9 @@ static bool poll_update_add_htlc_forward_origin(ln_channel_t *pChannel)
prev_short_channel_id, prev_htlc_id, preimage, p_cur)) {
LOGE("fail: ???\n");
}
ln_cb_param_nofity_final_add_htlc_recv_t param;
param.p_add_htlc = &msg;
ln_callback(pChannel, LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV, &param);
} else {
if (!ln_update_fail_htlc_forward_2(
prev_short_channel_id, prev_htlc_id, reason.buf, reason.len, p_cur)) {
Expand Down Expand Up @@ -1145,6 +1153,7 @@ void ln_idle_proc(ln_channel_t *pChannel, uint32_t FeeratePerKw)

if (!M_INIT_CH_EXCHANGED(pChannel->init_flag)) return;
if (!M_INIT_FLAG_REEST_EXCHNAGED(pChannel->init_flag)) return;
if (pChannel->status != LN_STATUS_NORMAL_OPE) return;

if (ln_is_shutdowning(pChannel)) {
/*ignore*/poll_update_add_htlc_forward_closing(pChannel);
Expand Down Expand Up @@ -1642,8 +1651,9 @@ static bool check_recv_add_htlc_bolt4_final(
bool detect = false;
for (;;) {
detect = false;
if (!ln_db_preimage_cur_get(p_cur, &detect, &preimage)) break; //from invoice
if (!ln_db_preimage_cur_get(p_cur, &detect, &preimage, NULL)) break; //from invoice
if (!detect) continue;
if (preimage.state != LN_DB_PREIMAGE_STATE_UNUSED) continue;
memcpy(pPreimage, preimage.preimage, LN_SZ_PREIMAGE);
ln_payment_hash_calc(preimage_hash, pPreimage);
if (memcmp(preimage_hash, pForwardParam->p_payment_hash, BTC_SZ_HASH256)) continue;
Expand Down Expand Up @@ -1843,6 +1853,7 @@ static bool commitment_signed_send(ln_channel_t *pChannel)
static bool revoke_and_ack_send(ln_channel_t *pChannel)
{
LOGD("BEGIN\n");
bool irrevocably = false;

uint8_t prev_secret[BTC_SZ_PRIVKEY];
ln_derkey_local_storage_create_prev_per_commitment_secret(&pChannel->keys_local, prev_secret, NULL);
Expand Down Expand Up @@ -1880,7 +1891,7 @@ static bool revoke_and_ack_send(ln_channel_t *pChannel)
utl_buf_free(&buf);

if (ln_update_info_irrevocably_committed_htlcs_exists(&pChannel->update_info)) {
ln_callback(pChannel, LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE, NULL);
irrevocably = true;
}

for (uint32_t idx = 0; idx < ARRAY_SIZE(pChannel->update_info.updates); idx++) {
Expand Down Expand Up @@ -1910,6 +1921,10 @@ static bool revoke_and_ack_send(ln_channel_t *pChannel)
ln_update_info_clear_irrevocably_committed_updates(&pChannel->update_info);
M_DB_CHANNEL_SAVE(pChannel);

if (irrevocably) {
ln_callback(pChannel, LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE, NULL);
}

LOGD("END\n");
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions ln/ln_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@
#define M_STR(item,value) M_QQ(item) ":" M_QQ(value)
#define M_VAL(item,value) M_QQ(item) ":" value

#ifdef PTARM_USE_PRINTFUNC
#ifndef PTARM_UTL_LOG_MACRO_DISABLED
#if defined(PTARM_USE_PRINTFUNC) && defined(PTARM_DEBUG)
static const char *KEYS_STR[LN_BASEPOINT_IDX_NUM + 1] = {
"bp_funding", "bp_revocation", "bp_payment", "bp_delayed", "bp_htlc", "bp_per_commit"
};
static const char *SCR_STR[LN_SCRIPT_IDX_NUM] = {
"remotekey", "delayedkey", "revocationkey", "local_htlckey", "remote_htlckey"
};
#endif //PTARM_USE_PRINTFUNC
#endif //PTARM_USE_PRINTFUNC || PTARM_DEBUG
#endif //PTARM_UTL_LOG_MACRO_DISABLED


/**************************************************************************
Expand Down Expand Up @@ -98,7 +100,6 @@ void ln_print_keys_2(
const ln_funding_info_t *pFundingInfo, const ln_derkey_local_keys_t *pKeysLocal,
const ln_derkey_remote_keys_t *pKeysRemote)
{
//#ifdef M_DBG_VERBOSE
#ifdef PTARM_DEBUG
LOGD(" funding_txid: ");
TXIDD(pFundingInfo->txid);
Expand Down Expand Up @@ -131,10 +132,9 @@ void ln_print_keys_2(

LOGD("prev_percommit: ");
DUMPD(pKeysRemote->prev_per_commitment_point, BTC_SZ_PUBKEY);
#endif
//#else
// (void)fp; (void)pLocal; (void)pRemote;
//#endif //M_DBG_VERBOSE
#else
(void)pFundingInfo; (void)pKeysLocal; (void)pKeysRemote;
#endif //PTARM_DEBUG
}

#endif //PTARM_USE_PRINTFUNC
4 changes: 2 additions & 2 deletions ln/ln_routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <cinttypes>
#include <stdbool.h>
#include <assert.h>

Expand Down Expand Up @@ -596,7 +596,7 @@ lnerr_route_t ln_routing_calculate(

//戻り値の作成
pResult->num_hops = (uint8_t)route.size();
const uint8_t *p_next;
const uint8_t *p_next = NULL;

for (int lp = 0; lp < pResult->num_hops - 1; lp++) {
const uint8_t *p_now = groute[route[lp]].p_node;
Expand Down
9 changes: 4 additions & 5 deletions ln/ln_setupctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void ln_init_localfeatures_set(uint8_t lf)
}


void HIDDEN ln_error_set(ln_channel_t *pChannel, int Err, const char *pFormat, ...)
void /*HIDDEN*/ ln_error_set(ln_channel_t *pChannel, int Err, const char *pFormat, ...)
{
va_list ap;

Expand All @@ -95,9 +95,9 @@ bool /*HIDDEN*/ ln_init_send(ln_channel_t *pChannel, bool bInitRouteSync, bool b
msg.gflen = 0;
msg.p_globalfeatures = NULL;
pChannel->lfeature_local = mInitLocalFeatures[0] | (bInitRouteSync ? LN_INIT_LF_ROUTE_SYNC : 0);
#ifdef USE_GQUERY
#ifdef USE_GOSSIP_QUERY
pChannel->lfeature_local |= LN_INIT_LF_OPT_GSP_QUERY;
#endif //USE_GQUERY
#endif //USE_GOSSIP_QUERY
msg.lflen = sizeof(pChannel->lfeature_local);
msg.p_localfeatures = &pChannel->lfeature_local;
LOGD("localfeatures: ");
Expand Down Expand Up @@ -183,9 +183,8 @@ bool HIDDEN ln_init_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t
}


bool /*HIDDEN*/ ln_error_send(ln_channel_t *pChannel, int Err, const char *pFormat, ...)
bool /*HIDDEN*/ ln_error_send(ln_channel_t *pChannel)
{
ln_error_set(pChannel, Err, pFormat);
ln_msg_error_t msg;
msg.p_channel_id = pChannel->channel_id;
msg.p_data = (const uint8_t *)pChannel->err_msg;
Expand Down
7 changes: 4 additions & 3 deletions ln/ln_setupctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
LOGE("[%s:%d]fail: %s\n", __func__, (int)__LINE__, pChannel->err_msg); \
}
#define M_SEND_ERR(pChannel, err, fmt, ...) { \
ln_error_send(pChannel, err, fmt, ##__VA_ARGS__); \
ln_error_set(pChannel, err, fmt, ##__VA_ARGS__); \
ln_error_send(pChannel); \
LOGE("[%s:%d]fail: %s\n", __func__, (int)__LINE__, pChannel->err_msg); \
}

Expand All @@ -71,11 +72,11 @@
*/
void ln_init_localfeatures_set(uint8_t lf);

void HIDDEN ln_error_set(ln_channel_t *pChannel, int Err, const char *pFormat, ...);
void /*HIDDEN*/ ln_error_set(ln_channel_t *pChannel, int Err, const char *pFormat, ...);

bool /*HIDDEN*/ ln_init_send(ln_channel_t *pChannel, bool bInitRouteSync, bool bHaveCnl);
bool HIDDEN ln_init_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len);
bool /*HIDDEN*/ ln_error_send(ln_channel_t *pChannel, int Err, const char *pFormat, ...);
bool /*HIDDEN*/ ln_error_send(ln_channel_t *pChannel);
bool HIDDEN ln_error_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len);
bool /*HIDDEN*/ ln_ping_send(ln_channel_t *pChannel, uint16_t PingLen, uint16_t PongLen);
bool HIDDEN ln_ping_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len);
Expand Down
2 changes: 1 addition & 1 deletion ln/ln_update_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool ln_update_info_clear_htlc(ln_update_info_t *pInfo, uint16_t UpdateIdx)
//clear htlc
ln_htlc_t *p_htlc = &pInfo->htlcs[p_update->type_specific_idx];
if (p_htlc->buf_preimage.len) {
/*ignore*/ ln_db_preimage_del(p_htlc->buf_preimage.buf); //XXX: delete outside the function
/*ignore*/ ln_db_preimage_used(p_htlc->buf_preimage.buf); //XXX: delete outside the function
}
utl_buf_free(&p_htlc->buf_preimage);
utl_buf_free(&p_htlc->buf_onion_reason);
Expand Down
4 changes: 3 additions & 1 deletion ln/ln_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/** @def LN_DB_VERSION
* @brief database version
*/
#define LN_DB_VERSION ((int32_t)(-68))
#define LN_DB_VERSION ((int32_t)(-70))
/*
-1 : first
-2 : ln_update_add_htlc_t変更
Expand Down Expand Up @@ -114,6 +114,8 @@
-66: update `ln_channel_t::shutdown_flag`
-67: update `ln_channel_t::status`
-68: add `ln_channel_t::prev_remote_commit_txid`
-69: add `ln_db_preimage_t::status` (auto update: -68 ==> -69)
-70: add `ln_db_wallet_t::mined_height` (bitcoind auto update: -69 ==> -70)
*/

#endif /* LN_VERSION_H__ */
6 changes: 2 additions & 4 deletions ln/tests/test_ln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ extern "C" {
// FAKE_VALUE_FUNC(bool, ln_db_cnlupd_load, utl_buf_t *, uint32_t *, uint64_t, uint8_t);
// FAKE_VALUE_FUNC(bool, ln_db_preimage_del, const uint8_t *);
// FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_open, void **);
// FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *);
// FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *, const char**);
// FAKE_VALUE_FUNC(bool, ln_db_channel_search, ln_db_func_cmp_t, void *);
// FAKE_VALUE_FUNC(bool, ln_db_channel_search_readonly, ln_db_func_cmp_t, void *);
// FAKE_VALUE_FUNC(bool, ln_db_payment_hash_save, const uint8_t*, const uint8_t*, ln_commit_tx_output_type_t, uint32_t);
// FAKE_VALUE_FUNC(bool, ln_db_preimage_search, ln_db_func_preimage_t, void*);
// FAKE_VALUE_FUNC(bool, ln_db_preimage_set_expiry, void *, uint32_t);

// FAKE_VALUE_FUNC(bool, ln_msg_open_channel_write, utl_buf_t *, const ln_open_channel_t *);
// FAKE_VALUE_FUNC(bool, ln_msg_open_channel_read, ln_open_channel_t*, const uint8_t*, uint16_t);
Expand Down Expand Up @@ -94,7 +93,6 @@ class ln: public testing::Test {
// RESET_FAKE(ln_db_channel_search_readonly)
// RESET_FAKE(ln_db_payment_hash_save)
// RESET_FAKE(ln_db_preimage_search)
// RESET_FAKE(ln_db_preimage_set_expiry)
// RESET_FAKE(ln_msg_open_channel_read)
// RESET_FAKE(ln_msg_accept_channel_write)
// RESET_FAKE(ln_msg_accept_channel_read)
Expand Down Expand Up @@ -147,7 +145,7 @@ class ln: public testing::Test {
case LN_CB_TYPE_WAIT_FUNDING_TX: p_str = "LN_CB_TYPE_WAIT_FUNDING_TX"; break;
case LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV: p_str = "LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV"; break;
case LN_CB_TYPE_NOTIFY_ANNODB_UPDATE: p_str = "LN_CB_TYPE_NOTIFY_ANNODB_UPDATE"; break;
case LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE: p_str = "LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE"; break;
case LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV: p_str = "LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV"; break;
Expand Down
4 changes: 1 addition & 3 deletions ln/tests/test_ln_htlcflag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ FAKE_VOID_FUNC(ln_db_preimage_cur_close, void *, bool);
FAKE_VALUE_FUNC(bool, ln_db_cnlupd_load, utl_buf_t *, uint32_t *, uint64_t, uint8_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_del, const uint8_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_open, void **);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *, const char**);
FAKE_VALUE_FUNC(bool, ln_db_channel_search, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_channel_search_readonly, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_payment_hash_save, const uint8_t*, const uint8_t*, ln_commit_tx_output_type_t, uint32_t);
FAKE_VALUE_FUNC(bool, ln_db_preimage_search, ln_db_func_preimage_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_set_expiry, void *, uint32_t);

FAKE_VALUE_FUNC(bool, ln_msg_open_channel_write, utl_buf_t *, const ln_msg_open_channel_t *);
FAKE_VALUE_FUNC(bool, ln_msg_open_channel_read, ln_msg_open_channel_t*, const uint8_t*, uint16_t);
Expand Down Expand Up @@ -92,7 +91,6 @@ class ln_htlc_flag: public testing::Test {
RESET_FAKE(ln_db_channel_search_readonly)
RESET_FAKE(ln_db_payment_hash_save)
RESET_FAKE(ln_db_preimage_search)
RESET_FAKE(ln_db_preimage_set_expiry)
RESET_FAKE(ln_msg_open_channel_read)
RESET_FAKE(ln_msg_accept_channel_write)
RESET_FAKE(ln_msg_accept_channel_read)
Expand Down
13 changes: 13 additions & 0 deletions ln/tests/test_ln_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ TEST_F(ln, ln_node_addr_dec_skip_addr2)
}


TEST_F(ln, ln_node_addr_dec_ng_no_addr)
{
const char CONN_STR[] = "03694d1090cbaef885bcdf56ce47e78b62e130b929107d32f501b1628c4e01bd53"
"@:12345";

ln_node_conn_t conn;

memset(&conn, 0, sizeof(conn));
bool ret = ln_node_addr_dec(&conn, CONN_STR);
ASSERT_FALSE(ret);
}


TEST_F(ln, ln_node_addr_dec_ng_addr_len1)
{
const char CONN_STR[] = "03694d1090cbaef885bcdf56ce47e78b62e130b929107d32f501b1628c4e01bd53"
Expand Down
57 changes: 15 additions & 42 deletions ln/tests/test_ln_proto_acceptchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ FAKE_VOID_FUNC(ln_db_preimage_cur_close, void *, bool);
FAKE_VALUE_FUNC(bool, ln_db_cnlupd_load, utl_buf_t *, uint32_t *, uint64_t, uint8_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_del, const uint8_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_open, void **);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *, const char**);
FAKE_VALUE_FUNC(bool, ln_db_channel_search, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_channel_search_readonly, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_payment_hash_save, const uint8_t*, const uint8_t*, ln_commit_tx_output_type_t, uint32_t);
FAKE_VALUE_FUNC(bool, ln_db_preimage_search, ln_db_func_preimage_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_set_expiry, void *, uint32_t);

FAKE_VALUE_FUNC(bool, ln_msg_open_channel_write, utl_buf_t *, const ln_msg_open_channel_t *);
FAKE_VALUE_FUNC(bool, ln_msg_open_channel_read, ln_msg_open_channel_t*, const uint8_t*, uint16_t);
Expand Down Expand Up @@ -97,7 +96,6 @@ class ln: public testing::Test {
RESET_FAKE(ln_db_channel_search_readonly)
RESET_FAKE(ln_db_payment_hash_save)
RESET_FAKE(ln_db_preimage_search)
RESET_FAKE(ln_db_preimage_set_expiry)
RESET_FAKE(ln_msg_open_channel_read)
RESET_FAKE(ln_msg_accept_channel_write)
RESET_FAKE(ln_msg_accept_channel_read)
Expand Down Expand Up @@ -150,7 +148,7 @@ class ln: public testing::Test {
case LN_CB_TYPE_WAIT_FUNDING_TX: p_str = "LN_CB_TYPE_WAIT_FUNDING_TX"; break;
case LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV: p_str = "LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV"; break;
case LN_CB_TYPE_NOTIFY_ANNODB_UPDATE: p_str = "LN_CB_TYPE_NOTIFY_ANNODB_UPDATE"; break;
case LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE: p_str = "LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE"; break;
case LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV: p_str = "LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV"; break;
Expand Down Expand Up @@ -272,8 +270,7 @@ TEST_F(ln, ln_accept_channel_recv_ok)
LnInit(&channel);
channel.funding_info.role = LN_FUNDING_ROLE_FUNDER; //funder

const uint8_t CHANGE_SPK[] = { 0x12, 0x34, 0x56 };

static utl_buf_t two_of_two = UTL_BUF_INIT;
static uint8_t pubkey[BTC_SZ_PUBKEY];
class dummy {
public:
Expand All @@ -282,8 +279,10 @@ TEST_F(ln, ln_accept_channel_recv_ok)
switch (Type) {
case LN_CB_TYPE_SIGN_FUNDING_TX:
{
LOGD("LN_CB_TYPE_SIGN_FUNDING_TX\n");
ln_cb_param_sign_funding_tx_t *p_sig = (ln_cb_param_sign_funding_tx_t *)pTypeSpecificParam;
p_sig->ret = true; //署名OK
btc_tx_add_vout_spk(p_sig->p_tx, p_sig->amount, &two_of_two);
}
break;
default:
Expand Down Expand Up @@ -311,29 +310,27 @@ TEST_F(ln, ln_accept_channel_recv_ok)
channel.p_callback = dummy::callback;
ln_msg_accept_channel_read_fake.custom_fake = dummy::ln_msg_accept_channel_read;

memcpy(pubkey, LN_DUMMY::PUB, sizeof(pubkey));
memcpy(pubkey, LN_DUMMY::PUB2, sizeof(pubkey));
channel.commit_info_local.dust_limit_sat = 10000;
channel.commit_info_local.channel_reserve_sat = 800;
memcpy(channel.channel_id, LN_DUMMY::CHANNEL_ID, LN_SZ_CHANNEL_ID);
channel.funding_info.funding_satoshis = 100000;

#ifdef USE_BITCOIND
channel.establish.p_fundin = (ln_fundin_t *)UTL_DBG_CALLOC(1, sizeof(ln_fundin_t));
ln_fundin_t *p_fundin = channel.establish.p_fundin;
utl_buf_alloccopy(&p_fundin->change_spk, CHANGE_SPK, sizeof(CHANGE_SPK));
p_fundin->amount = 500000;
#endif

memcpy(channel.keys_local.basepoints[LN_BASEPOINT_IDX_FUNDING], LN_DUMMY::PUB1, BTC_SZ_PUBKEY);
memcpy(channel.keys_remote.basepoints[LN_BASEPOINT_IDX_FUNDING], LN_DUMMY::PUB2, BTC_SZ_PUBKEY);

utl_buf_init(&channel.funding_info.wit_script);
btc_script_2of2_create_redeem_sorted(
&channel.funding_info.wit_script, &channel.funding_info.key_order,
channel.keys_local.basepoints[LN_BASEPOINT_IDX_FUNDING],
channel.keys_remote.basepoints[LN_BASEPOINT_IDX_FUNDING]);
btc_script_p2wsh_create_scriptpk(&two_of_two, &channel.funding_info.wit_script);

bool ret = ln_accept_channel_recv(&channel, NULL, 0);
ASSERT_TRUE(ret);

#ifdef USE_BITCOIND
utl_buf_free(&p_fundin->change_spk);
UTL_DBG_FREE(channel.establish.p_fundin);
#endif
utl_buf_free(&two_of_two);

ln_term(&channel);
}

Expand All @@ -351,8 +348,6 @@ TEST_F(ln, ln_accept_channel_recv_receiver1)
LnInit(&channel);
channel.funding_info.role = LN_FUNDING_ROLE_FUNDER; //funder

const uint8_t CHANGE_SPK[] = { 0x12, 0x34, 0x56 };

static uint8_t pubkey[BTC_SZ_PUBKEY];
class dummy {
public:
Expand Down Expand Up @@ -396,22 +391,12 @@ TEST_F(ln, ln_accept_channel_recv_receiver1)
memcpy(channel.channel_id, LN_DUMMY::CHANNEL_ID, LN_SZ_CHANNEL_ID);
channel.funding_info.funding_satoshis = 100000;

#ifdef USE_BITCOIND
channel.establish.p_fundin = (ln_fundin_t *)UTL_DBG_CALLOC(1, sizeof(ln_fundin_t));
ln_fundin_t *p_fundin = channel.establish.p_fundin;
utl_buf_alloccopy(&p_fundin->change_spk, CHANGE_SPK, sizeof(CHANGE_SPK));
#endif

memcpy(channel.keys_local.basepoints[LN_BASEPOINT_IDX_FUNDING], LN_DUMMY::PUB1, BTC_SZ_PUBKEY);
memcpy(channel.keys_remote.basepoints[LN_BASEPOINT_IDX_FUNDING], LN_DUMMY::PUB2, BTC_SZ_PUBKEY);

bool ret = ln_accept_channel_recv(&channel, NULL, 0);
ASSERT_FALSE(ret);

#ifdef USE_BITCOIND
utl_buf_free(&p_fundin->change_spk);
UTL_DBG_FREE(channel.establish.p_fundin);
#endif
ln_term(&channel);
}

Expand All @@ -430,8 +415,6 @@ TEST_F(ln, ln_accept_channel_recv_receiver2)
LnInit(&channel);
channel.funding_info.role = LN_FUNDING_ROLE_FUNDER; //funder

const uint8_t CHANGE_SPK[] = { 0x12, 0x34, 0x56 };

static uint8_t pubkey[BTC_SZ_PUBKEY];
class dummy {
public:
Expand Down Expand Up @@ -475,21 +458,11 @@ TEST_F(ln, ln_accept_channel_recv_receiver2)
memcpy(channel.channel_id, LN_DUMMY::CHANNEL_ID, LN_SZ_CHANNEL_ID);
channel.funding_info.funding_satoshis = 100000;

#ifdef USE_BITCOIND
channel.establish.p_fundin = (ln_fundin_t *)UTL_DBG_CALLOC(1, sizeof(ln_fundin_t));
ln_fundin_t *p_fundin = channel.establish.p_fundin;
utl_buf_alloccopy(&p_fundin->change_spk, CHANGE_SPK, sizeof(CHANGE_SPK));
#endif

memcpy(channel.keys_local.basepoints[LN_BASEPOINT_IDX_FUNDING], LN_DUMMY::PUB1, BTC_SZ_PUBKEY);
memcpy(channel.keys_remote.basepoints[LN_BASEPOINT_IDX_FUNDING], LN_DUMMY::PUB2, BTC_SZ_PUBKEY);

bool ret = ln_accept_channel_recv(&channel, NULL, 0);
ASSERT_FALSE(ret);

#ifdef USE_BITCOIND
utl_buf_free(&p_fundin->change_spk);
UTL_DBG_FREE(channel.establish.p_fundin);
#endif
ln_term(&channel);
}
2 changes: 1 addition & 1 deletion ln/tests/test_ln_proto_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ln: public testing::Test {
case LN_CB_TYPE_WAIT_FUNDING_TX: p_str = "LN_CB_TYPE_WAIT_FUNDING_TX"; break;
case LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV: p_str = "LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV"; break;
case LN_CB_TYPE_NOTIFY_ANNODB_UPDATE: p_str = "LN_CB_TYPE_NOTIFY_ANNODB_UPDATE"; break;
case LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE: p_str = "LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE"; break;
case LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV: p_str = "LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV"; break;
Expand Down
6 changes: 2 additions & 4 deletions ln/tests/test_ln_proto_openchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ FAKE_VOID_FUNC(ln_db_preimage_cur_close, void *, bool);
FAKE_VALUE_FUNC(bool, ln_db_cnlupd_load, utl_buf_t *, uint32_t *, uint64_t, uint8_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_del, const uint8_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_open, void **);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *, const char**);
FAKE_VALUE_FUNC(bool, ln_db_channel_search, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_channel_search_readonly, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_payment_hash_save, const uint8_t*, const uint8_t*, ln_commit_tx_output_type_t, uint32_t);
FAKE_VALUE_FUNC(bool, ln_db_preimage_search, ln_db_func_preimage_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_set_expiry, void *, uint32_t);

FAKE_VALUE_FUNC(bool, ln_msg_open_channel_write, utl_buf_t *, const ln_msg_open_channel_t *);
FAKE_VALUE_FUNC(bool, ln_msg_open_channel_read, ln_msg_open_channel_t*, const uint8_t*, uint16_t);
Expand Down Expand Up @@ -97,7 +96,6 @@ class ln: public testing::Test {
RESET_FAKE(ln_db_channel_search_readonly)
RESET_FAKE(ln_db_payment_hash_save)
RESET_FAKE(ln_db_preimage_search)
RESET_FAKE(ln_db_preimage_set_expiry)
RESET_FAKE(ln_msg_open_channel_read)
RESET_FAKE(ln_msg_accept_channel_write)
RESET_FAKE(ln_msg_accept_channel_read)
Expand Down Expand Up @@ -150,7 +148,7 @@ class ln: public testing::Test {
case LN_CB_TYPE_WAIT_FUNDING_TX: p_str = "LN_CB_TYPE_WAIT_FUNDING_TX"; break;
case LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV: p_str = "LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV"; break;
case LN_CB_TYPE_NOTIFY_ANNODB_UPDATE: p_str = "LN_CB_TYPE_NOTIFY_ANNODB_UPDATE"; break;
case LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE: p_str = "LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE"; break;
case LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV: p_str = "LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV"; break;
Expand Down
18 changes: 12 additions & 6 deletions ln/tests/test_ln_proto_updateaddhtlc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ FAKE_VOID_FUNC(ln_db_preimage_cur_close, void *, bool);
FAKE_VALUE_FUNC(bool, ln_db_cnlupd_load, utl_buf_t *, uint32_t *, uint64_t, uint8_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_del, const uint8_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_open, void **);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *);
FAKE_VALUE_FUNC(bool, ln_db_preimage_cur_get, void *, bool *, ln_db_preimage_t *, const char**);
FAKE_VALUE_FUNC(bool, ln_db_preimage_used, const uint8_t *);
FAKE_VALUE_FUNC(bool, ln_db_channel_search, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_channel_search_readonly, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_channel_search_readonly_nokey, ln_db_func_cmp_t, void *);
FAKE_VALUE_FUNC(bool, ln_db_payment_hash_save, const uint8_t*, const uint8_t*, ln_commit_tx_output_type_t, uint32_t);
FAKE_VALUE_FUNC(bool, ln_db_preimage_search, ln_db_func_preimage_t, void*);
FAKE_VALUE_FUNC(bool, ln_db_preimage_set_expiry, void *, uint32_t);
FAKE_VALUE_FUNC(bool, ln_db_forward_add_htlc_save, const ln_db_forward_t *);

FAKE_VALUE_FUNC(bool, ln_msg_open_channel_write, utl_buf_t *, const ln_msg_open_channel_t *);
Expand All @@ -95,12 +95,12 @@ class ln: public testing::Test {
RESET_FAKE(ln_db_preimage_del)
RESET_FAKE(ln_db_preimage_cur_open)
RESET_FAKE(ln_db_preimage_cur_get)
RESET_FAKE(ln_db_preimage_used)
RESET_FAKE(ln_db_channel_search)
RESET_FAKE(ln_db_channel_search_readonly)
RESET_FAKE(ln_db_channel_search_readonly_nokey)
RESET_FAKE(ln_db_payment_hash_save)
RESET_FAKE(ln_db_preimage_search)
RESET_FAKE(ln_db_preimage_set_expiry)
RESET_FAKE(ln_db_forward_add_htlc_save)
RESET_FAKE(ln_msg_open_channel_read)
RESET_FAKE(ln_msg_accept_channel_write)
Expand Down Expand Up @@ -155,7 +155,7 @@ class ln: public testing::Test {
case LN_CB_TYPE_WAIT_FUNDING_TX: p_str = "LN_CB_TYPE_WAIT_FUNDING_TX"; break;
case LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV: p_str = "LN_CB_TYPE_NOTIFY_FUNDING_LOCKED_RECV"; break;
case LN_CB_TYPE_NOTIFY_ANNODB_UPDATE: p_str = "LN_CB_TYPE_NOTIFY_ANNODB_UPDATE"; break;
case LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADD_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_ADDFINAL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV: p_str = "LN_CB_TYPE_NOTIFY_FULFILL_HTLC_RECV"; break;
case LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE: p_str = "LN_CB_TYPE_NOTIFY_REV_AND_ACK_EXCHANGE"; break;
case LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV: p_str = "LN_CB_TYPE_NOTIFY_UPDATE_FEE_RECV"; break;
Expand Down Expand Up @@ -434,12 +434,15 @@ TEST_F(ln, update_add_htlc_recv1)
static bool ln_db_preimage_cur_open(void **ppCur) {
return true;
}
static bool ln_db_preimage_cur_get(void *pCur, bool *pDetect, ln_db_preimage_t *pPreimage) {
static bool ln_db_preimage_cur_get(void *pCur, bool *pDetect, ln_db_preimage_t *pPreimage, const char**ppBolt11) {
*pDetect = true;
pPreimage->amount_msat = LN_UPDATE_ADD_HTLC_A::AMOUNT_MSAT;
memcpy(pPreimage->preimage, LN_UPDATE_ADD_HTLC_A::PREIMAGE, LN_SZ_PREIMAGE);
pPreimage->creation_time = 1538375408;
pPreimage->expiry = LN_UPDATE_ADD_HTLC_A::CLTV_EXPIRY;
if (ppBolt11) {
*ppBolt11 = "";
}
return true;
}
static void callback(ln_cb_type_t Type, void *pCommonParam, void *pTypeSpecificParam) {
Expand Down Expand Up @@ -504,12 +507,15 @@ TEST_F(ln, update_add_htlc_recv2)
static bool ln_db_preimage_cur_open(void **ppCur) {
return true;
}
static bool ln_db_preimage_cur_get(void *pCur, bool *pDetect, ln_db_preimage_t *pPreimage) {
static bool ln_db_preimage_cur_get(void *pCur, bool *pDetect, ln_db_preimage_t *pPreimage, const char **ppBolt11) {
*pDetect = true;
pPreimage->amount_msat = LN_UPDATE_ADD_HTLC_A::AMOUNT_MSAT;
memcpy(pPreimage->preimage, LN_UPDATE_ADD_HTLC_A::PREIMAGE, LN_SZ_PREIMAGE);
pPreimage->creation_time = 1538375408;
pPreimage->expiry = LN_UPDATE_ADD_HTLC_A::CLTV_EXPIRY;
if (ppBolt11) {
*ppBolt11 = "";
}
return true;
}
static void callback(ln_cb_type_t Type, void *pCommonParam, void *pTypeSpecificParam) {
Expand Down
Loading