erigon-pulse/cmd/devnet/accounts/accounts.go
battlmonstr 3698e7f476
devnet: configuration fixes (#8592)
* fix "genesis hash does not match" when dev nodes connect  
The "dev" nodes need to have the same --miner.etherbase in order to
generate the same genesis ExtraData by DeveloperGenesisBlock(). Override
DevnetEtherbase global var that's used if --miner.etherbase is not
passed. (for NonBlockProducer case)

* fix missing private key for the hardcoded DevnetEtherbase  
Fixes panic if SigKey is not found. Bor non-producers will use a default
`DevnetEtherbase` while Dev nodes modify it. Save hardcoded
DevnetEtherbase/DevnetSignPrivateKey into accounts so that SigKey can
recover it.

* refactor devnet.node to contain Node config  
This avoids interface{} type casts and fixes an error with
Heimdall.validatorSet == nil

* add connection retries to rpcCall and Subscribe of requestGenerator  
Fixes "connection refused" errors due to node not ready to handle early
RPC requests.

* fix deadlock in Heimdall.NodeStarted

* fix GetBlockByNumber
Fixes "cannot unmarshal string into Go struct field body.transactions of
type jsonrpc.RPCTransaction"

* demote "no of blocks on childchain is less than confirmations
required" to Info (#8626)

* demote "mismatched pending subpool size" to Debug (#8615)

* revert wiggle testing code
2023-11-01 11:08:47 +01:00

89 lines
1.8 KiB
Go

package accounts
import (
"crypto/ecdsa"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/crypto"
)
const DevAddress = "0x67b1d87101671b127f5f8714789C7192f7ad340e"
type Account struct {
Name string
Address libcommon.Address
sigKey *ecdsa.PrivateKey
}
func init() {
core.DevnetSignKey = func(addr libcommon.Address) *ecdsa.PrivateKey {
return SigKey(addr)
}
devnetEtherbaseAccount := &Account{
"DevnetEtherbase",
core.DevnetEtherbase,
core.DevnetSignPrivateKey,
}
accountsByAddress[core.DevnetEtherbase] = devnetEtherbaseAccount
accountsByName[devnetEtherbaseAccount.Name] = devnetEtherbaseAccount
}
var accountsByAddress = map[libcommon.Address]*Account{}
var accountsByName = map[string]*Account{}
func NewAccount(name string) *Account {
if account, ok := accountsByName[name]; ok {
return account
}
sigKey, _ := crypto.GenerateKey()
account := &Account{
Name: name,
Address: crypto.PubkeyToAddress(sigKey.PublicKey),
sigKey: sigKey,
}
accountsByAddress[account.Address] = account
accountsByName[name] = account
return account
}
func (a *Account) SigKey() *ecdsa.PrivateKey {
return a.sigKey
}
func GetAccount(account string) *Account {
if account, ok := accountsByName[account]; ok {
return account
}
if account, ok := accountsByAddress[libcommon.HexToAddress(account)]; ok {
return account
}
return nil
}
func SigKey(source interface{}) *ecdsa.PrivateKey {
switch source := source.(type) {
case libcommon.Address:
if account, ok := accountsByAddress[source]; ok {
return account.sigKey
}
if source == core.DevnetEtherbase {
return core.DevnetSignPrivateKey
}
case string:
if account := GetAccount(source); account != nil {
return account.sigKey
}
}
return nil
}