lnd-tool 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +57 -14
- data/exe/lnd-tool +50 -0
- data/lib/lnd/tool/daemon.rb +1 -1
- data/lib/lnd/tool/store/htlc_event.rb +29 -1
- data/lib/lnd/tool/version.rb +1 -1
- data/lnd-tool.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6d5e1b2aa6a45fc2bc9f9e1fc3d3b5ac739c8deb0708a03beb95d372b0d8ba9
|
4
|
+
data.tar.gz: cc803a39f5a7f95a98ba3b4dfd6a24fa79e863f1b6b74ddcd22dfa8134d74cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 381b5cdf5cc19157ab025feb2f2a4ec7c40ac5ca3b1af1c38e2786a470d52eadfe2f370cd707b826d0084e34061be18cdf3968936f51fbfa51760f56fbfa122d
|
7
|
+
data.tar.gz: 450bfd39f6963e3c49ea70420fafb48d9acea6b392b4b180a16ed510b573c22493f0b080cc043975a6add3b32f460f9b5dd3e4723767598fd7856742856e75a4
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# LND::Tool [](https://github.com/azuchi/lnd-tool/actions/workflows/main.yml) [](https://badge.fury.io/rb/lnd-tool) [](LICENSE)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This is a tool for LND written in Ruby. Subscribe to htlc events in LND and save their contents to SQLite3.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,22 +20,67 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
### Configuration
|
24
|
+
|
25
|
+
First, create a configuration file for the gRPC connection to LND.
|
26
|
+
|
27
|
+
* config.yml
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
lnd:
|
31
|
+
credentials_path: 'Path to credential file like $LND_HOME/tls.cert.'
|
32
|
+
macaroon_path: 'Path to the macaroon file created by lnd like $LND_HOME/data/chain/bitcoin/mainnet/admin.macaroon'
|
33
|
+
host: 'lnd host'
|
34
|
+
port: 10009 # gRPC port
|
35
|
+
```
|
36
|
+
|
37
|
+
### Capture HTLC events
|
38
|
+
|
39
|
+
Run following command specifying the above configuration file.
|
40
|
+
|
41
|
+
$ lnd-tool capture_htlc --config "Path to configuration file"
|
42
|
+
|
43
|
+
Run process in the background as a daemon and starts capturing the HTLC event.
|
26
44
|
|
27
|
-
|
45
|
+
A directory `$HOME/.lnd-tool` will be created and a SQLite3 database named `storage.db`
|
46
|
+
will be created in it. You can access this database:
|
28
47
|
|
29
|
-
|
48
|
+
$ sqlite3 $HOME/.lnd-tool
|
49
|
+
SQLite version 3.27.2 2019-02-25 16:06:06
|
50
|
+
Enter ".help" for usage hints.
|
51
|
+
sqlite> .tables
|
52
|
+
HtlcEvent
|
53
|
+
sqlite> .header on
|
54
|
+
sqlite> .mode column
|
55
|
+
sqlite> select * from HtlcEvent;
|
56
|
+
id incoming_channel_id outgoing_channel_id incoming_htlc_id outgoing_htlc_id timestamp_ns event_type forward_event forward_fail_event settle_event link_fail_event created_datetime
|
57
|
+
---------- ------------------- ------------------- ---------------- ---------------- ------------------- ---------- ------------- ------------------ ------------ -------------------------------------------------------------------------------------------------------------------- -------------------
|
58
|
+
1 759077539161571329 781080965883559937 201 0 1637643738317254952 FORWARD {"info":{"incomingTimelock":711047,"outgoingTimelock":711007,"incomingAmtMsat":"250004750","outgoingAmtMsat":"250001250"},"wireFailure":"TEMPORARY_CHANNEL_FAILURE","failureDetail":"INSUFFICIENT_BALANCE","failureString":"insufficient bandwidth to route htlc"} 2021-11-23 14:02:18
|
59
|
+
2 759077539161571329 781080965883559937 202 0 1637643771224622997 FORWARD {"info":{"incomingTimelock":711047,"outgoingTimelock":711007,"incomingAmtMsat":"973389706","outgoingAmtMsat":"973378973"},"wireFailure":"TEMPORARY_CHANNEL_FAILURE","failureDetail":"INSUFFICIENT_BALANCE","failureString":"insufficient bandwidth to route htlc"} 2021-11-23 14:02:51
|
30
60
|
|
31
|
-
|
61
|
+
If you stop the capturing, run following command:
|
32
62
|
|
33
|
-
|
63
|
+
$ lnd-tool stop_capture
|
34
64
|
|
35
|
-
|
65
|
+
### Search HTLC events
|
36
66
|
|
37
|
-
|
67
|
+
You can use the `query_htlc` command to retrieve the data of HTLC events stored in SQLite3.
|
68
|
+
Since it is a search to the database, it can be run even if the capture process is not running.
|
38
69
|
|
39
|
-
|
70
|
+
$ lnd-tool query_htlc
|
71
|
+
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
72
|
+
| HTLC Events |
|
73
|
+
+--------------------+---------------+--------------------+---------------+---------------------------+------------+--------------+------------------+---------------+---------------+
|
74
|
+
| incoming channel | incoming htlc | outgoing channel | outgoing htlc | timestamp | event type | result | detail | incoming msat | outgoing msat |
|
75
|
+
+--------------------+---------------+--------------------+---------------+---------------------------+------------+--------------+------------------+---------------+---------------+
|
76
|
+
| 759077539161571329 | 259 | 781080965883559937 | 0 | 2021-11-29 13:29:57 +0900 | FORWARD | LINK_FAIL | FEE_INSUFFICIENT | 75002825 | 75001075 |
|
77
|
+
| 759526139822866433 | 32 | 759077539161571329 | 441 | 2021-11-25 16:34:48 +0900 | FORWARD | FORWARD FAIL | | | |
|
78
|
+
| 759526139822866433 | 32 | 759077539161571329 | 441 | 2021-11-25 16:34:44 +0900 | FORWARD | FORWARD | | 100050900 | 100000000 |
|
79
|
+
| 759526139822866433 | 31 | 759077539161571329 | 440 | 2021-11-25 16:34:39 +0900 | FORWARD | FORWARD FAIL | | | |
|
80
|
+
| 759526139822866433 | 31 | 759077539161571329 | 440 | 2021-11-25 16:34:36 +0900 | FORWARD | FORWARD | | 11005 | 10000 |
|
81
|
+
+--------------------+---------------+--------------------+---------------+---------------------------+------------+--------------+------------------+---------------+---------------+
|
40
82
|
|
41
|
-
|
83
|
+
The `query_htlc` command has the following options.
|
42
84
|
|
43
|
-
|
85
|
+
* `event`: Option to specify the event type(`send`, `receive`, `forward`). e.g. `$ lnd-tool query_htlc --event=forward`
|
86
|
+
* `limit`: Option to narrows down the number of data. e.g. `$lnd-tool query_htlc --limit=30`
|
data/exe/lnd-tool
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'lnd/tool'
|
4
4
|
require 'thor'
|
5
5
|
require 'yaml'
|
6
|
+
require 'terminal-table'
|
6
7
|
|
7
8
|
# CLI class of lnd-tool
|
8
9
|
class CLI < Thor
|
@@ -33,6 +34,55 @@ class CLI < Thor
|
|
33
34
|
LND::Tool::Daemon.stop
|
34
35
|
end
|
35
36
|
|
37
|
+
desc 'query_htlc', 'Query the captured data in SQLite DB.'
|
38
|
+
option :event, type: :string,
|
39
|
+
desc: 'Targets the specified type of event. Valid type are "send", "receive", "forward".'
|
40
|
+
option :limit, type: :numeric, desc: 'Maximum number of data'
|
41
|
+
def query_htlc
|
42
|
+
if options['event'] && !%w[send receive forward].include?(options['event'])
|
43
|
+
raise Thor::Error, 'event must be specified as send, receive, or forward.'
|
44
|
+
end
|
45
|
+
|
46
|
+
headers = [
|
47
|
+
'incoming channel',
|
48
|
+
'incoming htlc',
|
49
|
+
'outgoing channel',
|
50
|
+
'outgoing htlc',
|
51
|
+
'timestamp',
|
52
|
+
'event type',
|
53
|
+
'result',
|
54
|
+
'detail',
|
55
|
+
'incoming msat',
|
56
|
+
'outgoing msat'
|
57
|
+
]
|
58
|
+
store = LND::Tool::Store::HTLCEvent.new
|
59
|
+
rows = store.query(event_type: options['event']&.upcase, limit: options['limit']).map do |r|
|
60
|
+
result, detail, htlc = if r.forward_event
|
61
|
+
['FORWARD', nil, r.forward_event.info]
|
62
|
+
elsif r.forward_fail_event
|
63
|
+
['FORWARD FAIL']
|
64
|
+
elsif r.settle_event
|
65
|
+
['SETTLE']
|
66
|
+
elsif r.link_fail_event
|
67
|
+
['LINK_FAIL', r.link_fail_event.wire_failure, r.link_fail_event.info]
|
68
|
+
end
|
69
|
+
[
|
70
|
+
{ value: r.incoming_channel_id, alignment: :right },
|
71
|
+
{ value: r.incoming_htlc_id, alignment: :right },
|
72
|
+
{ value: r.outgoing_channel_id, alignment: :right },
|
73
|
+
{ value: r.outgoing_htlc_id, alignment: :right },
|
74
|
+
Time.at(r.timestamp_ns / 1000000000),
|
75
|
+
r.event_type,
|
76
|
+
result,
|
77
|
+
detail,
|
78
|
+
{ value: htlc&.incoming_amt_msat, alignment: :right },
|
79
|
+
{ value: htlc&.outgoing_amt_msat, alignment: :right }
|
80
|
+
]
|
81
|
+
end
|
82
|
+
table = Terminal::Table.new(title: 'HTLC Events', headings: headers, rows: rows)
|
83
|
+
puts table
|
84
|
+
end
|
85
|
+
|
36
86
|
end
|
37
87
|
|
38
88
|
CLI.start(ARGV)
|
data/lib/lnd/tool/daemon.rb
CHANGED
@@ -55,7 +55,35 @@ module LND
|
|
55
55
|
incoming_htlc_id, outgoing_htlc_id, timestamp_ns, event_type, forward_event, forward_fail_event,
|
56
56
|
settle_event, link_fail_event FROM HtlcEvent ORDER BY created_datetime DESC
|
57
57
|
SQL
|
58
|
-
db.query(query)
|
58
|
+
convert(db.query(query))
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [String] event_type event type condition
|
62
|
+
# @param [Integer] limit limit for return value
|
63
|
+
# @return [Array]
|
64
|
+
def query(event_type: nil, limit: nil)
|
65
|
+
query = <<~SQL
|
66
|
+
SELECT incoming_channel_id, outgoing_channel_id,
|
67
|
+
incoming_htlc_id, outgoing_htlc_id, timestamp_ns, event_type, forward_event, forward_fail_event,
|
68
|
+
settle_event, link_fail_event FROM HtlcEvent
|
69
|
+
SQL
|
70
|
+
bind = []
|
71
|
+
if event_type
|
72
|
+
query << ' WHERE event_type = ?'
|
73
|
+
bind << event_type
|
74
|
+
end
|
75
|
+
query << ' ORDER BY created_datetime DESC'
|
76
|
+
if limit
|
77
|
+
query << ' LIMIT ?'
|
78
|
+
bind << limit
|
79
|
+
end
|
80
|
+
convert(db.query(query, bind))
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def convert(recode_sets)
|
86
|
+
recode_sets.lazy.map do |result|
|
59
87
|
forward_event = result[6] ? Routerrpc::ForwardEvent.decode_json(result[6]) : nil
|
60
88
|
forward_fail_event = result[7] ? Routerrpc::ForwardFailEvent.decode_json(result[7]) : nil
|
61
89
|
settle_event = result[8] ? Routerrpc::SettleEvent.decode_json(result[8]) : nil
|
data/lib/lnd/tool/version.rb
CHANGED
data/lnd-tool.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
# Uncomment to register a new dependency of your gem
|
31
31
|
spec.add_dependency 'lnrpc', '~> 0.13.0'
|
32
32
|
spec.add_dependency 'sqlite3', '~> 1.4.2'
|
33
|
+
spec.add_dependency 'terminal-table', '~> 3.0.2'
|
33
34
|
spec.add_dependency 'thor', '~> 1.1.0'
|
34
35
|
|
35
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lnd-tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lnrpc
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.4.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: terminal-table
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: thor
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|