Skip to content

Commit

Permalink
Make sure the block IssuingTime comes after LatestParentBlockIssuingTime
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed May 10, 2024
1 parent 339e93d commit 3bf9950
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, n

if blockParams.BlockHeader.IssuingTime == nil {
issuingTime := time.Now().UTC()
if issuingTime.Before(blockIssuanceInfo.LatestParentBlockIssuingTime) {
issuingTime = blockIssuanceInfo.LatestParentBlockIssuingTime.Add(time.Millisecond * 30)
}

blockParams.BlockHeader.IssuingTime = &issuingTime
}

Expand Down Expand Up @@ -246,6 +250,10 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts .
// set the issuing time last to ensure the timestamp is greater than that of the parents selected.
if blockParams.BlockHeader.IssuingTime == nil {
issuingTime := time.Now().UTC()
if issuingTime.Before(blockIssuanceInfo.LatestParentBlockIssuingTime) {
issuingTime = blockIssuanceInfo.LatestParentBlockIssuingTime.Add(time.Millisecond * 30)
}

blockParams.BlockHeader.IssuingTime = &issuingTime
}
blockBuilder.IssuingTime(*blockParams.BlockHeader.IssuingTime)
Expand Down

0 comments on commit 3bf9950

Please sign in to comment.