funding

package
v0.6.4-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const Subsystem = "FNDG"

Variables

This section is empty.

Functions

func AbandonCanceledChannels

func AbandonCanceledChannels(matchedOrders map[order.Nonce][]*order.MatchedOrder,
	batchTx *wire.MsgTx, wallet lndclient.WalletKitClient,
	baseClient BaseClient, fetchOrder order.Fetcher) error

AbandonCanceledChannels removes all channels from lnd's channel database that were created for an iteration of a batch that never made it to chain in the provided configuration. This should be called whenever a batch is replaced with an updated version because some traders were offline or rejected the batch. If a non-nil error is returned, something with reading the local order or extracting the channel outpoint went wrong and we should fail hard. If the channel cannot be abandoned for some reason, the error is just logged but not returned.

func CancelPendingFundingShims

func CancelPendingFundingShims(matchedOrders map[order.Nonce][]*order.MatchedOrder,
	baseClient BaseClient, fetchOrder order.Fetcher) error

CancelPendingFundingShims cancels all funding shims we registered when preparing for the orders in a batch. This should be called if for any reason we need to reject the batch, so we're able to process any subsequent modified batches.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type BaseClient

type BaseClient interface {
	// FundingStateStep is an advanced funding related call that allows the
	// caller to either execute some preparatory steps for a funding
	// workflow, or manually progress a funding workflow.
	FundingStateStep(ctx context.Context, req *lnrpc.FundingTransitionMsg,
		opts ...grpc.CallOption) (*lnrpc.FundingStateStepResp, error)

	// OpenChannel attempts to open a singly funded channel specified in the
	// request to a remote peer.
	OpenChannel(ctx context.Context, req *lnrpc.OpenChannelRequest,
		opts ...grpc.CallOption) (lnrpc.Lightning_OpenChannelClient,
		error)

	// ListPeers returns a verbose listing of all currently active peers.
	ListPeers(ctx context.Context, req *lnrpc.ListPeersRequest,
		opts ...grpc.CallOption) (*lnrpc.ListPeersResponse, error)

	// SubscribePeerEvents creates a uni-directional stream from the server
	// to the client in which any events relevant to the state of peers are
	// sent over. Events include peers going online and offline.
	SubscribePeerEvents(ctx context.Context, r *lnrpc.PeerEventSubscription,
		opts ...grpc.CallOption) (
		lnrpc.Lightning_SubscribePeerEventsClient, error)

	// AbandonChannel removes all channel state from the database except for
	// a close summary. This method can be used to get rid of permanently
	// unusable channels due to bugs fixed in newer versions of lnd. This
	// method can also be used to remove externally funded channels where
	// the funding transaction was never broadcast. Only available for
	// non-externally funded channels in dev build.
	AbandonChannel(ctx context.Context, in *lnrpc.AbandonChannelRequest,
		opts ...grpc.CallOption) (*lnrpc.AbandonChannelResponse, error)

	// SubscribeChannelEvents creates a uni-directional stream from the
	// server to the client in which any updates relevant to the state of
	// the channels are sent over. Events include new active channels,
	// inactive channels, and closed channels.
	SubscribeChannelEvents(ctx context.Context,
		in *lnrpc.ChannelEventSubscription, opts ...grpc.CallOption) (
		lnrpc.Lightning_SubscribeChannelEventsClient, error)
}

BaseClient is an interface that contains all methods necessary to open a channel with a funding shim and query peer connections.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is responsible for everything channel funding related during the match making process.

func NewManager

func NewManager(cfg *ManagerConfig) *Manager

NewManager creates a new funding manager from the given config.

func (*Manager) BatchChannelSetup

func (m *Manager) BatchChannelSetup(
	batch *order.Batch) (map[wire.OutPoint]*chaninfo.ChannelInfo, error)

BatchChannelSetup will attempt to establish new funding flows with all matched takers (people buying our channels) in the passed batch. This method will block until the channel is considered pending. Once this phase is complete, and the batch execution transaction broadcast, the channel will be finalized and locked in.

func (*Manager) DeletePendingBatch

func (m *Manager) DeletePendingBatch() error

