Skip to content

Commit f79cce5

Browse files
gballetmkalininfjl
authored
eth/catalyst: add catalyst API prototype (#22641)
This change adds the --catalyst flag, enabling an RPC API for eth2 integration. In this initial version, catalyst mode also disables all peer-to-peer networking. Co-authored-by: Mikhail Kalinin <noblesse.knight@gmail.com> Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent 4f3ba67 commit f79cce5

13 files changed

Lines changed: 823 additions & 12 deletions

File tree

‎cmd/geth/config.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"gopkg.in/urfave/cli.v1"
2929

3030
"github.com/ethereum/go-ethereum/cmd/utils"
31+
"github.com/ethereum/go-ethereum/eth/catalyst"
3132
"github.com/ethereum/go-ethereum/eth/ethconfig"
3233
"github.com/ethereum/go-ethereum/internal/ethapi"
3334
"github.com/ethereum/go-ethereum/metrics"
@@ -143,7 +144,17 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
143144
if ctx.GlobalIsSet(utils.OverrideBerlinFlag.Name) {
144145
cfg.Eth.OverrideBerlin = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideBerlinFlag.Name))
145146
}
146-
backend := utils.RegisterEthService(stack, &cfg.Eth)
147+
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
148+
149+
// Configure catalyst.
150+
if ctx.GlobalBool(utils.CatalystFlag.Name) {
151+
if eth == nil {
152+
utils.Fatalf("Catalyst does not work in light client mode.")
153+
}
154+
if err := catalyst.Register(stack, eth); err != nil {
155+
utils.Fatalf("%v", err)
156+
}
157+
}
147158

148159
// Configure GraphQL if requested
149160
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {

‎cmd/geth/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ var (
151151
utils.EVMInterpreterFlag,
152152
utils.MinerNotifyFullFlag,
153153
configFileFlag,
154+
utils.CatalystFlag,
154155
}
155156

156157
rpcFlags = []cli.Flag{

‎cmd/geth/usage.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
235235
utils.SnapshotFlag,
236236
utils.BloomFilterSizeFlag,
237237
cli.HelpFlag,
238+
utils.CatalystFlag,
238239
},
239240
},
240241
}

‎cmd/utils/flags.go‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,11 @@ var (
755755
Usage: "External EVM configuration (default = built-in interpreter)",
756756
Value: "",
757757
}
758+
759+
CatalystFlag = cli.BoolFlag{
760+
Name: "catalyst",
761+
Usage: "Catalyst mode (eth2 integration testing)",
762+
}
758763
)
759764

760765
// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1186,10 +1191,11 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
11861191
cfg.NetRestrict = list
11871192
}
11881193

1189-
if ctx.GlobalBool(DeveloperFlag.Name) {
1194+
if ctx.GlobalBool(DeveloperFlag.Name) || ctx.GlobalBool(CatalystFlag.Name) {
11901195
// --dev mode can't use p2p networking.
11911196
cfg.MaxPeers = 0
1192-
cfg.ListenAddr = ":0"
1197+
cfg.ListenAddr = ""
1198+
cfg.NoDial = true
11931199
cfg.NoDiscovery = true
11941200
cfg.DiscoveryV5 = false
11951201
}
@@ -1693,14 +1699,16 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
16931699
}
16941700

16951701
// RegisterEthService adds an Ethereum client to the stack.
1696-
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) ethapi.Backend {
1702+
// The second return value is the full node instance, which may be nil if the
1703+
// node is running as a light client.
1704+
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend, *eth.Ethereum) {
16971705
if cfg.SyncMode == downloader.LightSync {
16981706
backend, err := les.New(stack, cfg)
16991707
if err != nil {
17001708
Fatalf("Failed to register the Ethereum service: %v", err)
17011709
}
17021710
stack.RegisterAPIs(tracers.APIs(backend.ApiBackend))
1703-
return backend.ApiBackend
1711+
return backend.ApiBackend, nil
17041712
}
17051713
backend, err := eth.New(stack, cfg)
17061714
if err != nil {
@@ -1713,7 +1721,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) ethapi.Backend
17131721
}
17141722
}
17151723
stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
1716-
return backend.APIBackend
1724+
return backend.APIBackend, backend
17171725
}
17181726

17191727
// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to

‎consensus/ethash/consensus.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uin
315315
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
316316
next := new(big.Int).Add(parent.Number, big1)
317317
switch {
318+
case config.IsCatalyst(next):
319+
return big.NewInt(1)
318320
case config.IsMuirGlacier(next):
319321
return calcDifficultyEip2384(time, parent)
320322
case config.IsConstantinople(next):

‎core/blockchain.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,22 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
16931693
return n, err
16941694
}
16951695

1696+
// InsertChainWithoutSealVerification works exactly the same
1697+
// except for seal verification, seal verification is omitted
1698+
func (bc *BlockChain) InsertChainWithoutSealVerification(block *types.Block) (int, error) {
1699+
bc.blockProcFeed.Send(true)
1700+
defer bc.blockProcFeed.Send(false)
1701+
1702+
// Pre-checks passed, start the full block imports
1703+
bc.wg.Add(1)
1704+
bc.chainmu.Lock()
1705+
n, err := bc.insertChain(types.Blocks([]*types.Block{block}), false)
1706+
bc.chainmu.Unlock()
1707+
bc.wg.Done()
1708+
1709+
return n, err
1710+
}
1711+
16961712
// insertChain is the internal implementation of InsertChain, which assumes that
16971713
// 1) chains are contiguous, and 2) The chain mutex is held.
16981714
//

‎eth/backend.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
223223
}); err != nil {
224224
return nil, err
225225
}
226+
226227
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
227228
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
228229

0 commit comments

Comments
 (0)