Skip to content

Commit

Permalink
keysend performance test PPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsafier committed Mar 27, 2024
1 parent e0894c8 commit 1f3bcdb
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions LNUnit.Tests/AbcLightningFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ public async Task SetupNetwork(string image = "lightninglabs/lnd", string tag =

Builder.AddPolarLNDNode("alice",
[
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
RemoteName = "bob"
},
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
RemoteName = "bob"
},
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
RemoteName = "bob"
},
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
Expand All @@ -135,6 +150,24 @@ public async Task SetupNetwork(string image = "lightninglabs/lnd", string tag =

Builder.AddPolarLNDNode("carol",
[
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
RemotePushOnStart = 1_000_000, // 1MSat
RemoteName = "bob"
},
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
RemotePushOnStart = 1_000_000, // 1MSat
RemoteName = "bob"
},
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
RemotePushOnStart = 1_000_000, // 1MSat
RemoteName = "bob"
},
new LNUnitNetworkDefinition.Channel
{
ChannelSize = 10_000_000, //10MSat
Expand Down Expand Up @@ -442,6 +475,77 @@ public async Task SuccessfulKeysend()
Assert.That(payment.Status, Is.EqualTo(Payment.Types.PaymentStatus.Succeeded));
}


/// <summary>
/// Keysend from Alice and Carol to Bob, see how many can clear in 10s.
/// </summary>
/// <param name="threads"></param>
[Test]
[Category("Payment")]
[NonParallelizable]
[Timeout(60000)]
[TestCase(2)]
[TestCase(4)]
[TestCase(8)]
[TestCase(16)]
[TestCase(32)]
public async Task Keysend_To_Bob_PaymentsPerSecondMax_Threaded(int threads)
{
Builder.CancelAllInterceptors();
var aliceSettings = await Builder.GetLNDSettingsFromContainer("alice", _lndRoot);
var bobSettings = await Builder.GetLNDSettingsFromContainer("bob", _lndRoot);
var carolSettings = await Builder.GetLNDSettingsFromContainer("carol", _lndRoot);
var alice = new LNDNodeConnection(aliceSettings);
var bob = new LNDNodeConnection(bobSettings);
var carol = new LNDNodeConnection(carolSettings);

await Task.Delay(1000); //TODO: why? we are not checking channels are up

var sw = Stopwatch.StartNew();
var success_count = 0;
var fail_count = 0;
var cts = new CancellationTokenSource();

while (sw.ElapsedMilliseconds <= 10_000)
{
Task.WaitAll(
Parallel.ForAsync(0, threads, cts.Token, async (i, token) =>
{
var payment = await alice.KeysendPayment(bob.LocalNodePubKey, 1, 100000000, "Hello World", 6,
new Dictionary<ulong, byte[]> { { 99999, new byte[] { 11, 11, 11 } } });
if (payment.Status == Payment.Types.PaymentStatus.Succeeded)
{
Interlocked.Increment(ref success_count);
}
else
{
Interlocked.Increment(ref fail_count);
}
}),
Parallel.ForAsync(0, threads, cts.Token, async (i, token) =>
{
var payment = await carol.KeysendPayment(bob.LocalNodePubKey, 1, 100000000, "Hello World", 6,
new Dictionary<ulong, byte[]> { { 99999, new byte[] { 11, 11, 11 } } });
if (payment.Status == Payment.Types.PaymentStatus.Succeeded)
{
Interlocked.Increment(ref success_count);
}
else
{
Interlocked.Increment(ref fail_count);
}
Interlocked.Increment(ref success_count);
}));
}
sw.Stop();
var attempted_pps = (fail_count + success_count) / (sw.ElapsedMilliseconds / 1000.0);
$"Attempted Payments: {fail_count + success_count}".Print();
$"Successful: {success_count}".Print();
$"Failed : {fail_count}".Print();
var successful_pps = success_count / (sw.ElapsedMilliseconds / 1000.0);
$"Successful Payments per second: {successful_pps}".Print();
}

[Test]
[Category("LNUnit")]
[NonParallelizable]
Expand Down

0 comments on commit 1f3bcdb

Please sign in to comment.