Skip to content

Commit

Permalink
Merge branch 'master' into upgrade/go-ethereum/v1.9.21-2021609142421
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardolyn committed Jun 15, 2021
2 parents 3f23db9 + c1d6176 commit d574312
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
utils.LegacyBootnodesV4Flag,
utils.LegacyBootnodesV5Flag,
utils.DataDirFlag,
utils.RaftLogDirFlag,
utils.AncientFlag,
utils.KeyStoreDirFlag,
utils.ExternalSignerFlag,
Expand Down
18 changes: 16 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ var (
Usage: "Data directory for the databases and keystore",
Value: DirectoryString(node.DefaultDataDir()),
}
RaftLogDirFlag = DirectoryFlag{
Name: "raftlogdir",
Usage: "Raft log directory for the raft-state, raft-snap and raft-wal folders",
Value: DirectoryString(node.DefaultDataDir()),
}
AncientFlag = DirectoryFlag{
Name: "datadir.ancient",
Usage: "Data directory for ancient chain segments (default = inside chaindata)",
Expand Down Expand Up @@ -1385,6 +1390,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
setWS(ctx, cfg)
setNodeUserIdent(ctx, cfg)
setDataDir(ctx, cfg)
setRaftLogDir(ctx, cfg)
setSmartCard(ctx, cfg)

if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
Expand Down Expand Up @@ -1461,6 +1467,14 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
}
}

func setRaftLogDir(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(RaftLogDirFlag.Name) {
cfg.RaftLogDir = ctx.GlobalString(RaftLogDirFlag.Name)
} else {
cfg.RaftLogDir = cfg.DataDir
}
}

// Quorum
//
// Read plugin settings from --plugins flag. Overwrite settings defined in --config if any
Expand Down Expand Up @@ -2006,7 +2020,7 @@ func RegisterPermissionService(stack *node.Node, useDns bool) {

func RegisterRaftService(stack *node.Node, ctx *cli.Context, nodeCfg *node.Config, ethService *eth.Ethereum) {
blockTimeMillis := ctx.GlobalInt(RaftBlockTimeFlag.Name)
datadir := ctx.GlobalString(DataDirFlag.Name)
raftLogDir := nodeCfg.RaftLogDir // default value is set either 'datadir' or 'raftlogdir'
joinExistingId := ctx.GlobalInt(RaftJoinExistingFlag.Name)
useDns := ctx.GlobalBool(RaftDNSEnabledFlag.Name)
raftPort := uint16(ctx.GlobalInt(RaftPortFlag.Name))
Expand Down Expand Up @@ -2044,7 +2058,7 @@ func RegisterRaftService(stack *node.Node, ctx *cli.Context, nodeCfg *node.Confi
}
}

_, err := raft.New(stack, ethService.BlockChain().Config(), myId, raftPort, joinExisting, blockTimeNanos, ethService, peers, datadir, useDns)
_, err := raft.New(stack, ethService.BlockChain().Config(), myId, raftPort, joinExisting, blockTimeNanos, ethService, peers, raftLogDir, useDns)
if err != nil {
Fatalf("raft: Failed to register the Raft service: %v", err)
}
Expand Down
4 changes: 4 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type Config struct {
// in memory.
DataDir string

// RaftLogDir is the file system folder the node use for raft-state, raft-snap and
// raft-wal folders.
RaftLogDir string

// Configuration of peer-to-peer networking.
P2P p2p.Config

Expand Down
4 changes: 2 additions & 2 deletions raft/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RaftService struct {
pendingLogsFeed *event.Feed
}

func New(stack *node.Node, chainConfig *params.ChainConfig, raftId, raftPort uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*enode.Node, datadir string, useDns bool) (*RaftService, error) {
func New(stack *node.Node, chainConfig *params.ChainConfig, raftId, raftPort uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*enode.Node, raftLogDir string, useDns bool) (*RaftService, error) {
service := &RaftService{
eventMux: stack.EventMux(),
chainDb: e.ChainDb(),
Expand All @@ -56,7 +56,7 @@ func New(stack *node.Node, chainConfig *params.ChainConfig, raftId, raftPort uin
service.minter = newMinter(chainConfig, service, blockTime)

var err error
if service.raftProtocolManager, err = NewProtocolManager(raftId, raftPort, service.blockchain, service.eventMux, startPeers, joinExisting, datadir, service.minter, service.downloader, useDns, stack.Server()); err != nil {
if service.raftProtocolManager, err = NewProtocolManager(raftId, raftPort, service.blockchain, service.eventMux, startPeers, joinExisting, raftLogDir, service.minter, service.downloader, useDns, stack.Server()); err != nil {
return nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions raft/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ var errNoLeaderElected = errors.New("no leader is currently elected")
// Public interface
//

func NewProtocolManager(raftId uint16, raftPort uint16, blockchain *core.BlockChain, mux *event.TypeMux, bootstrapNodes []*enode.Node, joinExisting bool, datadir string, minter *minter, downloader *downloader.Downloader, useDns bool, p2pServer *p2p.Server) (*ProtocolManager, error) {
waldir := fmt.Sprintf("%s/raft-wal", datadir)
snapdir := fmt.Sprintf("%s/raft-snap", datadir)
quorumRaftDbLoc := fmt.Sprintf("%s/quorum-raft-state", datadir)
func NewProtocolManager(raftId uint16, raftPort uint16, blockchain *core.BlockChain, mux *event.TypeMux, bootstrapNodes []*enode.Node, joinExisting bool, raftLogDir string, minter *minter, downloader *downloader.Downloader, useDns bool, p2pServer *p2p.Server) (*ProtocolManager, error) {
waldir := fmt.Sprintf("%s/raft-wal", raftLogDir)
snapdir := fmt.Sprintf("%s/raft-snap", raftLogDir)
quorumRaftDbLoc := fmt.Sprintf("%s/quorum-raft-state", raftLogDir)

manager := &ProtocolManager{
bootstrapNodes: bootstrapNodes,
Expand Down
4 changes: 2 additions & 2 deletions raft/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func prepareServiceContext(key *ecdsa.PrivateKey) (stack *node.Node, cfg *node.C
}

func startRaftNode(id, port uint16, tmpWorkingDir string, key *ecdsa.PrivateKey, nodes []*enode.Node) (*RaftService, error) {
datadir := fmt.Sprintf("%s/node%d", tmpWorkingDir, id)
raftlogdir := fmt.Sprintf("%s/node%d", tmpWorkingDir, id)

stack, _, err := prepareServiceContext(key)
if err != nil {
Expand All @@ -166,7 +166,7 @@ func startRaftNode(id, port uint16, tmpWorkingDir string, key *ecdsa.PrivateKey,
return nil, err
}

s, err := New(stack, params.QuorumTestChainConfig, id, port, false, 100*time.Millisecond, e, nodes, datadir, false)
s, err := New(stack, params.QuorumTestChainConfig, id, port, false, 100*time.Millisecond, e, nodes, raftlogdir, false)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d574312

Please sign in to comment.