Skip to content

Commit

Permalink
check mainnet genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Sep 24, 2024
1 parent 15bfb63 commit 44185aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
6 changes: 4 additions & 2 deletions cmd/XDC/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/XDCx"
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
"github.com/XinFinOrg/XDPoSChain/internal/debug"
"github.com/XinFinOrg/XDPoSChain/log"
Expand Down Expand Up @@ -246,14 +247,15 @@ func makeFullNode(ctx *cli.Context) (*node.Node, XDCConfig) {
// Register XDCX's OrderBook service if requested.
// enable in default
utils.RegisterXDCXService(stack, &cfg.XDCX)
utils.RegisterEthService(stack, &cfg.Eth)
eth := utils.RegisterEthService(stack, &cfg.Eth)

// Warn users to migrate if they have a legacy freezer format.
if eth != nil {
firstIdx := uint64(0)
// Hack to speed up check for mainnet because we know
// the first non-empty block.
if ctx.GlobalIsSet(utils.MainnetFlag.Name) {
ghash := core.GetCanonicalHash(eth.ChainDb(), 0)
if cfg.Eth.NetworkId == 1 && ghash == params.MainnetGenesisHash {
firstIdx = 46147
}
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx)
Expand Down
35 changes: 21 additions & 14 deletions cmd/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,36 @@ import (
)

// RegisterEthService adds an Ethereum client to the stack.
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) {
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) *eth.Ethereum {
var err error
if cfg.SyncMode == downloader.LightSync {
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, cfg)
})
} else {
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
var XDCXServ *XDCx.XDCX
ctx.Service(&XDCXServ)
var lendingServ *XDCxlending.Lending
ctx.Service(&lendingServ)
fullNode, err := eth.New(ctx, cfg, XDCXServ, lendingServ)
if fullNode != nil && cfg.LightServ > 0 {
ls, _ := les.NewLesServer(fullNode, cfg)
fullNode.AddLesServer(ls)
}
return fullNode, err
})
if err != nil {
Fatalf("Failed to register the Ethereum service: %v", err)
}
return nil
}
var backend *eth.Ethereum
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
var XDCXServ *XDCx.XDCX
ctx.Service(&XDCXServ)
var lendingServ *XDCxlending.Lending
ctx.Service(&lendingServ)
fullNode, err := eth.New(ctx, cfg, XDCXServ, lendingServ)
if fullNode != nil && cfg.LightServ > 0 {
ls, _ := les.NewLesServer(fullNode, cfg)
fullNode.AddLesServer(ls)
}
backend = fullNode
return fullNode, err
})

if err != nil {
Fatalf("Failed to register the Ethereum service: %v", err)
}
return backend
}

// RegisterShhService configures Whisper and adds it to the given node.
Expand Down
23 changes: 23 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ func (n *Node) Start() error {
return nil
}

// Close stops the Node and releases resources acquired in
// Node constructor New.
func (n *Node) Close() error {
var errs []error

// Terminate all subsystems and collect any errors
if err := n.Stop(); err != nil && err != ErrNodeStopped {
errs = append(errs, err)
}
if err := n.accman.Close(); err != nil {
errs = append(errs, err)
}
// Report any errors that might have occurred
switch len(errs) {
case 0:
return nil
case 1:
return errs[0]
default:
return fmt.Errorf("%v", errs)
}
}

func (n *Node) openDataDir() error {
if n.config.DataDir == "" {
return nil // ephemeral
Expand Down

0 comments on commit 44185aa

Please sign in to comment.