Skip to content

Commit

Permalink
Merge pull request #1717 from OffchainLabs/l3-timing-fixes
Browse files Browse the repository at this point in the history
Miscellaneous L3 timing fixes
  • Loading branch information
PlasmaPower authored Jun 24, 2023
2 parents e6b4b74 + d8482ba commit 47f76bb
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 127 deletions.
7 changes: 4 additions & 3 deletions arbnode/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []type
}

requestId := common.BigToHash(parsedLog.MessageIndex)
parentChainBlockNumber, err := arbutil.CorrespondingL1BlockNumber(ctx, b.client, parsedLog.Raw.BlockNumber)
parentChainBlockNumber := parsedLog.Raw.BlockNumber
l1BlockNumber, err := arbutil.CorrespondingL1BlockNumber(ctx, b.client, parentChainBlockNumber)
if err != nil {
return nil, err
}
Expand All @@ -206,14 +207,14 @@ func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []type
Header: &arbostypes.L1IncomingMessageHeader{
Kind: parsedLog.Kind,
Poster: parsedLog.Sender,
BlockNumber: parentChainBlockNumber,
BlockNumber: l1BlockNumber,
Timestamp: parsedLog.Timestamp,
RequestId: &requestId,
L1BaseFee: parsedLog.BaseFeeL1,
},
L2msg: data,
},
ParentChainBlockNumber: parentChainBlockNumber,
ParentChainBlockNumber: parsedLog.Raw.BlockNumber,
}
err = msg.Message.FillInBatchGasCost(batchFetcher)
if err != nil {
Expand Down
96 changes: 48 additions & 48 deletions arbnode/delayed_seq_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,48 @@ func TestSequencerReorgFromDelayed(t *testing.T) {
serializedInitMsgBatch := make([]byte, 40)
binary.BigEndian.PutUint64(serializedInitMsgBatch[32:], 1)
initMsgBatch := &SequencerInboxBatch{
BlockHash: [32]byte{},
BlockNumber: 0,
SequenceNumber: 0,
BeforeInboxAcc: [32]byte{},
AfterInboxAcc: [32]byte{1},
AfterDelayedAcc: initMsgDelayed.AfterInboxAcc(),
AfterDelayedCount: 1,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedInitMsgBatch,
BlockHash: [32]byte{},
ParentChainBlockNumber: 0,
SequenceNumber: 0,
BeforeInboxAcc: [32]byte{},
AfterInboxAcc: [32]byte{1},
AfterDelayedAcc: initMsgDelayed.AfterInboxAcc(),
AfterDelayedCount: 1,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedInitMsgBatch,
}
serializedUserMsgBatch := make([]byte, 40)
binary.BigEndian.PutUint64(serializedUserMsgBatch[32:], 2)
userMsgBatch := &SequencerInboxBatch{
BlockHash: [32]byte{},
BlockNumber: 0,
SequenceNumber: 1,
BeforeInboxAcc: [32]byte{1},
AfterInboxAcc: [32]byte{2},
AfterDelayedAcc: userDelayed.AfterInboxAcc(),
AfterDelayedCount: 2,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedUserMsgBatch,
BlockHash: [32]byte{},
ParentChainBlockNumber: 0,
SequenceNumber: 1,
BeforeInboxAcc: [32]byte{1},
AfterInboxAcc: [32]byte{2},
AfterDelayedAcc: userDelayed.AfterInboxAcc(),
AfterDelayedCount: 2,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedUserMsgBatch,
}
emptyBatch := &SequencerInboxBatch{
BlockHash: [32]byte{},
BlockNumber: 0,
SequenceNumber: 2,
BeforeInboxAcc: [32]byte{2},
AfterInboxAcc: [32]byte{3},
AfterDelayedAcc: userDelayed.AfterInboxAcc(),
AfterDelayedCount: 2,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedUserMsgBatch,
BlockHash: [32]byte{},
ParentChainBlockNumber: 0,
SequenceNumber: 2,
BeforeInboxAcc: [32]byte{2},
AfterInboxAcc: [32]byte{3},
AfterDelayedAcc: userDelayed.AfterInboxAcc(),
AfterDelayedCount: 2,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedUserMsgBatch,
}
err = tracker.AddSequencerBatches(ctx, nil, []*SequencerInboxBatch{initMsgBatch, userMsgBatch, emptyBatch})
Require(t, err)
Expand Down Expand Up @@ -123,18 +123,18 @@ func TestSequencerReorgFromDelayed(t *testing.T) {
}

emptyBatch = &SequencerInboxBatch{
BlockHash: [32]byte{},
BlockNumber: 0,
SequenceNumber: 1,
BeforeInboxAcc: [32]byte{1},
AfterInboxAcc: [32]byte{2},
AfterDelayedAcc: initMsgDelayed.AfterInboxAcc(),
AfterDelayedCount: 1,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedInitMsgBatch,
BlockHash: [32]byte{},
ParentChainBlockNumber: 0,
SequenceNumber: 1,
BeforeInboxAcc: [32]byte{1},
AfterInboxAcc: [32]byte{2},
AfterDelayedAcc: initMsgDelayed.AfterInboxAcc(),
AfterDelayedCount: 1,
TimeBounds: bridgegen.ISequencerInboxTimeBounds{},
rawLog: types.Log{},
dataLocation: 0,
bridgeAddress: [20]byte{},
serialized: serializedInitMsgBatch,
}
err = tracker.AddSequencerBatches(ctx, nil, []*SequencerInboxBatch{emptyBatch})
Require(t, err)
Expand Down
12 changes: 6 additions & 6 deletions arbnode/inbox_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (r *InboxReader) Start(ctxIn context.Context) error {
}

// assumes l1block is recent so we could do a simple-search from the end
func (r *InboxReader) recentL1BlockToMsg(ctx context.Context, l1block uint64) (arbutil.MessageIndex, error) {
func (r *InboxReader) recentParentChainBlockToMsg(ctx context.Context, parentChainBlock uint64) (arbutil.MessageIndex, error) {
batch, err := r.tracker.GetBatchCount()
if err != nil {
return 0, err
Expand All @@ -183,7 +183,7 @@ func (r *InboxReader) recentL1BlockToMsg(ctx context.Context, l1block uint64) (a
if err != nil {
return 0, err
}
if meta.L1Block <= l1block {
if meta.ParentChainBlock <= parentChainBlock {
return meta.MessageCount, nil
}
}
Expand All @@ -194,15 +194,15 @@ func (r *InboxReader) GetSafeMsgCount(ctx context.Context) (arbutil.MessageIndex
if err != nil {
return 0, err
}
return r.recentL1BlockToMsg(ctx, l1block)
return r.recentParentChainBlockToMsg(ctx, l1block)
}

func (r *InboxReader) GetFinalizedMsgCount(ctx context.Context) (arbutil.MessageIndex, error) {
l1block, err := r.l1Reader.LatestFinalizedBlockNr(ctx)
if err != nil {
return 0, err
}
return r.recentL1BlockToMsg(ctx, l1block)
return r.recentParentChainBlockToMsg(ctx, l1block)
}

func (r *InboxReader) Tracker() *InboxTracker {
Expand Down Expand Up @@ -575,7 +575,7 @@ func (r *InboxReader) GetSequencerMessageBytes(ctx context.Context, seqNum uint6
if err != nil {
return nil, err
}
blockNum := arbmath.UintToBig(metadata.L1Block)
blockNum := arbmath.UintToBig(metadata.ParentChainBlock)
seqBatches, err := r.sequencerInbox.LookupBatchesInRange(ctx, blockNum, blockNum)
if err != nil {
return nil, err
Expand All @@ -587,7 +587,7 @@ func (r *InboxReader) GetSequencerMessageBytes(ctx context.Context, seqNum uint6
}
seenBatches = append(seenBatches, batch.SequenceNumber)
}
return nil, fmt.Errorf("sequencer batch %v not found in L1 block %v (found batches %v)", seqNum, metadata.L1Block, seenBatches)
return nil, fmt.Errorf("sequencer batch %v not found in L1 block %v (found batches %v)", seqNum, metadata.ParentChainBlock, seenBatches)
}

func (r *InboxReader) GetLastReadBlockAndBatchCount() (uint64, uint64) {
Expand Down
6 changes: 3 additions & 3 deletions arbnode/inbox_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type BatchMetadata struct {
Accumulator common.Hash
MessageCount arbutil.MessageIndex
DelayedMessageCount uint64
L1Block uint64
ParentChainBlock uint64
}

func (t *InboxTracker) GetBatchMetadata(seqNum uint64) (BatchMetadata, error) {
Expand Down Expand Up @@ -619,7 +619,7 @@ func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client arbutil.L
Accumulator: batch.AfterInboxAcc,
DelayedMessageCount: batch.AfterDelayedCount,
MessageCount: batchMessageCounts[batch.SequenceNumber],
L1Block: batch.BlockNumber,
ParentChainBlock: batch.ParentChainBlockNumber,
}
batchMetas[batch.SequenceNumber] = meta
metaBytes, err := rlp.EncodeToBytes(meta)
Expand Down Expand Up @@ -663,7 +663,7 @@ func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client arbutil.L
newMessageCount := prevbatchmeta.MessageCount + arbutil.MessageIndex(len(messages))
var latestL1Block uint64
if len(batches) > 0 {
latestL1Block = batches[len(batches)-1].BlockNumber
latestL1Block = batches[len(batches)-1].ParentChainBlockNumber
}
var latestTimestamp uint64
if len(messages) > 0 {
Expand Down
6 changes: 6 additions & 0 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,12 @@ func (n *Node) Start(ctx context.Context) error {
return fmt.Errorf("error starting inbox reader: %w", err)
}
}
if n.DelayedSequencer != nil && n.SeqCoordinator == nil {
err = n.DelayedSequencer.ForceSequenceDelayed(ctx)
if err != nil {
return fmt.Errorf("error performing initial delayed sequencing: %w", err)
}
}
err = n.Execution.TxPublisher.Start(ctx)
if err != nil {
return fmt.Errorf("error starting transaction puiblisher: %w", err)
Expand Down
46 changes: 23 additions & 23 deletions arbnode/sequencer_inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ func (i *SequencerInbox) GetAccumulator(ctx context.Context, sequenceNumber uint
}

type SequencerInboxBatch struct {
BlockHash common.Hash
BlockNumber uint64
SequenceNumber uint64
BeforeInboxAcc common.Hash
AfterInboxAcc common.Hash
AfterDelayedAcc common.Hash
AfterDelayedCount uint64
TimeBounds bridgegen.ISequencerInboxTimeBounds
rawLog types.Log
dataLocation batchDataLocation
bridgeAddress common.Address
serialized []byte // nil if serialization isn't cached yet
BlockHash common.Hash
ParentChainBlockNumber uint64
SequenceNumber uint64
BeforeInboxAcc common.Hash
AfterInboxAcc common.Hash
AfterDelayedAcc common.Hash
AfterDelayedCount uint64
TimeBounds bridgegen.ISequencerInboxTimeBounds
rawLog types.Log
dataLocation batchDataLocation
bridgeAddress common.Address
serialized []byte // nil if serialization isn't cached yet
}

func (m *SequencerInboxBatch) getSequencerData(ctx context.Context, client arbutil.L1Interface) ([]byte, error) {
Expand Down Expand Up @@ -222,17 +222,17 @@ func (i *SequencerInbox) LookupBatchesInRange(ctx context.Context, from, to *big
}
lastSeqNum = &seqNum
batch := &SequencerInboxBatch{
BlockHash: log.BlockHash,
BlockNumber: log.BlockNumber,
SequenceNumber: seqNum,
BeforeInboxAcc: parsedLog.BeforeAcc,
AfterInboxAcc: parsedLog.AfterAcc,
AfterDelayedAcc: parsedLog.DelayedAcc,
AfterDelayedCount: parsedLog.AfterDelayedMessagesRead.Uint64(),
rawLog: log,
TimeBounds: parsedLog.TimeBounds,
dataLocation: batchDataLocation(parsedLog.DataLocation),
bridgeAddress: log.Address,
BlockHash: log.BlockHash,
ParentChainBlockNumber: log.BlockNumber,
SequenceNumber: seqNum,
BeforeInboxAcc: parsedLog.BeforeAcc,
AfterInboxAcc: parsedLog.AfterAcc,
AfterDelayedAcc: parsedLog.DelayedAcc,
AfterDelayedCount: parsedLog.AfterDelayedMessagesRead.Uint64(),
rawLog: log,
TimeBounds: parsedLog.TimeBounds,
dataLocation: batchDataLocation(parsedLog.DataLocation),
bridgeAddress: log.Address,
}
messages = append(messages, batch)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func findImportantRoots(ctx context.Context, chainDb ethdb.Database, stack *node
if err != nil {
return nil, err
}
if meta.L1Block <= l1BlockNum {
if meta.ParentChainBlock <= l1BlockNum {
signedBlockNum := arbutil.MessageCountToBlockNumber(meta.MessageCount, genesisNum)
blockNum := uint64(signedBlockNum)
l2Hash := rawdb.ReadCanonicalHash(chainDb, blockNum)
Expand Down
4 changes: 2 additions & 2 deletions nodeInterface/NodeInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ func (n NodeInterface) GetL1Confirmations(c ctx, evm mech, blockHash bytes32) (u
if err != nil {
return 0, err
}
if latestL1Block < meta.L1Block || arbutil.BlockNumberToMessageCount(blockNum, genesis) > meta.MessageCount {
if latestL1Block < meta.ParentChainBlock || arbutil.BlockNumberToMessageCount(blockNum, genesis) > meta.MessageCount {
return 0, nil
}
canonicalHash := bc.GetCanonicalHash(header.Number.Uint64())
if canonicalHash != header.Hash() {
return 0, errors.New("block hash is non-canonical")
}
confs := (latestL1Block - meta.L1Block) + 1 + node.InboxReader.GetDelayBlocks()
confs := (latestL1Block - meta.ParentChainBlock) + 1 + node.InboxReader.GetDelayBlocks()
return confs, nil
}

Expand Down
15 changes: 8 additions & 7 deletions staker/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ type Assertion struct {
}

type NodeInfo struct {
NodeNum uint64
L1BlockProposed uint64
Assertion *Assertion
InboxMaxCount *big.Int
AfterInboxBatchAcc common.Hash
NodeHash common.Hash
WasmModuleRoot common.Hash
NodeNum uint64
L1BlockProposed uint64
ParentChainBlockProposed uint64
Assertion *Assertion
InboxMaxCount *big.Int
AfterInboxBatchAcc common.Hash
NodeHash common.Hash
WasmModuleRoot common.Hash
}

func (n *NodeInfo) AfterState() *validator.ExecutionState {
Expand Down
Loading

0 comments on commit 47f76bb

Please sign in to comment.