auctioneer

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: 35 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// MaxUnusedAccountKeyLookup is the number of successive account keys
	// that we try and the server does not know of before aborting recovery.
	// This is necessary to skip "holes" in our list of keys that can happen
	// if the user tries to open an account but that fails. Then some keys
	// aren't used.
	MaxUnusedAccountKeyLookup = 50
)
View Source
const Subsystem = "AUCT"

Variables

View Source
var (
	// ErrServerShutdown is the error that is returned if the auction server
	// signals it's going to shut down.
	ErrServerShutdown = errors.New("server shutting down")

	// ErrServerErrored is the error that is returned if the auction server
	// sends back an error instead of a proper message.
	ErrServerErrored = errors.New("server sent unexpected error")

	// ErrClientShutdown is the error that is returned if the trader client
	// itself is shutting down.
	ErrClientShutdown = errors.New("client shutting down")

	// ErrAuthCanceled is returned if the authentication process of a single
	// account subscription is aborted.
	ErrAuthCanceled = errors.New("authentication was canceled")
)
View Source
var (
	// ErrAcctResNotCompleted is the error wrapped by
	// AcctResNotCompletedError that can be used with errors.Is() to
	// avoid type assertions.
	ErrAcctResNotCompleted = errors.New("account reservation not completed")
)
View Source
var (
	// ErrBatchNotFinalized is an error returned by the auctioneer when we
	// attempt to query it for a batch snapshot, but the batch has not been
	// finalized by them yet.
	ErrBatchNotFinalized = errors.New("batch snapshot not found")
)

Functions

func IsOrderNotFoundErr

func IsOrderNotFoundErr(err error) bool

IsOrderNotFoundErr tries to match the given error with ErrNoOrder. Useful to check rpc errors from the server.

func MarshallNodeTier

func MarshallNodeTier(nodeTier order.NodeTier) (auctioneerrpc.NodeTier, error)

MarshallNodeTier maps the node tier integer into the enum used on the RPC interface.

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 AcctResNotCompletedError

type AcctResNotCompletedError struct {
	// Value is the value of the account reflected in the on-chain output
	// that backs the existence of an account.
	Value btcutil.Amount

	// AcctKey is the raw account key of the account we didn't find in our
	// database.
	AcctKey [33]byte

	// AuctioneerKey is the raw base auctioneer's key in the 2-of-2
	// multi-sig construction of a CLM account.
	AuctioneerKey [33]byte

	// InitialBatchKey is the raw initial batch key that is used to tweak
	// the trader key of an account.
	InitialBatchKey [33]byte

	// HeightHint is the block height at the time of the reservation. Even
	// if the transaction was published, it cannot have happened in an
	// earlier block.
	HeightHint uint32

	// Expiry is the expiration block height of an account. After this
	// point, the trader is able to withdraw the funds from their account
	// without cooperation of the auctioneer.
	Expiry uint32

	// Version is the version of the account.
	Version uint32
}

AcctResNotCompletedError is returned if a trader tries to subscribe to an account that we don't know. This should only happen during recovery where the trader goes through a number of their keys to find accounts we still know the state of.

func AcctResNotCompletedErrFromRPC

func AcctResNotCompletedErrFromRPC(
	rpcAcc *auctioneerrpc.AuctionAccount) *AcctResNotCompletedError

AcctResNotCompletedErrFromRPC creates a new AcctResNotCompletedError from an RPC account message.

func (*AcctResNotCompletedError) Error

func (e *AcctResNotCompletedError) Error() string

Error implements the error interface.

func (*AcctResNotCompletedError) Unwrap

func (e *AcctResNotCompletedError) Unwrap() error

Unwrap returns the underlying error type.

type BatchCleaner

type BatchCleaner interface {
	// 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.
	DeletePendingBatch() 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.
	RemovePendingBatchArtifacts(
		matchedOrders map[order.Nonce][]*order.MatchedOrder,
		batchTx *wire.MsgTx) error
}

BatchCleaner abstracts the cleaning up of a trader's pending batch.

type BatchSource

type BatchSource interface {
	// PendingBatchSnapshot retrieves the snapshot of the currently pending
	// batch. If there isn't one, account.ErrNoPendingBatch is returned.
	PendingBatchSnapshot() (*clientdb.LocalBatchSnapshot, error)
}

BatchSource abstracts the source of a trader's pending batch.

type Client

type Client struct {
	StreamErrChan chan error

	FromServerChan chan *auctioneerrpc.ServerAuctionMessage
	// contains filtered or unexported fields
}

Client performs the client side part of auctions. This interface exists to be able to implement a stub.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient returns a new instance to initiate auctions with.

func (*Client) BatchSnapshot

func (c *Client) BatchSnapshot(ctx context.Context,
	targetBatch order.BatchID) (*auctioneerrpc.BatchSnapshotResponse,
	error)

BatchSnapshot returns information about a target batch including the clearing price of the batch, and the set of orders matched within the batch.

NOTE: This isn't wrapped in "native" types, as atm we only use this to shuffle information back to the client over our RPC interface.

