diff --git a/arbnode/delayed.go b/arbnode/delayed.go index 2995cc3d2f..f2c3d62004 100644 --- a/arbnode/delayed.go +++ b/arbnode/delayed.go @@ -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 } @@ -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 { diff --git a/arbnode/delayed_seq_reorg_test.go b/arbnode/delayed_seq_reorg_test.go index a34b83369f..a28eebb5dc 100644 --- a/arbnode/delayed_seq_reorg_test.go +++ b/arbnode/delayed_seq_reorg_test.go @@ -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) @@ -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) diff --git a/arbnode/inbox_reader.go b/arbnode/inbox_reader.go index c83e8e4af4..6ce9fd7172 100644 --- a/arbnode/inbox_reader.go +++ b/arbnode/inbox_reader.go @@ -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 @@ -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 } } @@ -194,7 +194,7 @@ 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) { @@ -202,7 +202,7 @@ func (r *InboxReader) GetFinalizedMsgCount(ctx context.Context) (arbutil.Message if err != nil { return 0, err } - return r.recentL1BlockToMsg(ctx, l1block) + return r.recentParentChainBlockToMsg(ctx, l1block) } func (r *InboxReader) Tracker() *InboxTracker { @@ -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 @@ -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) { diff --git a/arbnode/inbox_tracker.go b/arbnode/inbox_tracker.go index 3f8ba0d346..b6a1afd02b 100644 --- a/arbnode/inbox_tracker.go +++ b/arbnode/inbox_tracker.go @@ -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) { @@ -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) @@ -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 { diff --git a/arbnode/node.go b/arbnode/node.go index d9d46139ec..f1fc8e9e63 100644 --- a/arbnode/node.go +++ b/arbnode/node.go @@ -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) diff --git a/arbnode/sequencer_inbox.go b/arbnode/sequencer_inbox.go index a08e5b5c5a..2adfcb60b3 100644 --- a/arbnode/sequencer_inbox.go +++ b/arbnode/sequencer_inbox.go @@ -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) { @@ -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) } diff --git a/cmd/nitro/init.go b/cmd/nitro/init.go index c5faec4dd8..2284695961 100644 --- a/cmd/nitro/init.go +++ b/cmd/nitro/init.go @@ -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) diff --git a/nodeInterface/NodeInterface.go b/nodeInterface/NodeInterface.go index 41475b167d..fd1e224b0f 100644 --- a/nodeInterface/NodeInterface.go +++ b/nodeInterface/NodeInterface.go @@ -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 } diff --git a/staker/assertion.go b/staker/assertion.go index 19ee65e251..8d09abf866 100644 --- a/staker/assertion.go +++ b/staker/assertion.go @@ -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 { diff --git a/staker/l1_validator.go b/staker/l1_validator.go index 1d182bd3c1..f16d4c9538 100644 --- a/staker/l1_validator.go +++ b/staker/l1_validator.go @@ -261,14 +261,14 @@ func (v *L1Validator) blockNumberFromGlobalState(gs validator.GoGlobalState) (in } func (v *L1Validator) generateNodeAction(ctx context.Context, stakerInfo *OurStakerInfo, strategy StakerStrategy, makeAssertionInterval time.Duration) (nodeAction, bool, error) { - startState, prevInboxMaxCount, startStateProposed, err := lookupNodeStartState(ctx, v.rollup, stakerInfo.LatestStakedNode, stakerInfo.LatestStakedNodeHash) + startState, prevInboxMaxCount, startStateProposedL1, startStateProposedParentChain, err := lookupNodeStartState(ctx, v.rollup, stakerInfo.LatestStakedNode, stakerInfo.LatestStakedNodeHash) if err != nil { return nil, false, fmt.Errorf("error looking up node %v (hash %v) start state: %w", stakerInfo.LatestStakedNode, stakerInfo.LatestStakedNodeHash, err) } - startStateProposedHeader, err := v.client.HeaderByNumber(ctx, new(big.Int).SetUint64(startStateProposed)) + startStateProposedHeader, err := v.client.HeaderByNumber(ctx, new(big.Int).SetUint64(startStateProposedParentChain)) if err != nil { - return nil, false, fmt.Errorf("error looking up L1 header of block %v of node start state: %w", startStateProposed, err) + return nil, false, fmt.Errorf("error looking up L1 header of block %v of node start state: %w", startStateProposedParentChain, err) } startStateProposedTime := time.Unix(int64(startStateProposedHeader.Time), 0) @@ -358,7 +358,7 @@ func (v *L1Validator) generateNodeAction(ctx context.Context, stakerInfo *OurSta return nil, false, fmt.Errorf("error getting rollup minimum assertion period: %w", err) } - timeSinceProposed := big.NewInt(int64(l1BlockNumber) - int64(startStateProposed)) + timeSinceProposed := big.NewInt(int64(l1BlockNumber) - int64(startStateProposedL1)) if timeSinceProposed.Cmp(minAssertionPeriod) < 0 { // Too soon to assert return nil, false, nil @@ -602,28 +602,28 @@ func (v *L1Validator) createNewNodeAction( return action, nil } -// Returns (execution state, inbox max count, L1 block proposed, error) -func lookupNodeStartState(ctx context.Context, rollup *RollupWatcher, nodeNum uint64, nodeHash common.Hash) (*validator.ExecutionState, *big.Int, uint64, error) { +// Returns (execution state, inbox max count, L1 block proposed, parent chain block proposed, error) +func lookupNodeStartState(ctx context.Context, rollup *RollupWatcher, nodeNum uint64, nodeHash common.Hash) (*validator.ExecutionState, *big.Int, uint64, uint64, error) { if nodeNum == 0 { creationEvent, err := rollup.LookupCreation(ctx) if err != nil { - return nil, nil, 0, fmt.Errorf("error looking up rollup creation event: %w", err) + return nil, nil, 0, 0, fmt.Errorf("error looking up rollup creation event: %w", err) } - parentChainBlockNumber, err := arbutil.CorrespondingL1BlockNumber(ctx, rollup.client, creationEvent.Raw.BlockNumber) + l1BlockNumber, err := arbutil.CorrespondingL1BlockNumber(ctx, rollup.client, creationEvent.Raw.BlockNumber) if err != nil { - return nil, nil, 0, err + return nil, nil, 0, 0, err } return &validator.ExecutionState{ GlobalState: validator.GoGlobalState{}, MachineStatus: validator.MachineStatusFinished, - }, big.NewInt(1), parentChainBlockNumber, nil + }, big.NewInt(1), l1BlockNumber, creationEvent.Raw.BlockNumber, nil } node, err := rollup.LookupNode(ctx, nodeNum) if err != nil { - return nil, nil, 0, err + return nil, nil, 0, 0, err } if node.NodeHash != nodeHash { - return nil, nil, 0, errors.New("looked up starting node but found wrong hash") + return nil, nil, 0, 0, errors.New("looked up starting node but found wrong hash") } - return node.AfterState(), node.InboxMaxCount, node.L1BlockProposed, nil + return node.AfterState(), node.InboxMaxCount, node.L1BlockProposed, node.ParentChainBlockProposed, nil } diff --git a/staker/rollup_watcher.go b/staker/rollup_watcher.go index 5a2089eca8..aaaa30ce32 100644 --- a/staker/rollup_watcher.go +++ b/staker/rollup_watcher.go @@ -143,13 +143,14 @@ func (r *RollupWatcher) LookupNode(ctx context.Context, number uint64) (*NodeInf return nil, err } return &NodeInfo{ - NodeNum: parsedLog.NodeNum, - L1BlockProposed: l1BlockProposed, - Assertion: NewAssertionFromSolidity(parsedLog.Assertion), - InboxMaxCount: parsedLog.InboxMaxCount, - AfterInboxBatchAcc: parsedLog.AfterInboxBatchAcc, - NodeHash: parsedLog.NodeHash, - WasmModuleRoot: parsedLog.WasmModuleRoot, + NodeNum: parsedLog.NodeNum, + L1BlockProposed: l1BlockProposed, + ParentChainBlockProposed: ethLog.BlockNumber, + Assertion: NewAssertionFromSolidity(parsedLog.Assertion), + InboxMaxCount: parsedLog.InboxMaxCount, + AfterInboxBatchAcc: parsedLog.AfterInboxBatchAcc, + NodeHash: parsedLog.NodeHash, + WasmModuleRoot: parsedLog.WasmModuleRoot, }, nil } @@ -195,13 +196,14 @@ func (r *RollupWatcher) LookupNodeChildren(ctx context.Context, nodeNum uint64, return nil, err } infos = append(infos, &NodeInfo{ - NodeNum: parsedLog.NodeNum, - L1BlockProposed: l1BlockProposed, - Assertion: NewAssertionFromSolidity(parsedLog.Assertion), - InboxMaxCount: parsedLog.InboxMaxCount, - AfterInboxBatchAcc: parsedLog.AfterInboxBatchAcc, - NodeHash: lastHash, - WasmModuleRoot: parsedLog.WasmModuleRoot, + NodeNum: parsedLog.NodeNum, + L1BlockProposed: l1BlockProposed, + ParentChainBlockProposed: ethLog.BlockNumber, + Assertion: NewAssertionFromSolidity(parsedLog.Assertion), + InboxMaxCount: parsedLog.InboxMaxCount, + AfterInboxBatchAcc: parsedLog.AfterInboxBatchAcc, + NodeHash: lastHash, + WasmModuleRoot: parsedLog.WasmModuleRoot, }) } return infos, nil diff --git a/system_tests/batch_poster_test.go b/system_tests/batch_poster_test.go index 3785c47c00..8c656cb2d3 100644 --- a/system_tests/batch_poster_test.go +++ b/system_tests/batch_poster_test.go @@ -118,7 +118,7 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) { if i == 0 { continue } - if batches[i-1].BlockNumber == batches[i].BlockNumber { + if batches[i-1].ParentChainBlockNumber == batches[i].ParentChainBlockNumber { foundMultipleInBlock = true break } diff --git a/system_tests/meaningless_reorg_test.go b/system_tests/meaningless_reorg_test.go index 31e20a67e2..851bf38ce0 100644 --- a/system_tests/meaningless_reorg_test.go +++ b/system_tests/meaningless_reorg_test.go @@ -49,8 +49,8 @@ func TestMeaninglessBatchReorg(t *testing.T) { metadata, err := arbNode.InboxTracker.GetBatchMetadata(1) Require(t, err) originalBatchBlock := batchReceipt.BlockNumber.Uint64() - if metadata.L1Block != originalBatchBlock { - Fatal(t, "Posted batch in block", originalBatchBlock, "but metadata says L1 block was", metadata.L1Block) + if metadata.ParentChainBlock != originalBatchBlock { + Fatal(t, "Posted batch in block", originalBatchBlock, "but metadata says L1 block was", metadata.ParentChainBlock) } _, l2Receipt := TransferBalance(t, "Owner", "Owner", common.Big1, l2Info, l2Client, ctx) @@ -88,10 +88,10 @@ func TestMeaninglessBatchReorg(t *testing.T) { } metadata, err = arbNode.InboxTracker.GetBatchMetadata(1) Require(t, err) - if metadata.L1Block == newBatchBlock { + if metadata.ParentChainBlock == newBatchBlock { break - } else if metadata.L1Block != originalBatchBlock { - Fatal(t, "Batch L1 block changed from", originalBatchBlock, "to", metadata.L1Block, "instead of expected", metadata.L1Block) + } else if metadata.ParentChainBlock != originalBatchBlock { + Fatal(t, "Batch L1 block changed from", originalBatchBlock, "to", metadata.ParentChainBlock, "instead of expected", metadata.ParentChainBlock) } time.Sleep(10 * time.Millisecond) } diff --git a/util/headerreader/header_reader.go b/util/headerreader/header_reader.go index 9fc563c194..f25fed02d9 100644 --- a/util/headerreader/header_reader.go +++ b/util/headerreader/header_reader.go @@ -380,6 +380,19 @@ func (s *HeaderReader) LastPendingCallBlockNr() uint64 { var ErrBlockNumberNotSupported = errors.New("block number not supported") +func headerIndicatesFinalitySupport(header *types.Header) bool { + if header.Difficulty.Sign() == 0 { + // This is an Ethereum PoS chain + return true + } + if types.DeserializeHeaderExtraInformation(header).ArbOSFormatVersion > 0 { + // This is an Arbitrum chain + return true + } + // This is probably an Ethereum PoW or Clique chain, which doesn't support finality + return false +} + func (s *HeaderReader) getCached(ctx context.Context, c *cachedBlockNumber) (uint64, error) { c.mutex.Lock() defer c.mutex.Unlock() @@ -390,7 +403,7 @@ func (s *HeaderReader) getCached(ctx context.Context, c *cachedBlockNumber) (uin if currentHead == c.headWhenCached { return c.blockNumber, nil } - if !s.config().UseFinalityData || currentHead.Difficulty.Sign() != 0 { + if !s.config().UseFinalityData || !headerIndicatesFinalitySupport(currentHead) { return 0, ErrBlockNumberNotSupported } header, err := s.client.HeaderByNumber(ctx, c.rpcBlockNum)