github.com/ethereum-optimism/optimism/l2geth@v0.0.0-20230612200230-50b04ade19e3/rollup/types.go (about)

     1  package rollup
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/ethereum-optimism/optimism/l2geth/common"
     8  	"github.com/ethereum-optimism/optimism/l2geth/core/types"
     9  )
    10  
    11  // OVMContext represents the blocknumber and timestamp
    12  // that exist during L2 execution
    13  type OVMContext struct {
    14  	blockNumber uint64
    15  	timestamp   uint64
    16  }
    17  
    18  // Backend represents the type of transactions that are being synced.
    19  // The different types have different security models.
    20  type Backend uint
    21  
    22  // String implements the Stringer interface
    23  func (s Backend) String() string {
    24  	switch s {
    25  	case BackendL1:
    26  		return "l1"
    27  	case BackendL2:
    28  		return "l2"
    29  	default:
    30  		return ""
    31  	}
    32  }
    33  
    34  // NewBackend creates a Backend from a human readable string
    35  func NewBackend(typ string) (Backend, error) {
    36  	switch typ {
    37  	case "l1":
    38  		return BackendL1, nil
    39  	case "l2":
    40  		return BackendL2, nil
    41  	default:
    42  		return 0, fmt.Errorf("Unknown Backend: %s", typ)
    43  	}
    44  }
    45  
    46  const (
    47  	// BackendL1 Backend involves syncing transactions that have been batched to
    48  	// Layer One. Once the transactions have been batched to L1, they cannot be
    49  	// removed assuming that they are not reorganized out of the chain.
    50  	BackendL1 Backend = iota
    51  	// BackendL2 Backend involves syncing transactions from the sequencer,
    52  	// meaning that the transactions may have not been batched to Layer One yet.
    53  	// This gives higher latency access to the sequencer data but no guarantees
    54  	// around the transactions as they have not been submitted via a batch to
    55  	// L1.
    56  	BackendL2
    57  )
    58  
    59  func isCtcTxEqual(a, b *types.Transaction) bool {
    60  	if a.To() == nil && b.To() != nil {
    61  		if !bytes.Equal(b.To().Bytes(), common.Address{}.Bytes()) {
    62  			return false
    63  		}
    64  	}
    65  	if a.To() != nil && b.To() == nil {
    66  		if !bytes.Equal(a.To().Bytes(), common.Address{}.Bytes()) {
    67  			return false
    68  		}
    69  		return false
    70  	}
    71  	if a.To() != nil && b.To() != nil {
    72  		if !bytes.Equal(a.To().Bytes(), b.To().Bytes()) {
    73  			return false
    74  		}
    75  	}
    76  	if !bytes.Equal(a.Data(), b.Data()) {
    77  		return false
    78  	}
    79  	if a.L1MessageSender() == nil && b.L1MessageSender() != nil {
    80  		return false
    81  	}
    82  	if a.L1MessageSender() != nil && b.L1MessageSender() == nil {
    83  		return false
    84  	}
    85  	if a.L1MessageSender() != nil && b.L1MessageSender() != nil {
    86  		if !bytes.Equal(a.L1MessageSender().Bytes(), b.L1MessageSender().Bytes()) {
    87  			return false
    88  		}
    89  	}
    90  	if a.Gas() != b.Gas() {
    91  		return false
    92  	}
    93  	return true
    94  }