Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Remove latestBlockIssuanceResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed May 13, 2024
1 parent e9f0b1e commit 6f98281
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,14 @@ func (i *BlockIssuer) CreateAndSubmitValidationBlock(ctx context.Context, alias
func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts ...options.Option[BasicBlockParams]) (*blocks.Block, error) {
blockParams := options.Apply(&BasicBlockParams{BlockHeader: &BlockHeaderParams{}}, opts)

blockIssuanceInfo := i.latestBlockIssuanceResponse(ctx)
blockIssuanceInfo, err := i.Client.BlockIssuance(ctx)
require.NoError(i.Testing, err)

if blockParams.BlockHeader.References == nil {
blockParams.BlockHeader.References = referencesFromBlockIssuanceResponse(blockIssuanceInfo)
}

err := i.setDefaultBlockParams(ctx, blockParams.BlockHeader)
err = i.setDefaultBlockParams(ctx, blockParams.BlockHeader)
require.NoError(i.Testing, err)

api := i.Client.APIForTime(*blockParams.BlockHeader.IssuingTime)
Expand Down Expand Up @@ -270,9 +271,6 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts .

modelBlock.ID().RegisterAlias(alias)

// mark the response as used so that the next time we query the node for the latest block issuance.
i.blockIssuanceResponseUsed = true

return blocks.NewBlock(modelBlock), err
}

Expand Down Expand Up @@ -415,21 +413,3 @@ func (i *BlockIssuer) GetNewBlockIssuanceResponse() *api.IssuanceBlockHeaderResp

return i.latestBlockIssuanceResp
}

func (i *BlockIssuer) latestBlockIssuanceResponse(context context.Context) *api.IssuanceBlockHeaderResponse {
i.mutex.Lock()
defer i.mutex.Unlock()

// If the response was already used to issue a block, we need to get a new response from the node.
// Otherwise we can reuse the cached response. For transactions with commitment inputs, we want to get a fresh response
// for the transaction creation, and then reuse that response for the block issuance, so we only mark the response as used
// if it was used for block issuance.
if i.blockIssuanceResponseUsed {
i.blockIssuanceResponseUsed = false
resp, err := i.Client.BlockIssuance(context)
require.NoError(i.Testing, err)
i.latestBlockIssuanceResp = resp
}

return i.latestBlockIssuanceResp
}

0 comments on commit 6f98281

Please sign in to comment.