Documentation ¶
Index ¶
- Constants
- Variables
- func MarshallNodeTier(nodeTier order.NodeTier) (auctioneerrpc.NodeTier, error)
- func UseLogger(logger btclog.Logger)
- type AcctResNotCompletedError
- type BatchCleaner
- type BatchSource
- type Client
- func (c *Client) BatchSnapshot(ctx context.Context, targetBatch order.BatchID) (*auctioneerrpc.BatchSnapshotResponse, error)
- func (c *Client) BatchSnapshots(ctx context.Context, req *auctioneerrpc.BatchSnapshotsRequest) (*auctioneerrpc.BatchSnapshotsResponse, error)
- func (c *Client) CancelOrder(ctx context.Context, noncePreimage lntypes.Preimage) error
- func (c *Client) DelAcctMailbox(ctx context.Context, sid [64]byte, acctKey *keychain.KeyDescriptor) error
- func (c *Client) DelSidecarMailbox(ctx context.Context, streamID [64]byte, ticket *sidecar.Ticket) error
- func (c *Client) HandleServerShutdown(err error) error
- func (c *Client) InitAccount(ctx context.Context, account *account.Account) error
- func (c *Client) InitAccountCipherBox(ctx context.Context, sid [64]byte, acctKey *keychain.KeyDescriptor) error
- func (c *Client) InitTicketCipherBox(ctx context.Context, sid [64]byte, ticket *sidecar.Ticket) error
- func (c *Client) IsSubscribed() bool
- func (c *Client) MarketInfo(ctx context.Context) (*auctioneerrpc.MarketInfoResponse, error)
- func (c *Client) ModifyAccount(ctx context.Context, account *account.Account, inputs []*wire.TxIn, ...) ([]byte, error)
- func (c *Client) NodeRating(ctx context.Context, nodeKeys ...*btcec.PublicKey) (*poolrpc.NodeRatingResponse, error)
- func (c *Client) OrderState(ctx context.Context, nonce order.Nonce) (*auctioneerrpc.ServerOrderStateResponse, error)
- func (c *Client) RecoverAccounts(ctx context.Context, accountKeys []*keychain.KeyDescriptor) ([]*account.Account, error)
- func (c *Client) RecvCipherBoxMsg(ctx context.Context, sid [64]byte) ([]byte, error)
- func (c *Client) ReserveAccount(ctx context.Context, value btcutil.Amount, expiry uint32, ...) (*account.Reservation, error)
- func (c *Client) SendAuctionMessage(msg *auctioneerrpc.ClientAuctionMessage) error
- func (c *Client) SendCipherBoxMsg(ctx context.Context, sid [64]byte, msg []byte) error
- func (c *Client) Start() error
- func (c *Client) StartAccountSubscription(ctx context.Context, acctKey *keychain.KeyDescriptor) error
- func (c *Client) Stop() error
- func (c *Client) SubmitOrder(ctx context.Context, o order.Order, serverParams *order.ServerOrderParams) error
- func (c *Client) Terms(ctx context.Context) (*terms.AuctioneerTerms, error)
- type Config
- type ErrChanSwitch
Constants ¶
const Subsystem = "AUCT"
Variables ¶
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") )
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") )
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 MarshallNodeTier ¶
func MarshallNodeTier(nodeTier order.NodeTier) (auctioneerrpc.NodeTier, error)
MarshallNodeTier maps the node tier integer into the enum used on the RPC interface.
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 }
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 (*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 ¶
func (c *Client) BatchSnapshots(ctx context.Context, req *auctioneerrpc.BatchSnapshotsRequest) ( *auctioneerrpc.BatchSnapshotsResponse, error)
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 ¶
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 ¶
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 ¶
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 ¶
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) ([]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. 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.
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 ¶
func (c *Client) OrderState(ctx context.Context, nonce order.Nonce) ( *auctioneerrpc.ServerOrderStateResponse, error)
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 ¶
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) (*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 ¶
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) 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) 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.
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 // 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 ¶
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.