migration8

package
v0.18.3-beta.rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const BreachHintSize = 16

BreachHintSize is the length of the identifier used to detect remote commitment broadcasts.

View Source
const SessionIDSize = 33

SessionIDSize is 33-bytes; it is a serialized, compressed public key.

Variables

View Source
var (

	// ErrUninitializedDB signals that top-level buckets for the database
	// have not been initialized.
	ErrUninitializedDB = errors.New("db not initialized")
)

Functions

func MigrateChannelMaxHeights

func MigrateChannelMaxHeights(tx kvdb.RwTx) error

MigrateChannelMaxHeights migrates the tower client db by collecting all the max commitment heights that have been backed up for each channel and then storing those heights alongside the channel info.

func ReadElement

func ReadElement(r io.Reader, element interface{}) error

ReadElement deserializes a single element from the provided io.Reader.

func ReadElements

func ReadElements(r io.Reader, elements ...interface{}) error

ReadElements deserializes the provided io.Reader into a variadic list of target elements.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

func WriteElement

func WriteElement(w io.Writer, element interface{}) error

WriteElement serializes a single element into the provided io.Writer.

func WriteElements

func WriteElements(w io.Writer, elements ...interface{}) error

WriteElements serializes a variadic list of elements into the given io.Writer.

Types

type BackupID

type BackupID struct {
	// ChanID is the channel id of the revoked commitment.
	ChanID ChannelID

	// CommitHeight is the commitment height of the revoked commitment.
	CommitHeight uint64
}

BackupID identifies a particular revoked, remote commitment by channel id and commitment height.

func (*BackupID) Decode

func (b *BackupID) Decode(r io.Reader) error

Decode reads a BackupID from the passed io.Reader.

func (*BackupID) Encode

func (b *BackupID) Encode(w io.Writer) error

Encode writes the BackupID from the passed io.Writer.

func (BackupID) String

func (b BackupID) String() string

String returns a human-readable encoding of a BackupID.

type BreachHint

type BreachHint [BreachHintSize]byte

BreachHint is the first 16-bytes of SHA256(txid), which is used to identify the breach transaction.

type ChannelID

type ChannelID [32]byte

ChannelID is a series of 32-bytes that uniquely identifies all channels within the network. The ChannelID is computed using the outpoint of the funding transaction (the txid, and output index). Given a funding output the ChannelID can be calculated by XOR'ing the big-endian serialization of the txid and the big-endian serialization of the output index, truncated to 2 bytes.

type CommittedUpdate

type CommittedUpdate struct {
	// SeqNum is the unique sequence number allocated by the session to this
	// update.
	SeqNum uint16

	CommittedUpdateBody
}

CommittedUpdate holds a state update sent by a client along with its allocated sequence number and the exact remote commitment the encrypted justice transaction can rectify.

type CommittedUpdateBody

type CommittedUpdateBody struct {
	// BackupID identifies the breached commitment that the encrypted blob
	// can spend from.
	BackupID BackupID

	// Hint is the 16-byte prefix of the revoked commitment transaction ID.
	Hint BreachHint

	// EncryptedBlob is a ciphertext containing the sweep information for
	// exacting justice if the commitment transaction matching the breach
	// hint is broadcast.
	EncryptedBlob []byte
}

CommittedUpdateBody represents the primary components of a CommittedUpdate. On disk, this is stored under the sequence number, which acts as its key.

func (*CommittedUpdateBody) Decode

func (u *CommittedUpdateBody) Decode(r io.Reader) error

Decode reads a CommittedUpdateBody from the passed io.Reader.

func (*CommittedUpdateBody) Encode

func (u *CommittedUpdateBody) Encode(w io.Writer) error

Encode writes the CommittedUpdateBody to the passed io.Writer.

type KVStore

type KVStore interface {
	// Put saves the specified key/value pair to the store. Keys that do not
	// already exist are added and keys that already exist are overwritten.
	Put(key, value []byte) error

	// Delete removes the specified key from the bucket. Deleting a key that
	// does not exist does not return an error.
	Delete(key []byte) error
}

KVStore is an interface representing a key-value store.

type RangeIndex

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

RangeIndex can be used to keep track of which numbers have been added to a set. It does so by keeping track of a sorted list of rangeItems. Each rangeItem has a start and end value of a range where all values in-between have been added to the set. It works well in situations where it is expected numbers in the set are not sparse.

func NewRangeIndex

func NewRangeIndex(ranges map[uint64]uint64,
	opts ...RangeIndexOption) (*RangeIndex, error)

NewRangeIndex constructs a new RangeIndex. An initial set of ranges may be passed to the function in the form of a map.

func (*RangeIndex) Add

func (a *RangeIndex) Add(newHeight uint64, kv KVStore) error

Add adds a single number to the range set. It first attempts to apply the necessary changes to the passed KV store and then only if this succeeds, will the changes be applied to the in-memory structure.

func (*RangeIndex) GetAllRanges

func (a *RangeIndex) GetAllRanges() map[uint64]uint64

GetAllRanges returns a copy of the range set in the form of a map.

func (*RangeIndex) IsInIndex

func (a *RangeIndex) IsInIndex(n uint64) bool

IsInIndex returns true if the given number is in the range set.

func (*RangeIndex) MaxHeight

func (a *RangeIndex) MaxHeight() uint64

MaxHeight returns the highest number covered in the range.

func (*RangeIndex) NumInSet

func (a *RangeIndex) NumInSet() uint64

NumInSet returns the number of items covered by the range set.

type RangeIndexOption

type RangeIndexOption func(*RangeIndex)

RangeIndexOption describes the signature of a functional option that can be used to modify the behaviour of a RangeIndex.

func WithSerializeUint64Fn

func WithSerializeUint64Fn(fn func(uint64) ([]byte, error)) RangeIndexOption

WithSerializeUint64Fn is a functional option that can be used to set the function to be used to do the serialization of a uint64 into a byte slice.

type SessionID

type SessionID [SessionIDSize]byte

SessionID is created from the remote public key of a client, and serves as a unique identifier and authentication for sending state updates.

func (SessionID) String

func (s SessionID) String() string

String returns a hex encoding of the session id.

Jump to

Keyboard shortcuts

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