Skip to content

Commit

Permalink
Miscellaneous L3 timing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Jun 23, 2023
1 parent 7c6240e commit 1411c8f
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 124 deletions.
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
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
26 changes: 13 additions & 13 deletions staker/l1_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 1411c8f

Please sign in to comment.