cnct: add new methods for resolvers
This commit is contained in:
7 files changed
+102
-98
No files matched your search
@@ -1733,14 +1733,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resKit := newContractResolverKit(resolverCfg)
|
resolver := newSuccessResolver(
|
||||||
resolver := &htlcSuccessResolver{
|
resolution, height,
|
||||||
htlcResolution: resolution,
|
htlc.RHash, htlc.Amt, resolverCfg,
|
||||||
broadcastHeight: height,
|
)
|
||||||
payHash: htlc.RHash,
|
|
||||||
htlcAmt: htlc.Amt,
|
|
||||||
contractResolverKit: *resKit,
|
|
||||||
}
|
|
||||||
htlcResolvers = append(htlcResolvers, resolver)
|
htlcResolvers = append(htlcResolvers, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1761,14 +1757,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resKit := newContractResolverKit(resolverCfg)
|
resolver := newTimeoutResolver(
|
||||||
resolver := &htlcTimeoutResolver{
|
resolution, height, htlc.HtlcIndex,
|
||||||
htlcResolution: resolution,
|
htlc.Amt, resolverCfg,
|
||||||
broadcastHeight: height,
|
)
|
||||||
htlcIndex: htlc.HtlcIndex,
|
|
||||||
htlcAmt: htlc.Amt,
|
|
||||||
contractResolverKit: *resKit,
|
|
||||||
}
|
|
||||||
htlcResolvers = append(htlcResolvers, resolver)
|
htlcResolvers = append(htlcResolvers, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1798,18 +1790,11 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
|||||||
ChanID: c.cfg.ShortChanID,
|
ChanID: c.cfg.ShortChanID,
|
||||||
}
|
}
|
||||||
|
|
||||||
resKit := newContractResolverKit(resolverCfg)
|
resolver := newIncomingContestResolver(
|
||||||
resolver := &htlcIncomingContestResolver{
|
htlc.RefundTimeout, circuitKey,
|
||||||
htlcExpiry: htlc.RefundTimeout,
|
resolution, height, htlc.RHash,
|
||||||
circuitKey: circuitKey,
|
htlc.Amt, resolverCfg,
|
||||||
htlcSuccessResolver: htlcSuccessResolver{
|
)
|
||||||
htlcResolution: resolution,
|
|
||||||
broadcastHeight: height,
|
|
||||||
payHash: htlc.RHash,
|
|
||||||
htlcAmt: htlc.Amt,
|
|
||||||
contractResolverKit: *resKit,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
htlcResolvers = append(htlcResolvers, resolver)
|
htlcResolvers = append(htlcResolvers, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1831,16 +1816,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resKit := newContractResolverKit(resolverCfg)
|
resolver := newOutgoingContestResolver(
|
||||||
resolver := &htlcOutgoingContestResolver{
|
resolution, height, htlc.HtlcIndex,
|
||||||
htlcTimeoutResolver: htlcTimeoutResolver{
|
htlc.Amt, resolverCfg,
|
||||||
htlcResolution: resolution,
|
)
|
||||||
broadcastHeight: height,
|
|
||||||
htlcIndex: htlc.HtlcIndex,
|
|
||||||
htlcAmt: htlc.Amt,
|
|
||||||
contractResolverKit: *resKit,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
htlcResolvers = append(htlcResolvers, resolver)
|
htlcResolvers = append(htlcResolvers, resolver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1850,14 +1829,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
|||||||
// a resolver to sweep our commitment output (but only if it wasn't
|
// a resolver to sweep our commitment output (but only if it wasn't
|
||||||
// trimmed).
|
// trimmed).
|
||||||
if contractResolutions.CommitResolution != nil {
|
if contractResolutions.CommitResolution != nil {
|
||||||
resKit := newContractResolverKit(resolverCfg)
|
resolver := newCommitSweepResolver(
|
||||||
resolver := &commitSweepResolver{
|
*contractResolutions.CommitResolution,
|
||||||
commitResolution: *contractResolutions.CommitResolution,
|
height, c.cfg.ChanPoint, resolverCfg,
|
||||||
broadcastHeight: height,
|
)
|
||||||
chanPoint: c.cfg.ChanPoint,
|
|
||||||
contractResolverKit: *resKit,
|
|
||||||
}
|
|
||||||
|
|
||||||
htlcResolvers = append(htlcResolvers, resolver)
|
htlcResolvers = append(htlcResolvers, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,19 @@ type commitSweepResolver struct {
|
|||||||
contractResolverKit
|
contractResolverKit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newCommitSweepResolver instantiates a new direct commit output resolver.
|
||||||
|
func newCommitSweepResolver(res lnwallet.CommitOutputResolution,
|
||||||
|
broadcastHeight uint32,
|
||||||
|
chanPoint wire.OutPoint, resCfg ResolverConfig) *commitSweepResolver {
|
||||||
|
|
||||||
|
return &commitSweepResolver{
|
||||||
|
contractResolverKit: *newContractResolverKit(resCfg),
|
||||||
|
commitResolution: res,
|
||||||
|
broadcastHeight: broadcastHeight,
|
||||||
|
chanPoint: chanPoint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ResolverKey returns an identifier which should be globally unique for this
|
// ResolverKey returns an identifier which should be globally unique for this
|
||||||
// particular resolver within the chain the original contract resides within.
|
// particular resolver within the chain the original contract resides within.
|
||||||
func (c *commitSweepResolver) ResolverKey() []byte {
|
func (c *commitSweepResolver) ResolverKey() []byte {
|
||||||
@@ -298,15 +311,6 @@ func newCommitSweepResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachConfig should be called once a resolved is successfully decoded from
|
|
||||||
// its stored format. This struct delivers the configuration items that
|
|
||||||
// resolvers need to complete their duty.
|
|
||||||
//
|
|
||||||
// NOTE: Part of the ContractResolver interface.
|
|
||||||
func (c *commitSweepResolver) AttachConfig(r ResolverConfig) {
|
|
||||||
c.contractResolverKit = *newContractResolverKit(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A compile time assertion to ensure commitSweepResolver meets the
|
// A compile time assertion to ensure commitSweepResolver meets the
|
||||||
// ContractResolver interface.
|
// ContractResolver interface.
|
||||||
var _ ContractResolver = (*commitSweepResolver)(nil)
|
var _ ContractResolver = (*commitSweepResolver)(nil)
|
||||||
@@ -46,11 +46,6 @@ type ContractResolver interface {
|
|||||||
// passed Writer.
|
// passed Writer.
|
||||||
Encode(w io.Writer) error
|
Encode(w io.Writer) error
|
||||||
|
|
||||||
// AttachConfig should be called once a resolved is successfully decoded
|
|
||||||
// from its stored format. This struct delivers the configuration items
|
|
||||||
// that resolvers need to complete their duty.
|
|
||||||
AttachConfig(ResolverConfig)
|
|
||||||
|
|
||||||
// Stop signals the resolver to cancel any current resolution
|
// Stop signals the resolver to cancel any current resolution
|
||||||
// processes, and suspend.
|
// processes, and suspend.
|
||||||
Stop()
|
Stop()
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/invoices"
|
"github.com/lightningnetwork/lnd/invoices"
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil"
|
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an
|
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an
|
||||||
@@ -34,6 +35,24 @@ type htlcIncomingContestResolver struct {
|
|||||||
htlcSuccessResolver
|
htlcSuccessResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newIncomingContestResolver instantiates a new incoming htlc contest resolver.
|
||||||
|
func newIncomingContestResolver(htlcExpiry uint32,
|
||||||
|
circuitKey channeldb.CircuitKey, res lnwallet.IncomingHtlcResolution,
|
||||||
|
broadcastHeight uint32, payHash lntypes.Hash,
|
||||||
|
htlcAmt lnwire.MilliSatoshi,
|
||||||
|
resCfg ResolverConfig) *htlcIncomingContestResolver {
|
||||||
|
|
||||||
|
success := newSuccessResolver(
|
||||||
|
res, broadcastHeight, payHash, htlcAmt, resCfg,
|
||||||
|
)
|
||||||
|
|
||||||
|
return &htlcIncomingContestResolver{
|
||||||
|
htlcExpiry: htlcExpiry,
|
||||||
|
circuitKey: circuitKey,
|
||||||
|
htlcSuccessResolver: *success,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve attempts to resolve this contract. As we don't yet know of the
|
// Resolve attempts to resolve this contract. As we don't yet know of the
|
||||||
// preimage for the contract, we'll wait for one of two things to happen:
|
// preimage for the contract, we'll wait for one of two things to happen:
|
||||||
//
|
//
|
||||||
@@ -319,15 +338,6 @@ func newIncomingContestResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
|||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachConfig should be called once a resolved is successfully decoded from
|
|
||||||
// its stored format. This struct delivers the configuration items that
|
|
||||||
// resolvers need to complete their duty.
|
|
||||||
//
|
|
||||||
// NOTE: Part of the ContractResolver interface.
|
|
||||||
func (h *htlcIncomingContestResolver) AttachConfig(r ResolverConfig) {
|
|
||||||
h.htlcSuccessResolver.AttachConfig(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A compile time assertion to ensure htlcIncomingContestResolver meets the
|
// A compile time assertion to ensure htlcIncomingContestResolver meets the
|
||||||
// ContractResolver interface.
|
// ContractResolver interface.
|
||||||
var _ ContractResolver = (*htlcIncomingContestResolver)(nil)
|
var _ ContractResolver = (*htlcIncomingContestResolver)(nil)
|
||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// htlcOutgoingContestResolver is a ContractResolver that's able to resolve an
|
// htlcOutgoingContestResolver is a ContractResolver that's able to resolve an
|
||||||
@@ -18,6 +20,21 @@ type htlcOutgoingContestResolver struct {
|
|||||||
htlcTimeoutResolver
|
htlcTimeoutResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newOutgoingContestResolver instantiates a new outgoing contested htlc
|
||||||
|
// resolver.
|
||||||
|
func newOutgoingContestResolver(res lnwallet.OutgoingHtlcResolution,
|
||||||
|
broadcastHeight uint32, htlcIndex uint64, htlcAmt lnwire.MilliSatoshi,
|
||||||
|
resCfg ResolverConfig) *htlcOutgoingContestResolver {
|
||||||
|
|
||||||
|
timeout := newTimeoutResolver(
|
||||||
|
res, broadcastHeight, htlcIndex, htlcAmt, resCfg,
|
||||||
|
)
|
||||||
|
|
||||||
|
return &htlcOutgoingContestResolver{
|
||||||
|
htlcTimeoutResolver: *timeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve commences the resolution of this contract. As this contract hasn't
|
// Resolve commences the resolution of this contract. As this contract hasn't
|
||||||
// yet timed out, we'll wait for one of two things to happen
|
// yet timed out, we'll wait for one of two things to happen
|
||||||
//
|
//
|
||||||
@@ -196,15 +213,6 @@ func newOutgoingContestResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
|||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachConfig should be called once a resolved is successfully decoded from
|
|
||||||
// its stored format. This struct delivers the configuration items that
|
|
||||||
// resolvers need to complete their duty.
|
|
||||||
//
|
|
||||||
// NOTE: Part of the ContractResolver interface.
|
|
||||||
func (h *htlcOutgoingContestResolver) AttachConfig(r ResolverConfig) {
|
|
||||||
h.htlcTimeoutResolver.AttachConfig(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A compile time assertion to ensure htlcOutgoingContestResolver meets the
|
// A compile time assertion to ensure htlcOutgoingContestResolver meets the
|
||||||
// ContractResolver interface.
|
// ContractResolver interface.
|
||||||
var _ ContractResolver = (*htlcOutgoingContestResolver)(nil)
|
var _ ContractResolver = (*htlcOutgoingContestResolver)(nil)
|
||||||
@@ -55,6 +55,21 @@ type htlcSuccessResolver struct {
|
|||||||
contractResolverKit
|
contractResolverKit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newSuccessResolver instanties a new htlc success resolver.
|
||||||
|
func newSuccessResolver(res lnwallet.IncomingHtlcResolution,
|
||||||
|
broadcastHeight uint32, payHash lntypes.Hash,
|
||||||
|
htlcAmt lnwire.MilliSatoshi,
|
||||||
|
resCfg ResolverConfig) *htlcSuccessResolver {
|
||||||
|
|
||||||
|
return &htlcSuccessResolver{
|
||||||
|
contractResolverKit: *newContractResolverKit(resCfg),
|
||||||
|
htlcResolution: res,
|
||||||
|
broadcastHeight: broadcastHeight,
|
||||||
|
payHash: payHash,
|
||||||
|
htlcAmt: htlcAmt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ResolverKey returns an identifier which should be globally unique for this
|
// ResolverKey returns an identifier which should be globally unique for this
|
||||||
// particular resolver within the chain the original contract resides within.
|
// particular resolver within the chain the original contract resides within.
|
||||||
//
|
//
|
||||||
@@ -323,15 +338,6 @@ func newSuccessResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
|||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachConfig should be called once a resolved is successfully decoded from
|
|
||||||
// its stored format. This struct delivers the configuration items that
|
|
||||||
// resolvers need to complete their duty.
|
|
||||||
//
|
|
||||||
// NOTE: Part of the ContractResolver interface.
|
|
||||||
func (h *htlcSuccessResolver) AttachConfig(r ResolverConfig) {
|
|
||||||
h.contractResolverKit = *newContractResolverKit(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A compile time assertion to ensure htlcSuccessResolver meets the
|
// A compile time assertion to ensure htlcSuccessResolver meets the
|
||||||
// ContractResolver interface.
|
// ContractResolver interface.
|
||||||
var _ ContractResolver = (*htlcSuccessResolver)(nil)
|
var _ ContractResolver = (*htlcSuccessResolver)(nil)
|
||||||
@@ -51,6 +51,21 @@ type htlcTimeoutResolver struct {
|
|||||||
contractResolverKit
|
contractResolverKit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newTimeoutResolver instantiates a new timeout htlc resolver.
|
||||||
|
func newTimeoutResolver(res lnwallet.OutgoingHtlcResolution,
|
||||||
|
broadcastHeight uint32, htlcIndex uint64,
|
||||||
|
htlcAmt lnwire.MilliSatoshi,
|
||||||
|
resCfg ResolverConfig) *htlcTimeoutResolver {
|
||||||
|
|
||||||
|
return &htlcTimeoutResolver{
|
||||||
|
contractResolverKit: *newContractResolverKit(resCfg),
|
||||||
|
htlcResolution: res,
|
||||||
|
broadcastHeight: broadcastHeight,
|
||||||
|
htlcIndex: htlcIndex,
|
||||||
|
htlcAmt: htlcAmt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ResolverKey returns an identifier which should be globally unique for this
|
// ResolverKey returns an identifier which should be globally unique for this
|
||||||
// particular resolver within the chain the original contract resides within.
|
// particular resolver within the chain the original contract resides within.
|
||||||
//
|
//
|
||||||
@@ -441,15 +456,6 @@ func newTimeoutResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
|||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachConfig should be called once a resolved is successfully decoded from
|
|
||||||
// its stored format. This struct delivers the configuration items that
|
|
||||||
// resolvers need to complete their duty.
|
|
||||||
//
|
|
||||||
// NOTE: Part of the ContractResolver interface.
|
|
||||||
func (h *htlcTimeoutResolver) AttachConfig(r ResolverConfig) {
|
|
||||||
h.contractResolverKit = *newContractResolverKit(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A compile time assertion to ensure htlcTimeoutResolver meets the
|
// A compile time assertion to ensure htlcTimeoutResolver meets the
|
||||||
// ContractResolver interface.
|
// ContractResolver interface.
|
||||||
var _ ContractResolver = (*htlcTimeoutResolver)(nil)
|
var _ ContractResolver = (*htlcTimeoutResolver)(nil)
|
||||||
Reference in new issue
Block a user