mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-03 07:43:39 +02:00
multi: add custom error messages to channel acceptor
This commit adds an optional error message to the channel acceptor's reponse to allow operators to inform (or insult) unsuccessful channel initiators as to the reason for their rejection. This field is added in addition to the existing accept field to maintain backwards compatibity. If we were to deprecate accept and interpret a non-nil error as rejecting the channel, then received a response with accept=false and a nil error, the server cannot tell whether this is a legacy rejection or new mesage type acceptance (due to nil error), so we keep both fields.
This commit is contained in:
@@ -120,7 +120,7 @@ func (c *channelAcceptorCtx) stop() {
|
||||
// queryAndAssert takes a map of open channel requests which we want to call
|
||||
// Accept for to the outcome we expect from the acceptor, dispatches each
|
||||
// request in a goroutine and then asserts that we get the outcome we expect.
|
||||
func (c *channelAcceptorCtx) queryAndAssert(queries map[*lnwire.OpenChannel]bool) {
|
||||
func (c *channelAcceptorCtx) queryAndAssert(queries map[*lnwire.OpenChannel]*ChannelAcceptResponse) {
|
||||
var (
|
||||
node = &btcec.PublicKey{
|
||||
X: big.NewInt(1),
|
||||
@@ -168,12 +168,14 @@ func TestMultipleAcceptClients(t *testing.T) {
|
||||
PendingChannelID: [32]byte{3},
|
||||
}
|
||||
|
||||
customError = errors.New("go away")
|
||||
|
||||
// Queries is a map of the channel IDs we will query Accept
|
||||
// with, and the set of outcomes we expect.
|
||||
queries = map[*lnwire.OpenChannel]bool{
|
||||
chan1: true,
|
||||
chan2: false,
|
||||
chan3: false,
|
||||
queries = map[*lnwire.OpenChannel]*ChannelAcceptResponse{
|
||||
chan1: NewChannelAcceptResponse(true, nil),
|
||||
chan2: NewChannelAcceptResponse(false, errChannelRejected),
|
||||
chan3: NewChannelAcceptResponse(false, customError),
|
||||
}
|
||||
|
||||
// Responses is a mocked set of responses from the remote
|
||||
@@ -190,6 +192,7 @@ func TestMultipleAcceptClients(t *testing.T) {
|
||||
chan3.PendingChannelID: {
|
||||
PendingChanId: chan3.PendingChannelID[:],
|
||||
Accept: false,
|
||||
Error: customError.Error(),
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -205,3 +208,41 @@ func TestMultipleAcceptClients(t *testing.T) {
|
||||
// Shutdown our acceptor.
|
||||
testCtx.stop()
|
||||
}
|
||||
|
||||
// TestInvalidResponse tests the case where our remote channel acceptor sends us
|
||||
// an invalid response, so the channel acceptor stream terminates.
|
||||
func TestInvalidResponse(t *testing.T) {
|
||||
var (
|
||||
chan1 = [32]byte{1}
|
||||
|
||||
// We make a single query, and expect it to fail with our
|
||||
// generic error because our response is invalid.
|
||||
queries = map[*lnwire.OpenChannel]*ChannelAcceptResponse{
|
||||
{
|
||||
PendingChannelID: chan1,
|
||||
}: NewChannelAcceptResponse(
|
||||
false, errChannelRejected,
|
||||
),
|
||||
}
|
||||
|
||||
// Create a single response which is invalid because it accepts
|
||||
// the channel but also contains an error message.
|
||||
responses = map[[32]byte]*lnrpc.ChannelAcceptResponse{
|
||||
chan1: {
|
||||
PendingChanId: chan1[:],
|
||||
Accept: true,
|
||||
Error: "has an error as well",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// Create and start our channel acceptor.
|
||||
testCtx := newChanAcceptorCtx(t, len(queries), responses)
|
||||
testCtx.start()
|
||||
|
||||
testCtx.queryAndAssert(queries)
|
||||
|
||||
// We do not expect our channel acceptor to exit because of one invalid
|
||||
// response, so we shutdown and assert here.
|
||||
testCtx.stop()
|
||||
}
|
||||
|
Reference in New Issue
Block a user