chainreg

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDecredMinHTLCInMAtoms is the default smallest value htlc this
	// node will accept. This value is proposed in the channel open
	// sequence and cannot be changed during the life of the channel.
	//
	// All forwarded payments are subjected to the min htlc constraint of
	// the routing policy of the outgoing channel. This implicitly controls
	// the minimum htlc value on the incoming channel too.
	DefaultDecredMinHTLCInMAtoms = lnwire.MilliAtom(1000)

	// DefaultDecredMinHTLCOutMAtoms is the default minimum htlc value that
	// we require for sending out htlcs. Our channel peer may have a lower
	// min htlc channel parameter, but we - by default - don't forward
	// anything under the value defined here.
	DefaultDecredMinHTLCOutMAtoms = lnwire.MilliAtom(1000)

	// DefaultDecredBaseFeeMAtoms is the default forwarding base fee.
	DefaultDecredBaseFeeMAtoms = lnwire.MilliAtom(1000)

	// DefaultDecredFeeRate is the default forwarding fee rate.
	DefaultDecredFeeRate = lnwire.MilliAtom(1)

	// DefaultDecredTimeLockDelta is the default forwarding time lock
	// delta.
	DefaultDecredTimeLockDelta = 80

	// DefaultDecredStaticFeePerKB is the fee rate of 10000 atom/kB
	DefaultDecredStaticFeePerKB = chainfee.AtomPerKByte(1e4)

	// DefaultDecredStaticMinRelayFeeRate is the min relay fee used for
	// static estimators.
	DefaultDecredStaticMinRelayFeeRate = chainfee.FeePerKBFloor
)
View Source
const Subsystem = "CHRE"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (

	// ChainDNSSeeds is a map of a chain's hash to the set of DNS seeds
	// that will be use to bootstrap peers upon first startup.
	//
	// The first item in the array is the primary host we'll use to attempt
	// the SRV lookup we require. If we're unable to receive a response
	// over UDP, then we'll fall back to manual TCP resolution. The second
	// item in the array is a special A record that we'll query in order to
	// receive the IP address of the current authoritative DNS server for
	// the network seed.
	//
	// TODO(roasbeef): extend and collapse these and chainparams.go into
	// struct like chaincfg.Params
	ChainDNSSeeds = map[chainhash.Hash][][2]string{
		// contains filtered or unexported fields
	}
)
View Source
var DecredMainNetParams = DecredNetParams{
	Params:   chaincfg.MainNetParams(),
	RPCPort:  "9109",
	CoinType: keychain.CoinTypeDecred,
	DcrwPort: "9111",
}

DecredMainNetParams contains parameters specific to the current Decred mainnet.

View Source
var DecredSimNetParams = DecredNetParams{
	Params:   chaincfg.SimNetParams(),
	RPCPort:  "19556",
	CoinType: keychain.CoinTypeTestnet,
	DcrwPort: "19558",
}

decredSimNetParams contains parameters specific to the simulation test network.

View Source
var DecredTestNetParams = DecredNetParams{
	Params:   chaincfg.TestNet3Params(),
	RPCPort:  "19109",
	CoinType: keychain.CoinTypeTestnet,
	DcrwPort: "19111",
}

decredTestNetParams contains parameters specific to the 3rd version of the test network.

View Source
var RegTestNetParams = DecredNetParams{
	Params:   chaincfg.RegNetParams(),
	RPCPort:  "19334",
	CoinType: keychain.CoinTypeTestnet,
}

regTestNetParams contains parameters specific to a local regtest network.

Functions

func DisableLog

func DisableLog()

DisableLog disables all logging output.

func GenDefaultDcrConstraints

func GenDefaultDcrConstraints() channeldb.ChannelConstraints

GenDefaultDcrChannelConstraints generates the default set of channel constraints that are to be used when funding a Decred channel.

func IsTestnet

func IsTestnet(params *DecredNetParams) bool

IsTestnet tests if the given params correspond to a testnet parameter configuration.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type ChainCode

type ChainCode uint32

ChainCode is an enum-like structure for keeping track of the chains currently supported within lnd.

const (
	// DecredChain is Decred's chain.
	DecredChain ChainCode = iota
)

func (ChainCode) String

func (c ChainCode) String() string

String returns a string representation of the target ChainCode.

type ChainControl

type ChainControl struct {
	// PartialChainControl is the part of the chain control that was
	// initialized purely from the configuration and doesn't contain any
	// wallet related elements.
	*PartialChainControl

	// ChainIO represents an abstraction over a source that can query the
	// blockchain.
	ChainIO lnwallet.BlockChainIO

	// Signer is used to provide signatures over things like transactions.
	Signer input.Signer

	// KeyRing represents a set of keys that we have the private keys to.
	KeyRing keychain.SecretKeyRing

	// Wc is an abstraction over some basic wallet commands. This base set
	// of commands will be provided to the Wallet *LightningWallet raw
	// pointer below.
	Wc lnwallet.WalletController

	// MsgSigner is used to sign arbitrary messages.
	MsgSigner lnwallet.MessageSigner

	// Wallet is our LightningWallet that also contains the abstract Wc
	// above. This wallet handles all of the lightning operations.
	Wallet *lnwallet.LightningWallet
}

ChainControl couples the three primary interfaces lnd utilizes for a particular chain together. A single ChainControl instance will exist for all the chains lnd is currently active on.

func NewChainControl

func NewChainControl(walletConfig lnwallet.Config,
	msgSigner lnwallet.MessageSigner,
	pcc *PartialChainControl) (*ChainControl, func(), error)

NewChainControl attempts to create a ChainControl instance according to the parameters in the passed configuration. Currently three branches of ChainControl instances exist: one backed by a running btcd full-node, another backed by a running bitcoind full-node, and the other backed by a running neutrino light client instance. When running with a neutrino light client instance, `neutrinoCS` must be non-nil.

type ChainRegistry

type ChainRegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ChainRegistry keeps track of the current chains

func NewChainRegistry

func NewChainRegistry() *ChainRegistry

NewChainRegistry creates a new ChainRegistry.

func (*ChainRegistry) ActiveChains

func (c *ChainRegistry) ActiveChains() []ChainCode

ActiveChains returns a slice containing the active chains.

func (*ChainRegistry) LookupChain

func (c *ChainRegistry) LookupChain(targetChain ChainCode) (*ChainControl, bool)

LookupChain attempts to lookup an active ChainControl instance for the target chain.

func (*ChainRegistry) LookupChainByHash

func (c *ChainRegistry) LookupChainByHash(
	chainHash chainhash.Hash) (*ChainControl, bool)

LookupChainByHash attempts to look up an active ChainControl which corresponds to the passed genesis hash.

func (*ChainRegistry) NumActiveChains

func (c *ChainRegistry) NumActiveChains() uint32

NumActiveChains returns the total number of active chains.

func (*ChainRegistry) PrimaryChain

func (c *ChainRegistry) PrimaryChain() ChainCode

PrimaryChain returns the primary chain for this running lnd instance. The primary chain is considered the "home base" while the other registered chains are treated as secondary chains.

func (*ChainRegistry) RegisterChain

func (c *ChainRegistry) RegisterChain(newChain ChainCode, cc *ChainControl)

RegisterChain assigns an active ChainControl instance to a target chain identified by its ChainCode.

func (*ChainRegistry) RegisterPrimaryChain

func (c *ChainRegistry) RegisterPrimaryChain(cc ChainCode)

RegisterPrimaryChain sets a target chain as the "home chain" for lnd.

type Config

type Config struct {
	// Decred defines the settings for the Decred chain.
	Decred *lncfg.Chain

	// PrimaryChain is a function that returns our primary chain via its
	// ChainCode.
	PrimaryChain func() ChainCode

	// HeightHintCacheQueryDisable is a boolean that disables height hint
	// queries if true.
	HeightHintCacheQueryDisable bool

	// DcrdMode defines settings for connecting to a dcrd instance.
	DcrdMode *lncfg.DcrdConfig

	// DcrwMode defines settings for connecting to a dcrwallet instance.
	DcrwMode *lncfg.DcrwalletConfig

	// FullDB is the full DB (the parent of ChanStateDB).
	FullDB *channeldb.DB

	// HeightHintDB is a pointer to the database that stores the height
	// hints.
	HeightHintDB kvdb.Backend

	// ChanStateDB is a pointer to the database that stores the channel
	// state.
	ChanStateDB *channeldb.ChannelStateDB

	// BlockCache is the main cache for storing block information.
	BlockCache *blockcache.BlockCache

	// WalletUnlockParams are the parameters that were used for unlocking
	// the main wallet.
	WalletUnlockParams *walletunlocker.WalletUnlockParams

	// ActiveNetParams details the current chain we are on.
	ActiveNetParams DecredNetParams

	// FeeURL defines the URL for fee estimation we will use. This field is
	// optional.
	FeeURL string

	// Dialer is a function closure that will be used to establish outbound
	// TCP connections to chain network peers in the event of a pruned block being
	// requested.
	Dialer func(string) (net.Conn, error)
}

Config houses necessary fields that a chainControl instance needs to function.

type DecredNetParams

type DecredNetParams struct {
	*chaincfg.Params
	RPCPort  string
	CoinType uint32
	DcrwPort string
}

DecredNetParams couples the p2p parameters of a network with the corresponding RPC port of a daemon running on the particular network.

type NoChainBackend added in v0.6.0

type NoChainBackend struct {
}

NoChainBackend is a mock implementation of the following interfaces:

  • chainview.FilteredChainView
  • chainntnfs.ChainNotifier
  • chainfee.Estimator

func (*NoChainBackend) DisconnectedBlocks added in v0.6.0

func (n *NoChainBackend) DisconnectedBlocks() <-chan *chainview.FilteredBlock

func (*NoChainBackend) EstimateFeePerKB added in v0.6.0

func (n *NoChainBackend) EstimateFeePerKB(uint32) (chainfee.AtomPerKByte,
	error)

func (*NoChainBackend) FilterBlock added in v0.6.0

func (*NoChainBackend) FilteredBlocks added in v0.6.0

func (n *NoChainBackend) FilteredBlocks() <-chan *chainview.FilteredBlock

func (*NoChainBackend) RegisterBlockEpochNtfn added in v0.6.0

func (n *NoChainBackend) RegisterBlockEpochNtfn(
	*chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error)

func (*NoChainBackend) RegisterConfirmationsNtfn added in v0.6.0

func (n *NoChainBackend) RegisterConfirmationsNtfn(*chainhash.Hash, []byte,
	uint32, uint32) (*chainntnfs.ConfirmationEvent, error)

func (*NoChainBackend) RegisterSpendNtfn added in v0.6.0

func (n *NoChainBackend) RegisterSpendNtfn(*wire.OutPoint, []byte,
	uint32) (*chainntnfs.SpendEvent, error)

func (*NoChainBackend) RelayFeePerKB added in v0.6.0

func (n *NoChainBackend) RelayFeePerKB() chainfee.AtomPerKByte

func (*NoChainBackend) Start added in v0.6.0

func (n *NoChainBackend) Start() error

func (*NoChainBackend) Started added in v0.6.0

func (n *NoChainBackend) Started() bool

func (*NoChainBackend) Stop added in v0.6.0

func (n *NoChainBackend) Stop() error

func (*NoChainBackend) UpdateFilter added in v0.6.0

func (n *NoChainBackend) UpdateFilter([]channeldb.EdgePoint, int64) error

type NoChainSource added in v0.6.0

type NoChainSource struct {
	BestBlockTime time.Time
	// contains filtered or unexported fields
}

NoChainSource is a mock implementation of chain.Interface. The mock is designed to return static values where necessary to make any caller believe the chain is fully synced to virtual block height 1 (hash 0x0000..0001). That should avoid calls to other methods completely since they are only used for advancing the chain forward.

func (*NoChainSource) BackEnd added in v0.6.0

func (n *NoChainSource) BackEnd() string

func (*NoChainSource) GetBestBlock added in v0.6.0

