diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 623f8ac811..a65a43ac30 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -328,7 +328,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { } // Start auxiliary services if enabled if ctx.GlobalBool(utils.MiningEnabledFlag.Name) { - var ethereum *eth.FullNodeService + var ethereum *eth.Ethereum if err := stack.Service(ðereum); err != nil { utils.Fatalf("ethereum service not running: %v", err) } diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go index 668efbfc76..2e07e94260 100644 --- a/cmd/gethrpctest/main.go +++ b/cmd/gethrpctest/main.go @@ -146,7 +146,7 @@ func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node // RunTest executes the specified test against an already pre-configured protocol // stack to ensure basic checks pass before running RPC tests. func RunTest(stack *node.Node, test *tests.BlockTest) error { - var ethereum *eth.FullNodeService + var ethereum *eth.Ethereum stack.Service(ðereum) blockchain := ethereum.BlockChain() diff --git a/common/natspec/natspec_e2e_test.go b/common/natspec/natspec_e2e_test.go index ac0bbe784c..2552605769 100644 --- a/common/natspec/natspec_e2e_test.go +++ b/common/natspec/natspec_e2e_test.go @@ -99,7 +99,7 @@ const ( type testFrontend struct { t *testing.T - ethereum *eth.FullNodeService + ethereum *eth.Ethereum xeth *xe.XEth wait chan *big.Int lastConfirm string @@ -123,7 +123,7 @@ func (self *testFrontend) ConfirmTransaction(tx string) bool { return true } -func testEth(t *testing.T) (ethereum *eth.FullNodeService, err error) { +func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) { tmp, err := ioutil.TempDir("", "natspec-test") if err != nil { diff --git a/console/console_test.go b/console/console_test.go index b40db06046..7738d0c442 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -76,7 +76,7 @@ func (p *hookedPrompter) SetWordCompleter(completer WordCompleter) {} type tester struct { workspace string stack *node.Node - ethereum *eth.FullNodeService + ethereum *eth.Ethereum console *Console input *hookedPrompter output *bytes.Buffer @@ -134,7 +134,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { t.Fatalf("failed to create JavaScript console: %v", err) } // Create the final tester and return - var ethereum *eth.FullNodeService + var ethereum *eth.Ethereum stack.Service(ðereum) return &tester{ diff --git a/eth/api.go b/eth/api.go index b4a314fca4..74a8151008 100644 --- a/eth/api.go +++ b/eth/api.go @@ -40,41 +40,41 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) -// PublicFullEthereumAPI provides an API to access Ethereum full node-related +// PublicEthereumAPI provides an API to access Ethereum full node-related // information. -type PublicFullEthereumAPI struct { - e *FullNodeService +type PublicEthereumAPI struct { + e *Ethereum } -// NewPublicFullEthereumAPI creates a new Etheruem protocol API for full nodes. -func NewPublicFullEthereumAPI(e *FullNodeService) *PublicFullEthereumAPI { - return &PublicFullEthereumAPI{e} +// NewPublicEthereumAPI creates a new Etheruem protocol API for full nodes. +func NewPublicEthereumAPI(e *Ethereum) *PublicEthereumAPI { + return &PublicEthereumAPI{e} } // Etherbase is the address that mining rewards will be send to -func (s *PublicFullEthereumAPI) Etherbase() (common.Address, error) { +func (s *PublicEthereumAPI) Etherbase() (common.Address, error) { return s.e.Etherbase() } // Coinbase is the address that mining rewards will be send to (alias for Etherbase) -func (s *PublicFullEthereumAPI) Coinbase() (common.Address, error) { +func (s *PublicEthereumAPI) Coinbase() (common.Address, error) { return s.Etherbase() } // Hashrate returns the POW hashrate -func (s *PublicFullEthereumAPI) Hashrate() *rpc.HexNumber { +func (s *PublicEthereumAPI) Hashrate() *rpc.HexNumber { return rpc.NewHexNumber(s.e.Miner().HashRate()) } // PublicMinerAPI provides an API to control the miner. // It offers only methods that operate on data that pose no security risk when it is publicly accessible. type PublicMinerAPI struct { - e *FullNodeService + e *Ethereum agent *miner.RemoteAgent } // NewPublicMinerAPI create a new PublicMinerAPI instance. -func NewPublicMinerAPI(e *FullNodeService) *PublicMinerAPI { +func NewPublicMinerAPI(e *Ethereum) *PublicMinerAPI { agent := miner.NewRemoteAgent() e.Miner().Register(agent) @@ -120,11 +120,11 @@ func (s *PublicMinerAPI) SubmitHashrate(hashrate rpc.HexNumber, id common.Hash) // PrivateMinerAPI provides private RPC methods to control the miner. // These methods can be abused by external users and must be considered insecure for use by untrusted users. type PrivateMinerAPI struct { - e *FullNodeService + e *Ethereum } // NewPrivateMinerAPI create a new RPC service which controls the miner of this node. -func NewPrivateMinerAPI(e *FullNodeService) *PrivateMinerAPI { +func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI { return &PrivateMinerAPI{e: e} } @@ -191,20 +191,20 @@ func (s *PrivateMinerAPI) MakeDAG(blockNr rpc.BlockNumber) (bool, error) { return true, nil } -// PrivateFullAdminAPI is the collection of Etheruem full node-related APIs +// PrivateAdminAPI is the collection of Etheruem full node-related APIs // exposed over the private admin endpoint. -type PrivateFullAdminAPI struct { - eth *FullNodeService +type PrivateAdminAPI struct { + eth *Ethereum } // NewPrivateAdminAPI creates a new API definition for the full node private // admin methods of the Ethereum service. -func NewPrivateFullAdminAPI(eth *FullNodeService) *PrivateFullAdminAPI { - return &PrivateFullAdminAPI{eth: eth} +func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI { + return &PrivateAdminAPI{eth: eth} } // ExportChain exports the current blockchain into a local file. -func (api *PrivateFullAdminAPI) ExportChain(file string) (bool, error) { +func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) { // Make sure we can create the file to export into out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm) if err != nil { @@ -230,7 +230,7 @@ func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool { } // ImportChain imports a blockchain from a local file. -func (api *PrivateFullAdminAPI) ImportChain(file string) (bool, error) { +func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) { // Make sure the can access the file to import in, err := os.Open(file) if err != nil { @@ -271,20 +271,20 @@ func (api *PrivateFullAdminAPI) ImportChain(file string) (bool, error) { return true, nil } -// PublicFullDebugAPI is the collection of Etheruem full node APIs exposed +// PublicDebugAPI is the collection of Etheruem full node APIs exposed // over the public debugging endpoint. -type PublicFullDebugAPI struct { - eth *FullNodeService +type PublicDebugAPI struct { + eth *Ethereum } -// NewPublicFullDebugAPI creates a new API definition for the full node- +// NewPublicDebugAPI creates a new API definition for the full node- // related public debug methods of the Ethereum service. -func NewPublicFullDebugAPI(eth *FullNodeService) *PublicFullDebugAPI { - return &PublicFullDebugAPI{eth: eth} +func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI { + return &PublicDebugAPI{eth: eth} } // DumpBlock retrieves the entire state of the database at a given block. -func (api *PublicFullDebugAPI) DumpBlock(number uint64) (state.World, error) { +func (api *PublicDebugAPI) DumpBlock(number uint64) (state.World, error) { block := api.eth.BlockChain().GetBlockByNumber(number) if block == nil { return state.World{}, fmt.Errorf("block #%d not found", number) @@ -296,17 +296,17 @@ func (api *PublicFullDebugAPI) DumpBlock(number uint64) (state.World, error) { return stateDb.RawDump(), nil } -// PrivateFullDebugAPI is the collection of Etheruem full node APIs exposed over +// PrivateDebugAPI is the collection of Etheruem full node APIs exposed over // the private debugging endpoint. -type PrivateFullDebugAPI struct { +type PrivateDebugAPI struct { config *core.ChainConfig - eth *FullNodeService + eth *Ethereum } -// NewPrivateFullDebugAPI creates a new API definition for the full node-related +// NewPrivateDebugAPI creates a new API definition for the full node-related // private debug methods of the Ethereum service. -func NewPrivateFullDebugAPI(config *core.ChainConfig, eth *FullNodeService) *PrivateFullDebugAPI { - return &PrivateFullDebugAPI{config: config, eth: eth} +func NewPrivateDebugAPI(config *core.ChainConfig, eth *Ethereum) *PrivateDebugAPI { + return &PrivateDebugAPI{config: config, eth: eth} } // BlockTraceResult is the returned value when replaying a block to check for @@ -319,7 +319,7 @@ type BlockTraceResult struct { // TraceBlock processes the given block's RLP but does not import the block in to // the chain. -func (api *PrivateFullDebugAPI) TraceBlock(blockRlp []byte, config *vm.Config) BlockTraceResult { +func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config *vm.Config) BlockTraceResult { var block types.Block err := rlp.Decode(bytes.NewReader(blockRlp), &block) if err != nil { @@ -336,7 +336,7 @@ func (api *PrivateFullDebugAPI) TraceBlock(blockRlp []byte, config *vm.Config) B // TraceBlockFromFile loads the block's RLP from the given file name and attempts to // process it but does not import the block in to the chain. -func (api *PrivateFullDebugAPI) TraceBlockFromFile(file string, config *vm.Config) BlockTraceResult { +func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config *vm.Config) BlockTraceResult { blockRlp, err := ioutil.ReadFile(file) if err != nil { return BlockTraceResult{Error: fmt.Sprintf("could not read file: %v", err)} @@ -345,7 +345,7 @@ func (api *PrivateFullDebugAPI) TraceBlockFromFile(file string, config *vm.Confi } // TraceBlockByNumber processes the block by canonical block number. -func (api *PrivateFullDebugAPI) TraceBlockByNumber(number uint64, config *vm.Config) BlockTraceResult { +func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config *vm.Config) BlockTraceResult { // Fetch the block that we aim to reprocess block := api.eth.BlockChain().GetBlockByNumber(number) if block == nil { @@ -361,7 +361,7 @@ func (api *PrivateFullDebugAPI) TraceBlockByNumber(number uint64, config *vm.Con } // TraceBlockByHash processes the block by hash. -func (api *PrivateFullDebugAPI) TraceBlockByHash(hash common.Hash, config *vm.Config) BlockTraceResult { +func (api *PrivateDebugAPI) TraceBlockByHash(hash common.Hash, config *vm.Config) BlockTraceResult { // Fetch the block that we aim to reprocess block := api.eth.BlockChain().GetBlockByHash(hash) if block == nil { @@ -389,7 +389,7 @@ func (t *TraceCollector) AddStructLog(slog vm.StructLog) { } // traceBlock processes the given block but does not save the state. -func (api *PrivateFullDebugAPI) traceBlock(block *types.Block, config *vm.Config) (bool, []vm.StructLog, error) { +func (api *PrivateDebugAPI) traceBlock(block *types.Block, config *vm.Config) (bool, []vm.StructLog, error) { // Validate and reprocess the block var ( blockchain = api.eth.BlockChain() @@ -452,7 +452,7 @@ func formatError(err error) string { // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. -func (api *PrivateFullDebugAPI) TraceTransaction(txHash common.Hash, logger *vm.LogConfig) (*ethapi.ExecutionResult, error) { +func (api *PrivateDebugAPI) TraceTransaction(txHash common.Hash, logger *vm.LogConfig) (*ethapi.ExecutionResult, error) { if logger == nil { logger = new(vm.LogConfig) } diff --git a/eth/api_backend.go b/eth/api_backend.go index 9dbebb226f..efcdb33619 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -36,7 +36,7 @@ import ( // EthApiBackend implements ethapi.Backend for full nodes type EthApiBackend struct { - eth *FullNodeService + eth *Ethereum gpo *gasprice.GasPriceOracle } diff --git a/eth/backend.go b/eth/backend.go index f0ca38cbd5..351cc27445 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -103,8 +103,8 @@ type Config struct { TestGenesisState ethdb.Database // Genesis state to seed the database with (testing only!) } -// FullNodeService implements the Ethereum full node service. -type FullNodeService struct { +// Ethereum implements the Ethereum full node service. +type Ethereum struct { chainConfig *core.ChainConfig // Channel for shutting down the service shutdownChan chan bool // Channel for shutting down the ethereum @@ -140,9 +140,9 @@ type FullNodeService struct { netRPCService *ethapi.PublicNetAPI } -// New creates a new FullNodeService object (including the +// New creates a new Ethereum object (including the // initialisation of the common Ethereum object) -func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) { +func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { chainDb, dappDb, err := CreateDBs(ctx, config) if err != nil { return nil, err @@ -156,7 +156,7 @@ func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) { return nil, err } - eth := &FullNodeService{ + eth := &Ethereum{ chainDb: chainDb, dappDb: dappDb, eventMux: ctx.EventMux, @@ -303,12 +303,12 @@ func CreatePoW(config *Config) (*ethash.Ethash, error) { // APIs returns the collection of RPC services the ethereum package offers. // NOTE, some of these services probably need to be moved to somewhere else. -func (s *FullNodeService) APIs() []rpc.API { +func (s *Ethereum) APIs() []rpc.API { return append(ethapi.GetAPIs(s.apiBackend, &s.solcPath, &s.solc), []rpc.API{ { Namespace: "eth", Version: "1.0", - Service: NewPublicFullEthereumAPI(s), + Service: NewPublicEthereumAPI(s), Public: true, }, { Namespace: "eth", @@ -333,16 +333,16 @@ func (s *FullNodeService) APIs() []rpc.API { }, { Namespace: "admin", Version: "1.0", - Service: NewPrivateFullAdminAPI(s), + Service: NewPrivateAdminAPI(s), }, { Namespace: "debug", Version: "1.0", - Service: NewPublicFullDebugAPI(s), + Service: NewPublicDebugAPI(s), Public: true, }, { Namespace: "debug", Version: "1.0", - Service: NewPrivateFullDebugAPI(s.chainConfig, s), + Service: NewPrivateDebugAPI(s.chainConfig, s), }, { Namespace: "net", Version: "1.0", @@ -356,11 +356,11 @@ func (s *FullNodeService) APIs() []rpc.API { }...) } -func (s *FullNodeService) ResetWithGenesisBlock(gb *types.Block) { +func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) { s.blockchain.ResetWithGenesisBlock(gb) } -func (s *FullNodeService) Etherbase() (eb common.Address, err error) { +func (s *Ethereum) Etherbase() (eb common.Address, err error) { eb = s.etherbase if (eb == common.Address{}) { firstAccount, err := s.AccountManager().AccountByIndex(0) @@ -373,36 +373,36 @@ func (s *FullNodeService) Etherbase() (eb common.Address, err error) { } // set in js console via admin interface or wrapper from cli flags -func (self *FullNodeService) SetEtherbase(etherbase common.Address) { +func (self *Ethereum) SetEtherbase(etherbase common.Address) { self.etherbase = etherbase self.miner.SetEtherbase(etherbase) } -func (s *FullNodeService) StopMining() { s.miner.Stop() } -func (s *FullNodeService) IsMining() bool { return s.miner.Mining() } -func (s *FullNodeService) Miner() *miner.Miner { return s.miner } - -func (s *FullNodeService) AccountManager() *accounts.Manager { return s.accountManager } -func (s *FullNodeService) BlockChain() *core.BlockChain { return s.blockchain } -func (s *FullNodeService) TxPool() *core.TxPool { return s.txPool } -func (s *FullNodeService) EventMux() *event.TypeMux { return s.eventMux } -func (s *FullNodeService) Pow() *ethash.Ethash { return s.pow } -func (s *FullNodeService) ChainDb() ethdb.Database { return s.chainDb } -func (s *FullNodeService) DappDb() ethdb.Database { return s.dappDb } -func (s *FullNodeService) IsListening() bool { return true } // Always listening -func (s *FullNodeService) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } -func (s *FullNodeService) NetVersion() int { return s.netVersionId } -func (s *FullNodeService) Downloader() *downloader.Downloader { return s.protocolManager.downloader } +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) AccountManager() *accounts.Manager { return s.accountManager } +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) Pow() *ethash.Ethash { return s.pow } +func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb } +func (s *Ethereum) DappDb() ethdb.Database { return s.dappDb } +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() int { return s.netVersionId } +func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader } // Protocols implements node.Service, returning all the currently configured // network protocols to start. -func (s *FullNodeService) Protocols() []p2p.Protocol { +func (s *Ethereum) Protocols() []p2p.Protocol { return s.protocolManager.SubProtocols } // Start implements node.Service, starting all internal goroutines needed by the -// FullNodeService protocol implementation. -func (s *FullNodeService) Start(srvr *p2p.Server) error { +// Ethereum protocol implementation. +func (s *Ethereum) Start(srvr *p2p.Server) error { s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.NetVersion()) if s.AutoDAG { s.StartAutoDAG() @@ -413,7 +413,7 @@ func (s *FullNodeService) Start(srvr *p2p.Server) error { // Stop implements node.Service, terminating all internal goroutines used by the // Ethereum protocol. -func (s *FullNodeService) Stop() error { +func (s *Ethereum) Stop() error { if s.stopDbUpgrade != nil { s.stopDbUpgrade() } @@ -433,7 +433,7 @@ func (s *FullNodeService) Stop() error { } // This function will wait for a shutdown and resumes main thread execution -func (s *FullNodeService) WaitForShutdown() { +func (s *Ethereum) WaitForShutdown() { <-s.shutdownChan } @@ -446,7 +446,7 @@ func (s *FullNodeService) WaitForShutdown() { // stop any number of times. // For any more sophisticated pattern of DAG generation, use CLI subcommand // makedag -func (self *FullNodeService) StartAutoDAG() { +func (self *Ethereum) StartAutoDAG() { if self.autodagquit != nil { return // already started } @@ -492,7 +492,7 @@ func (self *FullNodeService) StartAutoDAG() { } // stopAutoDAG stops automatic DAG pregeneration by quitting the loop -func (self *FullNodeService) StopAutoDAG() { +func (self *Ethereum) StopAutoDAG() { if self.autodagquit != nil { close(self.autodagquit) self.autodagquit = nil @@ -502,7 +502,7 @@ func (self *FullNodeService) StopAutoDAG() { // HTTPClient returns the light http client used for fetching offchain docs // (natspec, source for verification) -func (self *FullNodeService) HTTPClient() *httpclient.HTTPClient { +func (self *Ethereum) HTTPClient() *httpclient.HTTPClient { return self.httpclient } diff --git a/eth/bind.go b/eth/bind.go index 7eb15ca1b6..c1366464f9 100644 --- a/eth/bind.go +++ b/eth/bind.go @@ -42,7 +42,7 @@ type ContractBackend struct { // NewContractBackend creates a new native contract backend using an existing // Etheruem object. -func NewContractBackend(eth *FullNodeService) *ContractBackend { +func NewContractBackend(eth *Ethereum) *ContractBackend { return &ContractBackend{ eapi: ethapi.NewPublicEthereumAPI(eth.apiBackend, nil, nil), bcapi: ethapi.NewPublicBlockChainAPI(eth.apiBackend), diff --git a/eth/cpu_mining.go b/eth/cpu_mining.go index 143b9c98a3..3469d394e9 100644 --- a/eth/cpu_mining.go +++ b/eth/cpu_mining.go @@ -28,7 +28,7 @@ import ( const disabledInfo = "Set GO_OPENCL and re-build to enable." -func (s *FullNodeService) StartMining(threads int, gpus string) error { +func (s *Ethereum) StartMining(threads int, gpus string) error { eb, err := s.Etherbase() if err != nil { err = fmt.Errorf("Cannot start mining without etherbase address: %v", err) diff --git a/eth/gpu_mining.go b/eth/gpu_mining.go index 0208bba806..12fa746018 100644 --- a/eth/gpu_mining.go +++ b/eth/gpu_mining.go @@ -33,7 +33,7 @@ import ( "github.com/ethereum/go-ethereum/miner" ) -func (s *FullNodeService) StartMining(threads int, gpus string) error { +func (s *Ethereum) StartMining(threads int, gpus string) error { eb, err := s.Etherbase() if err != nil { err = fmt.Errorf("Cannot start mining without etherbase address: %v", err) diff --git a/release/release.go b/release/release.go index 07eb9359cf..21b5e2ce21 100644 --- a/release/release.go +++ b/release/release.go @@ -58,7 +58,7 @@ type ReleaseService struct { // releases and notify the user of such. func NewReleaseService(ctx *node.ServiceContext, config Config) (node.Service, error) { // Retrieve the Ethereum service dependency to access the blockchain - var ethereum *eth.FullNodeService + var ethereum *eth.Ethereum if err := ctx.Service(ðereum); err != nil { return nil, err }