Skip to content

Commit

Permalink
tapgarden: test fundBatch, external seedling keys
Browse files Browse the repository at this point in the history
In this commit, we add a unit test that funds a batch before finalize.
This test also provides external keys for some seedlings to ensure that
these are handled correctly during minting. We also update the planter
to reject fund and finalize calls if a batch is already funded.
  • Loading branch information
jharveyb committed Apr 9, 2024
1 parent 0920055 commit 132a2d0
Show file tree
Hide file tree
Showing 3 changed files with 341 additions and 47 deletions.
3 changes: 0 additions & 3 deletions tapgarden/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ type MintingBatch struct {
// GenesisPacket is the funded genesis packet that may or may not be
// fully signed. When broadcast, this will create all assets stored
// within this batch.
//
// NOTE: This field is only set if the state is beyond
// BatchStateCommitted.
GenesisPacket *tapsend.FundedPsbt

// RootAssetCommitment is the root Taproot Asset commitment for all the
Expand Down
21 changes: 19 additions & 2 deletions tapgarden/planter.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,13 @@ func (c *ChainPlanter) gardener() {
req.Resolve(batches)

case reqTypeFundBatch:
log.Infof("Funding batch")
if c.pendingBatch != nil &&
c.pendingBatch.IsFunded() {

req.Error(fmt.Errorf("batch already " +
"funded"))
break
}

fundReqParams, err :=
typedParam[FundParams](req)
Expand All @@ -898,6 +904,8 @@ func (c *ChainPlanter) gardener() {
break
}

req.Resolve(c.pendingBatch)

// TODO(jhb): follow-up PR: Implement SealBatch command
case reqTypeSealBatch:
req.Error(fmt.Errorf("not yet implemented"))
Expand Down Expand Up @@ -1190,6 +1198,15 @@ func (c *ChainPlanter) finalizeBatch(params FinalizeParams) (*BatchCaretaker,
err error
)

// Before modifying the pending batch, check if the batch was already
// funded. If so, reject any provided parameters, as they would conflict
// with those previously used for batch funding.
haveParams := params.FeeRate.IsSome() || params.SiblingTapTree.IsSome()
if haveParams && c.pendingBatch.IsFunded() {
return nil, fmt.Errorf("cannot provide finalize parameters " +
"if batch already funded")
}

// Process the finalize parameters.
feeRate = params.FeeRate.UnwrapToPtr()

Expand Down Expand Up @@ -1427,7 +1444,7 @@ func (c *ChainPlanter) prepAssetSeedling(ctx context.Context,
req.ScriptKey = asset.NewScriptKeyBip86(scriptKey)
}

// Now that we know the field are valid, we'll check to see if a batch
// Now that we know the seedling is valid, we'll check to see if a batch
// already exists.
switch {
// No batch, so we'll create a new one with only this seedling as part
Expand Down
Loading

0 comments on commit 132a2d0

Please sign in to comment.