From 6937a42f2d469513bed439a6250ce7ee82f0b68b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 16 Jun 2017 23:25:07 +0200 Subject: [PATCH] lnwallet: add new ShortChanID method to LightningChannel --- lnwallet/channel.go | 20 ++++++++++++++++---- lnwallet/interface_test.go | 5 +++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index f02e93c1..b4d0f9ac 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -677,9 +677,8 @@ type LightningChannel struct { // channel. RemoteFundingKey *btcec.PublicKey - // availableLocalBalance represent the amount of available money - // which might be procced by this channel at the specific point of - // time. + // availableLocalBalance represent the amount of available money which + // might be processed by this channel at the specific point of time. availableLocalBalance btcutil.Amount shutdown int32 @@ -801,7 +800,7 @@ func NewLightningChannel(signer Signer, events chainntnfs.ChainNotifier, // As a height hint, we'll try to use the opening height, but // if the channel isn't yet open, then we'll use the height it // was broadcast at. - heightHint := lc.channelState.OpeningHeight + heightHint := lc.channelState.ShortChanID.BlockHeight if heightHint == 0 { heightHint = lc.channelState.FundingBroadcastHeight } @@ -2333,9 +2332,22 @@ func (lc *LightningChannel) ReceiveFailHTLC(logIndex uint64) error { // created this active channel. This outpoint is used throughout various // subsystems to uniquely identify an open channel. func (lc *LightningChannel) ChannelPoint() *wire.OutPoint { + lc.RLock() + defer lc.RUnlock() + return lc.channelState.ChanID } +// ShortChanID returns the short channel ID for the channel. The short channel +// ID encodes the exact location in the main chain that the original +// funding output can be found. +func (lc *LightningChannel) ShortChanID() lnwire.ShortChannelID { + lc.RLock() + defer lc.RUnlock() + + return lc.channelState.ShortChanID +} + // genHtlcScript generates the proper P2WSH public key scripts for the // HTLC output modified by two-bits denoting if this is an incoming HTLC, and // if the HTLC is being applied to their commitment transaction or ours. diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index 4ed50eaf..cd595bcd 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -1355,10 +1355,11 @@ func TestLightningWallet(t *testing.T) { // Execute every test, clearing possibly mutated wallet state after // each step. for _, walletTest := range walletTests { + // TODO(roasbeef): run as parallel sub-tests? walletTest(miningNode, lnw, t) - // TODO(roasbeef): possible reset mining node's chainstate to - // initial level, cleanly wipe buckets + // TODO(roasbeef): possible reset mining node's + // chainstate to initial level, cleanly wipe buckets if err := clearWalletState(lnw); err != nil && err != bolt.ErrBucketNotFound { t.Fatalf("unable to wipe wallet state: %v", err)