From f31cbcbe4d7031bd0a7bf433bddff7d5fb47cf0d Mon Sep 17 00:00:00 2001 From: Enrique Avila Date: Wed, 16 Mar 2022 17:55:46 +0000 Subject: [PATCH] enabling apis for merge if chainConfig has TTD --- cmd/rpcdaemon/cli/config.go | 65 +++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index f0ab51e13e9..cef0292be65 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -287,26 +287,57 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger, } log.Info("if you run RPCDaemon on same machine with Erigon add --datadir option") } + var cc *params.ChainConfig + if err := db.View(context.Background(), func(tx kv.Tx) error { + genesisBlock, err := rawdb.ReadBlockByNumber(tx, 0) + if err != nil { + return err + } + cc, err = rawdb.ReadChainConfig(tx, genesisBlock.Hash()) + if err != nil { + return err + } + return nil + }); err != nil { + return nil, nil, nil, nil, nil, nil, nil, nil, ff, err + } + if cc == nil { + return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("chain config not found in db. Need start erigon at least once on this db") + } + + // if chain config has terminal total difficulty then rpc has to have these API's to function + if cc.TerminalTotalDifficulty != nil { + hasEthApiEnabled := false + hasEngineApiEnabled := false + hasNetApiEnabled := false + + for _, api := range cfg.API { + switch api { + case "eth": + hasEthApiEnabled = true + case "engine": + hasEngineApiEnabled = true + case "net": + hasNetApiEnabled = true + } + } + + if !hasEthApiEnabled { + cfg.API = append(cfg.API, "eth") + } + + if !hasEngineApiEnabled { + cfg.API = append(cfg.API, "engine") + } + + if !hasNetApiEnabled { + cfg.API = append(cfg.API, "net") + } + + } if cfg.SingleNodeMode { if cfg.Snapshot.Enabled { - var cc *params.ChainConfig - if err := db.View(context.Background(), func(tx kv.Tx) error { - genesisBlock, err := rawdb.ReadBlockByNumber(tx, 0) - if err != nil { - return err - } - cc, err = rawdb.ReadChainConfig(tx, genesisBlock.Hash()) - if err != nil { - return err - } - return nil - }); err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, ff, err - } - if cc == nil { - return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("chain config not found in db. Need start erigon at least once on this db") - } allSnapshots := snapshotsync.NewRoSnapshots(cfg.Snapshot, filepath.Join(cfg.DataDir, "snapshots")) allSnapshots.AsyncOpenAll(ctx)