From 17286562eb2f0dcd02dafdaf5da0fce5ff1f6096 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 27 Dec 2024 11:35:16 -0600 Subject: [PATCH] update IsTxTimeboosted method on BlockMetadata --- common/types.go | 12 +++++++++--- internal/ethapi/api.go | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/common/types.go b/common/types.go index 9527e833e..e2fe42e13 100644 --- a/common/types.go +++ b/common/types.go @@ -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 } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 41b807c60..7bcdcf57e 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -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