lnrpc+rpcserver: encode custom records as custom channel data

With this commit we encode the custom records as a TLV stream into the
custom channel data field of the invoice HTLC.
This allows the custom data parser to parse those records and replace it
with human-readable JSON on the RPC interface.
This commit is contained in:
Oliver Gugger
2024-09-12 17:59:38 +02:00
parent bbae7148aa
commit d37df75bc0
9 changed files with 144 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lncfg"
@@ -32,6 +33,7 @@ import (
"github.com/lightningnetwork/lnd/sweep"
"github.com/lightningnetwork/lnd/watchtower"
"github.com/lightningnetwork/lnd/watchtower/wtclient"
"google.golang.org/protobuf/proto"
)
// subRPCServerConfigs is special sub-config in the main configuration that
@@ -123,6 +125,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
modifiers ...netann.NodeAnnModifier) error,
parseAddr func(addr string) (net.Addr, error),
rpcLogger btclog.Logger, aliasMgr *aliasmgr.Manager,
auxDataParser fn.Option[AuxDataParser],
invoiceHtlcModifier *invoices.HtlcModificationInterceptor) error {
// First, we'll use reflect to obtain a version of the config struct
@@ -274,6 +277,20 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
reflect.ValueOf(aliasMgr.GetPeerAlias),
)
parseAuxData := func(m proto.Message) error {
return fn.MapOptionZ(
auxDataParser,
func(p AuxDataParser) error {
return p.InlineParseCustomData(
m,
)
},
)
}
subCfgValue.FieldByName("ParseAuxData").Set(
reflect.ValueOf(parseAuxData),
)
case *neutrinorpc.Config:
subCfgValue := extractReflectValue(subCfg)