cnct: store full htlc struct inside resolver

This change prepares for accessing the onion blob from a resolver.
This commit is contained in:
Joost Jager committed 2019-11-12 15:01:36 +01:00
1 parent a83be177c6
commit 50abb41e94
8 files changed
+82 -94

No files matched your search

+9 -16
View File
@@ -41,29 +41,22 @@ type htlcTimeoutResolver struct {
// TODO(roasbeef): wrap above into definite resolution embedding?
broadcastHeight uint32
// htlcIndex is the index of this HTLC within the trace of the
// additional commitment state machine.
htlcIndex uint64
// htlcAmt is the original amount of the htlc, not taking into
// account any fees that may have to be paid if it goes on chain.
htlcAmt lnwire.MilliSatoshi
// htlc contains information on the htlc that we are resolving on-chain.
htlc channeldb.HTLC
contractResolverKit
}
// newTimeoutResolver instantiates a new timeout htlc resolver.
func newTimeoutResolver(res lnwallet.OutgoingHtlcResolution,
broadcastHeight uint32, htlcIndex uint64,
htlcAmt lnwire.MilliSatoshi,
broadcastHeight uint32, htlc channeldb.HTLC,
resCfg ResolverConfig) *htlcTimeoutResolver {
return &htlcTimeoutResolver{
contractResolverKit: *newContractResolverKit(resCfg),
htlcResolution: res,
broadcastHeight: broadcastHeight,
htlcIndex: htlcIndex,
htlcAmt: htlcAmt,
htlc: htlc,
}
}
@@ -158,7 +151,7 @@ func (h *htlcTimeoutResolver) claimCleanUp(
// resolved, then exit.
if err := h.DeliverResolutionMsg(ResolutionMsg{
SourceChan: h.ShortChanID,
HtlcIndex: h.htlcIndex,
HtlcIndex: h.htlc.HtlcIndex,
PreImage: &pre,
}); err != nil {
return nil, err
@@ -353,7 +346,7 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
failureMsg := &lnwire.FailPermanentChannelFailure{}
if err := h.DeliverResolutionMsg(ResolutionMsg{
SourceChan: h.ShortChanID,
HtlcIndex: h.htlcIndex,
HtlcIndex: h.htlc.HtlcIndex,
Failure: failureMsg,
}); err != nil {
return nil, err
@@ -415,7 +408,7 @@ func (h *htlcTimeoutResolver) Encode(w io.Writer) error {
return err
}
if err := binary.Write(w, endian, h.htlcIndex); err != nil {
if err := binary.Write(w, endian, h.htlc.HtlcIndex); err != nil {
return err
}
@@ -450,7 +443,7 @@ func newTimeoutResolverFromReader(r io.Reader, resCfg ResolverConfig) (
return nil, err
}
if err := binary.Read(r, endian, &h.htlcIndex); err != nil {
if err := binary.Read(r, endian, &h.htlc.HtlcIndex); err != nil {
return nil, err
}
@@ -462,7 +455,7 @@ func newTimeoutResolverFromReader(r io.Reader, resCfg ResolverConfig) (
//
// NOTE: Part of the htlcContractResolver interface.
func (h *htlcTimeoutResolver) Supplement(htlc channeldb.HTLC) {
h.htlcAmt = htlc.Amt
h.htlc = htlc
}
// HtlcPoint returns the htlc's outpoint on the commitment tx.