From 6b34ebbe441bee76e528a6cb93ea7d433ce8fef7 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sun, 15 May 2022 01:50:30 +0800 Subject: [PATCH] rpcserver: fix wrong unit used in PushAmountSat --- lntest/itest/lnd_misc_test.go | 12 +++++++----- rpcserver.go | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lntest/itest/lnd_misc_test.go b/lntest/itest/lnd_misc_test.go index 6fb934bb4..9b5c365f1 100644 --- a/lntest/itest/lnd_misc_test.go +++ b/lntest/itest/lnd_misc_test.go @@ -374,10 +374,12 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { const customizedMinHtlc = 4200 chanAmt := btcutil.Amount(100000) + pushAmt := btcutil.Amount(1000) chanPoint := openChannelAndAssert( t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt, + PushAmt: pushAmt, MinHtlc: customizedMinHtlc, RemoteMaxHtlcs: aliceRemoteMaxHtlcs, }, @@ -415,12 +417,12 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { aliceChannel := resp.Channels[0] // Since Alice is the initiator, she pays the commit fee. - aliceBalance := int64(chanAmt) - aliceChannel.CommitFee + aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt) // Check the balance related fields are correct. require.Equal(t.t, aliceBalance, aliceChannel.LocalBalance) - require.Zero(t.t, aliceChannel.RemoteBalance) - require.Zero(t.t, aliceChannel.PushAmountSat) + require.EqualValues(t.t, pushAmt, aliceChannel.RemoteBalance) + require.EqualValues(t.t, pushAmt, aliceChannel.PushAmountSat) // Calculate the dust limit we'll use for the test. dustLimit := lnwallet.DustLimitForSize(input.UnknownWitnessSize) @@ -474,8 +476,8 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { // Check the balance related fields are correct. require.Equal(t.t, aliceBalance, bobChannel.RemoteBalance) - require.Zero(t.t, bobChannel.LocalBalance) - require.Zero(t.t, bobChannel.PushAmountSat) + require.EqualValues(t.t, pushAmt, bobChannel.LocalBalance) + require.EqualValues(t.t, pushAmt, bobChannel.PushAmountSat) // Check channel constraints match. Alice's local channel constraint // should be equal to Bob's remote channel constraint, and her remote diff --git a/rpcserver.go b/rpcserver.go index 6f1ab8f91..cc229b6d0 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4085,9 +4085,11 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel, // is the push amount. Otherwise, our starting balance is the push // amount. If there is no push amount, these values will simply be zero. if dbChannel.IsInitiator { - channel.PushAmountSat = uint64(dbChannel.InitialRemoteBalance) + amt := dbChannel.InitialRemoteBalance.ToSatoshis() + channel.PushAmountSat = uint64(amt) } else { - channel.PushAmountSat = uint64(dbChannel.InitialLocalBalance) + amt := dbChannel.InitialLocalBalance.ToSatoshis() + channel.PushAmountSat = uint64(amt) } if len(dbChannel.LocalShutdownScript) > 0 {