cnct: add new methods for resolvers
This commit is contained in:
parent
1e5eec990e
commit
32249cb72e
@ -1733,14 +1733,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
||||
continue
|
||||
}
|
||||
|
||||
resKit := newContractResolverKit(resolverCfg)
|
||||
resolver := &htlcSuccessResolver{
|
||||
htlcResolution: resolution,
|
||||
broadcastHeight: height,
|
||||
payHash: htlc.RHash,
|
||||
htlcAmt: htlc.Amt,
|
||||
contractResolverKit: *resKit,
|
||||
}
|
||||
resolver := newSuccessResolver(
|
||||
resolution, height,
|
||||
htlc.RHash, htlc.Amt, resolverCfg,
|
||||
)
|
||||
htlcResolvers = append(htlcResolvers, resolver)
|
||||
}
|
||||
|
||||
@ -1761,14 +1757,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
||||
continue
|
||||
}
|
||||
|
||||
resKit := newContractResolverKit(resolverCfg)
|
||||
resolver := &htlcTimeoutResolver{
|
||||
htlcResolution: resolution,
|
||||
broadcastHeight: height,
|
||||
htlcIndex: htlc.HtlcIndex,
|
||||
htlcAmt: htlc.Amt,
|
||||
contractResolverKit: *resKit,
|
||||
}
|
||||
resolver := newTimeoutResolver(
|
||||
resolution, height, htlc.HtlcIndex,
|
||||
htlc.Amt, resolverCfg,
|
||||
)
|
||||
htlcResolvers = append(htlcResolvers, resolver)
|
||||
}
|
||||
|
||||
@ -1798,18 +1790,11 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
||||
ChanID: c.cfg.ShortChanID,
|
||||
}
|
||||
|
||||
resKit := newContractResolverKit(resolverCfg)
|
||||
resolver := &htlcIncomingContestResolver{
|
||||
htlcExpiry: htlc.RefundTimeout,
|
||||
circuitKey: circuitKey,
|
||||
htlcSuccessResolver: htlcSuccessResolver{
|
||||
htlcResolution: resolution,
|
||||
broadcastHeight: height,
|
||||
payHash: htlc.RHash,
|
||||
htlcAmt: htlc.Amt,
|
||||
contractResolverKit: *resKit,
|
||||
},
|
||||
}
|
||||
resolver := newIncomingContestResolver(
|
||||
htlc.RefundTimeout, circuitKey,
|
||||
resolution, height, htlc.RHash,
|
||||
htlc.Amt, resolverCfg,
|
||||
)
|
||||
htlcResolvers = append(htlcResolvers, resolver)
|
||||
}
|
||||
|
||||
@ -1831,16 +1816,10 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
||||
continue
|
||||
}
|
||||
|
||||
resKit := newContractResolverKit(resolverCfg)
|
||||
resolver := &htlcOutgoingContestResolver{
|
||||
htlcTimeoutResolver: htlcTimeoutResolver{
|
||||
htlcResolution: resolution,
|
||||
broadcastHeight: height,
|
||||
htlcIndex: htlc.HtlcIndex,
|
||||
htlcAmt: htlc.Amt,
|
||||
contractResolverKit: *resKit,
|
||||
},
|
||||
}
|
||||
resolver := newOutgoingContestResolver(
|
||||
resolution, height, htlc.HtlcIndex,
|
||||
htlc.Amt, resolverCfg,
|
||||
)
|
||||
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
|
||||
// trimmed).
|
||||
if contractResolutions.CommitResolution != nil {
|
||||
resKit := newContractResolverKit(resolverCfg)
|
||||
resolver := &commitSweepResolver{
|
||||
commitResolution: *contractResolutions.CommitResolution,
|
||||
broadcastHeight: height,
|
||||
chanPoint: c.cfg.ChanPoint,
|
||||
contractResolverKit: *resKit,
|
||||
}
|
||||
|
||||
resolver := newCommitSweepResolver(
|
||||
*contractResolutions.CommitResolution,
|
||||
height, c.cfg.ChanPoint, resolverCfg,
|
||||
)
|
||||
htlcResolvers = append(htlcResolvers, resolver)
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,19 @@ type commitSweepResolver struct {
|
||||
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
|
||||
// particular resolver within the chain the original contract resides within.
|
||||
func (c *commitSweepResolver) ResolverKey() []byte {
|
||||
@ -298,15 +311,6 @@ func newCommitSweepResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
||||
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
|
||||
// ContractResolver interface.
|
||||
var _ ContractResolver = (*commitSweepResolver)(nil)
|
||||
|
@ -46,11 +46,6 @@ type ContractResolver interface {
|
||||
// passed Writer.
|
||||
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
|
||||
// processes, and suspend.
|
||||
Stop()
|
||||
|
@ -5,11 +5,12 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"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
|
||||
@ -34,6 +35,24 @@ type htlcIncomingContestResolver struct {
|
||||
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
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
// ContractResolver interface.
|
||||
var _ ContractResolver = (*htlcIncomingContestResolver)(nil)
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// htlcOutgoingContestResolver is a ContractResolver that's able to resolve an
|
||||
@ -18,6 +20,21 @@ type htlcOutgoingContestResolver struct {
|
||||
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
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
// ContractResolver interface.
|
||||
var _ ContractResolver = (*htlcOutgoingContestResolver)(nil)
|
||||
|
@ -55,6 +55,21 @@ type htlcSuccessResolver struct {
|
||||
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
|
||||
// particular resolver within the chain the original contract resides within.
|
||||
//
|
||||
@ -323,15 +338,6 @@ func newSuccessResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
||||
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
|
||||
// ContractResolver interface.
|
||||
var _ ContractResolver = (*htlcSuccessResolver)(nil)
|
||||
|
@ -51,6 +51,21 @@ type htlcTimeoutResolver struct {
|
||||
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
|
||||
// particular resolver within the chain the original contract resides within.
|
||||
//
|
||||
@ -441,15 +456,6 @@ func newTimeoutResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
||||
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
|
||||
// ContractResolver interface.
|
||||
var _ ContractResolver = (*htlcTimeoutResolver)(nil)
|
||||
|
Loading…
Reference in New Issue
Block a user