ChannelAcceptor
ChannelAcceptor dispatches a bi-directional streaming RPC in which OpenChannel requests are sent to the client and the client responds with a boolean that tells LND whether or not to accept the channel. This allows node operators to specify their own criteria for accepting inbound channels through a single persistent connection.
Source: lightning.proto
gRPC
info
This is a bidirectional-streaming RPC
rpc ChannelAcceptor (stream ChannelAcceptResponse) returns (stream ChannelAcceptRequest);
REST
HTTP Method | Path |
---|---|
POST | /v1/channels/acceptor |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new lnrpc.Lightning(GRPC_HOST, creds);
let request = {
accept: <bool>,
pending_chan_id: <bytes>,
error: <string>,
upfront_shutdown: <string>,
csv_delay: <uint32>,
reserve_sat: <uint64>,
in_flight_max_msat: <uint64>,
max_htlc_count: <uint32>,
min_htlc_in: <uint64>,
min_accept_depth: <uint32>,
zero_conf: <bool>,
};
let call = client.channelAcceptor({});
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
call.write(request);
// Console output:
// {
// "node_pubkey": <bytes>,
// "chain_hash": <bytes>,
// "pending_chan_id": <bytes>,
// "funding_amt": <uint64>,
// "push_amt": <uint64>,
// "dust_limit": <uint64>,
// "max_value_in_flight": <uint64>,
// "channel_reserve": <uint64>,
// "min_htlc": <uint64>,
// "fee_per_kw": <uint64>,
// "csv_delay": <uint32>,
// "max_accepted_htlcs": <uint32>,
// "channel_flags": <uint32>,
// "commitment_type": <CommitmentType>,
// "wants_zero_conf": <bool>,
// "wants_scid_alias": <bool>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the lightning.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
GRPC_HOST = 'localhost:10009'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = lightningstub.LightningStub(channel)
# Define a generator that returns an Iterable of ChannelAcceptResponse objects.
def request_generator():
# Initialization code here.
while True:
# Parameters here can be set as arguments to the generator.
request = lnrpc.ChannelAcceptResponse(
accept=<bool>,
pending_chan_id=<bytes>,
error=<string>,
upfront_shutdown=<string>,
csv_delay=<uint32>,
reserve_sat=<uint64>,
in_flight_max_msat=<uint64>,
max_htlc_count=<uint32>,
min_htlc_in=<uint64>,
min_accept_depth=<uint32>,
zero_conf=<bool>,
)
yield request
# Do things between iterations here.
request_iterable = request_generator()
for response in stub.ChannelAcceptor(request_iterable):
print(response)
# {
# "node_pubkey": <bytes>,
# "chain_hash": <bytes>,
# "pending_chan_id": <bytes>,
# "funding_amt": <uint64>,
# "push_amt": <uint64>,
# "dust_limit": <uint64>,
# "max_value_in_flight": <uint64>,
# "channel_reserve": <uint64>,
# "min_htlc": <uint64>,
# "fee_per_kw": <uint64>,
# "csv_delay": <uint32>,
# "max_accepted_htlcs": <uint32>,
# "channel_flags": <uint32>,
# "commitment_type": <CommitmentType>,
# "wants_zero_conf": <bool>,
# "wants_scid_alias": <bool>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
let requestBody = {
accept: <boolean>, // <bool>
pending_chan_id: <string>, // <bytes> (base64 encoded)
error: <string>, // <string>
upfront_shutdown: <string>, // <string>
csv_delay: <integer>, // <uint32>
reserve_sat: <string>, // <uint64>
in_flight_max_msat: <string>, // <uint64>
max_htlc_count: <integer>, // <uint32>
min_htlc_in: <string>, // <uint64>
min_accept_depth: <integer>, // <uint32>
zero_conf: <boolean>, // <bool>
};
let options = {
url: `https://${REST_HOST}/v1/channels/acceptor`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
form: JSON.stringify(requestBody),
}
request.post(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "node_pubkey": <string>, // <bytes>
// "chain_hash": <string>, // <bytes>
// "pending_chan_id": <string>, // <bytes>
// "funding_amt": <string>, // <uint64>
// "push_amt": <string>, // <uint64>
// "dust_limit": <string>, // <uint64>
// "max_value_in_flight": <string>, // <uint64>
// "channel_reserve": <string>, // <uint64>
// "min_htlc": <string>, // <uint64>
// "fee_per_kw": <string>, // <uint64>
// "csv_delay": <integer>, // <uint32>
// "max_accepted_htlcs": <integer>, // <uint32>
// "channel_flags": <integer>, // <uint32>
// "commitment_type": <string>, // <CommitmentType>
// "wants_zero_conf": <boolean>, // <bool>
// "wants_scid_alias": <boolean>, // <bool>
// }
// --------------------------
// Example with websockets:
// --------------------------
const WebSocket = require('ws');
const fs = require('fs');
const REST_HOST = 'localhost:8080'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
let ws = new WebSocket(`wss://${REST_HOST}/v1/channels/acceptor?method=POST`, {
// Work-around for self-signed certificates.
rejectUnauthorized: false,
headers: {
'Grpc-Metadata-Macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
});
let requestBody = {
accept: <bool>, // <bool>
pending_chan_id: <bytes>, // <bytes> (base64 encoded)
error: <string>, // <string>
upfront_shutdown: <string>, // <string>
csv_delay: <uint32>, // <uint32>
reserve_sat: <uint64>, // <uint64>
in_flight_max_msat: <uint64>, // <uint64>
max_htlc_count: <uint32>, // <uint32>
min_htlc_in: <uint64>, // <uint64>
min_accept_depth: <uint32>, // <uint32>
zero_conf: <bool>, // <bool>
};
ws.on('open', function() {
ws.send(JSON.stringify(requestBody));
});
ws.on('error', function(err) {
console.log('Error: ' + err);
});
ws.on('message', function(body) {
console.log(body);
});
// Console output:
// {
// "node_pubkey": <string>, // <bytes>
// "chain_hash": <string>, // <bytes>
// "pending_chan_id": <string>, // <bytes>
// "funding_amt": <string>, // <uint64>
// "push_amt": <string>, // <uint64>
// "dust_limit": <string>, // <uint64>
// "max_value_in_flight": <string>, // <uint64>
// "channel_reserve": <string>, // <uint64>
// "min_htlc": <string>, // <uint64>
// "fee_per_kw": <string>, // <uint64>
// "csv_delay": <integer>, // <uint32>
// "max_accepted_htlcs": <integer>, // <uint32>
// "channel_flags": <integer>, // <uint32>
// "commitment_type": <string>, // <CommitmentType>
// "wants_zero_conf": <boolean>, // <bool>
// "wants_scid_alias": <boolean>, // <bool>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/channels/acceptor'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'accept': <bool>,
'pending_chan_id': base64.b64encode(<bytes>),
'error': <string>,
'upfront_shutdown': <string>,
'csv_delay': <uint32>,
'reserve_sat': <uint64>,
'in_flight_max_msat': <uint64>,
'max_htlc_count': <uint32>,
'min_htlc_in': <uint64>,
'min_accept_depth': <uint32>,
'zero_conf': <bool>,
}
r = requests.post(url, headers=headers, stream=True, data=json.dumps(data), verify=TLS_PATH)
for raw_response in r.iter_lines():
json_response = json.loads(raw_response)
print(json_response)
# {
# "node_pubkey": <bytes>,
# "chain_hash": <bytes>,
# "pending_chan_id": <bytes>,
# "funding_amt": <uint64>,
# "push_amt": <uint64>,
# "dust_limit": <uint64>,
# "max_value_in_flight": <uint64>,
# "channel_reserve": <uint64>,
# "min_htlc": <uint64>,
# "fee_per_kw": <uint64>,
# "csv_delay": <uint32>,
# "max_accepted_htlcs": <uint32>,
# "channel_flags": <uint32>,
# "commitment_type": <CommitmentType>,
# "wants_zero_conf": <bool>,
# "wants_scid_alias": <bool>,
# }
# There is no CLI command for this RPC
Messages
lnrpc.ChannelAcceptResponse
Source: lightning.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
accept | bool | boolean | body |
pending_chan_id | bytes | string | body |
error | string | string | body |
upfront_shutdown | string | string | body |
csv_delay | uint32 | integer | body |
reserve_sat | uint64 | string | body |
in_flight_max_msat | uint64 | string | body |
max_htlc_count | uint32 | integer | body |
min_htlc_in | uint64 | string | body |
min_accept_depth | uint32 | integer | body |
zero_conf | bool | boolean | body |
lnrpc.ChannelAcceptRequest
Source: lightning.proto
Field | gRPC Type | REST Type |
---|---|---|
node_pubkey | bytes | string |
chain_hash | bytes | string |
pending_chan_id | bytes | string |
funding_amt | uint64 | string |
push_amt | uint64 | string |
dust_limit | uint64 | string |
max_value_in_flight | uint64 | string |
channel_reserve | uint64 | string |
min_htlc | uint64 | string |
fee_per_kw | uint64 | string |
csv_delay | uint32 | integer |
max_accepted_htlcs | uint32 | integer |
channel_flags | uint32 | integer |
commitment_type | CommitmentType | string |
wants_zero_conf | bool | boolean |
wants_scid_alias | bool | boolean |
Enums
lnrpc.CommitmentType
Name | Number |
---|---|
UNKNOWN_COMMITMENT_TYPE | 0 |
LEGACY | 1 |
STATIC_REMOTE_KEY | 2 |
ANCHORS | 3 |
SCRIPT_ENFORCED_LEASE | 4 |
SIMPLE_TAPROOT | 5 |
SIMPLE_TAPROOT_OVERLAY | 6 |