diff --git a/arbnode/delayed_seq_reorg_test.go b/arbnode/delayed_seq_reorg_test.go deleted file mode 100644 index 699eb3e8f6..0000000000 --- a/arbnode/delayed_seq_reorg_test.go +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright 2021-2022, Offchain Labs, Inc. -// For license information, see https://github.com/nitro/blob/master/LICENSE - -package arbnode - -import ( - "context" - "encoding/binary" - "testing" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/offchainlabs/nitro/arbos/arbostypes" - "github.com/offchainlabs/nitro/solgen/go/bridgegen" -) - -func TestSequencerReorgFromDelayed(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - exec, streamer, db, _ := NewTransactionStreamerForTest(t, common.Address{}) - tracker, err := NewInboxTracker(db, streamer, nil, DefaultSnapSyncConfig) - Require(t, err) - - err = streamer.Start(ctx) - Require(t, err) - exec.Start(ctx) - init, err := streamer.GetMessage(0) - Require(t, err) - - initMsgDelayed := &DelayedInboxMessage{ - BlockHash: [32]byte{}, - BeforeInboxAcc: [32]byte{}, - Message: init.Message, - } - delayedRequestId := common.BigToHash(common.Big1) - userDelayed := &DelayedInboxMessage{ - BlockHash: [32]byte{}, - BeforeInboxAcc: initMsgDelayed.AfterInboxAcc(), - Message: &arbostypes.L1IncomingMessage{ - Header: &arbostypes.L1IncomingMessageHeader{ - Kind: arbostypes.L1MessageType_EndOfBlock, - Poster: [20]byte{}, - BlockNumber: 0, - Timestamp: 0, - RequestId: &delayedRequestId, - L1BaseFee: common.Big0, - }, - }, - } - err = tracker.AddDelayedMessages([]*DelayedInboxMessage{initMsgDelayed, userDelayed}, false) - Require(t, err) - - serializedInitMsgBatch := make([]byte, 40) - binary.BigEndian.PutUint64(serializedInitMsgBatch[32:], 1) - initMsgBatch := &SequencerInboxBatch{ - BlockHash: [32]byte{}, - ParentChainBlockNumber: 0, - SequenceNumber: 0, - BeforeInboxAcc: [32]byte{}, - AfterInboxAcc: [32]byte{1}, - AfterDelayedAcc: initMsgDelayed.AfterInboxAcc(), - AfterDelayedCount: 1, - TimeBounds: bridgegen.IBridgeTimeBounds{}, - 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{}, - ParentChainBlockNumber: 0, - SequenceNumber: 1, - BeforeInboxAcc: [32]byte{1}, - AfterInboxAcc: [32]byte{2}, - AfterDelayedAcc: userDelayed.AfterInboxAcc(), - AfterDelayedCount: 2, - TimeBounds: bridgegen.IBridgeTimeBounds{}, - rawLog: types.Log{}, - dataLocation: 0, - bridgeAddress: [20]byte{}, - serialized: serializedUserMsgBatch, - } - emptyBatch := &SequencerInboxBatch{ - BlockHash: [32]byte{}, - ParentChainBlockNumber: 0, - SequenceNumber: 2, - BeforeInboxAcc: [32]byte{2}, - AfterInboxAcc: [32]byte{3}, - AfterDelayedAcc: userDelayed.AfterInboxAcc(), - AfterDelayedCount: 2, - TimeBounds: bridgegen.IBridgeTimeBounds{}, - rawLog: types.Log{}, - dataLocation: 0, - bridgeAddress: [20]byte{}, - serialized: serializedUserMsgBatch, - } - err = tracker.AddSequencerBatches(ctx, nil, []*SequencerInboxBatch{initMsgBatch, userMsgBatch, emptyBatch}) - Require(t, err) - - // Reorg out the user delayed message - err = tracker.ReorgDelayedTo(1, true) - Require(t, err) - - msgCount, err := streamer.GetMessageCount() - Require(t, err) - if msgCount != 1 { - Fail(t, "Unexpected tx streamer message count", msgCount, "(expected 1)") - } - - delayedCount, err := tracker.GetDelayedCount() - Require(t, err) - if delayedCount != 1 { - Fail(t, "Unexpected tracker delayed message count", delayedCount, "(expected 1)") - } - - batchCount, err := tracker.GetBatchCount() - Require(t, err) - if batchCount != 1 { - Fail(t, "Unexpected tracker batch count", batchCount, "(expected 1)") - } - - emptyBatch = &SequencerInboxBatch{ - BlockHash: [32]byte{}, - ParentChainBlockNumber: 0, - SequenceNumber: 1, - BeforeInboxAcc: [32]byte{1}, - AfterInboxAcc: [32]byte{2}, - AfterDelayedAcc: initMsgDelayed.AfterInboxAcc(), - AfterDelayedCount: 1, - TimeBounds: bridgegen.IBridgeTimeBounds{}, - rawLog: types.Log{}, - dataLocation: 0, - bridgeAddress: [20]byte{}, - serialized: serializedInitMsgBatch, - } - err = tracker.AddSequencerBatches(ctx, nil, []*SequencerInboxBatch{emptyBatch}) - Require(t, err) - - msgCount, err = streamer.GetMessageCount() - Require(t, err) - if msgCount != 2 { - Fail(t, "Unexpected tx streamer message count", msgCount, "(expected 2)") - } - - batchCount, err = tracker.GetBatchCount() - Require(t, err) - if batchCount != 2 { - Fail(t, "Unexpected tracker batch count", batchCount, "(expected 2)") - } -} diff --git a/arbnode/inbox_reader.go b/arbnode/inbox_reader.go index 77a0b6e7a2..31b0a60fa7 100644 --- a/arbnode/inbox_reader.go +++ b/arbnode/inbox_reader.go @@ -26,7 +26,6 @@ import ( type InboxReaderConfig struct { DelayBlocks uint64 `koanf:"delay-blocks" reload:"hot"` CheckDelay time.Duration `koanf:"check-delay" reload:"hot"` - HardReorg bool `koanf:"hard-reorg" reload:"hot"` MinBlocksToRead uint64 `koanf:"min-blocks-to-read" reload:"hot"` DefaultBlocksToRead uint64 `koanf:"default-blocks-to-read" reload:"hot"` TargetMessagesRead uint64 `koanf:"target-messages-read" reload:"hot"` @@ -50,7 +49,6 @@ func (c *InboxReaderConfig) Validate() error { func InboxReaderConfigAddOptions(prefix string, f *flag.FlagSet) { f.Uint64(prefix+".delay-blocks", DefaultInboxReaderConfig.DelayBlocks, "number of latest blocks to ignore to reduce reorgs") f.Duration(prefix+".check-delay", DefaultInboxReaderConfig.CheckDelay, "the maximum time to wait between inbox checks (if not enough new blocks are found)") - f.Bool(prefix+".hard-reorg", DefaultInboxReaderConfig.HardReorg, "erase future transactions in addition to overwriting existing ones on reorg") f.Uint64(prefix+".min-blocks-to-read", DefaultInboxReaderConfig.MinBlocksToRead, "the minimum number of blocks to read at once (when caught up lowers load on L1)") f.Uint64(prefix+".default-blocks-to-read", DefaultInboxReaderConfig.DefaultBlocksToRead, "the default number of blocks to read at once (will vary based on traffic by default)") f.Uint64(prefix+".target-messages-read", DefaultInboxReaderConfig.TargetMessagesRead, "if adjust-blocks-to-read is enabled, the target number of messages to read at once") @@ -61,7 +59,6 @@ func InboxReaderConfigAddOptions(prefix string, f *flag.FlagSet) { var DefaultInboxReaderConfig = InboxReaderConfig{ DelayBlocks: 0, CheckDelay: time.Minute, - HardReorg: false, MinBlocksToRead: 1, DefaultBlocksToRead: 100, TargetMessagesRead: 500, @@ -72,7 +69,6 @@ var DefaultInboxReaderConfig = InboxReaderConfig{ var TestInboxReaderConfig = InboxReaderConfig{ DelayBlocks: 0, CheckDelay: time.Millisecond * 10, - HardReorg: false, MinBlocksToRead: 1, DefaultBlocksToRead: 100, TargetMessagesRead: 500, @@ -337,7 +333,7 @@ func (r *InboxReader) run(ctx context.Context, hadError bool) error { missingDelayed = true } else if ourLatestDelayedCount > checkingDelayedCount { log.Info("backwards reorg of delayed messages", "from", ourLatestDelayedCount, "to", checkingDelayedCount) - err = r.tracker.ReorgDelayedTo(checkingDelayedCount, config.HardReorg) + err = r.tracker.ReorgDelayedTo(checkingDelayedCount) if err != nil { return err } @@ -372,11 +368,6 @@ func (r *InboxReader) run(ctx context.Context, hadError bool) error { if ourLatestBatchCount < checkingBatchCount { checkingBatchCount = ourLatestBatchCount missingSequencer = true - } else if ourLatestBatchCount > checkingBatchCount && config.HardReorg { - err = r.tracker.ReorgBatchesTo(checkingBatchCount) - if err != nil { - return err - } } if checkingBatchCount > 0 { checkingBatchSeqNum := checkingBatchCount - 1 @@ -564,7 +555,7 @@ func (r *InboxReader) run(ctx context.Context, hadError bool) error { } func (r *InboxReader) addMessages(ctx context.Context, sequencerBatches []*SequencerInboxBatch, delayedMessages []*DelayedInboxMessage) (bool, error) { - err := r.tracker.AddDelayedMessages(delayedMessages, r.config().HardReorg) + err := r.tracker.AddDelayedMessages(delayedMessages) if err != nil { return false, err } diff --git a/arbnode/inbox_tracker.go b/arbnode/inbox_tracker.go index b621b12650..259286fa62 100644 --- a/arbnode/inbox_tracker.go +++ b/arbnode/inbox_tracker.go @@ -403,7 +403,7 @@ func (t *InboxTracker) GetDelayedMessageBytes(ctx context.Context, seqNum uint64 return msg.Serialize() } -func (t *InboxTracker) AddDelayedMessages(messages []*DelayedInboxMessage, hardReorg bool) error { +func (t *InboxTracker) AddDelayedMessages(messages []*DelayedInboxMessage) error { var nextAcc common.Hash firstDelayedMsgToKeep := uint64(0) if len(messages) == 0 { @@ -439,17 +439,15 @@ func (t *InboxTracker) AddDelayedMessages(messages []*DelayedInboxMessage, hardR t.mutex.Lock() defer t.mutex.Unlock() - if !hardReorg { - // This math is safe to do as we know len(messages) > 0 - haveLastAcc, err := t.GetDelayedAcc(pos + uint64(len(messages)) - 1) - if err == nil { - if haveLastAcc == messages[len(messages)-1].AfterInboxAcc() { - // We already have these delayed messages - return nil - } - } else if !errors.Is(err, AccumulatorNotFoundErr) { - return err + // This math is safe to do as we know len(messages) > 0 + haveLastAcc, err := t.GetDelayedAcc(pos + uint64(len(messages)) - 1) + if err == nil { + if haveLastAcc == messages[len(messages)-1].AfterInboxAcc() { + // We already have these delayed messages + return nil } + } else if !errors.Is(err, AccumulatorNotFoundErr) { + return err } if pos > firstDelayedMsgToKeep { @@ -848,7 +846,7 @@ func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client arbutil.L return nil } -func (t *InboxTracker) ReorgDelayedTo(count uint64, canReorgBatches bool) error { +func (t *InboxTracker) ReorgDelayedTo(count uint64) error { t.mutex.Lock() defer t.mutex.Unlock() @@ -863,7 +861,7 @@ func (t *InboxTracker) ReorgDelayedTo(count uint64, canReorgBatches bool) error return errors.New("attempted to reorg to future delayed count") } - return t.setDelayedCountReorgAndWriteBatch(t.db.NewBatch(), count, canReorgBatches) + return t.setDelayedCountReorgAndWriteBatch(t.db.NewBatch(), count, false) } func (t *InboxTracker) ReorgBatchesTo(count uint64) error { diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index 9861bb673e..fff218fc21 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -229,10 +229,6 @@ func mainImpl() int { nodeConfig.Node.ParentChainReader.Enable = true } - if nodeConfig.Execution.Sequencer.Enable && nodeConfig.Node.ParentChainReader.Enable && nodeConfig.Node.InboxReader.HardReorg { - flag.Usage() - log.Crit("hard reorgs cannot safely be enabled with sequencer mode enabled") - } if nodeConfig.Execution.Sequencer.Enable != nodeConfig.Node.Sequencer { log.Error("consensus and execution must agree if sequencing is enabled or not", "Execution.Sequencer.Enable", nodeConfig.Execution.Sequencer.Enable, "Node.Sequencer", nodeConfig.Node.Sequencer) } diff --git a/system_tests/seqinbox_test.go b/system_tests/seqinbox_test.go index 4dc8f4a664..a61c17046f 100644 --- a/system_tests/seqinbox_test.go +++ b/system_tests/seqinbox_test.go @@ -139,7 +139,6 @@ func testSequencerInboxReaderImpl(t *testing.T, validator bool) { defer cancel() builder := NewNodeBuilder(ctx).DefaultConfig(t, true) - builder.nodeConfig.InboxReader.HardReorg = true if validator { builder.nodeConfig.BlockValidator.Enable = true }