Skip to content

Commit

Permalink
update IsTxTimeboosted method on BlockMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Dec 27, 2024
1 parent 561f8b3 commit 1728656
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,16 @@ func (b PrettyBytes) TerminalString() string {
type BlockMetadata []byte

// IsTxTimeboosted given a tx's index in the block returns whether the tx was timeboosted or not
func (b BlockMetadata) IsTxTimeboosted(txIndex int) bool {
func (b BlockMetadata) IsTxTimeboosted(txIndex int) (bool, error) {
if len(b) == 0 {
return false, errors.New("blockMetadata is not set")
}
if txIndex < 0 {
return false, fmt.Errorf("invalid transaction index- %d, should be positive", txIndex)
}
maxTxCount := (len(b) - 1) * 8
if txIndex >= maxTxCount {
return false
return false, nil
}
return b[1+(txIndex/8)]&(1<<(txIndex%8)) != 0
return b[1+(txIndex/8)]&(1<<(txIndex%8)) != 0, nil
}
5 changes: 4 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,10 @@ func marshalReceipt(ctx context.Context, receipt *types.Receipt, blockHash commo
return nil, err
}
if blockMetadata != nil {
fields["timeboosted"] = blockMetadata.IsTxTimeboosted(txIndex)
fields["timeboosted"], err = blockMetadata.IsTxTimeboosted(txIndex)
if err != nil {
log.Error("Error checking if a tx was timeboosted", "txIndex", txIndex, "txHash", tx.Hash(), "err", err)
}
}
}
return fields, nil
Expand Down

0 comments on commit 1728656

Please sign in to comment.