invoicesrpc: add HtlcModifier RPC endpoint and modifier RPC server

This commit introduces a singleton invoice HTLC modifier RPC server and
an endpoint to activate it. The server interfaces with the internal
invoice HTLC modifier interpreter, handling the marshalling between RPC
types and internal formats.
This commit is contained in:
ffranr authored and Oliver Gugger committed 2024-09-19 09:21:37 +02:00
1 parent 008d265cdb
commit 1975fa60e2
8 files changed
+813 -59

No files matched your search

+40
View File
@@ -30,6 +30,9 @@ const (
)
var (
// ErrServerShuttingDown is returned when the server is shutting down.
ErrServerShuttingDown = errors.New("server shutting down")
// macaroonOps are the set of capabilities that our minted macaroon (if
// it doesn't already exist) will have.
macaroonOps = []bakery.Op{
@@ -65,6 +68,10 @@ var (
Entity: "invoices",
Action: "write",
}},
"/invoicesrpc.Invoices/HtlcModifier": {{
Entity: "invoices",
Action: "write",
}},
}
// DefaultInvoicesMacFilename is the default name of the invoices
@@ -446,3 +453,36 @@ func (s *Server) LookupInvoiceV2(ctx context.Context,
return CreateRPCInvoice(&invoice, s.cfg.ChainParams)
}
// HtlcModifier is a bidirectional streaming RPC that allows a client to
// intercept and modify the HTLCs that attempt to settle the given invoice. The
// server will send HTLCs of invoices to the client and the client can modify
// some aspects of the HTLC in order to pass the invoice acceptance tests.
func (s *Server) HtlcModifier(
modifierServer Invoices_HtlcModifierServer) error {
modifier := newHtlcModifier(s.cfg.ChainParams, modifierServer)
reset, modifierQuit, err := s.cfg.HtlcModifier.RegisterInterceptor(
modifier.onIntercept,
)
if err != nil {
return fmt.Errorf("cannot register interceptor: %w", err)
}
defer reset()
log.Debugf("Invoice HTLC modifier client connected")
for {
select {
case <-modifierServer.Context().Done():
return modifierServer.Context().Err()
case <-modifierQuit:
return ErrServerShuttingDown
case <-s.quit:
return ErrServerShuttingDown
}
}
}