mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
work in progress
This commit is contained in:
parent
365c9016ce
commit
c79192e67e
9 changed files with 73 additions and 20 deletions
|
|
@ -261,15 +261,7 @@ func geth(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// startNode boots up the system node and all registered protocols, after which
|
func startInternalAccountManagement(ctx *cli.Context, stack *node.Node) {
|
||||||
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
|
|
||||||
// miner.
|
|
||||||
func startNode(ctx *cli.Context, stack *node.Node) {
|
|
||||||
debug.Memsize.Add("node", stack)
|
|
||||||
|
|
||||||
// Start up the node itself
|
|
||||||
utils.StartNode(stack)
|
|
||||||
|
|
||||||
// Unlock any account specifically requested
|
// Unlock any account specifically requested
|
||||||
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
|
|
||||||
|
|
@ -283,7 +275,6 @@ func startNode(ctx *cli.Context, stack *node.Node) {
|
||||||
// Register wallet event handlers to open and auto-derive wallets
|
// Register wallet event handlers to open and auto-derive wallets
|
||||||
events := make(chan accounts.WalletEvent, 16)
|
events := make(chan accounts.WalletEvent, 16)
|
||||||
stack.AccountManager().Subscribe(events)
|
stack.AccountManager().Subscribe(events)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Create a chain state reader for self-derivation
|
// Create a chain state reader for self-derivation
|
||||||
rpcClient, err := stack.Attach()
|
rpcClient, err := stack.Attach()
|
||||||
|
|
@ -321,6 +312,25 @@ func startNode(ctx *cli.Context, stack *node.Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// startNode boots up the system node and all registered protocols, after which
|
||||||
|
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
|
||||||
|
// miner.
|
||||||
|
func startNode(ctx *cli.Context, stack *node.Node) {
|
||||||
|
debug.Memsize.Add("node", stack)
|
||||||
|
|
||||||
|
// Start up the node itself
|
||||||
|
utils.StartNode(stack)
|
||||||
|
|
||||||
|
// Start account management
|
||||||
|
if ctx.IsSet(utils.ExternalSignerFlag.Name){
|
||||||
|
extApi := ctx.GlobalString(utils.ExternalSignerFlag.Name)
|
||||||
|
|
||||||
|
}else{
|
||||||
|
startInternalAccountManagement(ctx, stack)
|
||||||
|
}
|
||||||
|
|
||||||
// Start auxiliary services if enabled
|
// Start auxiliary services if enabled
|
||||||
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
|
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
|
||||||
// Mining only makes sense if a full Ethereum node is running
|
// Mining only makes sense if a full Ethereum node is running
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,11 @@ var (
|
||||||
Usage: "Password file to use for non-interactive password input",
|
Usage: "Password file to use for non-interactive password input",
|
||||||
Value: "",
|
Value: "",
|
||||||
}
|
}
|
||||||
|
ExternalSignerFlag = cli.StringFlag{
|
||||||
|
Name: "signer",
|
||||||
|
Usage: "External signer (url or path to ipc file)",
|
||||||
|
Value: "",
|
||||||
|
}
|
||||||
|
|
||||||
VMEnableDebugFlag = cli.BoolFlag{
|
VMEnableDebugFlag = cli.BoolFlag{
|
||||||
Name: "vmdebug",
|
Name: "vmdebug",
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ type Ethereum struct {
|
||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
engine consensus.Engine
|
engine consensus.Engine
|
||||||
accountManager *accounts.Manager
|
accountManager *accounts.Manager
|
||||||
|
externalSigner string
|
||||||
|
|
||||||
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
|
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
|
||||||
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
|
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
|
||||||
|
|
@ -372,6 +373,7 @@ func (s *Ethereum) IsListening() bool { return true } // Always
|
||||||
func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) }
|
func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) }
|
||||||
func (s *Ethereum) NetVersion() uint64 { return s.networkID }
|
func (s *Ethereum) NetVersion() uint64 { return s.networkID }
|
||||||
func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
|
func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
|
||||||
|
func (s *Ethereum) ExternalSigner() string { return s.externalSigner }
|
||||||
|
|
||||||
// Protocols implements node.Service, returning all the currently configured
|
// Protocols implements node.Service, returning all the currently configured
|
||||||
// network protocols to start.
|
// network protocols to start.
|
||||||
|
|
|
||||||
|
|
@ -211,13 +211,20 @@ type PrivateAccountAPI struct {
|
||||||
|
|
||||||
// NewPrivateAccountAPI create a new PrivateAccountAPI.
|
// NewPrivateAccountAPI create a new PrivateAccountAPI.
|
||||||
func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI {
|
func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI {
|
||||||
extapi, _ := NewExternalSigner()
|
p := &PrivateAccountAPI{
|
||||||
return &PrivateAccountAPI{
|
|
||||||
am: b.AccountManager(),
|
am: b.AccountManager(),
|
||||||
nonceLock: nonceLock,
|
nonceLock: nonceLock,
|
||||||
b: b,
|
b: b,
|
||||||
extapi: extapi,
|
|
||||||
}
|
}
|
||||||
|
if b.ExternalSigner() != "" {
|
||||||
|
extapi, err := NewExternalSigner(b.ExternalSigner())
|
||||||
|
if err == nil {
|
||||||
|
p.extapi = extapi
|
||||||
|
} else {
|
||||||
|
log.Error("Error initializing external signer", "url", b.ExternalSigner(), "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAccounts will return a list of addresses for accounts this node manages.
|
// ListAccounts will return a list of addresses for accounts this node manages.
|
||||||
|
|
@ -984,7 +991,18 @@ type PublicTransactionPoolAPI struct {
|
||||||
|
|
||||||
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
|
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
|
||||||
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI {
|
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI {
|
||||||
return &PublicTransactionPoolAPI{b, nonceLock, nil}
|
var (
|
||||||
|
extapi *ExternalSignerAPI
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if b.ExternalSigner() != "" {
|
||||||
|
extapi, err = NewExternalSigner(b.ExternalSigner())
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error initializing external signer", "url", b.ExternalSigner(), "error", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return &PublicTransactionPoolAPI{b, nonceLock, extapi}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
|
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
|
||||||
|
|
@ -1534,8 +1552,8 @@ type ExternalSignerAPI struct {
|
||||||
client *rpc.Client
|
client *rpc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExternalSigner() (*ExternalSignerAPI, error) {
|
func NewExternalSigner(endpoint string) (*ExternalSignerAPI, error) {
|
||||||
client, err := rpc.DialHTTP("http://localhost:8550")
|
client, err := rpc.DialHTTP(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ type Backend interface {
|
||||||
ChainDb() ethdb.Database
|
ChainDb() ethdb.Database
|
||||||
EventMux() *event.TypeMux
|
EventMux() *event.TypeMux
|
||||||
AccountManager() *accounts.Manager
|
AccountManager() *accounts.Manager
|
||||||
|
ExternalSigner() string
|
||||||
|
|
||||||
// BlockChain API
|
// BlockChain API
|
||||||
SetHead(number uint64)
|
SetHead(number uint64)
|
||||||
HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
|
HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,10 @@ func (b *LesApiBackend) AccountManager() *accounts.Manager {
|
||||||
return b.eth.accountManager
|
return b.eth.accountManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *LesApiBackend) ExternalSigner() string {
|
||||||
|
return b.eth.externalSigner
|
||||||
|
}
|
||||||
|
|
||||||
func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
|
func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
|
||||||
if b.eth.bloomIndexer == nil {
|
if b.eth.bloomIndexer == nil {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ type LightEthereum struct {
|
||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
engine consensus.Engine
|
engine consensus.Engine
|
||||||
accountManager *accounts.Manager
|
accountManager *accounts.Manager
|
||||||
|
externalSigner string
|
||||||
|
|
||||||
networkId uint64
|
networkId uint64
|
||||||
netRPCService *ethapi.PublicNetAPI
|
netRPCService *ethapi.PublicNetAPI
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,10 @@ type Config struct {
|
||||||
// NoUSB disables hardware wallet monitoring and connectivity.
|
// NoUSB disables hardware wallet monitoring and connectivity.
|
||||||
NoUSB bool `toml:",omitempty"`
|
NoUSB bool `toml:",omitempty"`
|
||||||
|
|
||||||
|
// ExternalSigner path/url to external signer. Implicitly disables native account
|
||||||
|
// management
|
||||||
|
ExternalSigner string `toml:",omitempty"`
|
||||||
|
|
||||||
// IPCPath is the requested location to place the IPC endpoint. If the path is
|
// IPCPath is the requested location to place the IPC endpoint. If the path is
|
||||||
// a simple file name, it is placed inside the data directory (or on the root
|
// a simple file name, it is placed inside the data directory (or on the root
|
||||||
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
|
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
|
||||||
|
|
|
||||||
14
node/node.go
14
node/node.go
|
|
@ -41,6 +41,7 @@ type Node struct {
|
||||||
eventmux *event.TypeMux // Event multiplexer used between the services of a stack
|
eventmux *event.TypeMux // Event multiplexer used between the services of a stack
|
||||||
config *Config
|
config *Config
|
||||||
accman *accounts.Manager
|
accman *accounts.Manager
|
||||||
|
extapi string // If non-empty, the ipc-path or http(s)-url to an external signer
|
||||||
|
|
||||||
ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
|
ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
|
||||||
instanceDirLock flock.Releaser // prevents concurrent use of instance directory
|
instanceDirLock flock.Releaser // prevents concurrent use of instance directory
|
||||||
|
|
@ -99,9 +100,15 @@ func New(conf *Config) (*Node, error) {
|
||||||
}
|
}
|
||||||
// Ensure that the AccountManager method works before the node has started.
|
// Ensure that the AccountManager method works before the node has started.
|
||||||
// We rely on this in cmd/geth.
|
// We rely on this in cmd/geth.
|
||||||
am, ephemeralKeystore, err := makeAccountManager(conf)
|
var (
|
||||||
if err != nil {
|
am *accounts.Manager
|
||||||
return nil, err
|
ephemeralKeystore string
|
||||||
|
)
|
||||||
|
if conf.ExternalSigner != "" {
|
||||||
|
var err error
|
||||||
|
if am, ephemeralKeystore, err = makeAccountManager(conf); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if conf.Logger == nil {
|
if conf.Logger == nil {
|
||||||
conf.Logger = log.New()
|
conf.Logger = log.New()
|
||||||
|
|
@ -110,6 +117,7 @@ func New(conf *Config) (*Node, error) {
|
||||||
// in the data directory or instance directory is delayed until Start.
|
// in the data directory or instance directory is delayed until Start.
|
||||||
return &Node{
|
return &Node{
|
||||||
accman: am,
|
accman: am,
|
||||||
|
extapi: conf.ExternalSigner,
|
||||||
ephemeralKeystore: ephemeralKeystore,
|
ephemeralKeystore: ephemeralKeystore,
|
||||||
config: conf,
|
config: conf,
|
||||||
serviceFuncs: []ServiceConstructor{},
|
serviceFuncs: []ServiceConstructor{},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue