• Mark Tyneway's avatar
    Refactor the SyncService to more closely implement the specification (#552) · a25acbbd
    Mark Tyneway authored
    * l2geth: add Backend enums and config parsing
    
    * l2geth: move OVMContext to types file
    
    * l2geth: implement syncservice spec
    
    * l2geth: fix error handling for get tx batch
    
    * l2geth: update tests to compile and pass
    
    * l2geth: add sync range functions
    
    * l2geth: add batch index indexing
    
    * l2geth: update syncservice hot path logging
    
    * l2geth: use indexed batch index
    
    * chore: add changeset
    
    * l2geth: sync spec refactor (#822)
    
    * l2geth: more in depth usage string
    
    * l2geth: add standard client getters for index
    
    * l2geth: refactor sync service into shared codepaths
    
    * l2geth: clean up tests
    
    * l2geth: better logging and error handling
    
    * test: improve test coverage around timestamps
    
    * l2geth: improve docstring
    
    * l2geth: rename variable
    
    * sync-service: better logline
    
    * l2geth: better logline
    
    * l2geth: test apply indexed transaction
    
    * l2geth: better logline
    
    * linting: fix
    
    * syncservice: fix logline
    
    * l2geth: add error and fix logline
    
    * l2geth: sync service tests
    
    * fix: get last confirmed enqueue (#846)
    
    * l2geth: fix get last confirmed enqueue
    
    * chore: add changeset
    
    * client: return error correctly
    
    * batch-submitter: updated config (#847)
    
    * batch-submitter: backwards compatible configuration
    
    * chore: add changeset
    
    * deps: update
    
    * js: move bcfg interface to core-utils
    
    * batch-submitter: parse USE_SENTRY and add to env example
    
    * chore: add changeset
    
    * batch-submitter: parse as float instead of int
    
    * batch-submitter: better error logging
    
    * l2geth: update rawdb logline
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    
    * l2geth: more robust testing
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    
    * l2geth: add sanity check for L1ToL2 timestamps
    
    * l2geth: handle error in single place
    
    * l2geth: fix test tx queue origin
    
    * l2geth: add new arg to start.sh
    
    * l2geth: return error in the SyncService.Start()
    
    * chore: go fmt
    Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
    a25acbbd
types.go 2.27 KB
package rollup

import (
	"bytes"
	"fmt"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
)

// OVMContext represents the blocknumber and timestamp
// that exist during L2 execution
type OVMContext struct {
	blockNumber uint64
	timestamp   uint64
}

// Backend represents the type of transactions that are being synced.
// The different types have different security models.
type Backend uint

// String implements the Stringer interface
func (s Backend) String() string {
	switch s {
	case BackendL1:
		return "l1"
	case BackendL2:
		return "l2"
	default:
		return ""
	}
}

// NewBackend creates a Backend from a human readable string
func NewBackend(typ string) (Backend, error) {
	switch typ {
	case "l1":
		return BackendL1, nil
	case "l2":
		return BackendL2, nil
	default:
		return 0, fmt.Errorf("Unknown Backend: %s", typ)
	}
}

const (
	// BackendL1 Backend involves syncing transactions that have been batched to
	// Layer One. Once the transactions have been batched to L1, they cannot be
	// removed assuming that they are not reorganized out of the chain.
	BackendL1 Backend = iota
	// BackendL2 Backend involves syncing transactions from the sequencer,
	// meaning that the transactions may have not been batched to Layer One yet.
	// This gives higher latency access to the sequencer data but no guarantees
	// around the transactions as they have not been submitted via a batch to
	// L1.
	BackendL2
)

func isCtcTxEqual(a, b *types.Transaction) bool {
	if a.To() == nil && b.To() != nil {
		if !bytes.Equal(b.To().Bytes(), common.Address{}.Bytes()) {
			return false
		}
	}
	if a.To() != nil && b.To() == nil {
		if !bytes.Equal(a.To().Bytes(), common.Address{}.Bytes()) {
			return false
		}
		return false
	}
	if a.To() != nil && b.To() != nil {
		if !bytes.Equal(a.To().Bytes(), b.To().Bytes()) {
			return false
		}
	}
	if !bytes.Equal(a.Data(), b.Data()) {
		return false
	}
	if a.L1MessageSender() == nil && b.L1MessageSender() != nil {
		return false
	}
	if a.L1MessageSender() != nil && b.L1MessageSender() == nil {
		return false
	}
	if a.L1MessageSender() != nil && b.L1MessageSender() != nil {
		if !bytes.Equal(a.L1MessageSender().Bytes(), b.L1MessageSender().Bytes()) {
			return false
		}
	}
	if a.Gas() != b.Gas() {
		return false
	}
	return true
}