migration25

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoChanInfoFound is returned when a particular channel does not
	// have any channels state.
	ErrNoChanInfoFound = fmt.Errorf("no chan info found")

	// ErrNoPastDeltas is returned when the channel delta bucket hasn't been
	// created.
	ErrNoPastDeltas = fmt.Errorf("channel has no recorded deltas")

	// ErrLogEntryNotFound is returned when we cannot find a log entry at
	// the height requested in the revocation log.
	ErrLogEntryNotFound = fmt.Errorf("log entry not found")

	// ErrNoCommitmentsFound is returned when a channel has not set
	// commitment states.
	ErrNoCommitmentsFound = fmt.Errorf("no commitments found")
)
View Source
var (

	// ErrNoChanDBExists is returned when a channel bucket hasn't been
	// created.
	ErrNoChanDBExists = fmt.Errorf("channel db has not yet been created")

	// ErrNoActiveChannels  is returned when there is no active (open)
	// channels within the database.
	ErrNoActiveChannels = fmt.Errorf("no active channels exist")

	// ErrChannelNotFound is returned when we attempt to locate a channel
	// for a specific chain, but it is not found.
	ErrChannelNotFound = fmt.Errorf("channel not found")
)

Functions

func CreateChanBucket

func CreateChanBucket(tx kvdb.RwTx, c *OpenChannel) (kvdb.RwBucket, error)

func DKeyLocator

func DKeyLocator(r io.Reader, val interface{}, buf *[8]byte, l uint64) error

DKeyLocator is a decoder for keychain.KeyLocator.

func EKeyLocator

func EKeyLocator(w io.Writer, val interface{}, buf *[8]byte) error

EKeyLocator is an encoder for keychain.KeyLocator.

func FetchChanBucket

func FetchChanBucket(tx kvdb.RwTx, c *OpenChannel) (kvdb.RwBucket, error)

FetchChanBucket is a helper function that returns the bucket where a channel's data resides in given: the public key for the node, the outpoint, and the chainhash that the channel resides on.

func FetchChanCommitment

func FetchChanCommitment(chanBucket kvdb.RBucket,
	local bool) (mig.ChannelCommitment, error)

FetchChanCommitment fetches a channel commitment. This function is exported so it can be used by later migrations.

func FetchChanCommitments

func FetchChanCommitments(chanBucket kvdb.RBucket, channel *OpenChannel) error

FetchChanCommitments fetches both the local and remote commitments. This function is exported so it can be used by later migrations.

func GetOptionalUpfrontShutdownScript

func GetOptionalUpfrontShutdownScript(chanBucket kvdb.RBucket, key []byte,
	script *lnwire.DeliveryAddress) error

GetOptionalUpfrontShutdownScript reads the shutdown script stored under the key provided if it is present. Upfront shutdown scripts are optional, so the function returns with no error if the key is not present.

func MakeKeyLocRecord

func MakeKeyLocRecord(typ tlv.Type, keyLoc *keychain.KeyLocator) tlv.Record

MakeKeyLocRecord creates a Record out of a KeyLocator using the passed Type and the EKeyLocator and DKeyLocator functions. The size will always be 8 as KeyFamily is uint32 and the Index is uint32.

func MigrateInitialBalances

func MigrateInitialBalances(tx kvdb.RwTx) error

MigrateInitialBalances patches the two new fields, InitialLocalBalance and InitialRemoteBalance, for all the open channels. It does so by reading the revocation log at height 0 to learn the initial balances and then updates the channel's info. The channel info is saved in the nested bucket which is accessible via nodePub:chainHash:chanPoint. If any of the sub-buckets turns out to be nil, we will log the error and continue to process the rest.

func PutChanCommitment

func PutChanCommitment(chanBucket kvdb.RwBucket, c *mig.ChannelCommitment,
	local bool) error

func PutChanCommitments

func PutChanCommitments(chanBucket kvdb.RwBucket, channel *OpenChannel) error

func PutOptionalUpfrontShutdownScript

func PutOptionalUpfrontShutdownScript(chanBucket kvdb.RwBucket, key []byte,
	script []byte) error

PutOptionalUpfrontShutdownScript adds a shutdown script under the key provided if it has a non-zero length.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type ChannelStatus