func (*Client) BatchSnapshots

BatchSnapshots returns a list of batch snapshots starting at the start batch ID and going back through the history of batches, returning at most the number of specified batches. A maximum of 100 snapshots can be queried in one call. If no start batch ID is provided, the most recent finalized batch is used as the starting point to go back from.

NOTE: This isn't wrapped in "native" types, as atm we only use this to shuffle information back to the client over our RPC interface.

func (*Client) CancelOrder

func (c *Client) CancelOrder(ctx context.Context, noncePreimage lntypes.Preimage) error

CancelOrder sends an order cancellation message to the server.

func (*Client) DelAcctMailbox

func (c *Client) DelAcctMailbox(ctx context.Context, sid [64]byte,
	acctKey *keychain.KeyDescriptor) error

DelAcctMailbox tears down the mailbox that the sidecar ticket provider used to communicate with the recipient.

func (*Client) DelSidecarMailbox

func (c *Client) DelSidecarMailbox(ctx context.Context,
	streamID [64]byte, ticket *sidecar.Ticket) error

DelSidecarMailbox tears down the mailbox the sidecar ticket recipient used to communicate with the provider.

func (*Client) HandleServerShutdown

func (c *Client) HandleServerShutdown(err error) error

HandleServerShutdown handles the signal from the server that it is going to shut down. In that case, we try to reconnect a number of times with an incremental backoff time we wait between trials. If the connection succeeds, all previous subscriptions are sent again.

func (*Client) InitAccount

func (c *Client) InitAccount(ctx context.Context, account *account.Account) error

InitAccount initializes an account with the auctioneer such that it can be used once fully confirmed.

func (*Client) InitAccountCipherBox

func (c *Client) InitAccountCipherBox(ctx context.Context, sid [64]byte,
	acctKey *keychain.KeyDescriptor) error

InitAccountCipherBox attempts to initialize a new CipherBox using the account key as an authentication mechanism.

func (*Client) InitTicketCipherBox

func (c *Client) InitTicketCipherBox(ctx context.Context, sid [64]byte,
	ticket *sidecar.Ticket) error

InitAccountCipherBox attempts to initialize a new CipherBox using the sidecar ticket as the authentication method.

func (*Client) IsSubscribed

func (c *Client) IsSubscribed() bool

IsSubscribed returns true if at least one account is in an active state and the subscription stream to the server was established successfully.

func (*Client) MarketInfo

func (c *Client) MarketInfo(ctx context.Context) (
	*auctioneerrpc.MarketInfoResponse, error)

MarketInfo returns information about the current number of open orders and open interest in units of all open markets.

NOTE: This isn't wrapped in "native" types, as atm we only use this to shuffle information back to the client over our RPC interface.

func (*Client) ModifyAccount

func (c *Client) ModifyAccount(ctx context.Context, account *account.Account,
	inputs []*wire.TxIn, outputs []*wire.TxOut,
	modifiers []account.Modifier, traderNonces []byte,
	previousOutputs []*wire.TxOut) ([]byte, []byte, error)

ModifyAccount sends an intent to the auctioneer that we'd like to modify the account with the associated trader key. The auctioneer's signature is returned, allowing us to broadcast a transaction spending from the account allowing our modifications to take place. If the account spend is a MuSig2 spend, then the trader's nonces must be sent and the server's nonces are returned upon success. The inputs and outputs provided should exclude the account input being spent and the account output potentially being recreated, since the auctioneer can construct those themselves. If no modifiers are present, then the auctioneer will interpret the request as an account closure. The previous outputs must always contain the UTXO information for _every_ input of the transaction, so inputs+account_input.

func (*Client) NodeRating

func (c *Client) NodeRating(ctx context.Context,
	nodeKeys ...*btcec.PublicKey) (*poolrpc.NodeRatingResponse, error)

NodeRating returns the current up to date ratings information for the target node pubkey.

func (*Client) OrderState

OrderState queries the state of an order on the server. This only returns the state as it's currently known to the server's database. For real-time updates on the state, the SubscribeBatchAuction stream should be used.

func (*Client) RecoverAccounts

func (c *Client) RecoverAccounts(ctx context.Context,
	accountKeys []*keychain.KeyDescriptor) ([]*account.Account, error)

RecoverAccounts tries to recover all given accounts with the help of the auctioneer server. Because the trader derives a new account key for each attempt of opening an account, there can be "holes" in our list of keys that are actually used. For example if there is insufficient balance in lnd, a key gets "used up" but no account is ever created with it. We'll do a sweep to ensure we generate a key only up to the point where it's required. The total number of requested recoveries is returned upon completion.

func (*Client) RecvCipherBoxMsg

func (c *Client) RecvCipherBoxMsg(ctx context.Context,
	sid [64]byte) ([]byte, error)

RecvCipherBoxMsg attempts to read a message from the cipher box identified by the passed stream ID.

func (*Client) ReserveAccount

func (c *Client) ReserveAccount(ctx context.Context, value btcutil.Amount,
	expiry uint32, traderKey *btcec.PublicKey,
	version account.Version) (*account.Reservation, error)

