Skip to content

Commit

Permalink
rpcserver: fix wrong unit used in PushAmountSat
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed May 15, 2022
1 parent 2c4136d commit 6b34ebb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lntest/itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6b34ebb

Please sign in to comment.