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

Add basic bitcoin signet support #5025

Merged
merged 3 commits into from
May 27, 2021
Merged

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Feb 14, 2021

Fixes #5018.

Depends on btcsuite/btcd#1692.
Depends on btcsuite/btcwallet#735.

Updates to the latest btcd version (which is why the diff is that large) and adds basic signet support.

@guggero guggero added backend Related to the node backend software/interface (e.g. btcd, bitcoin-core) bitcoind Bitcoin Core backend P2 should be fixed if one has time chain handling 32-bit labels Feb 14, 2021
@guggero guggero added this to the 0.13.0 milestone Feb 14, 2021
@guggero
Copy link
Collaborator Author

guggero commented Mar 4, 2021

I added the prefix as decide on in the spec PR (lightning/bolts#844).
Turns out a change in btcwallet is also required so added that PR as well.

@guggero
Copy link
Collaborator Author

guggero commented Apr 22, 2021

Rebased. @Roasbeef any particular reason for moving this to 0.14 or just because the dependencies weren't ready yet?

@wakiyamap
Copy link

wakiyamap commented May 3, 2021

I'm using google translate so I'm sorry if it's strange English.

zpay32/decode.go
https://github.com/lightningnetwork/lnd/pull/5025/files#diff-da9268b6d458ca0e80aab05fe9e6a79fe7049567efd48d77895ac50c9996db82R66

var netPrefixLength = len(net.Bech32HRPSegwit) + 2
->
var netPrefixLength = len(expectedPrefix) + 2

At the time of decoding, if it is tbs, the length will be calculated one less.
I get an error on amount, err := decodeAmount(hrp[netPrefixLength:])

exmaple
lntbs200u1psgl2a7pp5xuslr4k4g9n83w6j2mpeh3l84alwd68dh73rfgk9sfvlq9qtptyqdq2w3sk6ctddycqzpgsp5mk3cmhmmfgk2569khklxpg2gq6xfzj7ujv6ackw09cdfxm5g3vms9q8zqqyssqy8evtn0xt46t7xvvm3y4jf50n9zn7g7xs3uyuq6wj7zwpgulevhn5f45s0zevhgh0ssu2jncnepfpx2z7wus6zgk2usvqa5kp8d07qsp027kan

bad len(tb) + 2 -> s200
correct len(tbs) + 2 -> 200

@guggero
Copy link
Collaborator Author

guggero commented May 4, 2021

Thanks for the input @wakiyamap! Will fix that asap.

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

I tried a basic open channel end-to-end test between two local nodes (both connected to a local btcd instance) on the default signet and noticed the funding transaction failed to broadcast:

unmatched backend error: -26: TX rejected: transaction 3a7c4ba762cafe3bfe8db312abde4db5ff200e4d066564f21c00393a7a2d64ab has witness data, but segwit isn't active yet

Segwit is indeed active as I received P2WKH funds from a faucet, so it seems there's an issue with btcd determining whether the deployment is active when using signet's segwit deployment parameters.

DeploymentSegwit: {
	BitNumber:  1,
	StartTime:  0,             // Always available for vote
	ExpireTime: math.MaxInt64, // Never expires.
},

// BitcoinSigNetParams contains parameters specific to the signet test network.
var BitcoinSigNetParams = BitcoinNetParams{
Params: &bitcoinCfg.SigNetParams,
RPCPort: "38334",
Copy link
Contributor

Choose a reason for hiding this comment

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

Port should be 38332.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right. We didn't do the if wallet then 38334 else 38332 dance in btcd. So had to add a special case in lnd since we always subtract 2 for bitcoind.

@guggero
Copy link
Collaborator Author

guggero commented May 11, 2021

Thanks for testing this E2E! I figured out what the problem was. Going to fix it in btcd itself, no changes in lnd needed for the deployment. Was my misunderstanding on how the deployments actually work...

Will be fixed in btcsuite/btcd#1718.

@guggero guggero force-pushed the signet branch 2 times, most recently from ddbbb56 to a6d6f5e Compare May 11, 2021 12:34
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

The new dependent btcd PR has been merged now as well.

config.go Show resolved Hide resolved
@guggero
Copy link
Collaborator Author

guggero commented May 12, 2021

The new dependent btcd PR has been merged now as well.

We don't necessarily need to pull in the dependency as the fix was for running btcd on signet itself. But we can update the dependency in case we want to make sure we use the latest version for itests.
@wpaulino do you think we should update the dep?

@guggero guggero requested review from carlaKC and removed request for joostjager May 12, 2021 11:53
@wpaulino
Copy link
Contributor

Ah didn't realize the new one wasn't strictly dependent, it could be useful for those (if any) who choose to install btcd through make btcd. I wouldn't consider it a blocker though.

Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Small set of changes for such a nice feature! LGTM

config.go Outdated
Comment on lines 1046 to 1048
str := "%s: Invalid signet challenge, " +
"hex decode failed: %v"
err := fmt.Errorf(str, funcName, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why separate string and error here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wanted to follow the style of the rest of the file. But you're right, I like the more compact style more as well, fixed.

guggero added 3 commits May 18, 2021 13:06
With this commit we make lnd compatible with the public signet test
network.
The Core devs decided to us the same bech32 HRP for Signet as is used
for the current Testnet3. This might be okay for on-chain addresses
since they are compatible in theory. But for invoices we want to use a
distinct HRP to distinguish testnet from signet.
Also see spec PR
lightning/bolts#844 for more
information about the reasoning.
This commit updates the btcd version to a more recent one in which a bug
was fixed that lead to SegWit and Taproot not being activated properly
on signet.
This update is not strictly necessary for lnd to work but we include it
in case anyone wants to install btcd through lnd's Makefile.
@guggero
Copy link
Collaborator Author

guggero commented May 18, 2021

I added a commit to bump btcd to the most recent version so installing it through lnd's Makefile gives users a signet compatible version.

@Roasbeef, @cfromknecht any chance we can get this in for v0.13.0-beta.rcX?

@vwoo
Copy link
Contributor

vwoo commented May 25, 2021

Default rpc port seems to be incorrectly 38330.

// works
bitcoind.rpchost=x.x.x.x:38332

// fails, see log below
bitcoind.rpchost=x.x.x.x

2021-05-25 12:53:38.521 [INF] LNWL: Opened wallet
2021-05-25 12:53:38.619 [INF] CHRE: Primary chain is set to: bitcoin
2021-05-25 12:54:56.057 [ERR] LTND: unable to create chain control: Post "http://x.x.x.x:38330": dial tcp x.x.x.x:38330: connect: operation timed out
2021-05-25 12:54:56.058 [INF] LTND: Shutdown complete

unable to create chain control: Post "http://x.x.x.x:38330": dial tcp x.x.x.x:38330: connect: operation timed out

@Roasbeef
Copy link
Member

cc @guggero ^

rpcPort = 19443
case cfg.Bitcoin.Active && cfg.Bitcoin.SigNet:
rpcPort = 38332
Copy link
Member

Choose a reason for hiding this comment

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

@vwoo perhaps something is being morphed before the call is made? We enforce the default port here

Copy link
Contributor

Choose a reason for hiding this comment

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

If I change the signet port from 38332 to 38334 in chainreg/chainparams.go then the default port works.

Just following the pattern in the rest of chainparams.go where the port is always +2.

bitcoind --help | grep rpcport
mainnet: 8332
testnet: 18332
signet: 38332

chainreg/chainparams.go
mainnet: 8334
testnet: 18334
signet: 38332

Seems like the pattern break is intentional but maybe there was a mixup between chainregistry.go and chainparams.go?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vwoo see #5351.

@Roasbeef Roasbeef modified the milestones: v0.14.0, 0.13.0 May 27, 2021
@Roasbeef
Copy link
Member

Gonna merge as is, AFAICT the port information is correct here. Want to include this in the next rc, and can do another one if it turns out there's actually something afoot here.

@Roasbeef Roasbeef merged commit 0ed72b8 into lightningnetwork:master May 27, 2021
@guggero guggero deleted the signet branch May 27, 2021 07:47
@b3h3rkz
Copy link

b3h3rkz commented Jun 10, 2021

I have nothing special to add here but to say I love that this came in at this time!!!

Timely and kudos to everyone involved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
32-bit backend Related to the node backend software/interface (e.g. btcd, bitcoin-core) bitcoind Bitcoin Core backend chain handling P2 should be fixed if one has time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signet
8 participants