Browse Source

lint: fix proto message no-copy linter warnings

master
Andras Banki-Horvath 3 years ago
parent
commit
80bc46e614
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8
  1. 10
      chanacceptor/rpcacceptor.go
  2. 18
      chanacceptor/rpcacceptor_test.go

10
chanacceptor/rpcacceptor.go

@ -169,7 +169,7 @@ func (r *RPCAcceptor) Run() error {
defer r.wg.Wait() defer r.wg.Wait()
// Create a channel that responses from acceptors are sent into. // Create a channel that responses from acceptors are sent into.
responses := make(chan lnrpc.ChannelAcceptResponse) responses := make(chan *lnrpc.ChannelAcceptResponse)
// errChan is used by the receive loop to signal any errors that occur // errChan is used by the receive loop to signal any errors that occur
// during reading from the stream. This is primarily used to shutdown // during reading from the stream. This is primarily used to shutdown
@ -193,7 +193,7 @@ func (r *RPCAcceptor) Run() error {
// dispatches them into the responses channel provided, sending any errors that // dispatches them into the responses channel provided, sending any errors that
// occur into the error channel provided. // occur into the error channel provided.
func (r *RPCAcceptor) receiveResponses(errChan chan error, func (r *RPCAcceptor) receiveResponses(errChan chan error,
responses chan lnrpc.ChannelAcceptResponse) { responses chan *lnrpc.ChannelAcceptResponse) {
for { for {
resp, err := r.receive() resp, err := r.receive()
@ -205,7 +205,7 @@ func (r *RPCAcceptor) receiveResponses(errChan chan error,
var pendingID [32]byte var pendingID [32]byte
copy(pendingID[:], resp.PendingChanId) copy(pendingID[:], resp.PendingChanId)
openChanResp := lnrpc.ChannelAcceptResponse{ openChanResp := &lnrpc.ChannelAcceptResponse{
Accept: resp.Accept, Accept: resp.Accept,
PendingChanId: pendingID[:], PendingChanId: pendingID[:],
Error: resp.Error, Error: resp.Error,
@ -236,7 +236,7 @@ func (r *RPCAcceptor) receiveResponses(errChan chan error,
// Accept() function, dispatching them to our acceptor stream and coordinating // Accept() function, dispatching them to our acceptor stream and coordinating
// return of responses to their callers. // return of responses to their callers.
func (r *RPCAcceptor) sendAcceptRequests(errChan chan error, func (r *RPCAcceptor) sendAcceptRequests(errChan chan error,
responses chan lnrpc.ChannelAcceptResponse) error { responses chan *lnrpc.ChannelAcceptResponse) error {
// Close the done channel to indicate that the acceptor is no longer // Close the done channel to indicate that the acceptor is no longer
// listening and any in-progress requests should be terminated. // listening and any in-progress requests should be terminated.
@ -332,7 +332,7 @@ func (r *RPCAcceptor) sendAcceptRequests(errChan chan error,
// acceptor, returning a boolean indicating whether to accept the channel, an // acceptor, returning a boolean indicating whether to accept the channel, an
// error to send to the peer, and any validation errors that occurred. // error to send to the peer, and any validation errors that occurred.
func (r *RPCAcceptor) validateAcceptorResponse(dustLimit btcutil.Amount, func (r *RPCAcceptor) validateAcceptorResponse(dustLimit btcutil.Amount,
req lnrpc.ChannelAcceptResponse) (bool, error, lnwire.DeliveryAddress, req *lnrpc.ChannelAcceptResponse) (bool, error, lnwire.DeliveryAddress,
error) { error) {
channelStr := hex.EncodeToString(req.PendingChanId) channelStr := hex.EncodeToString(req.PendingChanId)

18
chanacceptor/rpcacceptor_test.go

@ -27,7 +27,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
dustLimit btcutil.Amount dustLimit btcutil.Amount
response lnrpc.ChannelAcceptResponse response *lnrpc.ChannelAcceptResponse
accept bool accept bool
acceptorErr error acceptorErr error
error error error error
@ -35,7 +35,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
}{ }{
{ {
name: "accepted with error", name: "accepted with error",
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: true, Accept: true,
Error: customError.Error(), Error: customError.Error(),
}, },
@ -45,7 +45,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
}, },
{ {
name: "custom error too long", name: "custom error too long",
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: false, Accept: false,
Error: strings.Repeat(" ", maxErrorLength+1), Error: strings.Repeat(" ", maxErrorLength+1),
}, },
@ -55,7 +55,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
}, },
{ {
name: "accepted", name: "accepted",
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: true, Accept: true,
UpfrontShutdown: validAddr, UpfrontShutdown: validAddr,
}, },
@ -66,7 +66,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
}, },
{ {
name: "rejected with error", name: "rejected with error",
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: false, Accept: false,
Error: customError.Error(), Error: customError.Error(),
}, },
@ -76,7 +76,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
}, },
{ {
name: "rejected with no error", name: "rejected with no error",
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: false, Accept: false,
}, },
accept: false, accept: false,
@ -85,7 +85,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
}, },
{ {
name: "invalid upfront shutdown", name: "invalid upfront shutdown",
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: true, Accept: true,
UpfrontShutdown: "invalid addr", UpfrontShutdown: "invalid addr",
}, },
@ -96,7 +96,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
{ {
name: "reserve too low", name: "reserve too low",
dustLimit: 100, dustLimit: 100,
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: true, Accept: true,
ReserveSat: 10, ReserveSat: 10,
}, },
@ -107,7 +107,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
{ {
name: "max htlcs too high", name: "max htlcs too high",
dustLimit: 100, dustLimit: 100,
response: lnrpc.ChannelAcceptResponse{ response: &lnrpc.ChannelAcceptResponse{
Accept: true, Accept: true,
MaxHtlcCount: 1 + input.MaxHTLCNumber/2, MaxHtlcCount: 1 + input.MaxHTLCNumber/2,
}, },

Loading…
Cancel
Save