lnwallet: add [our|their]HtlcIndex to the commitment struct

With these new fields, we’ll be able to properly reconstruct the log
state after a restart, as each commitment will now note both the
current HTLC and log index.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-09 22:23:17 -08:00
parent 145cd0b2b6
commit d790eeb375
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"container/list" "container/list"
"crypto/sha256" "crypto/sha256"
"errors"
"fmt" "fmt"
"runtime" "runtime"
"sort" "sort"
@ -92,7 +91,7 @@ const (
// payments requested by the wallet/daemon. // payments requested by the wallet/daemon.
type PaymentHash [32]byte type PaymentHash [32]byte
// UpdateType is the exact type of an entry within the shared HTLC log. // updateType is the exact type of an entry within the shared HTLC log.
type updateType uint8 type updateType uint8
const ( const (
@ -107,10 +106,11 @@ const (
// which contains the Fail entry. // which contains the Fail entry.
Fail Fail
// MalformedFail is an update type which removes a prior HTLC entry from the // MalformedFail is an update type which removes a prior HTLC entry
// log. Adding a MalformedFail entry to ones log will modify the _remote_ // from the log. Adding a MalformedFail entry to ones log will modify
// parties update log once a new commitment view has been evaluated which // the _remote_ parties update log once a new commitment view has been
// contains the MalformedFail entry. The difference from Fail type lie in // evaluated which contains the MalformedFail entry. The difference
// from Fail type lie in
// the different data we have to store. // the different data we have to store.
MalformedFail MalformedFail
@ -184,7 +184,7 @@ type PaymentDescriptor struct {
// localOutputIndex is the output index of this HTLc output in the // localOutputIndex is the output index of this HTLc output in the
// commitment transaction of the local node. // commitment transaction of the local node.
// //
// NOTE: If the output is dust from the PoV of the local comimtnet // NOTE: If the output is dust from the PoV of the local commitment
// chain, then this value will be -1. // chain, then this value will be -1.
localOutputIndex int32 localOutputIndex int32
@ -274,8 +274,8 @@ type commitment struct {
// update number of this commitment. // update number of this commitment.
height uint64 height uint64
// isOurs indicates whether this is the local or remote node's version of // isOurs indicates whether this is the local or remote node's version
// the commitment. // of the commitment.
isOurs bool isOurs bool
// [our|their]MessageIndex are indexes into the HTLC log, up to which // [our|their]MessageIndex are indexes into the HTLC log, up to which
@ -287,6 +287,14 @@ type commitment struct {
ourMessageIndex uint64 ourMessageIndex uint64
theirMessageIndex uint64 theirMessageIndex uint64
// [our|their]HtlcIndex are the current running counters for the HTLC's
// offered by either party. This value is incremented each time a party
// offers a new HTLC. The log update methods that consume HTLC's will
// reference these counters, rather than the running cumulative message
// counters.
ourHtlcIndex uint64
theirHtlcIndex uint64
// txn is the commitment transaction generated by including any HTLC // txn is the commitment transaction generated by including any HTLC
// updates whose index are below the two indexes listed above. If this // updates whose index are below the two indexes listed above. If this
// commitment is being added to the remote chain, then this txn is // commitment is being added to the remote chain, then this txn is
@ -305,16 +313,16 @@ type commitment struct {
theirBalance lnwire.MilliSatoshi theirBalance lnwire.MilliSatoshi
// fee is the amount that will be paid as fees for this commitment // fee is the amount that will be paid as fees for this commitment
// transaction. The fee is recorded here so that it can be added // transaction. The fee is recorded here so that it can be added back
// back and recalculated for each new update to the channel state. // and recalculated for each new update to the channel state.
fee btcutil.Amount fee btcutil.Amount
// feePerKw is the fee per kw used to calculate this commitment // feePerKw is the fee per kw used to calculate this commitment
// transaction's fee. // transaction's fee.
feePerKw btcutil.Amount feePerKw btcutil.Amount
// dustLimit is the limit on the commitment transaction such that no output // dustLimit is the limit on the commitment transaction such that no
// values should be below this amount. // output values should be below this amount.
dustLimit btcutil.Amount dustLimit btcutil.Amount
// outgoingHTLCs is a slice of all the outgoing HTLC's (from our PoV) // outgoingHTLCs is a slice of all the outgoing HTLC's (from our PoV)
@ -327,12 +335,14 @@ type commitment struct {
// [outgoing|incoming]HTLCIndex is an index that maps an output index // [outgoing|incoming]HTLCIndex is an index that maps an output index
// on the commitment transaction to the payment descriptor that // on the commitment transaction to the payment descriptor that
// represents the HTLC output. Note that these fields are only // represents the HTLC output.
// populated if this commitment state belongs to the local node. These //
// maps are used when validating any HTLC signatures which are part of // NOTE: that these fields are only populated if this commitment state
// the local commitment state. We use this map in order to locate the // belongs to the local node. These maps are used when validating any
// details needed to validate an HTLC signature while iterating of the // HTLC signatures which are part of the local commitment state. We use
// outputs int he local commitment view. // this map in order to locate the details needed to validate an HTLC
// signature while iterating of the outputs in the local commitment
// view.
outgoingHTLCIndex map[int32]*PaymentDescriptor outgoingHTLCIndex map[int32]*PaymentDescriptor
incomingHTLCIndex map[int32]*PaymentDescriptor incomingHTLCIndex map[int32]*PaymentDescriptor
} }