Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage 2 major review #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions tutorial/01-lncli.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ To see all the commands available for `lncli`, simply type `lncli --help` or
`lncli -h`.

### Setting up Bitcoin addresses

Let's create a new Bitcoin address for Alice. This will be the address that
stores Alice's on-chain balance.

Expand Down Expand Up @@ -324,8 +325,9 @@ Generate 400 blocks, so that Alice gets the reward. We need at least 100 blocks
because coinbase funds can't be spent until after 100 confirmations, and we
need about 300 to activate segwit.
window with `$GOPATH` and `$PATH` set.

```bash
alice$ btcctl --simnet --rpcuser=kek --rpcpass=kek generate 400
btcctl --simnet --rpcuser=kek --rpcpass=kek generate 400
```

Check that segwit is active:
Expand All @@ -335,11 +337,13 @@ btcctl --simnet --rpcuser=kek --rpcpass=kek getblockchaininfo | grep -A 1 segwit

Check Alice's wallet balance. `--witness_only=true` specifies that we only want
to consider witness outputs when calculating the wallet balance.

```bash
alice$ lncli-alice walletbalance --witness_only=true
```

It's no fun if only Alice any money. Let's give some to Charlie as well:

```bash
# Quit btcd
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek --miningaddr=<CHARLIE_ADDRESS>
Expand Down Expand Up @@ -423,20 +427,33 @@ bob$ lncli-bob listpeers
```

Finish up the P2P network by connecting Bob to Charlie:

```bash
charlie$ lncli-charlie connect <BOB_PUBKEY>@localhost:10012
```

and testing their connections:

```bash
# Check that Charlie has added Bob as a peer:
charlie$ lncli-charlie listpeers

# Check that Bob has added Charlie as a peer
bob$ lncli-bob listpeers
```

### Setting up Lightning Network

Before we can send payment, we will need to set up payment channels from Alice
to Bob, and Bob to Charlie.

First, let's open the Alice<-->Bob channel.

```bash
alice$ lncli-alice openchannel --node_key=<BOB_PUBKEY> --local_amt=1000000
```
- `--local_amt` specifies the amount of money that Alice will commit to the

- `--local_amt` specifies the amount of Satoshi that Alice will commit to the
channel. To see the full list of options, you can try `lncli openchannel
--help`.

Expand All @@ -446,6 +463,7 @@ btcctl --simnet --rpcuser=kek --rpcpass=kek generate 6
```

Check that Alice<-->Bob channel was created:

```bash
alice$ lncli-alice listchannels
{
Expand Down Expand Up @@ -476,27 +494,29 @@ Finally, to the exciting part - sending payments! Let's send a payment from
Alice to Bob.

First, Bob will need to generate an invoice:

```bash
bob$ lncli-bob addinvoice --value=10000
bob$ lncli-bob addinvoice --value=100000
{
"r_hash": "<a_random_rhash_value>",
"pay_req": "<encoded_invoice>",
}
```

Send the payment from Alice to Bob:

```bash
alice$ lncli-alice sendpayment --pay_req=<encoded_invoice>
{
"payment_preimage": "baf6929fc95b3824fb774a4b75f6c8a1ad3aaef04efbf26cc064904729a21e28",
"payment_route": {
"total_time_lock": 1,
"total_amt": 10000,
"total_amt": 100000,
"hops": [
{
"chan_id": 495879744192512,
"chan_capacity": 1000000,
"amt_to_forward": 10000
"amt_to_forward": 100000
}
]
}
Expand All @@ -513,6 +533,7 @@ bob$ lncli-bob listchannels

Now that we know how to send single-hop payments, sending multi hop payments is
not that much more difficult. Let's set up a channel from Bob<-->Charlie:

```bash
charlie$ lncli-charlie openchannel --node_key=<BOB_PUBKEY> --local_amt=800000 --push_amt=200000

Expand All @@ -524,6 +545,7 @@ Note that this time, we supplied the `--push_amt` argument, which specifies the
amount of money we want to other party to have at the first channel state.

Let's make a payment from Alice to Charlie by routing through Bob:

```bash
charlie$ lncli-charlie addinvoice --value=10000
alice$ lncli-alice sendpayment --pay_req=<encoded_invoice>
Expand Down Expand Up @@ -562,6 +584,7 @@ alice$ lncli-alice listchannels
The Channel point consists of two numbers separated by a colon, which uniquely
identifies the channel. The first number is `funding_txid` and the second
number is `output_index`.

```bash
# Close the Alice<-->Bob channel from Alice's side.
alice$ lncli-alice closechannel --funding_txid=<funding_txid> --output_index=<output_index>
Expand All @@ -573,7 +596,7 @@ btcctl --simnet --rpcuser=kek --rpcpass=kek generate 1
# channel. Recall that Bob previously had no on-chain Bitcoin:
alice$ lncli-bob walletbalance
{
"balance": "20001"
"balance": "110001"
}
```

Expand Down
Loading