-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface between batcher -> proposer to speed up proposals of sa…
…fe head
- Loading branch information
Showing
11 changed files
with
243 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package batcher | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ethereum-optimism/optimism/op-batcher/batcher" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" | ||
"github.com/ethereum-optimism/optimism/op-service/predeploys" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
var ErrWithdrawalDetected = errors.New("withdrawal detected") | ||
|
||
type ChannelOut interface { | ||
derive.ChannelOut | ||
Blocks() []*types.Block | ||
} | ||
|
||
func ChannelOutFactory(metricer Metricer) batcher.ChannelOutFactory { | ||
return func(cfg batcher.ChannelConfig, rollupCfg *rollup.Config) (derive.ChannelOut, error) { | ||
co, err := batcher.NewChannelOut(cfg, rollupCfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
wrapped := &channelOut{ | ||
ChannelOut: co, | ||
} | ||
metricer.RegisterChannel(wrapped) | ||
return wrapped, nil | ||
} | ||
} | ||
|
||
type channelOut struct { | ||
derive.ChannelOut | ||
fullErr error | ||
blocks []*types.Block | ||
} | ||
|
||
func (c *channelOut) Blocks() []*types.Block { | ||
return c.blocks | ||
} | ||
|
||
func (c *channelOut) AddBlock(config *rollup.Config, block *types.Block) (*derive.L1BlockInfo, error) { | ||
c.blocks = append(c.blocks, block) | ||
if block.Bloom().Test(predeploys.L2ToL1MessagePasserAddr.Bytes()) { | ||
c.fullErr = ErrWithdrawalDetected | ||
} | ||
return c.ChannelOut.AddBlock(config, block) | ||
} | ||
|
||
func (c *channelOut) FullErr() error { | ||
if c.fullErr != nil { | ||
return c.fullErr | ||
} | ||
return c.ChannelOut.FullErr() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package batcher | ||
|
||
import ( | ||
"github.com/ethereum-optimism/optimism/op-batcher/metrics" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
type Metricer interface { | ||
metrics.Metricer | ||
RegisterChannel(out ChannelOut) | ||
} | ||
|
||
type metricer struct { | ||
metrics.Metricer | ||
log log.Logger | ||
proposerClient *rpc.Client | ||
channels map[derive.ChannelID]ChannelOut | ||
} | ||
|
||
func NewMetricer(m metrics.Metricer, log log.Logger, proposerClient *rpc.Client) Metricer { | ||
return &metricer{ | ||
Metricer: m, | ||
log: log, | ||
proposerClient: proposerClient, | ||
channels: make(map[derive.ChannelID]ChannelOut), | ||
} | ||
} | ||
|
||
func (m *metricer) RegisterChannel(out ChannelOut) { | ||
m.channels[out.ID()] = out | ||
} | ||
|
||
func (m *metricer) RecordChannelFullySubmitted(id derive.ChannelID) { | ||
m.Metricer.RecordChannelFullySubmitted(id) | ||
|
||
channel, ok := m.channels[id] | ||
if !ok { | ||
return | ||
} | ||
delete(m.channels, id) | ||
var numbers []uint64 | ||
for _, b := range channel.Blocks() { | ||
numbers = append(numbers, b.NumberU64()) | ||
} | ||
if err := m.proposerClient.Call(nil, "admin_blocksBatched", numbers); err != nil { | ||
m.log.Error("failed to notify Proposer of batched blocks", "err", err) | ||
} | ||
} | ||
|
||
func (m *metricer) RecordChannelTimedOut(id derive.ChannelID) { | ||
m.Metricer.RecordChannelTimedOut(id) | ||
delete(m.channels, id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package flags | ||
|
||
import ( | ||
"github.com/ethereum-optimism/optimism/op-batcher/flags" | ||
opservice "github.com/ethereum-optimism/optimism/op-service" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func prefixEnvVar(name string) []string { | ||
return opservice.PrefixEnvVar(flags.EnvVarPrefix, name) | ||
} | ||
|
||
var ( | ||
ProposerRpcFlag = &cli.StringFlag{ | ||
Name: "proposer-rpc", | ||
Usage: "HTTP provider URL for the Proposer", | ||
EnvVars: prefixEnvVar("PROPOSER_RPC"), | ||
Required: true, | ||
} | ||
) | ||
|
||
var requiredFlags = []cli.Flag{ | ||
ProposerRpcFlag, | ||
} | ||
|
||
func init() { | ||
Flags = append(requiredFlags, flags.Flags...) | ||
} | ||
|
||
var Flags []cli.Flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package rpc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
gethrpc "github.com/ethereum/go-ethereum/rpc" | ||
|
||
"github.com/ethereum-optimism/optimism/op-service/metrics" | ||
"github.com/ethereum-optimism/optimism/op-service/rpc" | ||
) | ||
|
||
type ProposerDriver interface { | ||
BlocksBatched(numbers []uint64) error | ||
} | ||
|
||
type adminAPI struct { | ||
*rpc.CommonAdminAPI | ||
b ProposerDriver | ||
} | ||
|
||
func NewAdminAPI(dr ProposerDriver, m metrics.RPCMetricer, log log.Logger) gethrpc.API { | ||
return gethrpc.API{ | ||
Namespace: "admin", | ||
Service: &adminAPI{ | ||
CommonAdminAPI: rpc.NewCommonAdminAPI(m, log), | ||
b: dr, | ||
}, | ||
} | ||
} | ||
|
||
func (a *adminAPI) BlocksBatched(_ context.Context, numbers []uint64) error { | ||
return a.b.BlocksBatched(numbers) | ||
} |
Oops, something went wrong.