migration30

package
v0.16.0-beta.rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OutputIndexEmpty is used when the output index doesn't exist.
	OutputIndexEmpty = math.MaxUint16
)

Variables

View Source
var (

	// ErrNoRevocationsFound is returned when revocation state for a
	// particular channel cannot be found.
	ErrNoRevocationsFound = errors.New("no revocations found")

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

	// ErrOutputIndexTooBig is returned when the output index is greater
	// than uint16.
	ErrOutputIndexTooBig = errors.New("output index is over uint16")
)

Functions

func MigrateRevocationLog

func MigrateRevocationLog(db kvdb.Backend, cfg MigrateRevLogConfig) error

MigrateRevocationLog migrates the old revocation logs into the newer format and deletes them once finished, with the deletion only happens once ALL the old logs have been migrates.

func RHashDecoder

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

RHashDecoder is the customized decoder which skips decoding the empty hash.

func RHashEncoder

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

RHashEncoder is the customized encoder which skips encoding the empty hash.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type CommitmentKeyRing

type CommitmentKeyRing struct {
	// CommitPoint is the "per commitment point" used to derive the tweak
	// for each base point.
	CommitPoint *btcec.PublicKey

	// LocalCommitKeyTweak is the tweak used to derive the local public key
	// from the local payment base point or the local private key from the
	// base point secret. This may be included in a SignDescriptor to
	// generate signatures for the local payment key.
	//
	// NOTE: This will always refer to "our" local key, regardless of
	// whether this is our commit or not.
	LocalCommitKeyTweak []byte

	// LocalHtlcKeyTweak is the tweak used to derive the local HTLC key
	// from the local HTLC base point. This value is needed in order to
	// derive the final key used within the HTLC scripts in the commitment
	// transaction.
	//
	// NOTE: This will always refer to "our" local HTLC key, regardless of
	// whether this is our commit or not.
	LocalHtlcKeyTweak []byte

	// LocalHtlcKey is the key that will be used in any clause paying to
	// our node of any HTLC scripts within the commitment transaction for
	// this key ring set.
	//
	// NOTE: This will always refer to "our" local HTLC key, regardless of
	// whether this is our commit or not.
	LocalHtlcKey *btcec.PublicKey

	// RemoteHtlcKey is the key that will be used in clauses within the
	// HTLC script that send money to the remote party.
	//
	// NOTE: This will always refer to "their" remote HTLC key, regardless
	// of whether this is our commit or not.
	RemoteHtlcKey *btcec.PublicKey

	// ToLocalKey is the commitment transaction owner's key which is
	// included in HTLC success and timeout transaction scripts. This is
	// the public key used for the to_local output of the commitment
	// transaction.
	//
	// NOTE: Who's key this is depends on the current perspective. If this
	// is our commitment this will be our key.
	ToLocalKey *btcec.PublicKey

	// ToRemoteKey is the non-owner's payment key in the commitment tx.
	// This is the key used to generate the to_remote output within the
	// commitment transaction.
	//
	// NOTE: Who's key this is depends on the current perspective. If this
	// is our commitment this will be their key.
	ToRemoteKey *btcec.PublicKey

	// RevocationKey is the key that can be used by the other party to
	// redeem outputs from a revoked commitment transaction if it were to
	// be published.
	//
	// NOTE: Who can sign for this key depends on the current perspective.
	// If this is our commitment, it means the remote node can sign for
	// this key in case of a breach.
	RevocationKey *btcec.PublicKey
}

CommitmentKeyRing holds all derived keys needed to construct commitment and HTLC transactions. The keys are derived differently depending whether the commitment transaction is ours or the remote peer's. Private keys associated with each key may belong to the commitment owner or the "other party" which is referred to in the field comments, regardless of which is local and which is remote.

func DeriveCommitmentKeys

func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
	isOurCommit bool, chanType mig25.ChannelType,
	localChanCfg, remoteChanCfg *mig.ChannelConfig) *CommitmentKeyRing

DeriveCommitmentKeys generates a new commitment key set using the base points and commitment point. The keys are derived differently depending on the type of channel, and whether the commitment transaction is ours or the remote peer's.

type HTLCEntry

type HTLCEntry struct {
	// RHash is the payment hash of the HTLC.
	RHash [32]byte

	// RefundTimeout is the absolute timeout on the HTLC that the sender
	// must wait before reclaiming the funds in limbo.
	RefundTimeout uint32

	// OutputIndex is the output index for this particular HTLC output
	// within the commitment transaction.
	//
	// NOTE: we use uint16 instead of int32 here to save us 2 bytes, which
	// gives us a max number of HTLCs of 65K.
	OutputIndex uint16

	// Incoming denotes whether we're the receiver or the sender of this
	// HTLC.
	//
	// NOTE: this field is the memory representation of the field
	// incomingUint.
	Incoming bool

	// Amt is the amount of satoshis this HTLC escrows.
	//
	// NOTE: this field is the memory representation of the field amtUint.
	Amt btcutil.Amount
	// contains filtered or unexported fields
}

