From 1220efc3491a1bdaa8f3694534dc36875f881369 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 15 Aug 2018 11:06:48 +0200 Subject: [PATCH] wip, updates --- cmd/clef/main.go | 2 +- cmd/geth/config.go | 2 -- cmd/geth/main.go | 11 ++++++----- cmd/utils/flags.go | 2 +- eth/api_backend.go | 3 ++- eth/backend.go | 26 +++++++++++++------------- internal/ethapi/api.go | 22 ++-------------------- internal/ethapi/backend.go | 2 +- les/api_backend.go | 3 ++- les/backend.go | 2 +- node/node.go | 3 +++ signer/core/cliui.go | 14 +++++++------- signer/rules/rules.go | 2 +- 13 files changed, 40 insertions(+), 54 deletions(-) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 85704754de..4b44a9d1df 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -591,7 +591,7 @@ func testExternalUI(api *core.SignerAPI) { checkErr("SignTransaction", err) _, err = api.Sign(ctx, common.MixedcaseAddress{}, common.Hex2Bytes("01020304")) checkErr("Sign", err) - _, err = api.List(ctx) + _, err = api.ListAccounts(ctx) checkErr("List", err) _, err = api.New(ctx) checkErr("New", err) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index e6bd4d5bef..7478adf6e6 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -152,9 +152,7 @@ func enableWhisper(ctx *cli.Context) bool { func makeFullNode(ctx *cli.Context) *node.Node { stack, cfg := makeConfigNode(ctx) - utils.RegisterEthService(stack, &cfg.Eth) - if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) { utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit) } diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e9464872b4..c3f44eade5 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -66,6 +66,7 @@ var ( utils.EthashDatasetDirFlag, utils.EthashDatasetsInMemoryFlag, utils.EthashDatasetsOnDiskFlag, + utils.ExternalSignerFlag, utils.TxPoolNoLocalsFlag, utils.TxPoolJournalFlag, utils.TxPoolRejournalFlag, @@ -258,12 +259,8 @@ func geth(ctx *cli.Context) error { 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){ - extEndpoint := ctx.GlobalString(utils.ExternalSignerFlag.Name) + if extEndpoint := ctx.GlobalString(utils.ExternalSignerFlag.Name); extEndpoint != ""{ extApi, err := ethapi.NewExternalSigner(extEndpoint) if err != nil{ utils.Fatalf("Could not connect to external signer at %v: %v" , extEndpoint, err) @@ -271,6 +268,10 @@ func startNode(ctx *cli.Context, stack *node.Node) { log.Info("External signer connected", "url", extEndpoint) stack.SetExternalAPI(extApi) } + + // Start up the node itself + utils.StartNode(stack) + // Start auxiliary services if enabled if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { // Mining only makes sense if a full Ethereum node is running diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 45f46e7657..568f23820a 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1121,7 +1121,7 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) { }) } else { err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { - fullNode, err := eth.New(ctx, cfg) + fullNode, err := eth.New(ctx, cfg, stack.ExternalSignerAPI()) if fullNode != nil && cfg.LightServ > 0 { ls, _ := les.NewLesServer(fullNode, cfg) fullNode.AddLesServer(ls) diff --git a/eth/api_backend.go b/eth/api_backend.go index 5b5f81cfa5..653fdd5e5a 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/internal/ethapi" ) // EthAPIBackend implements ethapi.Backend for full nodes @@ -226,7 +227,7 @@ func (b *EthAPIBackend) ServiceFilter(ctx context.Context, session *bloombits.Ma go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests) } } -func (b *EthAPIBackend) ExternalSigner() string { +func (b *EthAPIBackend) ExternalSigner() *ethapi.ExternalSignerAPI { return b.eth.externalSigner } diff --git a/eth/backend.go b/eth/backend.go index 76fe24053d..c86a81706d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -76,7 +76,7 @@ type Ethereum struct { eventMux *event.TypeMux engine consensus.Engine - externalSigner string + externalSigner *ethapi.ExternalSignerAPI bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports @@ -100,7 +100,7 @@ func (s *Ethereum) AddLesServer(ls LesServer) { // New creates a new Ethereum object (including the // initialisation of the common Ethereum object) -func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { +func New(ctx *node.ServiceContext, config *Config, api *ethapi.ExternalSignerAPI) (*Ethereum, error) { if config.SyncMode == downloader.LightSync { return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") } @@ -119,6 +119,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { eth := &Ethereum{ config: config, + externalSigner: api, chainDb: chainDb, chainConfig: chainConfig, eventMux: ctx.EventMux, @@ -331,7 +332,6 @@ func (s *Ethereum) StartMining(local bool) error { log.Error("Etherbase account unavailable locally", "err", err) return fmt.Errorf("signer not configured: %v", err) - } if local { // If local (CPU) mining is started, we can disable the transaction rejection @@ -348,16 +348,16 @@ func (s *Ethereum) StopMining() { s.miner.Stop() } func (s *Ethereum) IsMining() bool { return s.miner.Mining() } func (s *Ethereum) Miner() *miner.Miner { return s.miner } -func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain } -func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } -func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } -func (s *Ethereum) Engine() consensus.Engine { return s.engine } -func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb } -func (s *Ethereum) IsListening() bool { return true } // Always listening -func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } -func (s *Ethereum) NetVersion() uint64 { return s.networkID } -func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader } -func (s *Ethereum) ExternalSigner() string { return s.externalSigner } +func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain } +func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } +func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } +func (s *Ethereum) Engine() consensus.Engine { return s.engine } +func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb } +func (s *Ethereum) IsListening() bool { return true } // Always listening +func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } +func (s *Ethereum) NetVersion() uint64 { return s.networkID } +func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader } +func (s *Ethereum) ExternalSigner() *ethapi.ExternalSignerAPI { return s.externalSigner } // Protocols implements node.Service, returning all the currently configured // network protocols to start. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b6b9503ae3..b51d2fd86d 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -191,14 +191,7 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI { p := &PrivateAccountAPI{ nonceLock: nonceLock, b: b, - } - 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) - } + extapi: b.ExternalSigner(), } return p } @@ -818,18 +811,7 @@ type PublicTransactionPoolAPI struct { // NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool. func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI { - 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} + return &PublicTransactionPoolAPI{b, nonceLock, b.ExternalSigner()} } // GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number. diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 6d7ca3efe4..2e785b853c 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -42,7 +42,7 @@ type Backend interface { SuggestPrice(ctx context.Context) (*big.Int, error) ChainDb() ethdb.Database EventMux() *event.TypeMux - ExternalSigner() string + ExternalSigner() *ExternalSignerAPI // BlockChain API SetHead(number uint64) diff --git a/les/api_backend.go b/les/api_backend.go index 136d41850e..b560bdbf4d 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -35,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/internal/ethapi" ) type LesApiBackend struct { @@ -182,7 +183,7 @@ func (b *LesApiBackend) EventMux() *event.TypeMux { return b.eth.eventMux } -func (b *LesApiBackend) ExternalSigner() string { +func (b *LesApiBackend) ExternalSigner() *ethapi.ExternalSignerAPI{ return b.eth.externalSigner } diff --git a/les/backend.go b/les/backend.go index df455537af..359a32c683 100644 --- a/les/backend.go +++ b/les/backend.go @@ -71,7 +71,7 @@ type LightEthereum struct { eventMux *event.TypeMux engine consensus.Engine - externalSigner string + externalSigner *ethapi.ExternalSignerAPI networkId uint64 netRPCService *ethapi.PublicNetAPI diff --git a/node/node.go b/node/node.go index faf6787255..60923b2c07 100644 --- a/node/node.go +++ b/node/node.go @@ -558,6 +558,9 @@ func (n *Node) SetExternalAPI(api *ethapi.ExternalSignerAPI){ n.extapi = api } +func (n *Node) ExternalSignerAPI() *ethapi.ExternalSignerAPI{ + return n.extapi +} // apis returns the collection of RPC descriptors this node offers. func (n *Node) apis() []rpc.API { return []rpc.API{ diff --git a/signer/core/cliui.go b/signer/core/cliui.go index c8e05f1f2f..29387eeb92 100644 --- a/signer/core/cliui.go +++ b/signer/core/cliui.go @@ -109,17 +109,17 @@ func (ui *CommandlineUI) ApproveTx(request *SignTxRequest) (SignTxResponse, erro fmt.Printf("\nWARNING: Invalid checksum on to-address!\n\n") } } else { - fmt.Printf("to: \n") + fmt.Printf("To: \n") } - fmt.Printf("from: %v\n", request.Transaction.From.String()) - fmt.Printf("value: %v wei\n", weival) - fmt.Printf("gas: %v\n", request.Transaction.Gas) - fmt.Printf("gasprice: %v wei\n", request.Transaction.GasPrice) - fmt.Printf("nonce: %v\n", request.Transaction.Nonce) + fmt.Printf("Trom: %v\n", request.Transaction.From.String()) + fmt.Printf("Value: %v wei\n", weival) + fmt.Printf("Gas: %v\n", request.Transaction.Gas) + fmt.Printf("Gasprice: %v wei\n", request.Transaction.GasPrice.ToInt()) + fmt.Printf("Nonce: %v\n", request.Transaction.Nonce) if request.Transaction.Data != nil { d := *request.Transaction.Data if len(d) > 0 { - fmt.Printf("data: %v\n", common.Bytes2Hex(d)) + fmt.Printf("Data: %v\n", common.Bytes2Hex(d)) } } if request.Callinfo != nil { diff --git a/signer/rules/rules.go b/signer/rules/rules.go index 4c6983763f..d5757dccad 100644 --- a/signer/rules/rules.go +++ b/signer/rules/rules.go @@ -194,7 +194,7 @@ func (r *rulesetUI) ApproveImport(request *core.ImportRequest) (core.ImportRespo return r.next.ApproveImport(request) } -func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) { +func (r *rulesetUI) ApproveListing(request *core.ListAccountsRequest) (core.ListAccountsResponse, error) { jsonreq, err := json.Marshal(request) approved, err := r.checkApproval("ApproveListing", jsonreq, err) if err != nil {