Commit e2640a96 authored by gary rong's avatar gary rong Committed by Péter Szilágyi

miner: fix miner stress test (#18039)

parent 79c7a69a
...@@ -22,7 +22,6 @@ package main ...@@ -22,7 +22,6 @@ package main
import ( import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"fmt"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
...@@ -40,7 +39,7 @@ import ( ...@@ -40,7 +39,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -62,11 +61,11 @@ func main() { ...@@ -62,11 +61,11 @@ func main() {
var ( var (
nodes []*node.Node nodes []*node.Node
enodes []string enodes []*enode.Node
) )
for _, sealer := range sealers { for _, sealer := range sealers {
// Start the node and wait until it's up // Start the node and wait until it's up
node, err := makeSealer(genesis, enodes) node, err := makeSealer(genesis)
if err != nil { if err != nil {
panic(err) panic(err)
} }
...@@ -76,18 +75,12 @@ func main() { ...@@ -76,18 +75,12 @@ func main() {
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
} }
// Connect the node to al the previous ones // Connect the node to al the previous ones
for _, enode := range enodes { for _, n := range enodes {
enode, err := discover.ParseNode(enode) node.Server().AddPeer(n)
if err != nil {
panic(err)
} }
node.Server().AddPeer(enode) // Start tracking the node and it's enode
}
// Start tracking the node and it's enode url
nodes = append(nodes, node) nodes = append(nodes, node)
enodes = append(enodes, node.Server().Self())
enode := fmt.Sprintf("enode://%s@127.0.0.1:%d", node.Server().NodeInfo().ID, node.Server().NodeInfo().Ports.Listener)
enodes = append(enodes, enode)
// Inject the signer key and start sealing with it // Inject the signer key and start sealing with it
store := node.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) store := node.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
...@@ -177,7 +170,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core ...@@ -177,7 +170,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core
return genesis return genesis
} }
func makeSealer(genesis *core.Genesis, nodes []string) (*node.Node, error) { func makeSealer(genesis *core.Genesis) (*node.Node, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := ioutil.TempDir("", "")
......
...@@ -21,7 +21,6 @@ package main ...@@ -21,7 +21,6 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"fmt"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
...@@ -41,7 +40,7 @@ import ( ...@@ -41,7 +40,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -62,11 +61,11 @@ func main() { ...@@ -62,11 +61,11 @@ func main() {
var ( var (
nodes []*node.Node nodes []*node.Node
enodes []string enodes []*enode.Node
) )
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
// Start the node and wait until it's up // Start the node and wait until it's up
node, err := makeMiner(genesis, enodes) node, err := makeMiner(genesis)
if err != nil { if err != nil {
panic(err) panic(err)
} }
...@@ -76,18 +75,12 @@ func main() { ...@@ -76,18 +75,12 @@ func main() {
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
} }
// Connect the node to al the previous ones // Connect the node to al the previous ones
for _, enode := range enodes { for _, n := range enodes {
enode, err := discover.ParseNode(enode) node.Server().AddPeer(n)
if err != nil {
panic(err)
} }
node.Server().AddPeer(enode) // Start tracking the node and it's enode
}
// Start tracking the node and it's enode url
nodes = append(nodes, node) nodes = append(nodes, node)
enodes = append(enodes, node.Server().Self())
enode := fmt.Sprintf("enode://%s@127.0.0.1:%d", node.Server().NodeInfo().ID, node.Server().NodeInfo().Ports.Listener)
enodes = append(enodes, enode)
// Inject the signer key and start sealing with it // Inject the signer key and start sealing with it
store := node.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) store := node.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
...@@ -155,7 +148,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { ...@@ -155,7 +148,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis {
return genesis return genesis
} }
func makeMiner(genesis *core.Genesis, nodes []string) (*node.Node, error) { func makeMiner(genesis *core.Genesis) (*node.Node, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := ioutil.TempDir("", "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment