bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 11쪽
begin with.
Danger of copying the dcrlnd database
Do not perform full-db backups
This section details why full-db backups are
not safe
in the current implementation of
dcrlnd
.
Do
not
perform full-db backups unless you have very deep knowledge on how LN operates, and how
dcrlnd
is implemented, and the
complete
loss of funds that might occur when using an incorrect db backup.
Given the need to prevent loss of funds by having some backup channel data, the initial idea for most sysadmins would be to perform a full backup of the
dcrlnd
DB in regular intervals (via
cp
,
rsync
or similar commands). This could, in principle, allow a node to pick up the channel states and resume operations from where it had the initial malfunction.
There is a fundamental problem in using backups created from a running
dcrlnd
instance, however: there are
no
assurances that a given backup DB copy has the
most recent
, unrevoked channel state.
Using an older backup with a revoked state (i.e. a revoked commitment transaction) would cause the local node to publish a transaction that is now completely redeemable by the remote node.
In other words, using a backup with an old state causes
all funds to be sent to the remote party
. On the public blockchain, this looks as if the local node tried to steal funds (by broadcasting an older commitment tx) and the remote node then performed the “breach” protocol, exacting justice for the incorrect behavior of their counterparty.
Therefore, trying to do a simple, continous backup of the
dcrlnd
DB is
unsafe
, in the sense that attempting to use such a backup risks all the funds in all of the node’s channels.
While it might be possible to offer some form of DB replication to increase reliability and safety for larger nodes and operators, this remains an open problem within the
dcrlnd
design and implementation.
The Data Loss Protect option
The Lightning Network
BOLTs
define a special channel feature called
option_data_loss_protect
(DLP). Triggering this option during channel re-establishment (for example, after suffering data loss) causes the other node to publish their most recent (unrevoked) commitment transaction, thus in principle allowing a node to get their funds back.
However to retrieve those funds a node still needs some minimal metadata about a channel - mainly the specific keys and scripts used to redeem the local funds of the commitment transaction.
In dcrlnd, this metadata and the mechanism to trigger restores is called the
Static Channel Backup
(SCB) data.
Note that since the DLP protocol involves asking the
remote
node to close a channel due to some local data loss, the remote node could attempt to send an older state that is more to its advantage.
However, nodes are disincentivized to do this because the local node could be lying to force the triggering of the DLP, and if the remote node publishes an old state, the local node would be able to use its newer state to send a justice transaction which claims all of the channel funds. Additionally, the local node could have previously set up a watchtower to remedy any breach attempts by their counterparty.
SCB File Contents
The SCB file contains information about the node’s currently open channels. For each channel, it stores the funding outpoint (that is, the transaction hash and index of the output that realizes the channel on-chain) plus the index of the keys necessary to redeem funds from the channel, along with some extra metadata such as the node ID and IP addresses of the corresponding remote node.
Note that the SCB file does
not
contain up-to-date information about the channels. That is, it does
not
store the current commitment transaction, commitment index, in-flight payments, revocation keys, etc.
In other words, an SCB file contains only a sort of
shell
channel information: the minimum amount of info necessary to locate and redeem funds that belong to the local node on commitments created by and stored by the
remote
party.
Therefore, this file doesn’t change during regular operations of a single, specific channel: the data in the SCB is valid for the entirety of the channel’s lifetime.
The SCB file is only updated once new channels are created (in which case the new channels are added to it) or closed (when a channel is finally removed from it).
The contents of the file are also
encrypted
using one of the node’s private keys so they are only valid and decodable by the original node that created them.
Note that SCB-based backups do not suffer from the limitations of the full DB copy procedure outlined previously. This is due to the fact that this method of backups does
not
attempt to restore channel operations but only to trigger a remote channel closure via the DLP protocol so that a node may retrive its funds.
Operating SCB Backups
The next sections provide a quick review on how to generate and use SCB-based LN backups.
Creating the SCB file
dcrlnd
automatically creates a valid SCB file named
channel.backup
every time a channel is opened or closed. This file can be found in the data dir of a
dcrlnd
install, in the
chain/decred/[network]
subdir. CLI users can use
dcrlncli
to generate an SCB file on-demand via the
exportchanbackups
command, containing the information of either a single or multiple channels.
Decrediton users can also generate a file by using the appropriate option in the GUI.
Users must maintain up to date copies of their SCB files so that they can retrieve their funds in case of data loss.
Restoring a Backup
Once a seed has been restored and the on-chain funds verified to be correct, the SCB file can be used to restore the channel shells and initiate the DLP protocol with the respective remote nodes.
CLI users can use the
restorechanbackup
command to apply the contents of an SCB file to the node.
Decrediton users can specify an SCB file during the initial creation of the LN wallet, which will trigger the DLP process.
Wallet and Account Matching
When using an SCB file to restore the channel data, the wallet seed and account used for LN operations (in case of Decrediton based wallets)
must
match the ones that created the SCB file, otherwise the restore operation fails.
In particular, Decrediton users
must
select the correct account to base their LN wallet on, when initializing it on a restored wallet, otherwise the setup of the LN node fails.
## /lightning-network/watchtowers
LN Watchtowers
Critical information to prevent theft of funds
LN nodes should remain online for as long as possible to monitor for on-chain breaches of a channel. The best alternative for
episodic
nodes (ones that don’t remain online continuously) is to use
watchtower
services to monitor the chain for them.
Watchtower Limitations
The current implementation of watchtowers is only able to recover funds already committed to in the channel,
not
from in-flight payments, thus it’s a good practice not to have a large number of outstanding payments at any one time when relying on watchtowers.
LN operates under the assumption that nodes can respond in a timely manner in case of
channel breaches
by broadcasting a so called
justice transaction
on-chain if the counter-party of a channel is (or becomes) malicious.
For many end-users however that isn’t feasible: it would mean leaving their computer running 24 hours a day and their wallet unlocked so that
dcrlnd
can perform its operations.
This document reviews the motivation for the existence of Watchtower services, how they work and how to interact with them.
Overview of Channel Breaches
This section can be skipped if you know what it means to
breach
an LN channel.
Lightning Network channels are realized on the blockchain as multisig, 2-of-2 outputs. This means both parties of a channel must cooperate in order to advance its
state
, which reflects the relative balances of the two participants and any outstanding (in-flight) payments:
Each state corresponds to a
commitment transaction
: a transaction signed by both parties that spends the multisig channel output and that pays the correct relative amount to each party.
Any commitment transaction is publishable by any of the two parties once a state is “locked in” (also referred as “irrevocably committed” to). This means
any point of the entire state history
is, in principle, publishable at any time.
The “any point of the entire state history” is key: even
old
states, ones that no longer reflect the most recent situation for the relative balances in the channel can be broadcast at any time by any of the parties.
This means that a malicious counter-party of one of your channels could attempt to cheat and steal funds from you by publishing an old commitment transaction that is more favorable to them.
For example, in the above picture, even though according to the correct accounting and the most recent state Alice has 0.3 DCR and Bob has 4.7 DCR, Alice could publish the commitment transaction corresponding to state number #13 on-chain and fetch 4.5 DCR to herself.
This event (publishing an old, revoked state) is called a
channel breach
: Alice breached her channel with Bob and is attempting to steal funds that actually belong to him.
Responding to Channel Breaches
Whenever a party detects their counter-party published an old commitment transaction that has been mined on the underlying blockchain, they can trigger a mechanism called a
justice transaction
(also sometimes called the
penalty
transaction). This is a transaction that fetches back the funds of the wrongly published commitment transaction, effectively penalizing the other participant for their incorrect behavior by giving the entire funds of the channel to the affected party.
This behavior is a part of the technical specification of the Lightning Network since it was
first proposed
.
However, it crucially depends on the capacity of nodes to
timely
observe the underlying blockchain for detecting these channel breaches and to respond to them by creating and signing appropriate justice transactions.
This implies the nodes need to remain online, they need to remain connected to the blockchain’s P2P network and they need to keep their wallet unlocked in order to sign the required transactions.
For routing nodes - that is, nodes that are meant to remain online routing payments between distant participants of the network - that is not an issue since remaining online and well-connected is part of their standard operating procedure.
However, for
ephemeral
or
episodic
nodes - ones that come online simply to make or receive an eventual payment and then go offline again - this is a harder requirement to achieve.
In fact, a large amount of end-users fall exactly into this category: users that open a channel and make a few payments a month. For these users, keeping their wallets online and unlocked for a significant amount of time is infeasible.
The solution for these users is to use a Watchtower Service.
Watchtower Basics
A Watchtower is an LN node that can watch the chain on behalf of a third party and can send an appropriate justice transaction if it detects a relevant breach of contract.
Every time a channel state is updated, the client node contacts the Watchtower and provides it information about the just
revoked
state: the relevant keys, signatures for the justice transaction and a partial copy of the hash of commitment transaction. The keys and signatures are encrypted using the full hash of the commitment transaction as key.
The Watchtower will then take that information as a hint and will begin to watch the chain for any signs that the provided transaction is mined. If it detects the partial tx hash on a block, it will find out the full hash of the revoked commitment transaction and will be able to decrypt the justice data.
At this moment it will re-assemble the justice tx and publish it on the network, returning any funds locked in the delayed output of the breached commitment (the so-called
to_local
output) to its rightful owner.
Limitations
The current implementation of the Watchtower feature can only redeem funds from the actually committed channel funds (that is, from the outputs that determine the relative balances of the channel participants).
In-flight payments (i.e. HTLCs) aren’t supported by the current watchtower protocol, therefore in case of breaches those funds will still be available for the breacher to redeem.
For nodes relying on Watchtowers, it is therefore recommended not to have individual states with many outstanding payments. In other words, users that are relying on watchtowers should generally wait until most of their in-flight payments are completed before they attempt a new one.
Using Watchtowers
CLI users may use the
wtclient
command to add, remove and query the state of the watchtowers in their
dcrlnd
node.
Note that
dcrlnd
must be started with the
--wtclient.active
flag in order to enable the use of the
wtclient
command via
dcrlncli
.
Decrediton users may use the “Watchtowers” tab to add a watchtower to their corresponding LN wallet.
In order to add a Watchtower to your node, you’ll need to find its public key (their Node Id in the lightning network) and the public IP address and port of their watchtower functionality.
## /lightning-network/dcrlncli/options-and-commands
dcrlncli Options and Commands
Last updated for dcrlnd release v0.3.0.
dcrlncli
is a client which controls Decred Lightning Network Daemon (
dcrlnd
) via RPC calls.
You can use
dcrlncli
for many things, such as checking your balance, managing channels,
creating transactions, and viewing network information.
dcrlncli
is not a daemon - it does not run permanently in the background - it calls the
requested RPC method, prints the response, and then terminates immediately.
Usage
dcrlncli [global options] command [command options] [arguments...]
Global Options
Flag
Info
--rpcserver value
Host:port of Decred LN daemon (default:
"localhost:10009"
)
--lnddir value
Path to dcrlnd’s base directory (default:
"~/.dcrlnd"
)
--tlscertpath value
Path to TLS certificate (default:
"~/.dcrlnd/tls.cert"
)
--chain value
,
-c value
The chain dcrlnd is running on e.g. decred (default:
"decred"
)
--testnet
Use the test network
--simnet
Use the simulation network
--regtest
Use the regression test network
--no-macaroons
Disable macaroon authentication
--macaroonpath value
Path to macaroon file
--macaroontimeout value
Anti-replay macaroon validity time in seconds (default:
60
)
--macaroonip value
If set, lock macaroon to specific IP address
--help
,
-h
Show help
--version
,
-v
Print the version
Commands
General Commands
Command
Info
getinfo
Returns basic information related to the active daemon.
getrecoveryinfo
Display information about an ongoing recovery attempt.
debuglevel
Set the debug level.
stop
Stop and shutdown the daemon.
version
Display lncli and lnd version info.
help, h
Shows a list of commands or help for one command
Autopilot Commands
Command
Info
autopilot
Interact with a running autopilot.
Channel Commands
Command
Info
openchannel
Open a channel to a node or an existing peer.
closechannel
Close an existing channel.
closeallchannels
Close all existing channels.
abandonchannel
Abandons an existing channel.
channelbalance
Returns the sum of the total available channel balance across all open channels.
pendingchannels
Display information pertaining to pending channels.
listchannels
List all open channels.
closedchannels
List all closed channels.
getnetworkinfo
Get statistical information about the current state of the network.
feereport
Display the current fee policies of all active channels.
updatechanpolicy
Update the channel policy for all channels, or a single channel.
exportchanbackup
Obtain a static channel back up for a selected channels, or all known channels
verifychanbackup
Verify an existing channel backup
restorechanbackup
Restore an existing single or multi-channel static channel backup
Graph Commands
Command
Info
describegraph
Describe the network graph.
getnodemetrics
Get node metrics.
getchaninfo
Get the state of a channel.
getnodeinfo
Get information on a specific node.
Invoice Commands
Command
Info
addinvoice
Add a new invoice.
lookupinvoice
Lookup an existing invoice by its payment hash.
listinvoices
List all invoices currently stored within the database. Any active debug invoices are ignored.
decodepayreq
Decode a payment request.
cancelinvoice
Cancels a (hold) invoice
addholdinvoice
Add a new hold invoice.
settleinvoice
Reveal a preimage and use it to settle the corresponding invoice.
Macaroon Commands
Command
Info
bakemacaroon
Bakes a new macaroon with the provided list of permissions and restrictions.
listmacaroonids
List all macaroons root key IDs in use.
deletemacaroonid
Delete a specific macaroon ID.
listpermissions
Lists all RPC method URIs and the macaroon permissions they require to be invoked.
printmacaroon
Print the content of a macaroon in a human readable format.
On-chain Commands
Command
Info
estimatefee
Get fee estimates for sending decred on-chain to multiple addresses.
sendmany
Send decred on-chain to multiple addresses.
sendcoins
Send decred on-chain to an address.
listunspent
List UTXOs available for spending.
listchaintxns
List transactions from the wallet.
Payment commands
Command
Info
sendpayment
Send a payment over lightning.
payinvoice
Pay an invoice over lightning.
sendtoroute
Send a payment over a predefined route.
listpayments
List all outgoing payments.
queryroutes
Query a route to a destination.
fwdinghistory
Query the history of all forwarded HTLCs.
trackpayment
Track progress of an existing payment.
querymc
Query the internal mission control state.
queryprob
Estimate a success probability.
resetmc
Reset internal mission control state.
buildroute
Build a route from a list of hop pubkeys.
Peer commands
Command
Info
connect
Connect to a remote dcrlnd peer.
disconnect
Disconnect a remote dcrlnd peer identified by public key.
listpeers
List all active, currently connected peers.
Startup commands
Command
Info
create
Initialize a wallet when starting dcrlnd for the first time.
unlock
Unlock an encrypted wallet at startup.
changepassword
Change an encrypted wallet’s password at startup.
Wallet commands
Command
Info
newaddress
Generates a new address.
walletbalance
Compute and display the wallet’s current balance.
signmessage
Sign a message with the node’s private key.
verifymessage
Verify a message signed with the signature.
wallet
Interact with the wallet.
Watchtower commands
Command
Info
tower
Interact with the watchtower.
wtclient
Interact with the watchtower client.
## /lightning-network/dcrlncli/autopilot
autopilot
dcrlncli autopilot
- Interact with a running autopilot.
Usage
dcrlncli autopilot [arguments...]
## /lightning-network/dcrlncli/openchannel
openchannel
dcrlncli openchannel
- Open a channel to a node or an existing peer.
Usage
dcrlncli openchannel [command options] node-key local-amt push-amt
Description
Attempt to open a new channel to an existing peer with the key node-key
optionally blocking until the channel is ‘open’.
One can also connect to a node before opening a new channel to it by
setting its host:port via the
--connect argument
. For this to work,
the
node_key
must be provided, rather than the
peer_id
. This is optional.
The channel will be initialized with
local-amt
atoms locally and
push-amt
atoms for the remote node. Note that specifying
push-amt
means you give that
amount to the remote node as part of the channel opening. Once the channel is open,
a
channelPoint
(
txid:vout
) of the funding output is returned.
One can manually set the fe프로젝트로 돌아가기