Skip to main content

HtlcInterceptor

HtlcInterceptor dispatches a bi-directional streaming RPC in which Forwarded HTLC requests are sent to the client and the client responds with a boolean that tells LND if this htlc should be intercepted. In case of interception, the htlc can be either settled, cancelled or resumed later by using the ResolveHoldForward endpoint.

Source: routerrpc/router.proto

gRPC

info

This is a bidirectional-streaming RPC

rpc HtlcInterceptor (stream ForwardHtlcInterceptResponse) returns (stream ForwardHtlcInterceptRequest);

REST

HTTP MethodPath
POST /v2/router/htlcinterceptor

Code Samples

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', 'routerrpc/router.proto'], loaderOptions);
const routerrpc = grpc.loadPackageDefinition(packageDefinition).routerrpc;
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 routerrpc.Router(GRPC_HOST, creds);
let request = {
incoming_circuit_key: <CircuitKey>,
action: <ResolveHoldForwardAction>,
preimage: <bytes>,
failure_message: <bytes>,
failure_code: <FailureCode>,
};
let call = client.htlcInterceptor({});
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:
// {
// "incoming_circuit_key": <CircuitKey>,
// "incoming_amount_msat": <uint64>,
// "incoming_expiry": <uint32>,
// "payment_hash": <bytes>,
// "outgoing_requested_chan_id": <uint64>,
// "outgoing_amount_msat": <uint64>,
// "outgoing_expiry": <uint32>,
// "custom_records": <CustomRecordsEntry>,
// "onion_blob": <bytes>,
// "auto_fail_height": <int32>,
// }

Messages

routerrpc.ForwardHtlcInterceptResponse

Source: routerrpc/router.proto

FieldgRPC TypeREST TypeREST Placement
incoming_circuit_key
CircuitKeyobjectbody
action
ResolveHoldForwardActionstringbody
preimage
bytesstringbody
failure_message
bytesstringbody
failure_code
FailureCodestringbody

routerrpc.ForwardHtlcInterceptRequest

Source: routerrpc/router.proto

FieldgRPC TypeREST Type
incoming_circuit_key
CircuitKeyobject
incoming_amount_msat
uint64string
incoming_expiry
uint32integer
payment_hash
bytesstring
outgoing_requested_chan_id
uint64string
outgoing_amount_msat
uint64string
outgoing_expiry
uint32integer
custom_records
CustomRecordsEntry[]object
onion_blob
bytesstring
auto_fail_height
int32integer

Nested Messages

routerrpc.CircuitKey

FieldgRPC TypeREST Type
chan_id
uint64string
htlc_id
uint64string

routerrpc.ForwardHtlcInterceptRequest.CustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

Enums

routerrpc.ResolveHoldForwardAction

NameNumber
SETTLE
0
FAIL
1
RESUME
2

lnrpc.Failure.FailureCode

NameNumber
RESERVED
0
INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS
1
INCORRECT_PAYMENT_AMOUNT
2
FINAL_INCORRECT_CLTV_EXPIRY
3
FINAL_INCORRECT_HTLC_AMOUNT
4
FINAL_EXPIRY_TOO_SOON
5
INVALID_REALM
6
EXPIRY_TOO_SOON
7
INVALID_ONION_VERSION
8
INVALID_ONION_HMAC
9
INVALID_ONION_KEY
10
AMOUNT_BELOW_MINIMUM
11
FEE_INSUFFICIENT
12
INCORRECT_CLTV_EXPIRY
13
CHANNEL_DISABLED
14
TEMPORARY_CHANNEL_FAILURE
15
REQUIRED_NODE_FEATURE_MISSING
16
REQUIRED_CHANNEL_FEATURE_MISSING
17
UNKNOWN_NEXT_PEER
18
TEMPORARY_NODE_FAILURE
19
PERMANENT_NODE_FAILURE
20
PERMANENT_CHANNEL_FAILURE
21
EXPIRY_TOO_FAR
22
MPP_TIMEOUT
23
INVALID_ONION_PAYLOAD
24
INTERNAL_FAILURE
997
UNKNOWN_FAILURE
998
UNREADABLE_FAILURE
999