Skip to content

Commit

Permalink
order: allow account version upgrade during batch
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jul 1, 2022
1 parent 71a6052 commit 94a0fe7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions order/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ type AccountDiff struct {
// NewExpiry is the new expiry height for this account. This field
// can be safely ignored if its value is 0.
NewExpiry uint32

// NewVersion is the version of the account that should be used after
// the batch went through. This field influences the type of account
// output that is created by this batch. If this differs from the
// CurrentVersion, then the account was upgraded in this batch.
NewVersion account.Version
}

// validateEndingState validates that the ending state of an account as
Expand Down
11 changes: 11 additions & 0 deletions order/batch_storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func (s *batchStorer) StorePendingBatch(batch *Batch) error {
)
}

// The account version can be upgraded during the batch
// if the client supports it.
if batch.Version.SupportsAccountTaprootUpgrade() &&
diff.NewVersion > acct.Version {

modifiers = append(
modifiers,
account.VersionModifier(diff.NewVersion),
)
}

// The account was fully spent on-chain. We need to wait for the
// batch (spend) TX to be confirmed still.
case auctioneerrpc.AccountDiff_OUTPUT_FULLY_SPENT,
Expand Down
7 changes: 7 additions & 0 deletions order/batch_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ func (v *batchVerifier) Verify(batch *Batch, bestHeight uint32) error {
acct.Expiry = diff.NewExpiry
}

// Update account version if needed.
if batch.Version.SupportsAccountTaprootUpgrade() &&
diff.NewVersion > acct.Version {

acct.Version = diff.NewVersion
}

// Make sure the ending state of the account is correct.
err := diff.validateEndingState(batch.BatchTX, acct)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions order/rpc_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/pool/account"
"github.com/lightninglabs/pool/auctioneerrpc"
"github.com/lightninglabs/pool/poolrpc"
"github.com/lightninglabs/pool/terms"
Expand Down Expand Up @@ -386,6 +387,7 @@ func ParseRPCBatch(prepareMsg *auctioneerrpc.OrderMatchPrepare) (*Batch,
EndingBalance: btcutil.Amount(diff.EndingBalance),
OutpointIndex: diff.OutpointIndex,
NewExpiry: diff.NewExpiry,
NewVersion: account.Version(diff.NewVersion),
},
)
}
Expand Down

0 comments on commit 94a0fe7

Please sign in to comment.