-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
rpc: anchor reserve check for SendOutputs
#7631
Conversation
SendOutputs
16f47eb
to
7e1fecf
Compare
7e1fecf
to
142f991
Compare
142f991
to
da6206b
Compare
lnrpc/walletrpc/walletkit_server.go
Outdated
@@ -1666,7 +1673,9 @@ func parseAddrType(addrType AddressType, | |||
switch addrType { | |||
case AddressType_UNKNOWN: | |||
if required { | |||
return nil, errors.New("an address type must be specified") | |||
return nil, errors.New( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for errors
we'd format it similar to fmt.Errorf
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I missed this style fix. Will add.
itest/lnd_onchain_test.go
Outdated
MinConfs: 1, | ||
} | ||
|
||
// We try to send the reserve violating transaction... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We try to send the reserve violating transaction... | |
// We try to send the reserve violating transaction. |
lnrpc/walletrpc/walletkit_server.go
Outdated
|
||
// We'll get the currently required reserve amount. | ||
reserve, err := w.RequiredReserve( | ||
ctx, &RequiredReserveRequest{AdditionalPublicChannels: 0}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm what if we need more public channels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AdditionalPublicChannels
is just an RPC parameter that allows you to plan ahead if you intend to open more channels in the near future. Not really related to this feature, as we just need to check the reserve for the current number of channels, so just remove that parameter as the default is 0 anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool got it, yeah make sense to use the default.
da6206b
to
041f6bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very close! Just a new nits in the itest.
itest/lnd_onchain_test.go
Outdated
ht.EnsureConnected(alice, bob) | ||
|
||
// We'll get the anchor reserve that is required for a single channel. | ||
reserve, _ := alice.RPC.WalletKit.RequiredReserve( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add RequiredReserve
to wallet_kit.go
and access it via alice.RPC.RequiredReserve
to avoid checking the RPC error?
itest/lnd_onchain_test.go
Outdated
} | ||
|
||
// We try to send the reserve violating transaction. | ||
_, err := alice.RPC.WalletKit.SendOutputs(context.Background(), req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use a timeout context here to avoid it hanging, tho almost will never happen, just in case. And we can use ht.Context()
here.
itest/lnd_onchain_test.go
Outdated
ht.MineBlocksAndAssertNumTxes(1, 0) | ||
|
||
// We expect SendOutputs to return the respective error. | ||
require.ErrorContains(ht, err, "the outputs to be send would leave "+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move the error check next to the rpc call
itest/lnd_onchain_test.go
Outdated
ht.MineBlocksAndAssertNumTxes(1, 1) | ||
|
||
// This second transaction should be published correctly. | ||
require.NoError(ht, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here re moving the error check, so we can skip mining and assertion if there does return an error, otherwise we won't see the NoError
fail because ht.MineBlocksAndAssertNumTxes
will fail first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only nits 🎉
lnrpc/walletrpc/walletkit_server.go
Outdated
|
||
// We'll get the currently required reserve amount. | ||
reserve, err := w.RequiredReserve( | ||
ctx, &RequiredReserveRequest{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can now fit on a single line.
lnrpc/walletrpc/walletkit_server.go
Outdated
} | ||
|
||
// Then we check if our current wallet balance undershoots the required | ||
// reserve if we'd send out the outputs sepcified in the request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo in the word "specified".
lnrpc/walletrpc/walletkit_server.go
Outdated
// Then we check if our current wallet balance undershoots the required | ||
// reserve if we'd send out the outputs sepcified in the request. | ||
if int64(walletBalance)-totalOutputValue < reserve.RequiredReserve { | ||
return nil, fmt.Errorf("the outputs to be send would leave " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/send/sent/. Also, should we mention anchor channels? E.g. "would leave insufficient reserves for anchor channels".
@@ -717,7 +719,8 @@ func (w *WalletKit) SendOutputs(ctx context.Context, | |||
// requirement, we can request that the wallet attempts to create this | |||
// transaction. | |||
tx, err := w.cfg.Wallet.SendOutputs( | |||
outputsToCreate, chainfee.SatPerKWeight(req.SatPerKw), minConfs, label, | |||
outputsToCreate, chainfee.SatPerKWeight(req.SatPerKw), minConfs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
itest/lnd_onchain_test.go
Outdated
// Alice opens an anchor channel and keeps twice the amount of the | ||
// anchor reserve in her wallet. | ||
chanAmt := fundingAmount - 2*btcutil.Amount(reserve.RequiredReserve) | ||
outpoint := ht.OpenChannel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could use the compact form here, since things seem to fit on one line:
outpoint := ht.OpenChannel(alice, bob, lntest.OpenChannelParams{
Amt: chanAmt,
CommitmentType: lnrpc.CommitmentType_ANCHORS,
SatPerVByte: 1,
})
itest/lnd_onchain_test.go
Outdated
ht.MineBlocksAndAssertNumTxes(1, 0) | ||
|
||
// We expect SendOutputs to return the respective error. | ||
require.ErrorContains(ht, err, "the outputs to be send would leave "+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should probably define this as an exported error, then we can string match on it here to shorten the line and also avoid braking the test when the message is updated.
d1c64ea
to
79a06d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM⛵️
Fixes #7591.
This PR adds a check to the
SendOutputs
RPC to prevent it from undershooting the anchor reserve requirement.