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

Docker examples #66

Merged
merged 3 commits into from
Jan 14, 2020
Merged

Docker examples #66

merged 3 commits into from
Jan 14, 2020

Conversation

fguisso
Copy link
Member

@fguisso fguisso commented Dec 12, 2019

Hello guys, I've been trying to script for a few months to automate my simnet environments and also update the example with LN docker-compose.

For now I have succeeded in building a Minimum Voting Wallet (MVW), see #12 , and interacting with dcrd and dcrwallet in a nice way. Just add a docker-compose up --build to get everything up and running.

I'm still going to improve some things, but I've opened PR so they can give me a light and tell if it's all by default since I'm not an expert docker.

What we have so far:
You can choose wallet_seed and wallet_pass from docker-compose.yml or using --build-args.
Thus, when docker creates the application, dcrwallet dockerfile uses two steps, one for creating the wallet, generating an address and saving that address to a volume like dcrd.conf, and the other for leaving the container clean only with what is needed. for the dcrwallet to run.
With this, dcrd runs with --miningaddr flag set for your wallet and you can generate blocks and init dcrwallet with ticketbuyer.

Next steps:

  • fix the dcrlnd files to work with this MVW
  • organize and update readme to find more UX tips to simplify example use.

I'm using this repos to refer in how MVW works:

@fguisso
Copy link
Member Author

fguisso commented Dec 13, 2019

Draft for doc
General workflow is the following:

  • Run docker-compose up --no-start to create network, volumes and build the services dcrd, dcrwallet, dcrctl and dcrlnd.

dcrd, dcrwallet and MVW

We need to start dcrd service and generate 100 blocks for the first coinbase to mature, because without coins, the MVW(Minimum Voting Wallet) can't buy tickets.

# Run dcrd service for the first time
docker-compose start dcrd

# Use dcrctl to generate 100 blocks
docker-compose run dcrctl generate 100

Now we can start the dcrwallet and the MVW will work great.
docker-compose start dcrwallet

dcrlnd, the history about Alice and Bob

Create Alices container and send funds from dcrwallet:

#Create "Alice"s container
docker-compose run -d --name alice dcrlnd

#Log into the "Alice" container
docker exec -it alice bash

# Generate a new backward compatible nested p2sh address for Alice:
alice$ dcrlncli -n simnet newaddress p2pkh

We can keep logged in Alice container, just need to use another terminal tab to execute commands in docker-compose.

  • Send 1DCR from dcrwallet to Alice address
#Send from MVW to Alice's LNWallet
docker-compose run dcrctl --wallet sendfrom deafult <alice_address> 1

#Generate a block to update the wallet balance
docker-compose run dcrctl generate 1

#Check Alice's wallet balance
alice$ dcrlncli -n simnet walletbalance

Create Bobs container and connect to Alice:

#Create "Bob"s container
`docker-compose run -d --name bob dcrlnd`

#Log into the "Bob" container
`docker exec -it bob bash`

Connect Bob node to Alice node

#Get identity pubkey from Bob's node
bob$ dcrlncli -n simnet getinfo
{
	"version": "0.2.0-pre+dev",
	------>"identity_pubkey": "02fe9daea36c1b1bd9e8dc1f5dc9edfc887d223199f2bac99e1cf92eb8cdb654e7",
	"alias": "02fe9daea36c1b1bd9e8",
	"color": "#3399ff",
	"num_pending_channels": 0,
	"num_active_channels": 0,
	"num_inactive_channels": 0,
	"num_peers": 0,
	"block_height": 101,
	"block_hash": "0000066c30cee9bae93a05b9b0edacef1fea1443f4b43a96f5d0761a70965c18",
	"best_header_timestamp": 1576527447,
	"synced_to_chain": true,
	"synced_to_graph": false,
	"testnet": false,
	"chains": [
		{
			"chain": "decred",
			"network": "simnet"
		}
	],
	"uris": null
}

#Connect Alice to Bob's node
alice$ dcrlncli -n simnet connect <bob_pubkey>@bob

# Check list of peers on "Alice" side:
alice$ dcrlncli -n simnet listpeers
{
    "peers": [
        {
            "pub_key": "02fe9daea36c1b1bd9e8dc1f5dc9edfc887d223199f2bac99e1cf92eb8cdb654e7",
            "address": "172.25.0.5:9735",
            "bytes_sent": "139",
            "bytes_recv": "139",
            "atoms_sent": "0",
            "atoms_recv": "0",
            "inbound": false,
            "ping_time": "0",
            "sync_type": "ACTIVE_SYNC"
        }
    ]
}

Create the Alice<->Bob channel.

# Open the channel with "Bob":
alice$ dcrlncli -n simnet openchannel --node_key=<bob_pubkey> --local_amt=1000000

# Include funding transaction in block thereby opening the channel:
# We need six confirmations to channel active
$ docker-compose run dcrctl generate 6

