Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdn: impl msg specs, support block/vote biz logic #2940

Open
wants to merge 9 commits into
base: develop_vdn
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ It expects the genesis file as argument.`,
utils.InitVDNPort,
utils.InitNetworkSize,
utils.InitNetworkIps,
utils.InitDisableLegacyP2P,
utils.InitDisableVDN,
configFileFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Expand Down Expand Up @@ -350,22 +352,27 @@ func createPorts(ipStr string, port int, size int) []int {
}

// Create config for node i in the cluster
func createNodeConfig(baseConfig gethConfig, enodes []*enode.Node, ip string, port int, size int, i int) gethConfig {
func createNodeConfig(baseConfig gethConfig, enodes []*enode.Node, ip string, port int, size int, i int, disableLegacyP2P bool) gethConfig {
baseConfig.Node.HTTPHost = ip
baseConfig.Node.P2P.ListenAddr = fmt.Sprintf(":%d", port)
baseConfig.Node.P2P.BootstrapNodes = make([]*enode.Node, size-1)
// Set the P2P connections between this node and the other nodes
for j := 0; j < i; j++ {
baseConfig.Node.P2P.BootstrapNodes[j] = enodes[j]
}
for j := i + 1; j < size; j++ {
baseConfig.Node.P2P.BootstrapNodes[j-1] = enodes[j]
if !disableLegacyP2P {
baseConfig.Node.P2P.BootstrapNodes = make([]*enode.Node, size-1)
// Set the P2P connections between this node and the other nodes
for j := 0; j < i; j++ {
baseConfig.Node.P2P.BootstrapNodes[j] = enodes[j]
}
for j := i + 1; j < size; j++ {
baseConfig.Node.P2P.BootstrapNodes[j-1] = enodes[j]
}
} else {
fmt.Println("skip legacy p2p boot node configuration...")
baseConfig.Node.P2P.BootstrapNodes = nil
}
return baseConfig
}

// Create configs for nodes in the cluster
func createNodeConfigs(baseConfig gethConfig, initDir string, ips []string, ports []int, vdnPorts []int, size int) ([]gethConfig, error) {
func createNodeConfigs(baseConfig gethConfig, initDir string, ips []string, ports []int, vdnPorts []int, size int, disableLegacyP2P bool, disableVDN bool) ([]gethConfig, error) {
// Create the nodes
enodes := make([]*enode.Node, size)
peerIDs := make([]peer.ID, size)
Expand All @@ -389,13 +396,15 @@ func createNodeConfigs(baseConfig gethConfig, initDir string, ips []string, port
// Create the configs
configs := make([]gethConfig, size)
for i := 0; i < size; i++ {
configs[i] = createNodeConfig(baseConfig, enodes, ips[i], ports[i], size, i)
configs[i] = createNodeConfig(baseConfig, enodes, ips[i], ports[i], size, i, disableLegacyP2P)
}

// set VDN bootnode, using the first node as bootnode default.
// TODO(galaio): may using enode url than multiaddr url in future?
for i := 1; i < size; i++ {
configs[i].Node.VDN.BootstrapPeers = []string{fmt.Sprintf("/ip4/%v/tcp/%d/p2p/%v", ips[0], vdnPorts[0], peerIDs[0])}
if !disableVDN {
// set VDN bootnode, using the first node as bootnode default.
// TODO(galaio): may using enode url than multiaddr url in future?
for i := 1; i < size; i++ {
configs[i].Node.VDN.BootstrapPeers = []string{fmt.Sprintf("/ip4/%v/tcp/%d/p2p/%v", ips[0], vdnPorts[0], peerIDs[0])}
}
}
return configs, nil
}
Expand All @@ -418,6 +427,8 @@ func initNetwork(ctx *cli.Context) error {
if vdnPort <= 0 {
utils.Fatalf("VDN port should be greater than 0")
}
disableLegacyP2P := ctx.Bool(utils.InitDisableLegacyP2P.Name)
disableVDN := ctx.Bool(utils.InitDisableVDN.Name)
ipStr := ctx.String(utils.InitNetworkIps.Name)
cfgFile := ctx.String(configFileFlag.Name)

Expand Down Expand Up @@ -456,7 +467,7 @@ func initNetwork(ctx *cli.Context) error {
return err
}

configs, err := createNodeConfigs(config, initDir, ips, ports, vdnPorts, size)
configs, err := createNodeConfigs(config, initDir, ips, ports, vdnPorts, size, disableLegacyP2P, disableVDN)
if err != nil {
utils.Fatalf("Failed to create node configs: %v", err)
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,16 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Usage: "the vdn p2p port of the nodes in the network",
Value: 13000,
}
InitDisableLegacyP2P = &cli.BoolFlag{
Name: "init.disable-legacyp2p",
Usage: "whether to enable legacy p2p",
Value: false,
}
InitDisableVDN = &cli.BoolFlag{
Name: "init.disable-vdn",
Usage: "whether to disable vdn",
Value: false,
}
MetricsInfluxDBOrganizationFlag = &cli.StringFlag{
Name: "metrics.influxdb.organization",
Usage: "InfluxDB organization name (v2 only)",
Expand Down
21 changes: 20 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ type Ethereum struct {

shutdownTracker *shutdowncheck.ShutdownTracker // Tracks if and when the node has shutdown ungracefully

votePool *vote.VotePool
votePool *vote.VotePool
vdnHandler *VDNHandler
}

// New creates a new Ethereum object (including the initialisation of the common Ethereum object),
Expand Down Expand Up @@ -413,6 +414,17 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, config.GPO, config.Miner.GasPrice)

if stack.VDNServer() != nil {
if eth.vdnHandler, err = NewVDNHandler(VDNHandlerConfig{
chain: eth.blockchain,
server: stack.VDNServer(),
votePool: eth.votePool,
eventMux: eth.eventMux,
}); err != nil {
return nil, err
}
}

// Start the RPC service
eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, networkID)

Expand Down Expand Up @@ -599,6 +611,10 @@ func (s *Ethereum) Start() error {

// Start the networking layer
s.handler.Start(s.p2pServer.MaxPeers, s.p2pServer.MaxPeersPerIP)

if s.vdnHandler != nil {
s.vdnHandler.Start()
}
return nil
}

Expand Down Expand Up @@ -661,6 +677,9 @@ func (s *Ethereum) Stop() error {
// Stop all the peer-related stuff first.
s.discmix.Close()
s.handler.Stop()
if s.vdnHandler != nil {
s.vdnHandler.Stop()
}

// Then stop everything else.
s.bloomIndexer.Close()
Expand Down
Loading