HTLCEntry specifies the minimal info needed to be stored on disk for ALL the historical HTLCs, which is useful for constructing RevocationLog when a breach is detected. The actual size of each HTLCEntry varies based on its RHash and Amt(sat), summarized as follows,

| RHash empty | Amt<=252 | Amt<=65,535 | Amt<=4,294,967,295 | otherwise |
|:-----------:|:--------:|:-----------:|:------------------:|:---------:|
|     true    |    19    |      21     |         23         |     26    |
|     false   |    51    |      53     |         55         |     58    |

So the size varies from 19 bytes to 58 bytes, where most likely to be 23 or 55 bytes.

NOTE: all the fields saved to disk use the primitive go types so they can be made into tlv records without further conversion.

func (*HTLCEntry) RHashLen

func (h *HTLCEntry) RHashLen() uint64

RHashLen is used by MakeDynamicRecord to return the size of the RHash.

NOTE: for zero hash, we return a length 0.

type MigrateRevLogConfig

type MigrateRevLogConfig interface {
	// GetNoAmountData returns true if the amount data of revoked commitment
	// transactions should not be stored in the revocation log.
	GetNoAmountData() bool
}

MigrateRevLogConfig is an interface that defines the config that should be passed to the MigrateRevocationLog function.

type MigrateRevLogConfigImpl

type MigrateRevLogConfigImpl struct {
	// NoAmountData if set to true will result in the amount data of revoked
	// commitment transactions not being stored in the revocation log.
	NoAmountData bool
}

MigrateRevLogConfigImpl implements the MigrationRevLogConfig interface.

func (*MigrateRevLogConfigImpl) GetNoAmountData

func (c *MigrateRevLogConfigImpl) GetNoAmountData() bool

GetNoAmountData returns true if the amount data of revoked commitment transactions should not be stored in the revocation log.

type RevocationLog

type RevocationLog struct {
	// OurOutputIndex specifies our output index in this commitment. In a
	// remote commitment transaction, this is the to remote output index.
	OurOutputIndex uint16

	// TheirOutputIndex specifies their output index in this commitment. In
	// a remote commitment transaction, this is the to local output index.
	TheirOutputIndex uint16

	// CommitTxHash is the hash of the latest version of the commitment
	// state, broadcast able by us.
	CommitTxHash [32]byte

	// HTLCEntries is the set of HTLCEntry's that are pending at this
	// particular commitment height.
	HTLCEntries []*HTLCEntry

	// OurBalance is the current available balance within the channel
	// directly spendable by us. In other words, it is the value of the
	// to_remote output on the remote parties' commitment transaction.
	//
	// NOTE: this is a pointer so that it is clear if the value is zero or
	// nil. Since migration 30 of the channeldb initially did not include
	// this field, it could be the case that the field is not present for
	// all revocation logs.
	OurBalance *lnwire.MilliSatoshi

	// TheirBalance is the current available balance within the channel
	// directly spendable by the remote node. In other words, it is the
	// value of the to_local output on the remote parties' commitment.
	//
	// NOTE: this is a pointer so that it is clear if the value is zero or
	// nil. Since migration 30 of the channeldb initially did not include
	// this field, it could be the case that the field is not present for
	// all revocation logs.
	TheirBalance *lnwire.MilliSatoshi
}

RevocationLog stores the info needed to construct a breach retribution. Its fields can be viewed as a subset of a ChannelCommitment's. In the database, all historical versions of the RevocationLog are saved using the CommitHeight as the key.

type ScriptInfo

type ScriptInfo struct {
	// PkScript is the output's PkScript.
	PkScript []byte

	// WitnessScript is the full script required to properly redeem the
	// output. This field should be set to the full script if a p2wsh
	// output is being signed. For p2wkh it should be set equal to the
	// PkScript.
	WitnessScript []byte
}

ScriptInfo holds a redeem script and hash.

func CommitScriptToRemote

func CommitScriptToRemote(chanType mig25.ChannelType, initiator bool,
	key *btcec.PublicKey, leaseExpiry uint32) (*ScriptInfo, uint32, error)

CommitScriptToRemote derives the appropriate to_remote script based on the channel's commitment type. The `initiator` argument should correspond to the owner of the commitment transaction which we are generating the to_remote script for. The second return value is the CSV delay of the output script, what must be satisfied in order to spend the output.

func CommitScriptToSelf

func CommitScriptToSelf(chanType mig25.ChannelType, initiator bool,
	selfKey, revokeKey *btcec.PublicKey, csvDelay, leaseExpiry uint32) (
	*ScriptInfo, error)

CommitScriptToSelf constructs the public key script for the output on the commitment transaction paying to the "owner" of said commitment transaction. The `initiator` argument should correspond to the owner of the commitment transaction which we are generating the to_local script for. If the other party learns of the preimage to the revocation hash, then they can claim all the settled funds in the channel, plus the unsettled funds.

Jump to

Keyboard shortcuts

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