Skip to content

Commit

Permalink
Fix for incorrectly chained rollups. (ten-protocol#1305)
Browse files Browse the repository at this point in the history
Co-authored-by: StefanIliev545 <[email protected]>
  • Loading branch information
StefanIliev545 and StefanIliev545 authored May 30, 2023
1 parent 46a2e08 commit 37adab1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions go/enclave/components/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package components

import (
"errors"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -15,6 +17,8 @@ const (
SubscriptionChannelBuffer = 10
)

var ErrDuplicateRollup = errors.New("duplicate rollup received")

type BlockIngestionType struct {
// IsLatest is true if this block was the canonical head of the L1 chain at the time it was submitted to enclave
// (if false then we are behind and catching up, expect to be fed another block immediately afterwards)
Expand Down
22 changes: 22 additions & 0 deletions go/enclave/components/rollup_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,32 @@ func (rc *rollupConsumerImpl) checkRollupsCorrectlyChained(rollup *core.Rollup,
// genesis rollup has no previous rollup to check
return nil
}

if rollup.Hash() == previousRollup.Hash() {
return fmt.Errorf("rollup already processed")
}

if rollup.NumberU64()-previousRollup.NumberU64() > 1 {
return fmt.Errorf("found gap in rollups between rollup %d and rollup %d",
previousRollup.NumberU64(), rollup.NumberU64())
}

// In case we have published two rollups for the same height
// This can happen when the first one takes too long to mine
if rollup.NumberU64() == previousRollup.NumberU64() {
if len(previousRollup.Batches) > len(rollup.Batches) {
return fmt.Errorf("received duplicate rollup at height %d with less batches than previous rollup", rollup.NumberU64())
}

for idx, batch := range previousRollup.Batches {
if rollup.Batches[idx].Hash() != batch.Hash() {
return fmt.Errorf("duplicate rollup at height %d has different batches at position %d", rollup.NumberU64(), idx)
}
}

return ErrDuplicateRollup
}

if rollup.NumberU64() <= previousRollup.NumberU64() {
return fmt.Errorf("expected new rollup but rollup %d height was less than or equal to previous rollup %d",
rollup.NumberU64(), previousRollup.NumberU64())
Expand Down
3 changes: 2 additions & 1 deletion go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ func (s *sequencer) ReceiveBlock(br *common.BlockAndReceipts, isLatest bool) (*c
return nil, err
}

if _, err = s.rollupConsumer.ProcessL1Block(br); err != nil {
_, err = s.rollupConsumer.ProcessL1Block(br)
if err != nil && !errors.Is(err, components.ErrDuplicateRollup) {
s.logger.Error("Encountered error while processing l1 block", log.ErrKey, err)
// Unsure what to do here; block has been stored
}
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/nodetype/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (val *obsValidator) ReceiveBlock(br *common.BlockAndReceipts, isLatest bool
}

rollup, err := val.rollupConsumer.ProcessL1Block(br)
if err != nil {
if err != nil && !errors.Is(err, components.ErrDuplicateRollup) {
// todo - log err?
val.logger.Error("Encountered error processing l1 block", log.ErrKey, err)
return ingestion, nil
Expand Down

0 comments on commit 37adab1

Please sign in to comment.