ReserveAccount reserves an account with the auctioneer. It returns the base public key we should use for them in our 2-of-2 multi-sig construction, and the initial batch key.

func (*Client) SendAuctionMessage

func (c *Client) SendAuctionMessage(msg *auctioneerrpc.ClientAuctionMessage) error

SendAuctionMessage sends an auction message through the long-lived stream to the auction server. A message can only be sent as a response to a server message, therefore the stream must already be open.

func (*Client) SendCipherBoxMsg

func (c *Client) SendCipherBoxMsg(ctx context.Context, sid [64]byte,
	msg []byte) error

SendCipherBoxMsg attempts to the passed message into the cipher box identified by the passed stream ID. This message will be on-blocking as long as the buffer size of the stream is not exceed.

TODO(roasbeef): option to expose a streaming interface?

func (*Client) Start

func (c *Client) Start() error

Start starts the client, establishing the connection to the server.

func (*Client) StartAccountSubscription

func (c *Client) StartAccountSubscription(ctx context.Context,
	acctKey *keychain.KeyDescriptor) error

StartAccountSubscription opens a stream to the server and subscribes to all updates that concern the given account, including all orders that spend from that account. Only a single stream is ever open to the server, so a second call to this method will send a second subscription over the same stream, multiplexing all messages into the same connection. A stream can be long-lived, so this can be called for every account as soon as it's confirmed open. This method will return as soon as the authentication was successful. Messages sent from the server can then be received on the FromServerChan channel.

func (*Client) Stop

func (c *Client) Stop() error

Stop shuts down the client connection to the auction server.

func (*Client) SubmitOrder

func (c *Client) SubmitOrder(ctx context.Context, o order.Order,
	serverParams *order.ServerOrderParams) error

SubmitOrder sends a fully finished order message to the server and interprets its answer.

func (*Client) Terms

func (c *Client) Terms(ctx context.Context) (*terms.AuctioneerTerms, error)

Terms returns the current dynamic auctioneer terms like max account size, max order duration in blocks and the auction fee schedule.

type Config

type Config struct {
	// ServerAddress is the domain:port of the auctioneer server.
	ServerAddress string

	// ProxyAddress is the SOCKS proxy that should be used to establish the
	// connection.
	ProxyAddress string

	// Insecure signals that no TLS should be used if set to true.
	Insecure bool

	// TLSPathServer is the path to a local file that holds the auction
	// server's TLS certificate. This is only needed if the server is using
	// a self signed cert.
	TLSPathServer string

	// DialOpts is a list of additional options that should be used when
	// dialing the gRPC connection.
	DialOpts []grpc.DialOption

	// Signer is the signing interface that is used to sign messages during
	// the authentication handshake with the auctioneer server.
	Signer lndclient.SignerClient

	// MinBackoff is the minimum time that is waited before the next re-
	// connect attempt is made. After each try the backoff is doubled until
	// MaxBackoff is reached.
	MinBackoff time.Duration

	// MaxBackoff is the maximum time that is waited between connection
	// attempts.
	MaxBackoff time.Duration

	// BatchSource provides information about the current pending batch, if
	// any.
	BatchSource BatchSource

	// BatchCleaner provides functionality to clean up the state of a
	// trader's pending batch.
	BatchCleaner BatchCleaner

	// BatchVersion is the batch version that we should use when
	// authenticating with the auction server.
	BatchVersion order.BatchVersion

	// GenUserAgent is a function that generates a complete user agent
	// string given the incoming request context.
	GenUserAgent func(context.Context) string

	// ConnectSidecar is a flag indicating that instead of connecting to the
	// default SubscribeBatchAuction RPC the client should connect to
	// SubscribeSidecar for getting batch updates.
	ConnectSidecar bool
}

Config holds the configuration options for the auctioneer client.

type ErrChanSwitch

type ErrChanSwitch struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ErrChanSwitch is a type that can switch incoming error messages between a main channel and a temporary channel in a concurrency safe way.

func NewErrChanSwitch

func NewErrChanSwitch(mainChan chan<- error) *ErrChanSwitch

NewErrChanSwitch creates a new error channel switcher with the given main channel that error messages are forwarded to by default.

func (*ErrChanSwitch) Divert

func (s *ErrChanSwitch) Divert(tempChan chan<- error)

Divert causes all incoming error messages to be sent to the given temporary channel from now on instead of the main error channel.

func (*ErrChanSwitch) ErrChan

func (s *ErrChanSwitch) ErrChan() chan<- error

ErrChan returns the incoming channel that errors can be sent to that are then switched in a concurrency safe way.

func (*ErrChanSwitch) Restore

func (s *ErrChanSwitch) Restore()

Restore causes all incoming error messages to be sent to the main channel again from now on.

func (*ErrChanSwitch) Start

func (s *ErrChanSwitch) Start()

Start spins up the internal goroutine that processes incoming messages.

func (*ErrChanSwitch) Stop

func (s *ErrChanSwitch) Stop()

Stop shuts down the goroutine that processes incoming messages.

Jump to

Keyboard shortcuts

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