DeletePendingBatch removes all references to the current pending batch without applying its staged updates to accounts and orders. If no pending batch exists, this acts as a no-op.

NOTE: This is part of the auctioneer.BatchCleaner interface.

func (*Manager) OfferSidecar

func (m *Manager) OfferSidecar(ctx context.Context, capacity,
	pushAmt btcutil.Amount, duration uint32,
	acctPubKey *keychain.KeyDescriptor,
	bid *order.Bid, auto bool) (*sidecar.Ticket, error)

OfferSidecar creates a sidecar channel offer and embeds it in a new sidecar ticket. The offer is signed with the local lnd's node public key. If a bid is passed along, then this indicates that the ticket is intended to be used for autonated sidecar negotiation.

func (*Manager) PrepChannelFunding

func (m *Manager) PrepChannelFunding(batch *order.Batch,
	getOrder order.Fetcher) error

PrepChannelFunding preps the backing node to either receive or initiate a channel funding based on the items in the order batch.

func (*Manager) RemovePendingBatchArtifacts

func (m *Manager) RemovePendingBatchArtifacts(
	matchedOrders map[order.Nonce][]*order.MatchedOrder,
	batchTx *wire.MsgTx) error

RemovePendingBatchArtifacts removes any funding shims or pending channels from a batch that was never finalized. Some non-terminal errors are logged only and not returned. Therefore if this method returns an error, it should be handled as terminal error.

NOTE: This is part of the auctioneer.BatchCleaner interface.

func (*Manager) SidecarBatchChannelSetup

func (m *Manager) SidecarBatchChannelSetup(batch *order.Batch,
	chanUpdates *subscribe.Client,
	getOrder order.Fetcher) (map[wire.OutPoint]*chaninfo.ChannelInfo,
	error)

SidecarBatchChannelSetup will attempt to establish new funding flows with all matched takers (people buying our channels) in the passed batch. This method will block until the channel is considered pending. Once this phase is complete, and the batch execution transaction broadcast, the channel will be finalized and locked in.

func (*Manager) Start

func (m *Manager) Start() error

Start starts the rpcServer, making it ready to accept incoming requests.

func (*Manager) Stop

func (m *Manager) Stop() error

Stop stops the server.

func (*Manager) SubscribePendingOpenChan

func (m *Manager) SubscribePendingOpenChan() (*subscribe.Client, error)

SubscribePendingOpenChan creates a new subscription client to receive events for pending open channels from lnd.

type ManagerConfig

type ManagerConfig struct {
	// DB is the client database.
	DB *clientdb.DB

	// WalletKit is an lndclient wrapped walletrpc client.
	WalletKit lndclient.WalletKitClient

	// LightningClient is an lndclient wrapped lnrpc client.
	LightningClient lndclient.LightningClient

	// SignerClient is an lndclient wrapped signrpc client.
	SignerClient lndclient.SignerClient

	// BaseClient is a raw lnrpc client that implements all methods the
	// funding manager needs.
	BaseClient BaseClient

	// NodePubKey is the connected lnd node's identity public key.
	NodePubKey *btcec.PublicKey

	// NewNodesOnly specifies if the funding manager should only accept
	// matched orders with channels from new nodes that the connected lnd
	// node doesn't already have channels with.
	NewNodesOnly bool

	// BatchStepTimeout is the timeout the manager uses when executing a
	// single batch step.
	BatchStepTimeout time.Duration

	// NotifyShimCreated is a function that should be called whenever a
	// funding shim is created for a bid order where we expect an incoming
	// channel at any moment.
	NotifyShimCreated func(ourBid *order.Bid, pendingChanID [32]byte)
}

ManagerConfig holds all the items passed into the funding manager externally.

type MatchRejectErr

type MatchRejectErr struct {
	// RejectedOrders is the map of matches we reject, keyed with our order
	// nonce.
	RejectedOrders map[order.Nonce]*auctioneerrpc.OrderReject
}

MatchRejectErr is an error type that is returned from the funding manager if the trader rejects certain orders instead of the whole batch.

func (*MatchRejectErr) Error

func (e *MatchRejectErr) Error() string

Error returns the underlying error string.

NOTE: This is part of the error interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL