Skip to content

Commit

Permalink
Merge pull request #1287 from njgheorghita/relocate-miner-module
Browse files Browse the repository at this point in the history
Move miner module to geth namespace
  • Loading branch information
njgheorghita authored Mar 19, 2019
2 parents 4acfb9d + 1f759f9 commit a22c6cc
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 65 deletions.
2 changes: 2 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Unreleased (latest source)
--------------------------
- Move ``web3.admin`` module to ``web3.geth`` namespace.
- `#1288 <https://github.com/ethereum/web3.py/pull/1288>`_
- Move ``web3.miner`` module to ``web3.geth`` namespace.
- `#1287 <https://github.com/ethereum/web3.py/pull/1287>`_
- Remove ``web3/utils`` directory in favor of ``web3/_utils``
- `#1282 <https://github.com/ethereum/web3.py/pull/1282>`_
- Implement ``eth_submitHashrate`` and ``eth_submitWork`` JSONRPC endpoints.
Expand Down
38 changes: 18 additions & 20 deletions docs/web3.miner.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
Miner API
=========

.. py:module:: web3.miner
.. py:module:: web3.geth.miner
.. py:class:: Miner
The ``web3.miner`` object exposes methods to interact with the RPC APIs under
the ``miner_`` namespace.
The ``web3.geth.miner`` object exposes methods to interact with the RPC APIs under
the ``miner_`` namespace that are supported by the Geth client.


Methods
-------

The following methods are available on the ``web3.miner`` namespace.
The following methods are available on the ``web3.geth.miner`` namespace.


.. py:method:: Miner.makeDAG(number)
.. py:method:: GethMiner.makeDAG(number)
* Delegates to ``miner_makeDag`` RPC Method

Generate the DAG for the given block number.

.. code-block:: python
>>> web3.miner.makeDag(10000)
>>> web3.geth.miner.makeDag(10000)
.. py:method:: Miner.setExtra(extra)
.. py:method:: GethMiner.setExtra(extra)
* Delegates to ``miner_setExtra`` RPC Method

Expand All @@ -35,10 +33,10 @@ The following methods are available on the ``web3.miner`` namespace.

.. code-block:: python
>>> web3.miner.setExtra('abcdefghijklmnopqrstuvwxyzABCDEF')
>>> web3.geth.miner.setExtra('abcdefghijklmnopqrstuvwxyzABCDEF')
.. py:method:: Miner.setGasPrice(gas_price)
.. py:method:: GethMiner.setGasPrice(gas_price)
* Delegates to ``miner_setGasPrice`` RPC Method

Expand All @@ -48,48 +46,48 @@ The following methods are available on the ``web3.miner`` namespace.

.. code-block:: python
>>> web3.miner.setGasPrice(19999999999)
>>> web3.geth.miner.setGasPrice(19999999999)
.. py:method:: Miner.start(num_threads)
.. py:method:: GethMiner.start(num_threads)
* Delegates to ``miner_start`` RPC Method

Start the CPU mining process using the given number of threads.

.. code-block:: python
>>> web3.miner.start(2)
>>> web3.geth.miner.start(2)
.. py:method:: Miner.stop()
.. py:method:: GethMiner.stop()
* Delegates to ``miner_stop`` RPC Method

Stop the CPU mining operation

.. code-block:: python
>>> web3.miner.stop()
>>> web3.geth.miner.stop()
.. py:method:: Miner.startAutoDAG()
.. py:method:: GethMiner.startAutoDAG()
* Delegates to ``miner_startAutoDag`` RPC Method

Enable automatic DAG generation.

.. code-block:: python
>>> web3.miner.startAutoDAG()
>>> web3.geth.miner.startAutoDAG()
.. py:method:: Miner.stopAutoDAG()
.. py:method:: GethMiner.stopAutoDAG()
* Delegates to ``miner_stopAutoDag`` RPC Method

Disable automatic DAG generation.

.. code-block:: python
>>> web3.miner.stopAutoDAG()
>>> web3.geth.miner.stopAutoDAG()
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_setExtra.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_miner_setExtra(web3_empty, wait_for_block):
# sanity
assert initial_extra != new_extra_data

web3.miner.setExtra(new_extra_data)
web3.geth.miner.setExtra(new_extra_data)

with Timeout(60) as timeout:
while True:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_setGasPrice.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_miner_setGasPrice(web3_empty, wait_for_block):
# sanity check
assert web3.eth.gasPrice > 1000

