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

miner/stress: initialize account backends explicitly #23699

Merged
merged 1 commit into from Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 21 additions & 12 deletions miner/stress/1559/main.go
Expand Up @@ -23,10 +23,9 @@ import (
"math/big"
"math/rand"
"os"
"path/filepath"
"os/signal"
"time"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/consensus/ethash"
Expand Down Expand Up @@ -58,12 +57,17 @@ func main() {
faucets[i], _ = crypto.GenerateKey()
}
// Pre-generate the ethash mining DAG so we don't race
ethash.MakeDataset(1, filepath.Join(os.Getenv("HOME"), ".ethash"))
ethash.MakeDataset(1, ethconfig.Defaults.Ethash.DatasetDir)

// Create an Ethash network based off of the Ropsten config
genesis := makeGenesis(faucets)

// Handle interrupts.
interruptCh := make(chan os.Signal, 5)
signal.Notify(interruptCh, os.Interrupt)

var (
stacks []*node.Node
nodes []*eth.Ethereum
enodes []*enode.Node
)
Expand All @@ -85,12 +89,6 @@ func main() {
// Start tracking the node and its enode
nodes = append(nodes, ethBackend)
enodes = append(enodes, stack.Server().Self())

// Inject the signer key and start sealing with it
store := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
if _, err := store.NewAccount(""); err != nil {
panic(err)
}
}

// Iterate over all the nodes and start mining
Expand All @@ -111,6 +109,16 @@ func main() {
signer = types.LatestSignerForChainID(genesis.Config.ChainID)
)
for {
// Stop when interrupted.
select {
case <-interruptCh:
for _, node := range stacks {
node.Close()
}
return
default:
}

// Pick a random mining node
index := rand.Intn(len(faucets))
backend := nodes[index%len(nodes)]
Expand Down Expand Up @@ -242,9 +250,10 @@ func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
GPO: ethconfig.Defaults.GPO,
Ethash: ethconfig.Defaults.Ethash,
Miner: miner.Config{
GasCeil: genesis.GasLimit * 11 / 10,
GasPrice: big.NewInt(1),
Recommit: time.Second,
Etherbase: common.Address{1},
GasCeil: genesis.GasLimit * 11 / 10,
GasPrice: big.NewInt(1),
Recommit: time.Second,
},
})
if err != nil {
Expand Down
25 changes: 21 additions & 4 deletions miner/stress/clique/main.go
Expand Up @@ -24,6 +24,7 @@ import (
"math/big"
"math/rand"
"os"
"os/signal"
"time"

"github.com/ethereum/go-ethereum/accounts/keystore"
Expand Down Expand Up @@ -59,11 +60,15 @@ func main() {
// Create a Clique network based off of the Rinkeby config
genesis := makeGenesis(faucets, sealers)

// Handle interrupts.
interruptCh := make(chan os.Signal, 5)
signal.Notify(interruptCh, os.Interrupt)

var (
stacks []*node.Node
nodes []*eth.Ethereum
enodes []*enode.Node
)

for _, sealer := range sealers {
// Start the node and wait until it's up
stack, ethBackend, err := makeSealer(genesis)
Expand All @@ -80,18 +85,20 @@ func main() {
stack.Server().AddPeer(n)
}
// Start tracking the node and its enode
stacks = append(stacks, stack)
nodes = append(nodes, ethBackend)
enodes = append(enodes, stack.Server().Self())

// Inject the signer key and start sealing with it
store := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
signer, err := store.ImportECDSA(sealer, "")
ks := keystore.NewKeyStore(stack.KeyStoreDir(), keystore.LightScryptN, keystore.LightScryptP)
signer, err := ks.ImportECDSA(sealer, "")
if err != nil {
panic(err)
}
if err := store.Unlock(signer, ""); err != nil {
if err := ks.Unlock(signer, ""); err != nil {
panic(err)
}
stack.AccountManager().AddBackend(ks)
}

// Iterate over all the nodes and start signing on them
Expand All @@ -106,6 +113,16 @@ func main() {
// Start injecting transactions from the faucet like crazy
nonces := make([]uint64, len(faucets))
for {
// Stop when interrupted.
select {
case <-interruptCh:
for _, node := range stacks {
node.Close()
}
return
default:
}

// Pick a random signer node
index := rand.Intn(len(faucets))
backend := nodes[index%len(nodes)]
Expand Down
34 changes: 22 additions & 12 deletions miner/stress/ethash/main.go
Expand Up @@ -23,10 +23,9 @@ import (
"math/big"
"math/rand"
"os"
"path/filepath"
"os/signal"
"time"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/consensus/ethash"
Expand Down Expand Up @@ -54,12 +53,17 @@ func main() {
faucets[i], _ = crypto.GenerateKey()
}
// Pre-generate the ethash mining DAG so we don't race
ethash.MakeDataset(1, filepath.Join(os.Getenv("HOME"), ".ethash"))
ethash.MakeDataset(1, ethconfig.Defaults.Ethash.DatasetDir)

// Create an Ethash network based off of the Ropsten config
genesis := makeGenesis(faucets)

// Handle interrupts.
interruptCh := make(chan os.Signal, 5)
signal.Notify(interruptCh, os.Interrupt)

var (
stacks []*node.Node
nodes []*eth.Ethereum
enodes []*enode.Node
)
Expand All @@ -79,14 +83,9 @@ func main() {
stack.Server().AddPeer(n)
}
// Start tracking the node and its enode
stacks = append(stacks, stack)
nodes = append(nodes, ethBackend)
enodes = append(enodes, stack.Server().Self())

// Inject the signer key and start sealing with it
store := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
if _, err := store.NewAccount(""); err != nil {
panic(err)
}
}

// Iterate over all the nodes and start mining
Expand All @@ -101,6 +100,16 @@ func main() {
// Start injecting transactions from the faucets like crazy
nonces := make([]uint64, len(faucets))
for {
// Stop when interrupted.
select {
case <-interruptCh:
for _, node := range stacks {
node.Close()
}
return
default:
}

// Pick a random mining node
index := rand.Intn(len(faucets))
backend := nodes[index%len(nodes)]
Expand Down Expand Up @@ -171,9 +180,10 @@ func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
GPO: ethconfig.Defaults.GPO,
Ethash: ethconfig.Defaults.Ethash,
Miner: miner.Config{
GasCeil: genesis.GasLimit * 11 / 10,
GasPrice: big.NewInt(1),
Recommit: time.Second,
Etherbase: common.Address{1},
GasCeil: genesis.GasLimit * 11 / 10,
GasPrice: big.NewInt(1),
Recommit: time.Second,
},
})
if err != nil {
Expand Down