github.com/decred/dcrlnd@v0.7.6/chanacceptor/interface.go (about) 1 package chanacceptor 2 3 import ( 4 "errors" 5 6 "github.com/decred/dcrd/dcrec/secp256k1/v4" 7 "github.com/decred/dcrd/dcrutil/v4" 8 "github.com/decred/dcrlnd/lnwire" 9 ) 10 11 var ( 12 // errChannelRejected is returned when the rpc channel acceptor rejects 13 // a channel due to acceptor timeout, shutdown, or because no custom 14 // error value is available when the channel was rejected. 15 errChannelRejected = errors.New("channel rejected") 16 ) 17 18 // ChannelAcceptRequest is a struct containing the requesting node's public key 19 // along with the lnwire.OpenChannel message that they sent when requesting an 20 // inbound channel. This information is provided to each acceptor so that they 21 // can each leverage their own decision-making with this information. 22 type ChannelAcceptRequest struct { 23 // Node is the public key of the node requesting to open a channel. 24 Node *secp256k1.PublicKey 25 26 // OpenChanMsg is the actual OpenChannel protocol message that the peer 27 // sent to us. 28 OpenChanMsg *lnwire.OpenChannel 29 } 30 31 // ChannelAcceptResponse is a struct containing the response to a request to 32 // open an inbound channel. Note that fields added to this struct must be added 33 // to the mergeResponse function to allow combining of responses from different 34 // acceptors. 35 type ChannelAcceptResponse struct { 36 // ChanAcceptError the error returned by the channel acceptor. If the 37 // channel was accepted, this value will be nil. 38 ChanAcceptError 39 40 // UpfrontShutdown is the address that we will set as our upfront 41 // shutdown address. 42 UpfrontShutdown lnwire.DeliveryAddress 43 44 // CSVDelay is the csv delay we require for the remote peer. 45 CSVDelay uint16 46 47 // Reserve is the amount that require the remote peer hold in reserve 48 // on the channel. 49 Reserve dcrutil.Amount 50 51 // InFlightTotal is the maximum amount that we allow the remote peer to 52 // hold in outstanding htlcs. 53 InFlightTotal lnwire.MilliAtom 54 55 // HtlcLimit is the maximum number of htlcs that we allow the remote 56 // peer to offer us. 57 HtlcLimit uint16 58 59 // MinHtlcIn is the minimum incoming htlc value allowed on the channel. 60 MinHtlcIn lnwire.MilliAtom 61 62 // MinAcceptDepth is the minimum depth that the initiator of the 63 // channel should wait before considering the channel open. 64 MinAcceptDepth uint16 65 } 66 67 // NewChannelAcceptResponse is a constructor for a channel accept response, 68 // which creates a response with an appropriately wrapped error (in the case of 69 // a rejection) so that the error will be whitelisted and delivered to the 70 // initiating peer. Accepted channels simply return a response containing a nil 71 // error. 72 func NewChannelAcceptResponse(accept bool, acceptErr error, 73 upfrontShutdown lnwire.DeliveryAddress, csvDelay, htlcLimit, 74 minDepth uint16, reserve dcrutil.Amount, inFlight, 75 minHtlcIn lnwire.MilliAtom) *ChannelAcceptResponse { 76 77 resp := &ChannelAcceptResponse{ 78 UpfrontShutdown: upfrontShutdown, 79 CSVDelay: csvDelay, 80 Reserve: reserve, 81 InFlightTotal: inFlight, 82 HtlcLimit: htlcLimit, 83 MinHtlcIn: minHtlcIn, 84 MinAcceptDepth: minDepth, 85 } 86 87 // If we want to accept the channel, we return a response with a nil 88 // error. 89 if accept { 90 return resp 91 } 92 93 // Use a generic error when no custom error is provided. 94 if acceptErr == nil { 95 acceptErr = errChannelRejected 96 } 97 98 resp.ChanAcceptError = ChanAcceptError{ 99 error: acceptErr, 100 } 101 102 return resp 103 } 104 105 // RejectChannel returns a boolean that indicates whether we should reject the 106 // channel. 107 func (c *ChannelAcceptResponse) RejectChannel() bool { 108 return c.error != nil 109 } 110 111 // ChannelAcceptor is an interface that represents a predicate on the data 112 // contained in ChannelAcceptRequest. 113 type ChannelAcceptor interface { 114 Accept(req *ChannelAcceptRequest) *ChannelAcceptResponse 115 }