Skip to content

Commit

Permalink
feat:Remove mandatory dependency on op-geth
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Jul 31, 2023
1 parent df22ce9 commit 02e0dd5
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
18 changes: 16 additions & 2 deletions op-node/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ func RollupNodeMain(ctx *cli.Context) error {
n, err := node.New(context.Background(), cfg, log, snapshotLog, VersionWithMeta, m)
if err != nil {
log.Error("Unable to create the rollup node", "error", err)
stateFile := ctx.String(flags.RPCAdminPersistence.Name)
if stateFile == "" {
//Modify admin_status does not depend on other business
log.Info("start abnormal_api because create the rollup node error ")
if err := n.InitAbnormalRPCServer(context.Background(), cfg); err != nil {
log.Error("Unable to abnormal rpc Server", "error", err)
return err
}
interruptNotify()
return nil
}
return err
}
log.Info("Starting rollup node", "version", VersionWithMeta)
Expand Down Expand Up @@ -162,6 +173,11 @@ func RollupNodeMain(ctx *cli.Context) error {
defer pprofCancel()
}

interruptNotify()
return nil
}

func interruptNotify() {
interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, []os.Signal{
os.Interrupt,
Expand All @@ -171,6 +187,4 @@ func RollupNodeMain(ctx *cli.Context) error {
}...)
<-interruptChannel

return nil

}
45 changes: 45 additions & 0 deletions op-node/node/abnormal_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package node

import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
)

type abnormalAPI struct {
ConfigPersistence ConfigPersistence
}

func NewAbnormalAPI(ConfigPersistence ConfigPersistence) *abnormalAPI {
return &abnormalAPI{
ConfigPersistence: ConfigPersistence,
}
}

func (n *abnormalAPI) ResetDerivationPipeline(ctx context.Context) error {
return nil
}

func (n *abnormalAPI) StartSequencer(ctx context.Context, blockHash common.Hash) error {
return errors.New("sequencer not running")
}

func (n *abnormalAPI) StopSequencer(ctx context.Context) (common.Hash, error) {
if err := n.ConfigPersistence.SequencerStopped(); err != nil {
return common.Hash{}, errors.New("SequencerStopped error")
}
return common.Hash{}, nil
}

func (n *abnormalAPI) SequencerActive(ctx context.Context) (bool, error) {
if state, err := n.ConfigPersistence.SequencerState(); err != nil {
return false, errors.New("SequencerStopped error")
} else if state != StateStarted {
return false, nil
}
return true, nil
}

func (n *abnormalAPI) AbnormalAPI(ctx context.Context) (bool, error) {
return true, nil
}
17 changes: 17 additions & 0 deletions op-node/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ func (n *OpNode) initRPCServer(ctx context.Context, cfg *Config) error {
return nil
}

func (n *OpNode) InitAbnormalRPCServer(ctx context.Context, cfg *Config) error {
server, err := newPureRPCServer(ctx, &cfg.RPC, n.log, n.appVersion)
if err != nil {
return err
}
if cfg.RPC.EnableAdmin {
server.EnableAbnormalAPI(NewAbnormalAPI(cfg.ConfigPersistence))
n.log.Info("Admin RPC enabled")
}
n.log.Info("Starting JSON-RPC server")
if err := server.Start(); err != nil {
return fmt.Errorf("unable to start RPC server: %w", err)
}
n.server = server
return nil
}

func (n *OpNode) initMetricsServer(ctx context.Context, cfg *Config) error {
if !cfg.Metrics.Enabled {
n.log.Info("metrics disabled")
Expand Down
19 changes: 19 additions & 0 deletions op-node/node/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ type rpcServer struct {
sources.L2Client
}

func newPureRPCServer(ctx context.Context, rpcCfg *RPCConfig, log log.Logger, appVersion string) (*rpcServer, error) {
// TODO: extend RPC config with options for WS, IPC and HTTP RPC connections
endpoint := net.JoinHostPort(rpcCfg.ListenAddr, strconv.Itoa(rpcCfg.ListenPort))
r := &rpcServer{
endpoint: endpoint,
appVersion: appVersion,
log: log,
}
return r, nil
}

func newRPCServer(ctx context.Context, rpcCfg *RPCConfig, rollupCfg *rollup.Config, l2Client l2EthClient, dr driverClient, log log.Logger, appVersion string, m metrics.Metricer) (*rpcServer, error) {
api := NewNodeAPI(rollupCfg, l2Client, dr, log.New("rpc", "node"), m)
// TODO: extend RPC config with options for WS, IPC and HTTP RPC connections
Expand All @@ -53,6 +64,14 @@ func (s *rpcServer) EnableAdminAPI(api *adminAPI) {
Authenticated: false,
})
}
func (s *rpcServer) EnableAbnormalAPI(api *abnormalAPI) {
s.apis = append(s.apis, rpc.API{
Namespace: "admin",
Version: "",
Service: api,
Authenticated: false,
})
}

func (s *rpcServer) EnableP2P(backend *p2p.APIBackend) {
s.apis = append(s.apis, rpc.API{
Expand Down

0 comments on commit 02e0dd5

Please sign in to comment.