Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Nov 21, 2024
1 parent 41d7436 commit bc93214
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
14 changes: 10 additions & 4 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,11 @@ func (s *TransactionStreamer) getMessageWithMetadataAndBlockInfo(seqNum arbutil.

key = dbKey(blockMetadataInputFeedPrefix, uint64(seqNum))
blockMetadata, err := s.db.Get(key)
if err != nil && !dbutil.IsErrNotFound(err) {
return nil, err
if err != nil {
if !dbutil.IsErrNotFound(err) {
return nil, err
}
blockMetadata = nil
}

msgWithBlockInfo := arbostypes.MessageWithMetadataAndBlockInfo{
Expand Down Expand Up @@ -1099,13 +1102,16 @@ func (s *TransactionStreamer) writeMessages(pos arbutil.MessageIndex, messages [

func (s *TransactionStreamer) BlockMetadataAtCount(count arbutil.MessageIndex) (arbostypes.BlockMetadata, error) {
if count == 0 {
return []byte{}, nil
return nil, nil
}
pos := count - 1

key := dbKey(blockMetadataInputFeedPrefix, uint64(pos))
blockMetadata, err := s.db.Get(key)
if err != nil && !dbutil.IsErrNotFound(err) {
if err != nil {
if dbutil.IsErrNotFound(err) {
return nil, nil
}
return nil, err
}
return blockMetadata, nil
Expand Down
13 changes: 10 additions & 3 deletions arbos/arbostypes/messagewithmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package arbostypes
import (
"context"
"encoding/binary"
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -36,12 +37,18 @@ var TestMessageWithMetadataAndRequestId = MessageWithMetadata{
}

// 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
}

func (m *MessageWithMetadata) Hash(sequenceNumber arbutil.MessageIndex, chainId uint64) (common.Hash, error) {
Expand Down
12 changes: 7 additions & 5 deletions broadcaster/message/message_blockmetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ func TestTimeboostedInDifferentScenarios(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
for txIndex, isTxTimeBoosted := range tc.txs {
if isTxTimeBoosted && !tc.blockMetadata.IsTxTimeboosted(txIndex) {
t.Fatalf("incorrect timeboosted bit for tx of index %d, it should be timeboosted", txIndex)
} else if !isTxTimeBoosted && tc.blockMetadata.IsTxTimeboosted(txIndex) {
t.Fatalf("incorrect timeboosted bit for tx of index %d, it shouldn't be timeboosted", txIndex)
for txIndex, want := range tc.txs {
have, err := tc.blockMetadata.IsTxTimeboosted(txIndex)
if err != nil {
t.Fatalf("error getting timeboosted bit for tx of index %d: %v", txIndex, err)
}
if want != have {
t.Fatalf("incorrect timeboosted bit for tx of index %d, Got: %v, Want: %v", txIndex, have, want)
}
}
})
Expand Down
8 changes: 5 additions & 3 deletions system_tests/timeboost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ func TestSequencerFeed_ExpressLaneAuction_ExpressLaneTxsHaveAdvantage_Timebooste
Require(t, err)
var foundUserTx bool
for txIndex, tx := range userTxBlock.Transactions() {
got, err := blockMetadataOfBlock.IsTxTimeboosted(txIndex)
Require(t, err)
if tx.Hash() == userTx.Hash() {
foundUserTx = true
if !isTimeboosted && blockMetadataOfBlock.IsTxTimeboosted(txIndex) {
if !isTimeboosted && got {
t.Fatalf("incorrect timeboosted bit for %s's tx, it shouldn't be timeboosted", user)
} else if isTimeboosted && !blockMetadataOfBlock.IsTxTimeboosted(txIndex) {
} else if isTimeboosted && !got {
t.Fatalf("incorrect timeboosted bit for %s's tx, it should be timeboosted", user)
}
} else if blockMetadataOfBlock.IsTxTimeboosted(txIndex) {
} else if got {
// Other tx's right now shouln't be timeboosted
t.Fatalf("incorrect timeboosted bit for nonspecified tx with index: %d, it shouldn't be timeboosted", txIndex)
}
Expand Down

0 comments on commit bc93214

Please sign in to comment.