mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-18 06:34:27 +01:00
nursery_store: update IncubateOutputs to take a slice of kid outputs
This commit is contained in:
@@ -95,22 +95,25 @@ import (
|
|||||||
// constraints have fully matured. The store exposes methods for enumerating its
|
// constraints have fully matured. The store exposes methods for enumerating its
|
||||||
// contents, and persisting state transitions detected by the utxo nursery.
|
// contents, and persisting state transitions detected by the utxo nursery.
|
||||||
type NurseryStore interface {
|
type NurseryStore interface {
|
||||||
|
// Incubate registers a set of CSV delayed outputs (incoming HTLC's on
|
||||||
// Incubate registers a commitment output and a slice of htlc outputs to
|
// our commitment transaction, or a commitment output), and a slice of
|
||||||
// be swept back into the user's wallet. The event is persisted to disk,
|
// outgoing htlc outputs to be swept back into the user's wallet. The
|
||||||
// such that the nursery can resume the incubation process after a
|
// event is persisted to disk, such that the nursery can resume the
|
||||||
// potential crash.
|
// incubation process after a potential crash.
|
||||||
Incubate(*kidOutput, []babyOutput) error
|
Incubate([]kidOutput, []babyOutput) error
|
||||||
|
|
||||||
// CribToKinder atomically moves a babyOutput in the crib bucket to the
|
// CribToKinder atomically moves a babyOutput in the crib bucket to the
|
||||||
// kindergarten bucket. The now mature kidOutput contained in the
|
// kindergarten bucket. Baby outputs are outgoing HTLC's which require
|
||||||
// babyOutput will be stored as it waits out the kidOutput's CSV delay.
|
// us to go to the second-layer to claim. The now mature kidOutput
|
||||||
|
// contained in the babyOutput will be stored as it waits out the
|
||||||
|
// kidOutput's CSV delay.
|
||||||
CribToKinder(*babyOutput) error
|
CribToKinder(*babyOutput) error
|
||||||
|
|
||||||
// PreschoolToKinder atomically moves a kidOutput from the preschool
|
// PreschoolToKinder atomically moves a kidOutput from the preschool
|
||||||
// bucket to the kindergarten bucket. This transition should be executed
|
// bucket to the kindergarten bucket. This transition should be
|
||||||
// after receiving confirmation of the preschool output's commitment
|
// executed after receiving confirmation of the preschool output.
|
||||||
// transaction.
|
// Incoming HTLC's we need to go to the second-layer to claim, and also
|
||||||
|
// our commitment outputs fall into this class.
|
||||||
PreschoolToKinder(*kidOutput) error
|
PreschoolToKinder(*kidOutput) error
|
||||||
|
|
||||||
// GraduateKinder atomically moves the kindergarten class at the
|
// GraduateKinder atomically moves the kindergarten class at the
|
||||||
@@ -121,8 +124,8 @@ type NurseryStore interface {
|
|||||||
// removed.
|
// removed.
|
||||||
GraduateKinder(height uint32) error
|
GraduateKinder(height uint32) error
|
||||||
|
|
||||||
// FetchPreschools returns a list of all outputs currently stored in the
|
// FetchPreschools returns a list of all outputs currently stored in
|
||||||
// preschool bucket.
|
// the preschool bucket.
|
||||||
FetchPreschools() ([]kidOutput, error)
|
FetchPreschools() ([]kidOutput, error)
|
||||||
|
|
||||||
// FetchClass returns a list of kindergarten and crib outputs whose
|
// FetchClass returns a list of kindergarten and crib outputs whose
|
||||||
@@ -300,18 +303,23 @@ func newNurseryStore(chainHash *chainhash.Hash,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incubate persists the beginning of the incubation process for the CSV-delayed
|
// Incubate persists the beginning of the incubation process for the
|
||||||
// commitment output and a list of two-stage htlc outputs.
|
// CSV-delayed outputs (commitment and incoming HTLC's), commitment output and
|
||||||
func (ns *nurseryStore) Incubate(kid *kidOutput, babies []babyOutput) error {
|
// a list of outgoing two-stage htlc outputs.
|
||||||
|
func (ns *nurseryStore) Incubate(kids []kidOutput, babies []babyOutput) error {
|
||||||
return ns.db.Update(func(tx *bolt.Tx) error {
|
return ns.db.Update(func(tx *bolt.Tx) error {
|
||||||
// Store commitment output in preschool bucket if not nil.
|
// If we have any kid outputs to incubate, then we'll attempt
|
||||||
if kid != nil {
|
// to add each of them to the nursery store. Any duplicate
|
||||||
if err := ns.enterPreschool(tx, kid); err != nil {
|
// outputs will be ignored.
|
||||||
|
for _, kid := range kids {
|
||||||
|
if err := ns.enterPreschool(tx, &kid); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all htlc outputs to the crib bucket.
|
// Next, we'll Add all htlc outputs to the crib bucket.
|
||||||
|
// Similarly, we'll ignore any outputs that have already been
|
||||||
|
// inserted.
|
||||||
for _, baby := range babies {
|
for _, baby := range babies {
|
||||||
if err := ns.enterCrib(tx, &baby); err != nil {
|
if err := ns.enterCrib(tx, &baby); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -384,7 +392,7 @@ func (ns *nurseryStore) CribToKinder(bby *babyOutput) error {
|
|||||||
// the block height at which the output was confirmed.
|
// the block height at which the output was confirmed.
|
||||||
maturityHeight := bby.ConfHeight() + bby.BlocksToMaturity()
|
maturityHeight := bby.ConfHeight() + bby.BlocksToMaturity()
|
||||||
|
|
||||||
// Retrive or create a height-channel bucket corresponding to
|
// Retrieve or create a height-channel bucket corresponding to
|
||||||
// the kidOutput's maturity height.
|
// the kidOutput's maturity height.
|
||||||
hghtChanBucketCsv, err := ns.createHeightChanBucket(tx,
|
hghtChanBucketCsv, err := ns.createHeightChanBucket(tx,
|
||||||
maturityHeight, chanPoint)
|
maturityHeight, chanPoint)
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import (
|
|||||||
//
|
//
|
||||||
// DESCRIPTION OF OUTPUT STATES
|
// DESCRIPTION OF OUTPUT STATES
|
||||||
//
|
//
|
||||||
|
// TODO(roasbeef): update comment with both new output types
|
||||||
|
//
|
||||||
// - CRIB (babyOutput) outputs are two-stage htlc outputs that are initially
|
// - CRIB (babyOutput) outputs are two-stage htlc outputs that are initially
|
||||||
// locked using a CLTV delay, followed by a CSV delay. The first stage of a
|
// locked using a CLTV delay, followed by a CSV delay. The first stage of a
|
||||||
// crib output requires broadcasting a presigned htlc timeout txn generated
|
// crib output requires broadcasting a presigned htlc timeout txn generated
|
||||||
|
|||||||
Reference in New Issue
Block a user