Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a boolean field to tx receipt object indicating if the tx was timeboosted #2760

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ func (n *Node) GetFinalizedMsgCount(ctx context.Context) (arbutil.MessageIndex,
return n.InboxReader.GetFinalizedMsgCount(ctx)
}

func (n *Node) WriteMessageFromSequencer(pos arbutil.MessageIndex, msgWithMeta arbostypes.MessageWithMetadata, msgResult execution.MessageResult, blockMetadata arbostypes.BlockMetadata) error {
func (n *Node) WriteMessageFromSequencer(pos arbutil.MessageIndex, msgWithMeta arbostypes.MessageWithMetadata, msgResult execution.MessageResult, blockMetadata common.BlockMetadata) error {
return n.TxStreamer.WriteMessageFromSequencer(pos, msgWithMeta, msgResult, blockMetadata)
}

Expand All @@ -1063,6 +1063,6 @@ func (n *Node) ValidatedMessageCount() (arbutil.MessageIndex, error) {
return n.BlockValidator.GetValidated(), nil
}

func (n *Node) BlockMetadataAtCount(count arbutil.MessageIndex) (arbostypes.BlockMetadata, error) {
func (n *Node) BlockMetadataAtCount(count arbutil.MessageIndex) (common.BlockMetadata, error) {
return n.TxStreamer.BlockMetadataAtCount(count)
}
11 changes: 6 additions & 5 deletions arbnode/seq_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/redis/go-redis/v9"
flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"

Expand Down Expand Up @@ -270,7 +271,7 @@ func (c *SeqCoordinator) signedBytesToMsgCount(ctx context.Context, data []byte)
}

// Acquires or refreshes the chosen one lockout and optionally writes a message into redis atomically.
func (c *SeqCoordinator) acquireLockoutAndWriteMessage(ctx context.Context, msgCountExpected, msgCountToWrite arbutil.MessageIndex, lastmsg *arbostypes.MessageWithMetadata, blockMetadata arbostypes.BlockMetadata) error {
func (c *SeqCoordinator) acquireLockoutAndWriteMessage(ctx context.Context, msgCountExpected, msgCountToWrite arbutil.MessageIndex, lastmsg *arbostypes.MessageWithMetadata, blockMetadata common.BlockMetadata) error {
var messageData *string
var messageSigData *string
if lastmsg != nil {
Expand Down Expand Up @@ -600,15 +601,15 @@ func (c *SeqCoordinator) deleteFinalizedMsgsFromRedis(ctx context.Context, final
return nil
}

func (c *SeqCoordinator) blockMetadataAt(ctx context.Context, pos arbutil.MessageIndex) (arbostypes.BlockMetadata, error) {
func (c *SeqCoordinator) blockMetadataAt(ctx context.Context, pos arbutil.MessageIndex) (common.BlockMetadata, error) {
blockMetadataStr, err := c.RedisCoordinator().Client.Get(ctx, redisutil.BlockMetadataKeyFor(pos)).Result()
if err != nil {
if errors.Is(err, redis.Nil) {
return nil, nil
}
return nil, err
}
return arbostypes.BlockMetadata(blockMetadataStr), nil
return common.BlockMetadata(blockMetadataStr), nil
}

func (c *SeqCoordinator) update(ctx context.Context) time.Duration {
Expand Down Expand Up @@ -675,7 +676,7 @@ func (c *SeqCoordinator) update(ctx context.Context) time.Duration {
log.Info("coordinator caught up to prev redis coordinator", "msgcount", localMsgCount, "prevMsgCount", c.prevRedisMessageCount)
}
var messages []arbostypes.MessageWithMetadata
var blockMetadataArr []arbostypes.BlockMetadata
var blockMetadataArr []common.BlockMetadata
msgToRead := localMsgCount
var msgReadErr error
for msgToRead < readUntil && localMsgCount >= remoteFinalizedMsgCount {
Expand Down Expand Up @@ -991,7 +992,7 @@ func (c *SeqCoordinator) CurrentlyChosen() bool {
return time.Now().Before(atomicTimeRead(&c.lockoutUntil))
}

func (c *SeqCoordinator) SequencingMessage(pos arbutil.MessageIndex, msg *arbostypes.MessageWithMetadata, blockMetadata arbostypes.BlockMetadata) error {
func (c *SeqCoordinator) SequencingMessage(pos arbutil.MessageIndex, msg *arbostypes.MessageWithMetadata, blockMetadata common.BlockMetadata) error {
if !c.CurrentlyChosen() {
return fmt.Errorf("%w: not main sequencer", execution.ErrRetrySequencer)
}
Expand Down
4 changes: 3 additions & 1 deletion arbnode/seq_coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/common"

"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/util/redisutil"
Expand Down Expand Up @@ -279,7 +281,7 @@ func TestSeqCoordinatorAddsBlockMetadata(t *testing.T) {
}

pos := arbutil.MessageIndex(1)
blockMetadataWant := arbostypes.BlockMetadata{0, 4}
blockMetadataWant := common.BlockMetadata{0, 4}
Require(t, coordinator.acquireLockoutAndWriteMessage(ctx, pos, pos+1, &arbostypes.EmptyTestMessageWithMetadata, blockMetadataWant))
blockMetadataGot, err := coordinator.blockMetadataAt(ctx, pos)
Require(t, err)
Expand Down
8 changes: 4 additions & 4 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (s *TransactionStreamer) GetProcessedMessageCount() (arbutil.MessageIndex,
return msgCount, nil
}

func (s *TransactionStreamer) AddMessages(pos arbutil.MessageIndex, messagesAreConfirmed bool, messages []arbostypes.MessageWithMetadata, blockMetadataArr []arbostypes.BlockMetadata) error {
func (s *TransactionStreamer) AddMessages(pos arbutil.MessageIndex, messagesAreConfirmed bool, messages []arbostypes.MessageWithMetadata, blockMetadataArr []common.BlockMetadata) error {
return s.AddMessagesAndEndBatch(pos, messagesAreConfirmed, messages, blockMetadataArr, nil)
}

Expand Down Expand Up @@ -679,7 +679,7 @@ func endBatch(batch ethdb.Batch) error {
return batch.Write()
}

func (s *TransactionStreamer) AddMessagesAndEndBatch(pos arbutil.MessageIndex, messagesAreConfirmed bool, messages []arbostypes.MessageWithMetadata, blockMetadataArr []arbostypes.BlockMetadata, batch ethdb.Batch) error {
func (s *TransactionStreamer) AddMessagesAndEndBatch(pos arbutil.MessageIndex, messagesAreConfirmed bool, messages []arbostypes.MessageWithMetadata, blockMetadataArr []common.BlockMetadata, batch ethdb.Batch) error {
messagesWithBlockInfo := make([]arbostypes.MessageWithMetadataAndBlockInfo, 0, len(messages))
for _, message := range messages {
messagesWithBlockInfo = append(messagesWithBlockInfo, arbostypes.MessageWithMetadataAndBlockInfo{
Expand Down Expand Up @@ -975,7 +975,7 @@ func (s *TransactionStreamer) WriteMessageFromSequencer(
pos arbutil.MessageIndex,
msgWithMeta arbostypes.MessageWithMetadata,
msgResult execution.MessageResult,
blockMetadata arbostypes.BlockMetadata,
blockMetadata common.BlockMetadata,
) error {
if err := s.ExpectChosenSequencer(); err != nil {
return err
Expand Down Expand Up @@ -1107,7 +1107,7 @@ func (s *TransactionStreamer) writeMessages(pos arbutil.MessageIndex, messages [
return nil
}

func (s *TransactionStreamer) BlockMetadataAtCount(count arbutil.MessageIndex) (arbostypes.BlockMetadata, error) {
func (s *TransactionStreamer) BlockMetadataAtCount(count arbutil.MessageIndex) (common.BlockMetadata, error) {
if count == 0 {
return nil, nil
}
Expand Down
20 changes: 1 addition & 19 deletions arbos/arbostypes/messagewithmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package arbostypes
import (
"context"
"encoding/binary"
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -20,12 +19,10 @@ type MessageWithMetadata struct {
DelayedMessagesRead uint64 `json:"delayedMessagesRead"`
}

type BlockMetadata []byte

type MessageWithMetadataAndBlockInfo struct {
MessageWithMeta MessageWithMetadata
BlockHash *common.Hash
BlockMetadata BlockMetadata
BlockMetadata common.BlockMetadata
}

var EmptyTestMessageWithMetadata = MessageWithMetadata{
Expand All @@ -37,21 +34,6 @@ var TestMessageWithMetadataAndRequestId = MessageWithMetadata{
Message: &TestIncomingMessageWithRequestId,
}

// IsTxTimeboosted given a tx's index in the block returns whether the tx was timeboosted or not
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, nil
}
return b[1+(txIndex/8)]&(1<<(txIndex%8)) != 0, nil
}

func (m *MessageWithMetadata) Hash(sequenceNumber arbutil.MessageIndex, chainId uint64) (common.Hash, error) {
serializedExtraData := make([]byte, 24)
binary.BigEndian.PutUint64(serializedExtraData[:8], uint64(sequenceNumber))
Expand Down
4 changes: 2 additions & 2 deletions broadcaster/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *Broadcaster) NewBroadcastFeedMessage(
message arbostypes.MessageWithMetadata,
sequenceNumber arbutil.MessageIndex,
blockHash *common.Hash,
blockMetadata arbostypes.BlockMetadata,
blockMetadata common.BlockMetadata,
) (*m.BroadcastFeedMessage, error) {
var messageSignature []byte
if b.dataSigner != nil {
Expand All @@ -70,7 +70,7 @@ func (b *Broadcaster) BroadcastSingle(
msg arbostypes.MessageWithMetadata,
seq arbutil.MessageIndex,
blockHash *common.Hash,
blockMetadata arbostypes.BlockMetadata,
blockMetadata common.BlockMetadata,
) (err error) {
defer func() {
if r := recover(); r != nil {
Expand Down
2 changes: 1 addition & 1 deletion broadcaster/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type BroadcastFeedMessage struct {
Message arbostypes.MessageWithMetadata `json:"message"`
BlockHash *common.Hash `json:"blockHash,omitempty"`
Signature []byte `json:"signature"`
BlockMetadata arbostypes.BlockMetadata `json:"blockMetadata,omitempty"`
BlockMetadata common.BlockMetadata `json:"blockMetadata,omitempty"`

CumulativeSumMsgSize uint64 `json:"-"`
}
Expand Down
4 changes: 2 additions & 2 deletions broadcaster/message/message_blockmetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package message
import (
"testing"

"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/ethereum/go-ethereum/common"
)

func TestTimeboostedInDifferentScenarios(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
name string
blockMetadata arbostypes.BlockMetadata
blockMetadata common.BlockMetadata
txs []bool // Array representing whether the tx is timeboosted or not. First tx is always false as its an arbitrum internal tx
}{
{
Expand Down
12 changes: 6 additions & 6 deletions execution/gethexec/blockmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/rpc"

"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/util/stopwaiter"
)

var ErrBlockMetadataApiBlocksLimitExceeded = errors.New("number of blocks requested for blockMetadata exceeded")

type BlockMetadataFetcher interface {
BlockMetadataAtCount(count arbutil.MessageIndex) (arbostypes.BlockMetadata, error)
BlockMetadataAtCount(count arbutil.MessageIndex) (common.BlockMetadata, error)
BlockNumberToMessageIndex(blockNum uint64) (arbutil.MessageIndex, error)
MessageIndexToBlockNumber(messageNum arbutil.MessageIndex) uint64
SetReorgEventsNotifier(reorgEventsNotifier chan struct{})
Expand All @@ -30,14 +30,14 @@ type BulkBlockMetadataFetcher struct {
fetcher BlockMetadataFetcher
reorgDetector chan struct{}
blocksLimit uint64
cache *lru.SizeConstrainedCache[arbutil.MessageIndex, arbostypes.BlockMetadata]
cache *lru.SizeConstrainedCache[arbutil.MessageIndex, common.BlockMetadata]
}

func NewBulkBlockMetadataFetcher(bc *core.BlockChain, fetcher BlockMetadataFetcher, cacheSize, blocksLimit uint64) *BulkBlockMetadataFetcher {
var cache *lru.SizeConstrainedCache[arbutil.MessageIndex, arbostypes.BlockMetadata]
var cache *lru.SizeConstrainedCache[arbutil.MessageIndex, common.BlockMetadata]
var reorgDetector chan struct{}
if cacheSize != 0 {
cache = lru.NewSizeConstrainedCache[arbutil.MessageIndex, arbostypes.BlockMetadata](cacheSize)
cache = lru.NewSizeConstrainedCache[arbutil.MessageIndex, common.BlockMetadata](cacheSize)
reorgDetector = make(chan struct{})
fetcher.SetReorgEventsNotifier(reorgDetector)
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func (b *BulkBlockMetadataFetcher) Fetch(fromBlock, toBlock rpc.BlockNumber) ([]
}
var result []NumberAndBlockMetadata
for i := start; i <= end; i++ {
var data arbostypes.BlockMetadata
var data common.BlockMetadata
var found bool
if b.cache != nil {
data, found = b.cache.Get(i)
Expand Down
6 changes: 3 additions & 3 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (s *ExecutionEngine) SetConsensus(consensus execution.FullConsensusClient)
s.consensus = consensus
}

func (s *ExecutionEngine) BlockMetadataAtCount(count arbutil.MessageIndex) (arbostypes.BlockMetadata, error) {
func (s *ExecutionEngine) BlockMetadataAtCount(count arbutil.MessageIndex) (common.BlockMetadata, error) {
if s.consensus != nil {
return s.consensus.BlockMetadataAtCount(count)
}
Expand Down Expand Up @@ -612,8 +612,8 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes.
// starting from the second byte, (N)th bit would represent if (N)th tx is timeboosted or not, 1 means yes and 0 means no
// blockMetadata[index / 8 + 1] & (1 << (index % 8)) != 0; where index = (N - 1), implies whether (N)th tx in a block is timeboosted
// note that number of txs in a block will always lag behind (len(blockMetadata) - 1) * 8 but it wont lag more than a value of 7
func (s *ExecutionEngine) blockMetadataFromBlock(block *types.Block, timeboostedTxs map[common.Hash]struct{}) arbostypes.BlockMetadata {
bits := make(arbostypes.BlockMetadata, 1+arbmath.DivCeil(uint64(len(block.Transactions())), 8))
func (s *ExecutionEngine) blockMetadataFromBlock(block *types.Block, timeboostedTxs map[common.Hash]struct{}) common.BlockMetadata {
bits := make(common.BlockMetadata, 1+arbmath.DivCeil(uint64(len(block.Transactions())), 8))
if len(timeboostedTxs) == 0 {
return bits
}
Expand Down
15 changes: 15 additions & 0 deletions execution/gethexec/sync_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"github.com/pkg/errors"
flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

"github.com/offchainlabs/nitro/execution"
)

Expand Down Expand Up @@ -122,3 +125,15 @@ func (s *SyncMonitor) Synced() bool {
func (s *SyncMonitor) SetConsensusInfo(consensus execution.ConsensusInfo) {
s.consensus = consensus
}

func (s *SyncMonitor) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
count, err := s.exec.BlockNumberToMessageIndex(blockNum)
if err != nil {
return nil, err
}
if s.consensus != nil {
return s.consensus.BlockMetadataAtCount(count + 1)
}
log.Debug("FullConsensusClient is not accessible to execution, BlockMetadataByNumber will return nil")
return nil, nil
}
4 changes: 2 additions & 2 deletions execution/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type ConsensusInfo interface {
Synced() bool
FullSyncProgressMap() map[string]interface{}
SyncTargetMessageCount() arbutil.MessageIndex
BlockMetadataAtCount(count arbutil.MessageIndex) (arbostypes.BlockMetadata, error)
BlockMetadataAtCount(count arbutil.MessageIndex) (common.BlockMetadata, error)

// TODO: switch from pulling to pushing safe/finalized
GetSafeMsgCount(ctx context.Context) (arbutil.MessageIndex, error)
Expand All @@ -93,7 +93,7 @@ type ConsensusInfo interface {
}

type ConsensusSequencer interface {
WriteMessageFromSequencer(pos arbutil.MessageIndex, msgWithMeta arbostypes.MessageWithMetadata, msgResult MessageResult, blockMetadata arbostypes.BlockMetadata) error
WriteMessageFromSequencer(pos arbutil.MessageIndex, msgWithMeta arbostypes.MessageWithMetadata, msgResult MessageResult, blockMetadata common.BlockMetadata) error
ExpectChosenSequencer() error
}

Expand Down
Loading
Loading