Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readonly mode #1355

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
1 change: 1 addition & 0 deletions l2geth/cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ var (
utils.RollupMaxCalldataSizeFlag,
utils.RollupBackendFlag,
utils.RollupEnforceFeesFlag,
utils.RollupReadOnlyFlag,
utils.RollupFeeThresholdDownFlag,
utils.RollupFeeThresholdUpFlag,
utils.SequencerClientHttpFlag,
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 @@ -78,6 +78,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupFeeThresholdDownFlag,
utils.RollupFeeThresholdUpFlag,
utils.SequencerClientHttpFlag,
utils.RollupReadOnlyFlag,
},
},
{
Expand Down
8 changes: 8 additions & 0 deletions l2geth/cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,11 @@ var (
Usage: "HTTP endpoint for the sequencer client",
EnvVar: "SEQUENCER_CLIENT_HTTP",
}
RollupReadOnlyFlag = cli.BoolFlag{
Name: "rollup.readonly",
Usage: "Enable read only mode",
EnvVar: "ROLLUP_READONLY",
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down Expand Up @@ -1149,6 +1154,9 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
if ctx.GlobalIsSet(SequencerClientHttpFlag.Name) {
cfg.SequencerClientHttp = ctx.GlobalString(SequencerClientHttpFlag.Name)
}
if ctx.GlobalIsSet(RollupReadOnlyFlag.Name) {
cfg.IsReadOnly = ctx.GlobalBool(RollupReadOnlyFlag.Name)
}
}

// setLes configures the les server and ultra light client settings from the command line flags.
Expand Down
5 changes: 5 additions & 0 deletions l2geth/eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type EthAPIBackend struct {
gpo *gasprice.Oracle
rollupGpo *gasprice.RollupOracle
verifier bool
readOnly bool
gasLimit uint64
UsingOVM bool
MaxCallDataSize int
Expand All @@ -57,6 +58,10 @@ func (b *EthAPIBackend) IsVerifier() bool {
return b.verifier
}

func (b *EthAPIBackend) IsReadOnly() bool {
return b.readOnly
}

func (b *EthAPIBackend) IsSyncing() bool {
return b.eth.syncService.IsSyncing()
}
Expand Down
2 changes: 1 addition & 1 deletion l2geth/eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", rcfg.UsingOVM)
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, rcfg.UsingOVM, config.Rollup.MaxCallDataSize}
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, nil, config.Rollup.IsVerifier, config.Rollup.IsReadOnly, config.Rollup.GasLimit, rcfg.UsingOVM, config.Rollup.MaxCallDataSize}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
Expand Down
11 changes: 7 additions & 4 deletions l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,10 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H
}

// GetBlockByNumber returns the requested canonical block.
// * When blockNr is -1 the chain head is returned.
// * When blockNr is -2 the pending chain head is returned.
// * When fullTx is true all transactions in the block are returned, otherwise
// only the transaction hash is returned.
// - When blockNr is -1 the chain head is returned.
// - When blockNr is -2 the pending chain head is returned.
// - When fullTx is true all transactions in the block are returned, otherwise
// only the transaction hash is returned.
func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
block, err := s.b.BlockByNumber(ctx, number)
if block != nil && err == nil {
Expand Down Expand Up @@ -1765,6 +1765,9 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
}

if s.b.IsVerifier() {
if s.b.IsReadOnly() {
return common.Hash{}, errors.New("Cannot send raw transaction in read-only mode")
}
sequencerURL := s.b.SequencerClientHttp()
if sequencerURL == "" {
return common.Hash{}, errNoSequencerURL
Expand Down
1 change: 1 addition & 0 deletions l2geth/internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Backend interface {

// Optimism-specific API
IsVerifier() bool
IsReadOnly() bool
IsSyncing() bool
GetEthContext() (uint64, uint64)
GetRollupContext() (uint64, uint64, uint64)
Expand Down
4 changes: 4 additions & 0 deletions l2geth/les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (b *LesApiBackend) IsVerifier() bool {
return false
}

func (b *LesApiBackend) IsReadOnly() bool {
return false
}

func (b *LesApiBackend) GasLimit() uint64 {
panic("not implemented")
}
Expand Down
2 changes: 2 additions & 0 deletions l2geth/rollup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ type Config struct {
FeeThresholdUp *big.Float
// HTTP endpoint of the sequencer
SequencerClientHttp string
// Only server the data reading requests
IsReadOnly bool
}
14 changes: 11 additions & 3 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type SyncService struct {
ctx context.Context
cancel context.CancelFunc
verifier bool
readOnly bool
db ethdb.Database
scope event.SubscriptionScope
txFeed event.Feed
Expand Down Expand Up @@ -127,6 +128,7 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
ctx: ctx,
cancel: cancel,
verifier: cfg.IsVerifier,
readOnly: cfg.IsReadOnly,
enable: cfg.Eth1SyncServiceEnable,
syncing: atomic.Value{},
bc: bc,
Expand Down Expand Up @@ -157,7 +159,7 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
// a remote server that indexes the layer one contracts. Place this
// code behind this if statement so that this can run without the
// requirement of the remote server being up.
if service.enable {
if service.enable && !cfg.IsReadOnly {
// Ensure that the rollup client can connect to a remote server
// before starting. Retry until it can connect.
tEnsure := time.NewTicker(10 * time.Second)
Expand Down Expand Up @@ -238,6 +240,12 @@ func (s *SyncService) Start() error {
log.Info("Running without syncing enabled")
return nil
}

if s.readOnly {
log.Info("Running in read only mode")
return nil
}

log.Info("Initializing Sync Service")
if err := s.updateGasPriceOracleCache(nil); err != nil {
return err
Expand Down Expand Up @@ -598,8 +606,8 @@ func (s *SyncService) GasPriceOracleOwnerAddress() *common.Address {
return &s.gasPriceOracleOwnerAddress
}

/// Update the execution context's timestamp and blocknumber
/// over time. This is only necessary for the sequencer.
// / Update the execution context's timestamp and blocknumber
// / over time. This is only necessary for the sequencer.
func (s *SyncService) updateL1BlockNumber() error {
context, err := s.client.GetLatestEthContext()
if err != nil {
Expand Down
Loading