github.com/ethereum-optimism/optimism@v1.7.2/op-node/rollup/sync/config.go (about)

     1  package sync
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type Mode int
     9  
    10  // There are two kinds of sync mode that the op-node does:
    11  //  1. In consensus-layer (CL) sync, the op-node fully drives the execution client and imports unsafe blocks &
    12  //     fetches unsafe blocks that it has missed.
    13  //  2. In execution-layer (EL) sync, the op-node tells the execution client to sync towards the tip of the chain.
    14  //     It will consolidate the chain as usual. This allows execution clients to snap sync if they are capable of it.
    15  const (
    16  	CLSync Mode = iota
    17  	ELSync Mode = iota
    18  )
    19  
    20  const (
    21  	CLSyncString string = "consensus-layer"
    22  	ELSyncString string = "execution-layer"
    23  )
    24  
    25  var Modes = []Mode{CLSync, ELSync}
    26  var ModeStrings = []string{CLSyncString, ELSyncString}
    27  
    28  func StringToMode(s string) (Mode, error) {
    29  	switch strings.ToLower(s) {
    30  	case CLSyncString:
    31  		return CLSync, nil
    32  	case ELSyncString:
    33  		return ELSync, nil
    34  	default:
    35  		return 0, fmt.Errorf("unknown sync mode: %s", s)
    36  	}
    37  }
    38  
    39  func (m Mode) String() string {
    40  	switch m {
    41  	case CLSync:
    42  		return CLSyncString
    43  	case ELSync:
    44  		return ELSyncString
    45  	default:
    46  		return "unknown"
    47  	}
    48  }
    49  
    50  func (m *Mode) Set(value string) error {
    51  	v, err := StringToMode(value)
    52  	if err != nil {
    53  		return err
    54  	}
    55  	*m = v
    56  	return nil
    57  }
    58  
    59  func (m *Mode) Clone() any {
    60  	cpy := *m
    61  	return &cpy
    62  }
    63  
    64  type Config struct {
    65  	// SyncMode is defined above.
    66  	SyncMode Mode `json:"syncmode"`
    67  	// SkipSyncStartCheck skip the sanity check of consistency of L1 origins of the unsafe L2 blocks when determining the sync-starting point.
    68  	// This defers the L1-origin verification, and is recommended to use in when utilizing --syncmode=execution-layer on op-node and --syncmode=snap on op-geth
    69  	// Warning: This will be removed when we implement proper checkpoints.
    70  	// Note: We probably need to detect the condition that snap sync has not complete when we do a restart prior to running sync-start if we are doing
    71  	// snap sync with a genesis finalization data.
    72  	SkipSyncStartCheck bool `json:"skip_sync_start_check"`
    73  }