type ChannelStatus uint8

ChannelStatus is a bit vector used to indicate whether an OpenChannel is in the default usable state, or a state where it shouldn't be used.

var (
	// ChanStatusDefault is the normal state of an open channel.
	ChanStatusDefault ChannelStatus

	// ChanStatusBorked indicates that the channel has entered an
	// irreconcilable state, triggered by a state desynchronization or
	// channel breach.  Channels in this state should never be added to the
	// htlc switch.
	ChanStatusBorked ChannelStatus = 1

	// ChanStatusCommitBroadcasted indicates that a commitment for this
	// channel has been broadcasted.
	ChanStatusCommitBroadcasted ChannelStatus = 1 << 1

	// ChanStatusLocalDataLoss indicates that we have lost channel state
	// for this channel, and broadcasting our latest commitment might be
	// considered a breach.
	//
	// TODO(halseh): actually enforce that we are not force closing such a
	// channel.
	ChanStatusLocalDataLoss ChannelStatus = 1 << 2

	// ChanStatusRestored is a status flag that signals that the channel
	// has been restored, and doesn't have all the fields a typical channel
	// will have.
	ChanStatusRestored ChannelStatus = 1 << 3

	// ChanStatusCoopBroadcasted indicates that a cooperative close for
	// this channel has been broadcasted. Older cooperatively closed
	// channels will only have this status set. Newer ones will also have
	// close initiator information stored using the local/remote initiator
	// status. This status is set in conjunction with the initiator status
	// so that we do not need to check multiple channel statues for
	// cooperative closes.
	ChanStatusCoopBroadcasted ChannelStatus = 1 << 4

	// ChanStatusLocalCloseInitiator indicates that we initiated closing
	// the channel.
	ChanStatusLocalCloseInitiator ChannelStatus = 1 << 5

	// ChanStatusRemoteCloseInitiator indicates that the remote node
	// initiated closing the channel.
	ChanStatusRemoteCloseInitiator ChannelStatus = 1 << 6
)

func (ChannelStatus) String

func (c ChannelStatus) String() string

String returns a human-readable representation of the ChannelStatus.

type ChannelType

type ChannelType uint8

ChannelType is an enum-like type that describes one of several possible channel types. Each open channel is associated with a particular type as the channel type may determine how higher level operations are conducted such as fee negotiation, channel closing, the format of HTLCs, etc. Structure-wise, a ChannelType is a bit field, with each bit denoting a modification from the base channel type of single funder.

const (

	// SingleFunderBit represents a channel wherein one party solely funds
	// the entire capacity of the channel.
	SingleFunderBit ChannelType = 0

	// DualFunderBit represents a channel wherein both parties contribute
	// funds towards the total capacity of the channel. The channel may be
	// funded symmetrically or asymmetrically.
	DualFunderBit ChannelType = 1 << 0

	// SingleFunderTweaklessBit is similar to the basic SingleFunder channel
	// type, but it omits the tweak for one's key in the commitment
	// transaction of the remote party.
	SingleFunderTweaklessBit ChannelType = 1 << 1

	// NoFundingTxBit denotes if we have the funding transaction locally on
	// disk. This bit may be on if the funding transaction was crafted by a
	// wallet external to the primary daemon.
	NoFundingTxBit ChannelType = 1 << 2

	// AnchorOutputsBit indicates that the channel makes use of anchor
	// outputs to bump the commitment transaction's effective feerate. This
	// channel type also uses a delayed to_remote output script.
	AnchorOutputsBit ChannelType = 1 << 3

	// FrozenBit indicates that the channel is a frozen channel, meaning
	// that only the responder can decide to cooperatively close the
	// channel.
	FrozenBit ChannelType = 1 << 4

	// ZeroHtlcTxFeeBit indicates that the channel should use zero-fee
	// second-level HTLC transactions.
	ZeroHtlcTxFeeBit ChannelType = 1 << 5

	// LeaseExpirationBit indicates that the channel has been leased for a
	// period of time, constraining every output that pays to the channel
	// initiator with an additional CLTV of the lease maturity.
	LeaseExpirationBit ChannelType = 1 << 6
)

