From 507520cda935ef05618a5ef8770ff2ba77518bd4 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 20 Jun 2016 21:56:54 -0700 Subject: [PATCH] lnwallet: move channelState from channeldb to channel.go --- lnwallet/channel.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 6ee9c2ad..4a0c8396 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -15,11 +15,46 @@ import ( "github.com/roasbeef/btcutil/txsort" ) +var ( + ErrChanClosing = fmt.Errorf("channel is being closed, operation disallowed") +) + const ( // TODO(roasbeef): make not random value MaxPendingPayments = 10 ) +// channelState is an enum like type which represents the current state of a +// particular channel. +type channelState uint8 + +const ( + // channelPending indicates this channel is still going through the + // funding workflow, and isn't yet open. + channelPending channelState = iota + + // channelOpen represents an open, active channel capable of + // sending/receiving HTLCs. + channelOpen + + // channelClosing represents a channel which is in the process of being + // closed. + channelClosing + + // channelClosed represents a channel which has been fully closed. Note + // that before a channel can be closed, ALL pending HTLC's must be + // settled/removed. + channelClosed + + // channelDispute indicates that an un-cooperative closure has been + // detected within the channel. + channelDispute + + // channelPendingPayment indicates that there a currently outstanding + // HTLC's within the channel. + channelPendingPayment +) + // PaymentHash presents the hash160 of a random value. This hash is used to // uniquely track incoming/outgoing payments within this channel, as well as // payments requested by the wallet/daemon. @@ -31,6 +66,9 @@ type LightningChannel struct { lnwallet *LightningWallet channelEvents chainntnfs.ChainNotifier + sync.RWMutex + status channelState + // TODO(roasbeef): Stores all previous R values + timeouts for each // commitment update, plus some other meta-data...Or just use OP_RETURN // to help out?