Devnet private key (#2639)

This commit is contained in:
Alex Sharov 2021-09-07 16:12:49 +07:00 committed by GitHub
parent a4f9df9ee8
commit dd7f197db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 20 deletions

View File

@ -232,8 +232,8 @@ var (
Usage: "Public address for block mining rewards", Usage: "Public address for block mining rewards",
Value: "0", Value: "0",
} }
MinerSigningKeyFlag = cli.StringFlag{ MinerSigningKeyFileFlag = cli.StringFlag{
Name: "miner.sigkey", Name: "miner.sigfile",
Usage: "Private key to sign blocks with", Usage: "Private key to sign blocks with",
Value: "", Value: "",
} }
@ -774,22 +774,18 @@ func SplitAndTrim(input string) (ret []string) {
// setEtherbase retrieves the etherbase from the directly specified // setEtherbase retrieves the etherbase from the directly specified
// command line flags. // command line flags.
func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) { func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(MinerSigningKeyFlag.Name) { var etherbase string
sigkey := ctx.GlobalString(MinerSigningKeyFlag.Name) if ctx.GlobalIsSet(MinerEtherbaseFlag.Name) {
if sigkey != "" { etherbase = ctx.GlobalString(MinerEtherbaseFlag.Name)
var err error
cfg.Miner.SigKey, err = crypto.HexToECDSA(sigkey)
if err != nil {
Fatalf("Failed to parse ECDSA private key: %v", err)
}
cfg.Miner.Etherbase = crypto.PubkeyToAddress(cfg.Miner.SigKey.PublicKey)
}
} else if ctx.GlobalIsSet(MinerEtherbaseFlag.Name) {
etherbase := ctx.GlobalString(MinerEtherbaseFlag.Name)
if etherbase != "" { if etherbase != "" {
cfg.Miner.Etherbase = common.HexToAddress(etherbase) cfg.Miner.Etherbase = common.HexToAddress(etherbase)
} }
} }
if etherbase == "" && ctx.GlobalString(ChainFlag.Name) == params.DevChainName {
cfg.Miner.SigKey = core.DevnetSignPrivateKey
cfg.Miner.Etherbase = core.DevnetEtherbase
}
} }
func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config, nodeName, dataDir string) { func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config, nodeName, dataDir string) {
@ -994,7 +990,7 @@ func SetupMinerCobra(cmd *cobra.Command, cfg *params.MiningConfig) {
panic(err) panic(err)
} }
if cfg.Enabled && len(cfg.Etherbase.Bytes()) == 0 { if cfg.Enabled && len(cfg.Etherbase.Bytes()) == 0 {
panic(fmt.Sprintf("Erigon supports only remote miners. Flag --%s or --%s is required", MinerNotifyFlag.Name, MinerSigningKeyFlag.Name)) panic(fmt.Sprintf("Erigon supports only remote miners. Flag --%s or --%s is required", MinerNotifyFlag.Name, MinerSigningKeyFileFlag.Name))
} }
cfg.Notify, err = flags.GetStringArray(MinerNotifyFlag.Name) cfg.Notify, err = flags.GetStringArray(MinerNotifyFlag.Name)
if err != nil { if err != nil {
@ -1061,7 +1057,7 @@ func setMiner(ctx *cli.Context, cfg *params.MiningConfig) {
cfg.Enabled = true cfg.Enabled = true
} }
if cfg.Enabled && len(cfg.Etherbase.Bytes()) == 0 { if cfg.Enabled && len(cfg.Etherbase.Bytes()) == 0 {
panic(fmt.Sprintf("Erigon supports only remote miners. Flag --%s or --%s is required", MinerNotifyFlag.Name, MinerSigningKeyFlag.Name)) panic(fmt.Sprintf("Erigon supports only remote miners. Flag --%s or --%s is required", MinerNotifyFlag.Name, MinerSigningKeyFileFlag.Name))
} }
if ctx.GlobalIsSet(MinerNotifyFlag.Name) { if ctx.GlobalIsSet(MinerNotifyFlag.Name) {
cfg.Notify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",") cfg.Notify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",")
@ -1152,7 +1148,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// SetEthConfig applies eth-related command line flags to the config. // SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, nodeConfig *node.Config, cfg *ethconfig.Config) { func SetEthConfig(ctx *cli.Context, nodeConfig *node.Config, cfg *ethconfig.Config) {
CheckExclusive(ctx, MinerSigningKeyFlag, MinerEtherbaseFlag) CheckExclusive(ctx, MinerSigningKeyFileFlag, MinerEtherbaseFlag)
setEtherbase(ctx, cfg) setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO) setGPO(ctx, &cfg.GPO)
setTxPool(ctx, &cfg.TxPool) setTxPool(ctx, &cfg.TxPool)

View File

@ -601,6 +601,9 @@ func DefaultSokolGenesisBlock() *Genesis {
} }
} }
var DevnetSignPrivateKey, _ = crypto.HexToECDSA("289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032")
var DevnetEtherbase = common.HexToAddress("970e8128ab834e8eac17ab8e3812f010678cf791") // crypto.PubkeyToAddress(DevnetSignPrivateKey.PublicKey)
// DeveloperGenesisBlock returns the 'geth --dev' genesis block. // DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
// Override the default period to the user requested one // Override the default period to the user requested one

View File

@ -533,7 +533,6 @@ func (s *Ethereum) StartMining(ctx context.Context, kv kv.RwDB, mining *stagedsy
if !cfg.Enabled { if !cfg.Enabled {
return nil return nil
} }
s.txPool.SetGasPrice(gasPrice) s.txPool.SetGasPrice(gasPrice)
// Configure the local mining address // Configure the local mining address

View File

@ -104,6 +104,7 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
if parent == nil { // todo: how to return error and don't stop Erigon? if parent == nil { // todo: how to return error and don't stop Erigon?
return fmt.Errorf(fmt.Sprintf("[%s] Empty block", logPrefix), "blocknum", executionAt) return fmt.Errorf(fmt.Sprintf("[%s] Empty block", logPrefix), "blocknum", executionAt)
} }
log.Info(fmt.Sprintf("[%s] Start mine", logPrefix), "block", executionAt+1)
blockNum := executionAt + 1 blockNum := executionAt + 1
signer := types.MakeSigner(&cfg.chainConfig, blockNum) signer := types.MakeSigner(&cfg.chainConfig, blockNum)
@ -285,7 +286,6 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
current.LocalTxs = types.NewTransactionsByPriceAndNonce(*signer, localTxs) current.LocalTxs = types.NewTransactionsByPriceAndNonce(*signer, localTxs)
current.RemoteTxs = types.NewTransactionsByPriceAndNonce(*signer, remoteTxs) current.RemoteTxs = types.NewTransactionsByPriceAndNonce(*signer, remoteTxs)
fmt.Printf("aa: %t, %t,%t\n", current == nil, cfg.miner.MiningBlock == nil, current.Header == nil)
return nil return nil
} }

View File

@ -78,6 +78,6 @@ var DefaultFlags = []cli.Flag{
utils.MinerEtherbaseFlag, utils.MinerEtherbaseFlag,
utils.MinerExtraDataFlag, utils.MinerExtraDataFlag,
utils.MinerNoVerfiyFlag, utils.MinerNoVerfiyFlag,
utils.MinerSigningKeyFlag, utils.MinerSigningKeyFileFlag,
utils.SentryAddrFlag, utils.SentryAddrFlag,
} }