lookout

package
v0.5.1-beta-rc4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOutputNotFound signals that the breached output could not be found
	// on the commitment transaction.
	ErrOutputNotFound = errors.New("unable to find output on commit tx")

	// ErrUnknownSweepAddrType signals that client provided an output that
	// was not p2wkh or p2wsh.
	ErrUnknownSweepAddrType = errors.New("sweep addr is not p2wkh or p2wsh")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

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 BlockFetcher

type BlockFetcher interface {
	// GetBlock fetches the block given the target block hash.
	GetBlock(*chainhash.Hash) (*wire.MsgBlock, error)
}

BlockFetcher supports the ability to fetch blocks from the backend or network.

type BreachPunisher

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

BreachPunisher handles the responsibility of constructing and broadcasting justice transactions. Justice transactions are constructed from previously accepted state updates uploaded by the watchtower's clients.

func NewBreachPunisher

func NewBreachPunisher(cfg *PunisherConfig) *BreachPunisher

NewBreachPunisher constructs a new BreachPunisher given a PunisherConfig.

func (*BreachPunisher) Punish

func (p *BreachPunisher) Punish(desc *JusticeDescriptor, quit <-chan struct{}) error

Punish constructs a justice transaction given a JusticeDescriptor and publishes is it to the network.

type Config

type Config struct {
	// DB provides persistent access to the watchtower's accepted state
	// updates such that they can be queried as new blocks arrive from the
	// network.
	DB DB

	// EpochRegistrar supports the ability to register for events corresponding to
	// newly created blocks.
	EpochRegistrar EpochRegistrar

	// BlockFetcher supports the ability to fetch blocks from the backend or
	// network.
	BlockFetcher BlockFetcher

	// Punisher handles the responsibility of crafting and broadcasting
	// justice transaction for any breached transactions.
	Punisher Punisher
}

Config houses the Lookout's required resources to properly fulfill it's duty, including block fetching, querying accepted state updates, and construction and publication of justice transactions.

type DB

type DB interface {
	// GetLookoutTip returns the last block epoch at which the tower
	// performed a match. If no match has been done, a nil epoch will be
	// returned.
	GetLookoutTip() (*chainntnfs.BlockEpoch, error)

	// QueryMatches searches its database for any state updates matching the
	// provided breach hints. If any matches are found, they will be
	// returned along with encrypted blobs so that justice can be exacted.
	QueryMatches([]wtdb.BreachHint) ([]wtdb.Match, error)

	// SetLookoutTip writes the best epoch for which the watchtower has
	// queried for breach hints.
	SetLookoutTip(*chainntnfs.BlockEpoch) error
}

DB abstracts the required persistent calls expected by the lookout. DB provides the ability to search for state updates that correspond to breach transactions confirmed in a particular block.

type EpochRegistrar

type EpochRegistrar interface {
	// RegisterBlockEpochNtfn registers for a new block epoch subscription.
	// The implementation must support historical dispatch, starting from
	// the provided chainntnfs.BlockEpoch when it is non-nil. The
	// notifications should be delivered in-order, and deliver reorged
	// blocks.
	RegisterBlockEpochNtfn(
		*chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error)
}

EpochRegistrar supports the ability to register for events corresponding to newly created blocks.

type JusticeDescriptor

type JusticeDescriptor struct {
	// BreachedCommitTx is the commitment transaction that caused the breach
	// to be detected.
	BreachedCommitTx *wire.MsgTx

	// SessionInfo contains the contract with the watchtower client and
	// the prenegotiated terms they agreed to.
	SessionInfo *wtdb.SessionInfo

	// JusticeKit contains the decrypted blob and information required to
	// construct the transaction scripts and witnesses.
	JusticeKit *blob.JusticeKit
}

JusticeDescriptor contains the information required to sweep a breached channel on behalf of a victim. It supports the ability to create the justice transaction that sweeps the commitments and recover a cut of the channel for the watcher's eternal vigilance.

func (*JusticeDescriptor) CreateJusticeTxn

func (p *JusticeDescriptor) CreateJusticeTxn() (*wire.MsgTx, error)

CreateJusticeTxn computes the justice transaction that sweeps a breaching commitment transaction. The justice transaction is constructed by assembling the witnesses using data provided by the client in a prior state update.

type Lookout

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

Lookout will check any incoming blocks against the transactions found in the database, and in case of matches send the information needed to create a penalty transaction to the punisher.

func New

func New(cfg *Config) *Lookout

New constructs a new Lookout from the given LookoutConfig.

func (*Lookout) Start

func (l *Lookout) Start() error

Start safely spins up the Lookout and begins monitoring for breaches.

func (*Lookout) Stop

func (l *Lookout) Stop() error

Stop safely shuts down the Lookout.

type Punisher

type Punisher interface {
	// Punish accepts a JusticeDescriptor, constructs the justice
	// transaction, and publishes the transaction to the network so it can
	// be mined. The second parameter is a quit channel so that long-running
	// operations required to track the confirmation of the transaction can
	// be canceled on shutdown.
	Punish(*JusticeDescriptor, <-chan struct{}) error
}

Punisher handles the construction and publication of justice transactions once they have been detected by the Service.

type PunisherConfig

type PunisherConfig struct {
	// PublishTx provides the ability to send a signed transaction to the
	// network.
	PublishTx func(*wire.MsgTx) error
}

PunisherConfig houses the resources required by the Punisher.

type Service

type Service interface {
	// Start safely starts up the Interface.
	Start() error

	// Stop safely stops the Interface.
	Stop() error
}

Service abstracts the lookout functionality, supporting the ability to start and stop. All communication and actions are driven via the database or chain events.

Jump to

Keyboard shortcuts

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