func (n *NoChainSource) GetBestBlock() (*chainhash.Hash, int32, error)

func (*NoChainSource) GetBlock added in v0.6.0

func (n *NoChainSource) GetBlock(*chainhash.Hash) (*wire.MsgBlock, error)

func (*NoChainSource) GetBlockHash added in v0.6.0

func (n *NoChainSource) GetBlockHash(int64) (*chainhash.Hash, error)

func (*NoChainSource) GetBlockHeader added in v0.6.0

func (n *NoChainSource) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader,
	error)

func (*NoChainSource) IsCurrent added in v0.6.0

func (n *NoChainSource) IsCurrent() bool

func (*NoChainSource) Notifications added in v0.6.0

func (n *NoChainSource) Notifications() <-chan interface{}

func (*NoChainSource) NotifyBlocks added in v0.6.0

func (n *NoChainSource) NotifyBlocks() error

func (*NoChainSource) NotifyReceived added in v0.6.0

func (n *NoChainSource) NotifyReceived([]stdaddr.Address) error

func (*NoChainSource) Rescan added in v0.6.0

func (*NoChainSource) SendRawTransaction added in v0.6.0

func (n *NoChainSource) SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash,
	error)

func (*NoChainSource) Start added in v0.6.0

func (n *NoChainSource) Start() error

func (*NoChainSource) Stop added in v0.6.0

func (n *NoChainSource) Stop()

func (*NoChainSource) WaitForShutdown added in v0.6.0

func (n *NoChainSource) WaitForShutdown()

type PartialChainControl added in v0.6.0

type PartialChainControl struct {
	// Cfg is the configuration that was used to create the partial chain
	// control.
	Cfg *Config

	// HealthCheck is a function which can be used to send a low-cost, fast
	// query to the chain backend to ensure we still have access to our
	// node.
	HealthCheck func() error

	// FeeEstimator is used to estimate an optimal fee for transactions
	// important to us.
	FeeEstimator chainfee.Estimator

	// ChainNotifier is used to receive blockchain events that we are
	// interested in.
	ChainNotifier chainntnfs.ChainNotifier

	// ChainView is used in the router for maintaining an up-to-date graph.
	ChainView chainview.FilteredChainView

	// RoutingPolicy is the routing policy we have decided to use.
	RoutingPolicy htlcswitch.ForwardingPolicy

	// MinHtlcIn is the minimum HTLC we will accept.
	MinHtlcIn lnwire.MilliAtom

	// ChannelConstraints is the set of default constraints that will be
	// used for any incoming or outgoing channel reservation requests.
	ChannelConstraints channeldb.ChannelConstraints

	// RPCConfig is the config to the remote dcrd instance when using a
	// sync mode that requires it.
	RPCConfig *rpcclient.ConnConfig
}

PartialChainControl contains all the primary interfaces of the chain control that can be purely constructed from the global configuration. No wallet instance is required for constructing this partial state.

func NewPartialChainControl added in v0.6.0

func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error)

NewPartialChainControl creates a new partial chain control that contains all the parts that can be purely constructed from the passed in global configuration and doesn't need any wallet instance yet.

type WalletConfig added in v0.6.0

type WalletConfig struct {
	// PrivatePass is the private wallet password to the underlying
	// btcwallet instance.
	PrivatePass []byte

	// PublicPass is the public wallet password to the underlying btcwallet
	// instance.
	PublicPass []byte

	// Birthday specifies the time the wallet was initially created.
	Birthday time.Time

	// RecoveryWindow specifies the address look-ahead for which to scan when
	// restoring a wallet.
	RecoveryWindow uint32

	// AccountNb is the root account from which the dcrlnd keys are
	// derived when running based on a remote wallet.
	AccountNb int32

	Syncer dcrwallet.WalletSyncer

	// CoinSelectionStrategy is the coin selection strategy to use when
	// sending coins on-chain.
	//
	// Note: not currently supported in dcrwallet.
	CoinSelectionStrategy btcwalletcompat.CoinSelectionStrategy
}

WalletConfig encapsulates the config parameters needed to init a wallet backend.

Jump to

Keyboard shortcuts

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