Merge pull request #7272 from positiveblue/fix-7270

rpc: check that closing address matches the current network for open channel requests
This commit is contained in:
Oliver Gugger 2023-01-05 17:15:55 +01:00 committed by GitHub
commit cfc48bd81c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 4 deletions

View file

@ -55,7 +55,7 @@ func newChanAcceptorCtx(t *testing.T, acceptCallCount int,
testCtx.acceptor = NewRPCAcceptor( testCtx.acceptor = NewRPCAcceptor(
testCtx.receiveResponse, testCtx.sendRequest, testTimeout*5, testCtx.receiveResponse, testCtx.sendRequest, testTimeout*5,
&chaincfg.TestNet3Params, testCtx.quit, &chaincfg.RegressionNetParams, testCtx.quit,
) )
return testCtx return testCtx
@ -162,7 +162,7 @@ func (c *channelAcceptorCtx) queryAndAssert(queries map[*lnwire.OpenChannel]*Cha
func TestMultipleAcceptClients(t *testing.T) { func TestMultipleAcceptClients(t *testing.T) {
testAddr := "bcrt1qwrmq9uca0t3dy9t9wtuq5tm4405r7tfzyqn9pp" testAddr := "bcrt1qwrmq9uca0t3dy9t9wtuq5tm4405r7tfzyqn9pp"
testUpfront, err := chancloser.ParseUpfrontShutdownAddress( testUpfront, err := chancloser.ParseUpfrontShutdownAddress(
testAddr, &chaincfg.TestNet3Params, testAddr, &chaincfg.RegressionNetParams,
) )
require.NoError(t, err) require.NoError(t, err)

View file

@ -20,7 +20,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
customError = errors.New("custom error") customError = errors.New("custom error")
validAddr = "bcrt1qwrmq9uca0t3dy9t9wtuq5tm4405r7tfzyqn9pp" validAddr = "bcrt1qwrmq9uca0t3dy9t9wtuq5tm4405r7tfzyqn9pp"
addr, _ = chancloser.ParseUpfrontShutdownAddress( addr, _ = chancloser.ParseUpfrontShutdownAddress(
validAddr, &chaincfg.TestNet3Params, validAddr, &chaincfg.RegressionNetParams,
) )
) )
@ -124,7 +124,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
// Create an acceptor, everything can be nil because // Create an acceptor, everything can be nil because
// we just need the params. // we just need the params.
acceptor := NewRPCAcceptor( acceptor := NewRPCAcceptor(
nil, nil, 0, &chaincfg.TestNet3Params, nil, nil, nil, 0, &chaincfg.RegressionNetParams, nil,
) )
accept, acceptErr, shutdown, err := acceptor.validateAcceptorResponse( accept, acceptErr, shutdown, err := acceptor.validateAcceptorResponse(

View file

@ -89,6 +89,9 @@ current gossip sync query status.
obtained via `QueryMissionControl`.]( obtained via `QueryMissionControl`.](
https://github.com/lightningnetwork/lnd/pull/6857) https://github.com/lightningnetwork/lnd/pull/6857)
* [Ensure that closing addresses match the node network for `OpenChannel`
requests](https://github.com/lightningnetwork/lnd/pull/7272)
## Wallet ## Wallet
* [Allows Taproot public keys and tap scripts to be imported as watch-only * [Allows Taproot public keys and tap scripts to be imported as watch-only

View file

@ -918,5 +918,10 @@ func ParseUpfrontShutdownAddress(address string,
return nil, fmt.Errorf("invalid address: %v", err) return nil, fmt.Errorf("invalid address: %v", err)
} }
if !addr.IsForNet(params) {
return nil, fmt.Errorf("invalid address: %v is not a %s "+
"address", addr, params.Name)
}
return txscript.PayToAddrScript(addr) return txscript.PayToAddrScript(addr)
} }

View file

@ -322,3 +322,58 @@ func TestMaxFeeBailOut(t *testing.T) {
}) })
} }
} }
// TestParseUpfrontShutdownAddress tests the we are able to parse the upfront
// shutdown address properly.
func TestParseUpfrontShutdownAddress(t *testing.T) {
t.Parallel()
var (
testnetAddress = "tb1qdfkmwwgdaa5dnezrlhtftvmj5qn2kwgp7n0z6r"
regtestAddress = "bcrt1q09crvvuj95x5nk64wsxf5n6ky0kr8358vpx4d8"
)
tests := []struct {
name string
address string
params chaincfg.Params
expectedErr string
}{
{
name: "invalid closing address",
address: "non-valid-address",
params: chaincfg.RegressionNetParams,
expectedErr: "invalid address",
},
{
name: "closing address from another net",
address: testnetAddress,
params: chaincfg.RegressionNetParams,
expectedErr: "not a regtest address",
},
{
name: "valid p2wkh closing address",
address: regtestAddress,
params: chaincfg.RegressionNetParams,
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
_, err := ParseUpfrontShutdownAddress(
tc.address, &tc.params,
)
if tc.expectedErr != "" {
require.ErrorContains(t, err, tc.expectedErr)
return
}
require.NoError(t, err)
})
}
}