# Check that channel with "Bob" was opened:
alice$ dcrlncli --n simnet listchannels
{
    "channels": [
        {
            "active": true,
            "remote_pubkey": "02fe9daea36c1b1bd9e8dc1f5dc9edfc887d223199f2bac99e1cf92eb8cdb654e7",
            "channel_point": "ed19031307d1ae49b06f38587e9336dac1015be11ad59432f84af9de4d4fdef7:0",
            "chan_id": "112150186164224",
            "capacity": "1000000",
            "local_balance": "996360",
            "remote_balance": "0",
            "commit_fee": "3640",
            "commit_size": "328",
            "fee_per_kb": "10000",
            "unsettled_balance": "0",
            "total_atoms_sent": "0",
            "total_atoms_received": "0",
            "num_updates": "0",
            "pending_htlcs": [
            ],
            "csv_delay": 288,
            "private": false,
            "initiator": true,
            "chan_status_flags": "ChanStatusDefault",
            "local_chan_reserve_atoms": "10000",
            "remote_chan_reserve_atoms": "10000",
            "static_remote_key": true
        }
    ]
}

Send the payment from Alice to Bob.

# Add invoice on "Bob" side:
bob$ dcrlncli -n simnet addinvoice --amt=10000
{
        "r_hash": "<your_random_rhash_here>", 
        "pay_req": "<encoded_invoice>", 
        "add_index": 1
}

# Send payment from "Alice" to "Bob":
alice$ dcrlncli -n simnet payinvoice <encoded_invoice>

# Check "Alice"'s channel balance
alice$ dcrlncli -n simnet channelbalance

# Check "Bob"'s channel balance
bob$ lncli -n simnet channelbalance

Now we have open channel in which we sent only one payment, let's imagine that we sent lots of them and we'd now like to close the channel. Let's do it!

# List the "Alice" channel and retrieve "channel_point" which represents
# the opened channel:
alice$ dcrlncli -n simnet listchannels
{
    "channels": [
        {
            "active": true,
            "remote_pubkey": "02fe9daea36c1b1bd9e8dc1f5dc9edfc887d223199f2bac99e1cf92eb8cdb654e7",
            ------>"channel_point": "ed19031307d1ae49b06f38587e9336dac1015be11ad59432f84af9de4d4fdef7:0",
            "chan_id": "112150186164224",
            "capacity": "1000000",
            "local_balance": "986360",
            "remote_balance": "10000",
            "commit_fee": "3640",
            "commit_size": "364",
            "fee_per_kb": "10000",
            "unsettled_balance": "0",
            "total_atoms_sent": "10000",
            "total_atoms_received": "0",
            "num_updates": "2",
            "pending_htlcs": [
            ],
            "csv_delay": 288,
            "private": false,
            "initiator": true,
            "chan_status_flags": "ChanStatusDefault",
            "local_chan_reserve_atoms": "10000",
            "remote_chan_reserve_atoms": "10000",
            "static_remote_key": true
        }
    ]
}


# Channel point consists of two numbers separated by a colon. The first one 
# is "funding_txid" and the second one is "output_index":
alice$ dcrlncli -n simnet closechannel <funding_txid> <output_index>

# Include close transaction in a block thereby closing the channel:
$ docker-compose run dcrctl generate 6

# Check "Alice" on-chain balance was credited by her settled amount in the channel:
alice$ dcrlncli -n simnet walletbalance

# Check "Bob" on-chain balance was credited with the funds he received in the
# channel:
bob$ dcrlncli -n simnet walletbalance
{
    "total_balance": "10000",
    "confirmed_balance": "10000",
    "unconfirmed_balance": "0"
}

@fguisso
Copy link
Member Author

fguisso commented Dec 16, 2019

@matheusd and @jholdstock can you review please?
I stopped by simnet since we need MVW, but the upstream LND tutorial has a part about using testnet, wanted an idea as to whether it is better to create another compose just for testnet or continue the example with more dcrlnd nodes?
https://github.com/lightningnetwork/lnd/tree/master/docker#connect-to-faucet-lightning-node

Copy link
Member

@matheusd matheusd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aside, but in simnet the coinbase maturity is 16 blocks: https://github.com/decred/dcrd/blob/master/chaincfg/simnetparams.go#L167

On a superficial pass, it seems in the right track.

Given in simnet you need the MVW and in testnet you probably won't anything and will instead use the online faucet and connect to other nodes I'd split this tutorial in two documents: One for simnet (where you specify the process of setting up the MVW) and one for testnet, where you direct users to the on-chain faucet and off-chain network map or known faucet nodes.

docker/README.md Outdated Show resolved Hide resolved
@fguisso fguisso changed the title (WIP) Docker Docker examples Dec 28, 2019
@fguisso fguisso marked this pull request as ready for review December 28, 2019 17:59
@jholdstock
Copy link
Member

I've run into some issues whilst testing this, going to debug with @fguisso on Matrix

Copy link
Member

@jholdstock jholdstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked through the issues and now this is working well! I have made some minor suggestions but otherwise LGTM, nice work

docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/README.md Outdated Show resolved Hide resolved
docker/dcrlnd/Dockerfile Outdated Show resolved Hide resolved
Update all docker files to work with dcrd and dcrlnd instead of btcd and lnd.
@matheusd matheusd merged commit ff8cedf into decred:master Jan 14, 2020
@matheusd matheusd mentioned this pull request Jan 15, 2020
4 tasks
@fguisso fguisso deleted the docker branch January 16, 2020 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants