From 04802ae23973e9b6e4b54e4af27c107889b9b71b Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sat, 18 Jun 2022 18:42:08 -0500 Subject: [PATCH] Add peers rpc to lnd (#4403) --- lnd-rpc/lnd-rpc.sbt | 4 +- .../src/main/protobuf/peersrpc/peers.proto | 115 ++++++++++++++++++ .../org/bitcoins/lnd/rpc/LndRpcClient.scala | 2 + 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 lnd-rpc/src/main/protobuf/peersrpc/peers.proto diff --git a/lnd-rpc/lnd-rpc.sbt b/lnd-rpc/lnd-rpc.sbt index 806b49830e..038b76b3dd 100644 --- a/lnd-rpc/lnd-rpc.sbt +++ b/lnd-rpc/lnd-rpc.sbt @@ -17,11 +17,13 @@ Compile / scalacOptions ++= Seq( "-Wconf:cat=deprecation:site=walletrpc\\..*:silent", "-Wconf:cat=deprecation:site=routerrpc\\..*:silent", "-Wconf:cat=deprecation:site=invoicesrpc\\..*:silent", + "-Wconf:cat=deprecation:site=peersrpc\\..*:silent", "-Wconf:cat=unused-imports:site=lnrpc:silent", "-Wconf:cat=unused-imports:site=signrpc:silent", "-Wconf:cat=unused-imports:site=walletrpc:silent", "-Wconf:cat=unused-imports:site=routerrpc:silent", - "-Wconf:cat=unused-imports:site=invoicesrpc:silent" + "-Wconf:cat=unused-imports:site=invoicesrpc:silent", + "-Wconf:cat=unused-imports:site=peersrpc:silent" ) TaskKeys.downloadLnd := { diff --git a/lnd-rpc/src/main/protobuf/peersrpc/peers.proto b/lnd-rpc/src/main/protobuf/peersrpc/peers.proto new file mode 100644 index 0000000000..a9d00daead --- /dev/null +++ b/lnd-rpc/src/main/protobuf/peersrpc/peers.proto @@ -0,0 +1,115 @@ +syntax = "proto3"; + +import "lightning.proto"; + +package peersrpc; + +option go_package = "github.com/lightningnetwork/lnd/lnrpc/peersrpc"; + +import "scalapb/scalapb.proto"; + +option (scalapb.options) = { + import: "org.bitcoins.lnd.rpc.LndUtils._" + scope: PACKAGE + field_transformations : [ + { + when : { + type: TYPE_UINT64 + } + set : {[scalapb.field] {type : 'org.bitcoins.core.number.UInt64' }} + }, + { + when : { + type: TYPE_UINT32 + } + set : {[scalapb.field] {type : 'org.bitcoins.core.number.UInt32' }} + } + ] +}; + +// Peers is a service that can be used to get information and interact +// with the other nodes of the newtwork. +service Peers { + /* lncli: peers updatenodeannouncement + UpdateNodeAnnouncement allows the caller to update the node parameters + and broadcasts a new version of the node announcement to its peers. + */ + rpc UpdateNodeAnnouncement (NodeAnnouncementUpdateRequest) + returns (NodeAnnouncementUpdateResponse); +} + +// UpdateAction is used to determine the kind of action we are referring to. +enum UpdateAction { + // ADD indicates this is an "insertion" kind of action. + ADD = 0; + + // REMOVE indicates this is a "deletion" kind of action. + REMOVE = 1; +} + +enum FeatureSet { + /* + SET_INIT identifies features that should be sent in an Init message to + a remote peer. + */ + SET_INIT = 0; + + /* + SET_LEGACY_GLOBAL identifies features that should be set in the legacy + GlobalFeatures field of an Init message, which maintains backwards + compatibility with nodes that haven't implemented flat features. + */ + SET_LEGACY_GLOBAL = 1; + + /* + SET_NODE_ANN identifies features that should be advertised on node + announcements. + */ + SET_NODE_ANN = 2; + + /* + SET_INVOICE identifies features that should be advertised on invoices + generated by the daemon. + */ + SET_INVOICE = 3; + + /* + SET_INVOICE_AMP identifies the features that should be advertised on + AMP invoices generated by the daemon. + */ + SET_INVOICE_AMP = 4; +} + +message UpdateAddressAction { + // Determines the kind of action. + UpdateAction action = 1; + + // The address used to apply the update action. + string address = 2; +} + +message UpdateFeatureAction { + // Determines the kind of action. + UpdateAction action = 1; + + // The feature bit used to apply the update action. + lnrpc.FeatureBit feature_bit = 2; +} + +message NodeAnnouncementUpdateRequest { + // Set of changes for the features that the node supports. + repeated UpdateFeatureAction feature_updates = 1; + + // Color is the node's color in hex code format. + string color = 2; + + // Alias or nick name of the node. + string alias = 3; + + // Set of changes for the node's known addresses. + repeated UpdateAddressAction address_updates = 4; +} + +message NodeAnnouncementUpdateResponse { + repeated lnrpc.Op ops = 1; +} diff --git a/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala b/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala index 314054c669..81e21c411a 100644 --- a/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala +++ b/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala @@ -37,6 +37,7 @@ import org.bitcoins.lnd.rpc.LndRpcClient._ import org.bitcoins.lnd.rpc.LndUtils._ import org.bitcoins.lnd.rpc.config._ import org.bitcoins.lnd.rpc.internal._ +import peersrpc.PeersClient import routerrpc._ import scodec.bits._ import signrpc._ @@ -145,6 +146,7 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)( lazy val signer: SignerClient = SignerClient(clientSettings) lazy val router: RouterClient = RouterClient(clientSettings) lazy val invoices: InvoicesClient = InvoicesClient(clientSettings) + lazy val peersClient: PeersClient = PeersClient(clientSettings) lazy val stateClient: StateClient = StateClient(clientSettings) def genSeed(): Future[GenSeedResponse] = {