func (ChannelType) HasAnchors

func (c ChannelType) HasAnchors() bool

HasAnchors returns true if this channel type has anchor outputs on its commitment.

func (ChannelType) HasFundingTx

func (c ChannelType) HasFundingTx() bool

HasFundingTx returns true if this channel type is one that has a funding transaction stored locally.

func (ChannelType) HasLeaseExpiration

func (c ChannelType) HasLeaseExpiration() bool

HasLeaseExpiration returns true if the channel originated from a lease.

func (ChannelType) IsDualFunder

func (c ChannelType) IsDualFunder() bool

IsDualFunder returns true if the ChannelType has the DualFunderBit set.

func (ChannelType) IsFrozen

func (c ChannelType) IsFrozen() bool

IsFrozen returns true if the channel is considered to be "frozen". A frozen channel means that only the responder can initiate a cooperative channel closure.

func (ChannelType) IsSingleFunder

func (c ChannelType) IsSingleFunder() bool

IsSingleFunder returns true if the channel type if one of the known single funder variants.

func (ChannelType) IsTweakless

func (c ChannelType) IsTweakless() bool

IsTweakless returns true if the target channel uses a commitment that doesn't tweak the key for the remote party.

func (ChannelType) ZeroHtlcTxFee

func (c ChannelType) ZeroHtlcTxFee() bool

ZeroHtlcTxFee returns true if this channel type uses second-level HTLC transactions signed with zero-fee.

type OpenChannel

type OpenChannel struct {
	mig.OpenChannel

	// ChanType denotes which type of channel this is.
	ChanType ChannelType

	// ChanStatus is the current status of this channel. If it is not in
	// the state Default, it should not be used for forwarding payments.
	//
	// NOTE: In `channeldb.OpenChannel`, this field is private. We choose
	// to export this private field such that following migrations can
	// access this field directly.
	ChanStatus ChannelStatus

	// InitialLocalBalance is the balance we have during the channel
	// opening. When we are not the initiator, this value represents the
	// push amount.
	InitialLocalBalance lnwire.MilliSatoshi

	// InitialRemoteBalance is the balance they have during the channel
	// opening.
	InitialRemoteBalance lnwire.MilliSatoshi

	// LocalShutdownScript is set to a pre-set script if the channel was
	// opened by the local node with option_upfront_shutdown_script set. If
	// the option was not set, the field is empty.
	LocalShutdownScript lnwire.DeliveryAddress

	// RemoteShutdownScript is set to a pre-set script if the channel was
	// opened by the remote node with option_upfront_shutdown_script set.
	// If the option was not set, the field is empty.
	RemoteShutdownScript lnwire.DeliveryAddress

	// ThawHeight is the height when a frozen channel once again becomes a
	// normal channel. If this is zero, then there're no restrictions on
	// this channel. If the value is lower than 500,000, then it's
	// interpreted as a relative height, or an absolute height otherwise.
	ThawHeight uint32

	// LastWasRevoke is a boolean that determines if the last update we
	// sent was a revocation (true) or a commitment signature (false).
	LastWasRevoke bool

	// RevocationKeyLocator stores the KeyLocator information that we will
	// need to derive the shachain root for this channel. This allows us to
	// have private key isolation from lnd.
	RevocationKeyLocator keychain.KeyLocator
}

OpenChannel embeds a mig.OpenChannel with the extra update-to-date fields.

NOTE: doesn't have the Packager field as it's not used in current migration.

func (*OpenChannel) FindPreviousStateLegacy

func (c *OpenChannel) FindPreviousStateLegacy(chanBucket kvdb.RBucket,
	updateNum uint64) (*mig.ChannelCommitment, error)

FindPreviousStateLegacy scans through the append-only log in an attempt to recover the previous channel state indicated by the update number. This method is intended to be used for obtaining the relevant data needed to claim all funds rightfully spendable in the case of an on-chain broadcast of the commitment transaction.

func (*OpenChannel) FundingTxPresent

func (c *OpenChannel) FundingTxPresent() bool

FundingTxPresent returns true if expect the funding transcation to be found on disk or already populated within the passed open channel struct.

Jump to

Keyboard shortcuts

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