Skip to content

Commit

Permalink
nuget package updates, proto updates for 0.18.3, interception test wi…
Browse files Browse the repository at this point in the history
…th NLightning BOLT11 example/test
  • Loading branch information
rsafier committed Aug 27, 2024
1 parent a8acb67 commit 1d14512
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ jobs:
dotnet pack /p:Version=$GITHUB_REF_NAME --configuration Release
package=$(ls bin/Release/LNUnit.LND.*.nupkg)
dotnet nuget push $package --api-key ${{ secrets.NUGET }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Pack and Push NuGet Package LNBolt
run: |
cd LNBolt
dotnet pack /p:Version=$GITHUB_REF_NAME --configuration Release
package=$(ls bin/Release/LNBolt.*.nupkg)
dotnet nuget push $package --api-key ${{ secrets.NUGET }} --source https://api.nuget.org/v3/index.json --skip-duplicate
4 changes: 2 additions & 2 deletions LNBolt.Tests/LNBolt.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<ItemGroup>
<PackageReference Include="EndianBinaryIO" Version="1.1.2"/>
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" Version="7.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="org.ldk" Version="0.0.123" />
<PackageReference Include="org.ldk" Version="0.0.123.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 3 additions & 3 deletions LNBolt/LNBolt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/rsafier/LNBolt</PackageProjectUrl>
<PackageId>LNBolt</PackageId>
<Version>1.2.1</Version>
<Version>1.7.2</Version>
<Authors>Richard Safier</Authors>
<PackageDescription>LNBolt - C# BOLT protocol helpers</PackageDescription>
<RepositoryUrl>https://github.com/rsafier/LNBolt</RepositoryUrl>
Expand All @@ -15,9 +15,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EndianBinaryIO" Version="1.1.2"/>
<PackageReference Include="NBitcoin" Version="7.0.36" />
<PackageReference Include="NBitcoin" Version="7.0.37" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0"/>
<PackageReference Include="ServiceStack.Text" Version="8.2.2" />
<PackageReference Include="ServiceStack.Text" Version="8.3.0" />
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
Expand Down
55 changes: 52 additions & 3 deletions LNUnit.LND/Grpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,8 @@ message SendCoinsRequest {
int64 sat_per_byte = 5 [deprecated = true];

/*
If set, then the amount field will be ignored, and lnd will attempt to
send all the coins under control of the internal wallet to the specified
address.
If set, the amount field should be unset. It indicates lnd will send all
wallet coins or all selected coins to the specified address.
*/
bool send_all = 6;

Expand All @@ -1208,6 +1207,9 @@ message SendCoinsRequest {

// The strategy to use for selecting coins.
CoinSelectionStrategy coin_selection_strategy = 10;

// A list of selected outpoints as inputs for the transaction.
repeated OutPoint outpoints = 11;
}
message SendCoinsResponse {
// The transaction ID of the transaction
Expand Down Expand Up @@ -3836,6 +3838,48 @@ message Invoice {
Note: Output only, don't specify for creating an invoice.
*/
map<string, AMPInvoiceState> amp_invoice_state = 28;

/*
Signals that the invoice should include blinded paths to hide the true
identity of the recipient.
*/
bool is_blinded = 29;

/*
Config values to use when creating blinded paths for this invoice. These
can be used to override the defaults config values provided in by the
global config. This field is only used if is_blinded is true.
*/
BlindedPathConfig blinded_path_config = 30;
}

message BlindedPathConfig {
/*
The minimum number of real hops to include in a blinded path. This doesn't
include our node, so if the minimum is 1, then the path will contain at
minimum our node along with an introduction node hop. If it is zero then
the shortest path will use our node as an introduction node.
*/
optional uint32 min_num_real_hops = 1;

/*
The number of hops to include in a blinded path. This doesn't include our
node, so if it is 1, then the path will contain our node along with an
introduction node or dummy node hop. If paths shorter than NumHops is
found, then they will be padded using dummy hops.
*/
optional uint32 num_hops = 2;

/*
The maximum number of blinded paths to select and add to an invoice.
*/
optional uint32 max_num_paths = 3;

/*
A list of node IDs of nodes that should not be used in any of our generated
blinded paths.
*/
repeated bytes node_omission_list = 4;
}

enum InvoiceHTLCState {
Expand Down Expand Up @@ -4044,6 +4088,11 @@ enum PaymentFailureReason {
Insufficient local balance.
*/
FAILURE_REASON_INSUFFICIENT_BALANCE = 5;

/*
The payment was canceled.
*/
FAILURE_REASON_CANCELED = 6;
}

message Payment {
Expand Down
50 changes: 50 additions & 0 deletions LNUnit.LND/Grpc/walletrpc/walletkit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ service WalletKit {
*/
rpc BumpFee (BumpFeeRequest) returns (BumpFeeResponse);

/* lncli: `wallet bumpforceclosefee`
BumpForceCloseFee is an endpoint that allows users to bump the fee of a
channel force close. This only works for channels with option_anchors.
*/
rpc BumpForceCloseFee (BumpForceCloseFeeRequest)
returns (BumpForceCloseFeeResponse);

/* lncli: `wallet listsweeps`
ListSweeps returns a list of the sweep transactions our node has produced.
Note that these sweeps may not be confirmed yet, as we record sweeps on
Expand Down Expand Up @@ -839,6 +846,9 @@ message EstimateFeeResponse {
confirmation target in the request.
*/
int64 sat_per_kw = 1;

// The current minimum relay fee based on our chain backend in sat/kw.
int64 min_relay_fee_sat_per_kw = 2;
}

enum WitnessType {
Expand Down Expand Up @@ -1223,6 +1233,46 @@ message BumpFeeResponse {
string status = 1;
}

message BumpForceCloseFeeRequest {
// The channel point which force close transaction we are attempting to
// bump the fee rate for.
lnrpc.ChannelPoint chan_point = 1;

// Optional. The deadline delta in number of blocks that the anchor output
// should be spent within to bump the closing transaction.
uint32 deadline_delta = 2;

/*
Optional. The starting fee rate, expressed in sat/vbyte. This value will be
used by the sweeper's fee function as its starting fee rate. When not set,
the sweeper will use the estimated fee rate using the target_conf as the
starting fee rate.
*/
uint64 starting_feerate = 3;

/*
Optional. Whether this cpfp transaction will be triggered immediately. When
set to true, the sweeper will consider all currently registered sweeps and
trigger new batch transactions including the sweeping of the anchor output
related to the selected force close transaction.
*/
bool immediate = 4;

/*
Optional. The max amount in sats that can be used as the fees. For already
registered anchor outputs if not set explicitly the old value will be used.
For channel force closes which have no HTLCs in their commitment transaction
this value has to be set to an appropriate amount to pay for the cpfp
transaction of the force closed channel otherwise the fee bumping will fail.
*/
uint64 budget = 5;
}

message BumpForceCloseFeeResponse {
// The status of the force close fee bump operation.
string status = 1;
}

message ListSweepsRequest {
/*
Retrieve the full sweep transaction details. If false, only the sweep txids
Expand Down
18 changes: 9 additions & 9 deletions LNUnit.LND/LNUnit.LND.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>LNUnit.LND</PackageId>
<Version>1.7.1</Version>
<Version>1.7.2</Version>
<PackageDescription>LNUnit LND Typed Clients</PackageDescription>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
Expand All @@ -20,12 +20,12 @@

<ItemGroup>
<PackageReference Include="EndianBinaryIO" Version="1.1.2"/>
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.62.0"/>
<PackageReference Include="Grpc.Net.Client" Version="2.62.0"/>
<PackageReference Include="Grpc.Net.Common" Version="2.62.0"/>
<PackageReference Include="Google.Protobuf" Version="3.27.3" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.65.0" />
<PackageReference Include="Grpc.Net.Client" Version="2.65.0" />
<PackageReference Include="Grpc.Net.Common" Version="2.65.0" />

<PackageReference Include="Grpc.Tools" Version="2.63.0">
<PackageReference Include="Grpc.Tools" Version="2.66.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -34,12 +34,12 @@

<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0"/>

<PackageReference Include="NBitcoin" Version="7.0.36" />
<PackageReference Include="NBitcoin" Version="7.0.37" />

<PackageReference Include="Portable.BouncyCastle" Version="1.9.0"/>

<PackageReference Include="Serilog" Version="3.1.1"/>
<PackageReference Include="ServiceStack.Text" Version="8.2.2" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="ServiceStack.Text" Version="8.3.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0"/>
</ItemGroup>

Expand Down
16 changes: 16 additions & 0 deletions LNUnit.Tests/AbcLightningFixtureBoltDb.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@


using System.Security.Cryptography;
using Google.Protobuf;
using LNBolt;
using Lnrpc;
using LNUnit.LND;
using NBitcoin;
using NLightning.Bolts.BOLT11.Types;
using NLightning.Bolts.BOLT9;
using NLightning.Common.Managers;
using NLightning.Common.Types;
using Routerrpc;
using ServiceStack;
using ServiceStack.Text;
using Feature = ServiceStack.Feature;

namespace LNUnit.Tests;

[TestFixture("boltdb", "lightninglabs/lnd", "daily-testing-only", "/root/.lnd", true)]
Expand All @@ -17,4 +32,5 @@ public AbcLightningAbstractTestsBoltDb(string dbType = "boltdb",
}



}
3 changes: 2 additions & 1 deletion LNUnit.Tests/AbcLightningFixturePostgres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public AbcLightningAbstractTestsPostgres(string dbType = "postgres",
{

}
}
}

82 changes: 82 additions & 0 deletions LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Security.Cryptography;
using Dasync.Collections;
using Docker.DotNet;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Grpc.Core;
using Invoicesrpc;
using LNBolt;
using Lnrpc;
using LNUnit.Extentions;
using LNUnit.LND;
Expand All @@ -14,11 +16,17 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NBitcoin;
using NLightning.Bolts.BOLT11.Types;
using NLightning.Bolts.BOLT9;
using NLightning.Common.Managers;
using NLightning.Common.Types;
using Routerrpc;
using Serilog;
using ServiceStack;
using ServiceStack.Text;
using Assert = NUnit.Framework.Assert;
using Network = NLightning.Common.Types.Network;

namespace LNUnit.Tests.Abstract;

Expand Down Expand Up @@ -228,7 +236,81 @@ public async Task<bool> IsRunning()
return false;
}

[Test]
[NonParallelizable]
[Category("Interceptor")]
public async Task VirtualNodeInvoicePaymentFlowDemo()
{
var virtualNodeKey = new Key(); //Random node key
SecureKeyManager.Initialize(virtualNodeKey.ToBytes());

Check failure on line 245 in LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests

LNUnit.Tests.Fixture.AbcLightningAbstractTestsPostgres("postgres","lightninglabs/lnd","daily-testing-only","/root/.lnd",True) ► VirtualNodeInvoicePaymentFlowDemo

Failed test found in: coverage/test-results.trx Error: System.InvalidOperationException : Secure key is already initialized.
Raw output
System.InvalidOperationException : Secure key is already initialized.
   at NLightning.Common.Managers.SecureKeyManager.Initialize(Byte[] privateKey)
   at LNUnit.Tests.Abstract.AbcLightningAbstractTests.VirtualNodeInvoicePaymentFlowDemo() in /home/runner/work/LNUnit/LNUnit/LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs:line 245
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.GetResult()
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
ConfigManager.Instance.Network = NLightning.Common.Types.Network.REG_TEST;
//Node we will intercept at and use as hint
var alice = await Builder!.WaitUntilAliasIsServerReady("alice");
//Node we will pay from
var bob = await Builder!.WaitUntilAliasIsServerReady("bob");
//Build the invoice
var preimageHexString = RandomNumberGenerator.GetHexString(64);
var hashHexString = SHA256.HashData(Convert.FromHexString(preimageHexString)).ToHex();
var paymentSecretHexString = RandomNumberGenerator.GetHexString(64);
var paymentHash = uint256.Parse(hashHexString);
var paymentSecret = uint256.Parse(paymentSecretHexString); ;
var invoice = new NLightning.Bolts.BOLT11.Invoice(10_000, "Hello NLightning, here is 10 sats", paymentHash, paymentSecret);
var shortChannelId = new ShortChannelId(6102, 1, 1);
var ri = new RoutingInfoCollection
{
new RoutingInfo( new PubKey(alice.LocalNodePubKeyBytes), shortChannelId, 0, 0, 42)
};
var f = new Features();
f.SetFeature(NLightning.Bolts.BOLT9.Feature.VAR_ONION_OPTIN, false, true);
f.SetFeature(NLightning.Bolts.BOLT9.Feature.PAYMENT_SECRET, false, true);
invoice.Features = f;
invoice.RoutingInfos = ri;
var paymentRequest = invoice.Encode();

//Setup interceptor to get virtual nodes stuff
var nodeClone = alice.Clone();
var i = new LNDSimpleHtlcInterceptorHandler(nodeClone, async x =>
{
var onionBlob = x.OnionBlob.ToByteArray();
var decoder = new OnionBlob(onionBlob);
var sharedSecret = LNTools.DeriveSharedSecret(decoder.EphemeralPublicKey, virtualNodeKey.ToBytes());
var hopPeel = decoder.Peel(sharedSecret, null, x.PaymentHash.ToByteArray());
Assert.That(paymentSecretHexString.ToLower(), Is.EqualTo(hopPeel.hopPayload.PaymentData.PaymentSecret.ToHex()));
//Logic for interception
$"Intercepted Payment {Convert.ToHexString(x.PaymentHash.ToByteArray())} on channel {x.IncomingCircuitKey.ChanId} for virtual node {virtualNodeKey.PubKey.ToHex()}"
.Print();
return new ForwardHtlcInterceptResponse
{
Action = ResolveHoldForwardAction.Settle,
Preimage = ByteString.CopyFrom(Convert.FromHexString(preimageHexString)), //we made invoice use preimage we know to settle
IncomingCircuitKey = x.IncomingCircuitKey
};
});
Builder.InterceptorHandlers.Add("alias", i);

//Pay the thing
var p = bob.RouterClient.SendPaymentV2(new SendPaymentRequest()
{
PaymentRequest = paymentRequest,
NoInflightUpdates = true,
TimeoutSeconds = 10
});
await p.ResponseStream.MoveNext(CancellationToken.None);
var paymentStatus = p.ResponseStream.Current;
//Did it work?
Assert.That(paymentStatus.Status, Is.EqualTo(Payment.Types.PaymentStatus.Succeeded));
await Task.Delay(2000); //if we don't delay LND shows this as unsettled, it returns true early, with HTLC tracking should verify in prod setup. Otherwise this stuff is phantom

var listChannels = await alice.LightningClient.ListChannelsAsync(new ListChannelsRequest()
{
Peer = ByteString.CopyFrom(bob.LocalNodePubKeyBytes)
});
Assert.That(listChannels.Channels.Sum(c => c.TotalSatoshisReceived), Is.EqualTo(10));

Check failure on line 308 in LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests

LNUnit.Tests.AbcLightningAbstractTestsBoltDb("boltdb","lightninglabs/lnd","daily-testing-only","/root/.lnd",True) ► VirtualNodeInvoicePaymentFlowDemo

Failed test found in: coverage/test-results.trx Error: Expected: 10 But was: 3996539
Raw output
  Expected: 10
  But was:  3996539

   at LNUnit.Tests.Abstract.AbcLightningAbstractTests.VirtualNodeInvoicePaymentFlowDemo() in /home/runner/work/LNUnit/LNUnit/LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs:line 308
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
   at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

1)    at LNUnit.Tests.Abstract.AbcLightningAbstractTests.VirtualNodeInvoicePaymentFlowDemo() in /home/runner/work/LNUnit/LNUnit/LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs:line 308


//Cleanup
Builder.CancelAllInterceptors();

}
///////
/// ///
[Test]
Expand Down
Loading

0 comments on commit 1d14512

Please sign in to comment.