Merge pull request #2166 from joostjager/cnct-fixes

cnct: add todo for invalid expiry value handling
This commit is contained in:
Johan T. Halseth 2018-11-09 08:43:43 +01:00 committed by GitHub
commit b0c6f666f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -834,10 +834,21 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) {
// If the current height is >= expiry-1, then a spend will be valid to
// be included in the next block, and we can immediately return the
// resolver.
//
// TODO(joostjager): Statement above may not be valid. For CLTV locks,
// the expiry value is the last _invalid_ block. The likely reason that
// this does not create a problem, is that utxonursery is checking the
// expiry again (in the proper way). Same holds for minus one operation
// below.
//
// Source:
// https://github.com/btcsuite/btcd/blob/991d32e72fe84d5fbf9c47cd604d793a0cd3a072/blockchain/validate.go#L154
if uint32(currentHeight) >= h.htlcResolution.Expiry-1 {
log.Infof("%T(%v): HTLC has expired (height=%v, expiry=%v), "+
"transforming into timeout resolver", h,
h.htlcResolution.ClaimOutpoint)
h.htlcResolution.ClaimOutpoint, currentHeight,
h.htlcResolution.Expiry)
return &h.htlcTimeoutResolver, nil
}