web3.miner.setGasPrice(initial_gas_price // 2)
web3.geth.miner.setGasPrice(initial_gas_price // 2)

with Timeout(60) as timeout:
while web3.eth.gasPrice == initial_gas_price:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_miner_start(web3_empty, wait_for_miner_start):
assert web3.eth.mining
assert web3.eth.hashrate

web3.miner.stop()
web3.geth.miner.stop()

with Timeout(60) as timeout:
while web3.eth.mining or web3.eth.hashrate:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_miner_stop(web3_empty):
assert web3.eth.mining
assert web3.eth.hashrate

web3.miner.stop()
web3.geth.miner.stop()

with Timeout(60) as timeout:
while web3.eth.mining or web3.eth.hashrate:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_setEtherBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ def test_miner_setEtherbase(web3_empty):
web3 = web3_empty
assert web3.eth.coinbase == web3.eth.accounts[0]
new_account = web3.personal.newAccount('this-is-a-password')
web3.miner.setEtherBase(new_account)
web3.geth.miner.setEtherBase(new_account)
assert web3.eth.coinbase == new_account
2 changes: 1 addition & 1 deletion tests/core/txpool-module/test_txpool_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def test_txpool_content(web3_empty):
web3 = web3_empty

web3.miner.stop()
web3.geth.miner.stop()

with Timeout(60) as timeout:
while web3.eth.hashrate or web3.eth.mining:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/txpool-module/test_txpool_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def test_txpool_inspect(web3_empty):
web3 = web3_empty

web3.miner.stop()
web3.geth.miner.stop()

with Timeout(60) as timeout:
while web3.eth.hashrate or web3.eth.mining:
Expand Down
10 changes: 5 additions & 5 deletions tests/generate_go_ethereum_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,22 @@ def verify_chain_state(web3, chain_data):


def mine_transaction_hash(web3, txn_hash):
web3.miner.start(1)
web3.geth.miner.start(1)
try:
return web3.eth.waitForTransactionReceipt(txn_hash, timeout=60)
finally:
web3.miner.stop()
web3.geth.miner.stop()


def mine_block(web3):
origin_block_number = web3.eth.blockNumber

start_time = time.time()
web3.miner.start(1)
web3.geth.miner.start(1)
while time.time() < start_time + 60:
block_number = web3.eth.blockNumber
if block_number > origin_block_number:
web3.miner.stop()
web3.geth.miner.stop()
return block_number
else:
time.sleep(0.1)
Expand Down Expand Up @@ -376,7 +376,7 @@ def setup_chain_state(web3):
# Block with Transaction
#
web3.personal.unlockAccount(coinbase, KEYFILE_PW)
web3.miner.start(1)
web3.geth.miner.start(1)
mined_txn_hash = web3.eth.sendTransaction({
'from': coinbase,
'to': coinbase,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/generate_fixtures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def mine_block(web3):
origin_block_number = web3.eth.blockNumber

start_time = time.time()
web3.miner.start(1)
web3.geth.miner.start(1)
while time.time() < start_time + 120:
block_number = web3.eth.blockNumber
if block_number > origin_block_number:
web3.miner.stop()
web3.geth.miner.stop()
return block_number
else:
time.sleep(0.1)
Expand All @@ -208,11 +208,11 @@ def mine_block(web3):

def mine_transaction_hash(web3, txn_hash):
start_time = time.time()
web3.miner.start(1)
web3.geth.miner.start(1)
while time.time() < start_time + 120:
receipt = web3.eth.getTransactionReceipt(txn_hash)
if receipt is not None:
web3.miner.stop()
web3.geth.miner.stop()
return receipt
else:
time.sleep(0.1)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/generate_fixtures/go_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def setup_chain_state(web3):
# Block with Transaction
#
web3.personal.unlockAccount(coinbase, common.KEYFILE_PW)
web3.miner.start(1)
web3.geth.miner.start(1)
mined_txn_hash = web3.eth.sendTransaction({
'from': coinbase,
'to': coinbase,
Expand Down
26 changes: 25 additions & 1 deletion web3/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
stopRPC,
stopWS,
)
from web3.miner import (
makeDag,
setEtherbase,
setExtra,
setGasPrice,
start,
startAutoDag,
stop,
stopAutoDag,
)
from web3.module import (
Module,
ModuleV2,
Expand Down Expand Up @@ -36,7 +46,7 @@ class Geth(Module):

class GethPersonal(ModuleV2):
"""
https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal
https://github.com/ethereum/go-ethereum/wiki/management-apis#personal
"""
ecRecover = ecRecover()
importRawKey = importRawKey()
Expand Down Expand Up @@ -70,3 +80,17 @@ class GethAdmin(ModuleV2):
startWS = startWS()
stopRPC = stopRPC()
stopWS = stopWS()


class GethMiner(ModuleV2):
"""
https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner
"""
makeDag = makeDag()
setExtra = setExtra()
setEtherbase = setEtherbase()
setGasPrice = setGasPrice()
start = start()
stop = stop()
startAutoDag = startAutoDag()
stopAutoDag = stopAutoDag()
6 changes: 2 additions & 4 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@
GethAdmin,
GethPersonal,
GethTxPool,
GethMiner,
)
from web3.iban import (
Iban,
)
from web3.manager import (
RequestManager as DefaultRequestManager,
)
from web3.miner import (
Miner,
)
from web3.net import (
Net,
)
Expand Down Expand Up @@ -88,12 +86,12 @@ def get_default_modules():
"eth": (Eth,),
"net": (Net,),
"version": (Version,),
"miner": (Miner,),
"parity": (Parity, {
"personal": (ParityPersonal,)
}),
"geth": (Geth, {
"admin": (GethAdmin,),
"miner": (GethMiner,),
"personal": (GethPersonal,),
"txpool": (GethTxPool,),
}),
Expand Down
Loading

0 comments on commit a22c6cc

Please sign in to comment.