Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-drinks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/l2geth": minor
---

Implement the SyncService spec
1 change: 1 addition & 0 deletions l2geth/cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ var (
utils.RollupEnableVerifierFlag,
utils.RollupAddressManagerOwnerAddressFlag,
utils.RollupTimstampRefreshFlag,
utils.RollupSyncTypeFlag,
utils.RollupPollIntervalFlag,
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
Expand Down
1 change: 1 addition & 0 deletions l2geth/cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupAddressManagerOwnerAddressFlag,
utils.RollupEnableVerifierFlag,
utils.RollupTimstampRefreshFlag,
utils.RollupSyncTypeFlag,
utils.RollupPollIntervalFlag,
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
Expand Down
14 changes: 14 additions & 0 deletions l2geth/cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,12 @@ var (
Value: time.Minute * 15,
EnvVar: "ROLLUP_TIMESTAMP_REFRESH",
}
RollupSyncTypeFlag = cli.StringFlag{
Name: "rollup.synctype",
Usage: "Transaction sync source",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Usage: "Transaction sync source",
Usage: "Transaction sync source (\"batched\" or \"sequenced\")",

Value: "batched",
EnvVar: "ROLLUP_SYNC_TYPE",
}
// Flag to enable verifier mode
RollupEnableVerifierFlag = cli.BoolFlag{
Name: "rollup.verifier",
Expand Down Expand Up @@ -1161,6 +1167,14 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
if ctx.GlobalIsSet(RollupL1GasPriceFlag.Name) {
cfg.L1GasPrice = GlobalBig(ctx, RollupL1GasPriceFlag.Name)
}
if ctx.GlobalIsSet(RollupSyncTypeFlag.Name) {
typ, err := rollup.NewSyncType(ctx.GlobalString(RollupSyncTypeFlag.Name))
if err != nil {
log.Error("Configured with unknown sync type")
typ, _ = rollup.NewSyncType("batched")
}
cfg.SyncType = typ
}
}

// setLes configures the les server and ultra light client settings from the command line flags.
Expand Down
19 changes: 19 additions & 0 deletions l2geth/core/rawdb/rollup_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,22 @@ func WriteHeadQueueIndex(db ethdb.KeyValueWriter, index uint64) {
log.Crit("Failed to store queue index", "err", err)
}
}

func ReadHeadVerifiedIndex(db ethdb.KeyValueReader) *uint64 {
data, _ := db.Get(headVerifiedIndexKey)
if len(data) == 0 {
return nil
}
ret := new(big.Int).SetBytes(data).Uint64()
return &ret
}

func WriteHeadVerifiedIndex(db ethdb.KeyValueWriter, index uint64) {
value := new(big.Int).SetUint64(index).Bytes()
if index == 0 {
value = []byte{0}
}
if err := db.Put(headVerifiedIndexKey, value); err != nil {
log.Crit("Failed to store verfied index", "err", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Suggested change
log.Crit("Failed to store verfied index", "err", err)
log.Crit("Failed to store verified index", "err", err)

}
}
4 changes: 3 additions & 1 deletion l2geth/core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ var (

// headIndexKey tracks the last processed ctc index
headIndexKey = []byte("LastIndex")
// headQueueIndexKey tracks th last processed queue index
// headQueueIndexKey tracks the last processed queue index
headQueueIndexKey = []byte("LastQueueIndex")
// headVerifiedIndexKey tracks the latest verified index
headVerifiedIndexKey = []byte("LastVerifiedIndex")

preimagePrefix = []byte("secure-key-") // preimagePrefix + hash -> preimage
configPrefix = []byte("ethereum-config-") // config prefix for the db
Expand Down
11 changes: 8 additions & 3 deletions l2geth/eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ func (b *EthAPIBackend) GetEthContext() (uint64, uint64) {
return bn, ts
}

func (b *EthAPIBackend) GetRollupContext() (uint64, uint64) {
func (b *EthAPIBackend) GetRollupContext() (uint64, uint64, uint64) {
i := uint64(0)
q := uint64(0)
v := uint64(0)
Comment thread
tynes marked this conversation as resolved.
index := b.eth.syncService.GetLatestIndex()
if index != nil {
i = *index
Expand All @@ -82,7 +83,11 @@ func (b *EthAPIBackend) GetRollupContext() (uint64, uint64) {
if queueIndex != nil {
q = *queueIndex
}
return i, q
verifiedIndex := b.eth.syncService.GetLatestVerifiedIndex()
if verifiedIndex != nil {
v = *verifiedIndex
}
return i, q, v
}

// ChainConfig returns the active chain configuration.
Expand Down Expand Up @@ -318,7 +323,7 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
return fmt.Errorf("Calldata cannot be larger than %d, sent %d", b.MaxCallDataSize, len(signedTx.Data()))
}
}
return b.eth.syncService.ApplyTransaction(signedTx)
return b.eth.syncService.ValidateAndApplySequencerTransaction(signedTx)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for the rename? Validation is something that every function should do anyway, don't think we should be explicitly saying it in the name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was copying the spec and there was strong opinions around naming the function that in the spec. I'm not super opinionated on this particular topic, but some functions assume validation has already happened

}
// OVM Disabled
return b.eth.txPool.AddLocal(signedTx)
Expand Down
1 change: 1 addition & 0 deletions l2geth/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883 h1:FSeK4fZCo
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jarcoal/httpmock v1.0.8 h1:8kI16SoO6LQKgPE7PvQuV+YuD/inwHd7fOOe2zMbo4k=
github.com/jarcoal/httpmock v1.0.8/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
17 changes: 12 additions & 5 deletions l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1913,9 +1913,15 @@ type EthContext struct {
BlockNumber uint64 `json:"blockNumber"`
Timestamp uint64 `json:"timestamp"`
}

// RollupContext represents the height of the rollup.
// Index is the last processed CanonicalTransactionChain index
// QueueIndex is the last processed `enqueue` index
// VerifiedIndex is the last processed CTC index that was batched
type RollupContext struct {
Index uint64 `json:"index"`
QueueIndex uint64 `json:"queueIndex"`
Index uint64 `json:"index"`
QueueIndex uint64 `json:"queueIndex"`
VerifiedIndex uint64 `json:"verifiedIndex"`
Comment thread
tynes marked this conversation as resolved.
Comment thread
tynes marked this conversation as resolved.
}

type rollupInfo struct {
Expand All @@ -1932,7 +1938,7 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo {
}
syncing := api.b.IsSyncing()
bn, ts := api.b.GetEthContext()
index, queueIndex := api.b.GetRollupContext()
index, queueIndex, verifiedIndex := api.b.GetRollupContext()

return rollupInfo{
Mode: mode,
Expand All @@ -1942,8 +1948,9 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo {
Timestamp: ts,
},
RollupContext: RollupContext{
Index: index,
QueueIndex: queueIndex,
Index: index,
QueueIndex: queueIndex,
VerifiedIndex: verifiedIndex,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion l2geth/internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Backend interface {
IsVerifier() bool
IsSyncing() bool
GetEthContext() (uint64, uint64)
GetRollupContext() (uint64, uint64)
GetRollupContext() (uint64, uint64, uint64)
GasLimit() uint64
GetDiff(*big.Int) (diffdb.Diff, error)
SuggestDataPrice(ctx context.Context) (*big.Int, error)
Expand Down
4 changes: 2 additions & 2 deletions l2geth/les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (b *LesApiBackend) GetEthContext() (uint64, uint64) {
return 0, 0
}

func (b *LesApiBackend) GetRollupContext() (uint64, uint64) {
return 0, 0
func (b *LesApiBackend) GetRollupContext() (uint64, uint64, uint64) {
return 0, 0, 0
}

func (b *LesApiBackend) IsSyncing() bool {
Expand Down
Loading