Skip to content

Commit

Permalink
refactor!: rename geth to node (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Apr 23, 2024
1 parent 7c61a82 commit 13ea0a1
Show file tree
Hide file tree
Showing 31 changed files with 154 additions and 142 deletions.
4 changes: 2 additions & 2 deletions docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ geth:
uri: http://localhost:5030
```

Now, the `ape-geth` core plugin will use the URL `http://localhost:5030` to connect and make requests.
Now, the `ape-node` core plugin will use the URL `http://localhost:5030` to connect and make requests.

**WARN**: Instead of using `ape-geth` to connect to an Infura or Alchemy node, use the [ape-infura](https://github.com/ApeWorX/ape-infura) or [ape-alchemy](https://github.com/ApeWorX/ape-alchemy) provider plugins instead, which have their own way of managing API keys via environment variables.
**WARN**: Instead of using `ape-node` to connect to an Infura or Alchemy node, use the [ape-infura](https://github.com/ApeWorX/ape-infura) or [ape-alchemy](https://github.com/ApeWorX/ape-alchemy) provider plugins instead, which have their own way of managing API keys via environment variables.

For more information on networking as a whole, see [this guide](./networks.html).

Expand Down
2 changes: 1 addition & 1 deletion docs/userguides/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ print(receipt.gas_used)

Notice that transacting returns a [ReceiptAPI](../methoddocs/api.html#ape.api.transactions.ReceiptAPI) object which contains all the receipt data, such as `gas_used`.

**NOTE**: If you need the `return_value` from a transaction, you have to either treat transaction as a call (see the section below!) or use a provider with tracing-features enabled (such as `ape-foundry` or `ape-geth`) and access the [return_value](../methoddocs/api.html#ape.api.transactions.ReceiptAPI.return_value) property on the receipt.
**NOTE**: If you need the `return_value` from a transaction, you have to either treat transaction as a call (see the section below!) or use a provider with tracing-features enabled (such as `ape-foundry` or `ape-node`) and access the [return_value](../methoddocs/api.html#ape.api.transactions.ReceiptAPI.return_value) property on the receipt.

```python
assert receipt.return_value == 123
Expand Down
36 changes: 18 additions & 18 deletions docs/userguides/networks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Networks

When interacting with a blockchain, you will have to select an ecosystem (e.g. Ethereum, Arbitrum, or Fantom), a network (e.g. Mainnet or Sepolia) and a provider (e.g. Eth-Tester, Geth, or Alchemy).
When interacting with a blockchain, you will have to select an ecosystem (e.g. Ethereum, Arbitrum, or Fantom), a network (e.g. Mainnet or Sepolia) and a provider (e.g. Eth-Tester, Node (Geth), or Alchemy).
Networks are part of ecosystems and typically defined in plugins.
For example, the `ape-ethereum` plugin comes with Ape and can be used for handling EVM-like behavior.

Expand All @@ -15,7 +15,7 @@ No matter what type of network you are using in Ape, you specify the network usi

Where `ecosystem-name` refers to the ecosystem, e.g. `ethereum`, `polygon`, `fantom`, or any valid ecosystem plugin name.
The `network-name` refers to a network such as `mainnet`, `local`, or something else defined by your ecosystem or custom network config.
And `provider-name` refers to the provider plugin in Ape, such as `geth` for a generic node or `foundry` if the network is more Anvil-based, or a different plugin altogether.
And `provider-name` refers to the provider plugin in Ape, such as `node` for a generic node or `foundry` if the network is more Anvil-based, or a different plugin altogether.

Commonly, the network triplet value is specified via the `--network` option in Ape CLI commands.
The following is a list of common Ape commands that can use the `--network` option:
Expand Down Expand Up @@ -79,10 +79,10 @@ Here is a list of all L2 network plugins supported by Ape:

**NOTE**: If you are connecting an L2 network or any other network that does not have a plugin, you can use the custom network support, which is described in the [next section](#custom-network-connection).

Once you have the L2 network plugin installed, you can configure its node's URI by setting the values in the `geth` (default node) core plugin via your `ape-config.yaml` file:
Once you have the L2 network plugin installed, you can configure its node's URI by setting the values in the `node` core plugin via your `ape-config.yaml` file:

```yaml
geth:
node:
<ecosystem-name>:
<network-name>:
uri: https://path.to.node.example.com
Expand Down Expand Up @@ -120,7 +120,7 @@ networks:
chain_id: 109 # Required
ecosystem: shibarium # The ecosystem name, can either be new or an existing
base_ecosystem_plugin: polygon # The ecosystem base-class, defaults to the default ecosystem
default_provider: geth # Default is the generic node provider
default_provider: node # Default is the generic node provider
```
The following paragraphs explain the different parameters of the custom network config.
Expand Down Expand Up @@ -168,13 +168,13 @@ networks:
base_ecosystem_plugin: polygon # Closest base class.
chain_id: 109 # This must be correct or txns will fail.
geth:
node:
shibarium:
mainnet:
uri: https://www.shibrpc.com
```

Now, when using `ethereum:apenet:geth`, it will connect to the RPC URL `https://apenet.example.com/rpc`.
Now, when using `ethereum:apenet:node`, it will connect to the RPC URL `https://apenet.example.com/rpc`.

#### Explorer URL

Expand All @@ -186,7 +186,7 @@ networks:
custom:
- name: customnetwork
chain_id: 31337
default_provider: geth
default_provider: node
```

To add a corresponding entry in `ape-etherscan` (assuming you are using `ape-etherscan` as your explorer plugin), add the following to your `ape-config.yaml` file:
Expand Down Expand Up @@ -314,24 +314,24 @@ It is meant for running tests and debugging contracts.
Out-of-the-box, Ape ships with two development providers you can use for the `local` network:

- [EthTester](https://github.com/ethereum/eth-tester)
- An Ephemeral Geth process
- An Ephemeral Node (defaults to Geth) process

```bash
ape test --network ::test
ape test --network ::geth # Launch a local development geth process
ape test --network ::node # Launch a local development node (geth) process
```

To learn more about testing in ape, follow [this guide](./testing.html).

## Live Networks

Use the core plugin `ape-geth` to connect to local or remote nodes via URI.
The geth plugin is abstract in that it represents any node, not just geth nodes.
Use the core plugin `ape-node` to connect to local or remote nodes via URI.
The node plugin is abstract in that it represents any node.
However, it will work best when connected to a geth node.
To configure network URIs in geth, you can use the `ape-config.yaml` file:
To configure network URIs in `node`, you can use the `ape-config.yaml` file:

```yaml
geth:
node:
ethereum:
mainnet:
uri: https://foo.node.bar
Expand Down Expand Up @@ -391,7 +391,7 @@ To run a network with a process, use the `ape networks run` command:
ape networks run
```

By default, `ape networks run` runs a development Geth process.
By default, `ape networks run` runs a development Node (geth) process.
To use a different network, such as `hardhat` or Anvil nodes, use the `--network` flag:

```shell
Expand Down Expand Up @@ -423,7 +423,7 @@ from ape import chain, networks
def main():
start_provider = chain.provider.name
with networks.ethereum.mainnet.use_provider("geth") as provider:
with networks.ethereum.mainnet.use_provider("node") as provider:
# We are using a different provider than the one we started with.
assert start_provider != provider.name
```
Expand All @@ -436,9 +436,9 @@ from ape import networks
@click.command()
def cli():
with networks.polygon.mainnet.use_provider("geth"):
with networks.polygon.mainnet.use_provider("node"):
...
with networks.ethereum.mainnet.use_provider("geth"):
with networks.ethereum.mainnet.use_provider("node"):
...
```

Expand Down
5 changes: 3 additions & 2 deletions docs/userguides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ ape test test_my_contract -I -s

## Test Providers

Out-of-the-box, your tests run using the `eth-tester` provider, which comes bundled with ape. If you have `geth` installed, you can use the `ape-geth` plugin that also comes with ape.
Out-of-the-box, your tests run using the `eth-tester` provider, which comes bundled with ape.
If you have Ethereum node software installed, you can use the `ape-node` plugin that also comes with ape.

```bash
ape test --network ethereum:local:geth
ape test --network ethereum:local:node
```

Each testing plugin should work the same way. You will have access to the same test accounts.
Expand Down
2 changes: 1 addition & 1 deletion docs/userguides/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Use the `show_trace=` kwarg on a contract call and Ape will display the trace be
token.balanceOf(account, show_trace=True)
```

**NOTE**: This may not work on all providers, but it should work on common ones such as `ape-hardhat` or `ape-geth`.
**NOTE**: This may not work on all providers, but it should work on common ones such as `ape-hardhat` or `ape-node`.

## Gas Reports

Expand Down
2 changes: 1 addition & 1 deletion src/ape/__modules__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"ape_compile",
"ape_console",
"ape_ethereum",
"ape_geth",
"ape_init",
"ape_networks",
"ape_node",
"ape_plugins",
"ape_run",
"ape_test",
Expand Down
8 changes: 4 additions & 4 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def custom_network(self) -> "NetworkAPI":
ecosystem=ethereum,
data_folder=self.data_folder / "custom",
request_header=request_header,
_default_provider="geth",
_default_provider="node",
_is_custom=True,
)

Expand Down Expand Up @@ -958,7 +958,7 @@ def is_adhoc(self) -> bool:
@cached_property
def providers(self): # -> Dict[str, Partial[ProviderAPI]]
"""
The providers of the network, such as Infura, Alchemy, or Geth.
The providers of the network, such as Infura, Alchemy, or Node.
Returns:
Dict[str, partial[:class:`~ape.api.providers.ProviderAPI`]]
Expand Down Expand Up @@ -1023,11 +1023,11 @@ def get_provider(
if ":" in provider_name:
# NOTE: Shortcut that allows `--network ecosystem:network:http://...` to work
provider_settings["uri"] = provider_name
provider_name = "geth"
provider_name = "node"

elif provider_name.endswith(".ipc"):
provider_settings["ipc_path"] = provider_name
provider_name = "geth"
provider_name = "node"

if provider_name in self.providers:
provider = self.providers[provider_name](provider_settings=provider_settings)
Expand Down
8 changes: 1 addition & 7 deletions src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,7 @@ def set_balance(self, address: AddressType, amount: int):

@log_instead_of_fail(default="<ProviderAPI>")
def __repr__(self) -> str:
try:
chain_id = self.chain_id
except Exception as err:
logger.error(str(err))
chain_id = None

return f"<{self.name} chain_id={self.chain_id}>" if chain_id else f"<{self.name}>"
return f"<{self.name.capitalize()} chain_id={self.chain_id}>"

@raises_not_implemented
def set_code( # type: ignore[empty-body]
Expand Down
6 changes: 3 additions & 3 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NetworkManager(BaseManager):
from ape import networks
# "networks" is the NetworkManager singleton
with networks.ethereum.mainnet.use_provider("geth"):
with networks.ethereum.mainnet.use_provider("node"):
...
"""

Expand Down Expand Up @@ -230,7 +230,7 @@ def create_custom_provider(

if provider_name is None:
if issubclass(provider_cls, EthereumNodeProvider):
name = "geth"
name = "node"

elif cls_name := getattr(provider_cls, "name", None):
name = cls_name
Expand Down Expand Up @@ -323,7 +323,7 @@ def get_network_choices(
e.g. ``--network [ECOSYSTEM:NETWORK:PROVIDER]``.
Each value is in the form ``ecosystem:network:provider`` and shortened options also
appear in the list. For example, ``::geth`` would default to ``:ethereum:local:geth``
appear in the list. For example, ``::node`` would default to ``:ethereum:local:node``
and both will be in the returned list. The values come from each
:class:`~ape.api.providers.ProviderAPI` that is installed.
Expand Down
6 changes: 3 additions & 3 deletions src/ape/managers/project/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ def contracts(self) -> Dict[str, ContractType]:
Returns:
Dict[str, ``ContractType``]
"""
if self.local_project.cached_manifest is None:
return self.load_contracts()
if contracts := self.local_project.contracts:
return contracts

return self.local_project.contracts
return self.load_contracts()

def __getattr__(self, attr_name: str) -> Any:
"""
Expand Down
8 changes: 6 additions & 2 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
class NetworkConfig(PluginConfig):
required_confirmations: int = 0

default_provider: Optional[str] = "geth"
default_provider: Optional[str] = "node"
"""
The default provider to use. If set to ``None``, ape will rely on
an external plugin supplying the provider implementation, such as
Expand Down Expand Up @@ -324,9 +324,13 @@ def size(self) -> int:
# (normal).
return self._size

number = self.number
if number is None:
raise APINotImplementedError()

# Try to get it from the provider.
if provider := self.network_manager.active_provider:
block = provider.get_block(self.number)
block = provider.get_block(number)
size = block._size
if size is not None and size > -1:
self._size = size
Expand Down
2 changes: 1 addition & 1 deletion src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ class EthereumNodeProvider(Web3Provider, ABC):
block_page_size: int = 5000
concurrency: int = 16

name: str = "geth"
name: str = "node"

"""Is ``None`` until known."""
can_use_parity_traces: Optional[bool] = None
Expand Down
2 changes: 1 addition & 1 deletion src/ape_networks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomNetwork(PluginConfig):
base_ecosystem_plugin: Optional[str] = None

"""The default provider plugin to use. Default is the default node provider."""
default_provider: str = "geth"
default_provider: str = "node"

"""The HTTP request header."""
request_header: Dict = {}
Expand Down
2 changes: 1 addition & 1 deletion src/ape_networks/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def make_sub_tree(data: Dict, create_tree: Callable) -> Tree:

@cli.command(short_help="Start a node process")
@ape_cli_context()
@network_option(default="ethereum:local:geth")
@network_option(default="ethereum:local:node")
def run(cli_ctx, provider):
"""
Start a subprocess node as if running independently
Expand Down
9 changes: 4 additions & 5 deletions src/ape_geth/__init__.py → src/ape_node/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from ape import plugins
from ape.api.networks import LOCAL_NETWORK_NAME

from .provider import Geth as GethProvider
from .provider import GethConfig, GethDev, GethNetworkConfig
from .provider import EthereumNetworkConfig, EthereumNodeConfig, GethDev, Node
from .query import OTSQueryEngine


@plugins.register(plugins.Config)
def config_class():
return GethConfig
return EthereumNodeConfig


@plugins.register(plugins.ProviderPlugin)
def providers():
networks_dict = GethNetworkConfig().model_dump()
networks_dict = EthereumNetworkConfig().model_dump()
networks_dict.pop(LOCAL_NETWORK_NAME)
for network_name in networks_dict:
yield "ethereum", network_name, GethProvider
yield "ethereum", network_name, Node

yield "ethereum", LOCAL_NETWORK_NAME, GethDev

Expand Down
Loading

0 comments on commit 13ea0a1

Please sign in to comment.