• Joshua Gutow's avatar
    Eager Batch Derivation (#2882) · 0fea4f52
    Joshua Gutow authored
    * Eager Batch Derivation
    
    Does the following:
    - Split the batch queue into a batch queue & payload attributes queue
    - Change batch derivation rules to enable eager batch derivation
    - Eagerly create payload attributes
    
    * Cleanup inclusion block
    
    * Batch Queue: Add tests
    
    Only for the batch queue & not the attributes queue.
    
    * Fix lint + go mod tidy
    
    * backport fixes from attributes-cleanup
    
    * Update op-node/rollup/derive/batch_queue.go
    Co-authored-by: default avatarDiederik Loerakker <proto@protolambda.com>
    
    * address PR comments
    
    * revert testlog
    
    * use timestamp as RNG seed
    
    * explain anti overflow check
    
    * fix lint
    
    * better logging
    
    * only adjust maxL2Time based on minL2Time when epoch is not already started (#2939)
    Co-authored-by: default avatarDiederik Loerakker <proto@protolambda.com>
    Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
    0fea4f52
progress.go 1.29 KB
package derive

import (
	"errors"
	"fmt"

	"github.com/ethereum-optimism/optimism/op-node/eth"
)

var ReorgErr = errors.New("reorg")

// Progress represents the progress of a derivation stage:
// the input L1 block that is being processed, and whether it's fully processed yet.
type Progress struct {
	Origin eth.L1BlockRef
	// Closed means that the Current has no more data that the stage may need.
	Closed bool
}

func (pr *Progress) Update(outer Progress) (changed bool, err error) {
	if outer.Origin.Number < pr.Origin.Number {
		return false, nil
	}
	if pr.Closed {
		if outer.Closed {
			if pr.Origin.ID() != outer.Origin.ID() {
				return true, fmt.Errorf("outer stage changed origin from %s to %s without opening it", pr.Origin, outer.Origin)
			}
			return false, nil
		} else {
			if pr.Origin.Hash != outer.Origin.ParentHash {
				return true, fmt.Errorf("detected internal pipeline reorg of L1 origin data from %s to %s: %w", pr.Origin, outer.Origin, ReorgErr)
			}
			pr.Origin = outer.Origin
			pr.Closed = false
			return true, nil
		}
	} else {
		if pr.Origin.ID() != outer.Origin.ID() {
			return true, fmt.Errorf("outer stage changed origin from %s to %s before closing it", pr.Origin, outer.Origin)
		}
		if outer.Closed {
			pr.Closed = true
			return true, nil
		} else {
			return false, nil
		}
	}
}