Dynamic¶
erpc.dynamic ¶
Dynamic configuration updates for eRPC processes.
Supports runtime config changes via stop -> rewrite -> start cycle, since eRPC does not support SIGHUP-based config reload natively.
Examples:
Update the full config::
from erpc.dynamic import update_config
diff = update_config(process, new_config)
print(diff)
Hot-add an upstream::
from erpc.dynamic import add_upstream
add_upstream(process, chain_id=137, endpoint="https://polygon.llamarpc.com")
ConfigDiff
dataclass
¶
Tracks what changed between two eRPC configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
added_upstreams |
dict[int, list[str]]
|
Chain IDs and their endpoints that were added entirely. |
removed_upstreams |
dict[int, list[str]]
|
Chain IDs and their endpoints that were removed entirely. |
added_endpoints |
dict[int, list[str]]
|
New endpoints added to existing chains. |
removed_endpoints |
dict[int, list[str]]
|
Endpoints removed from existing chains. |
changed_fields |
list[str]
|
List of scalar field names that changed. |
Examples:
>>> diff = ConfigDiff(added_upstreams={137: ["https://polygon.example.com"]})
>>> diff.has_changes
True
Source code in erpc/dynamic.py
has_changes
property
¶
Whether any differences were detected.
Returns:
| Type | Description |
|---|---|
bool
|
|
__str__ ¶
Human-readable summary of config changes.
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string describing all detected changes. |
Source code in erpc/dynamic.py
atomic_write_config ¶
Write config to a file atomically (write to temp, then rename).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ERPCConfig
|
The eRPC configuration to write. |
required |
path
|
Path
|
Target file path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path the config was written to. |
Source code in erpc/dynamic.py
update_config ¶
Update a running eRPC process with a new configuration.
Performs a stop -> rewrite config -> start cycle since eRPC does not support SIGHUP-based config reload natively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
ERPCProcess
|
The running ERPCProcess to update. |
required |
new_config
|
ERPCConfig
|
The new configuration to apply. |
required |
Returns:
| Type | Description |
|---|---|
ConfigDiff
|
A ConfigDiff describing what changed. |
Raises:
| Type | Description |
|---|---|
ERPCNotRunning
|
If the process is not currently running. |
Source code in erpc/dynamic.py
add_upstream ¶
Add an upstream endpoint to a running eRPC process.
If the chain ID does not exist yet, it will be created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
ERPCProcess
|
The running ERPCProcess to update. |
required |
chain_id
|
int
|
EVM chain identifier. |
required |
endpoint
|
str
|
RPC endpoint URL to add. |
required |
Returns:
| Type | Description |
|---|---|
ConfigDiff
|
A ConfigDiff describing what changed. |
Raises:
| Type | Description |
|---|---|
ERPCNotRunning
|
If the process is not currently running. |
Source code in erpc/dynamic.py
remove_upstream ¶
Remove an upstream endpoint from a running eRPC process.
If the endpoint is the last one for a chain, the chain is removed entirely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
ERPCProcess
|
The running ERPCProcess to update. |
required |
chain_id
|
int
|
EVM chain identifier. |
required |
endpoint
|
str
|
RPC endpoint URL to remove. |
required |
Returns:
| Type | Description |
|---|---|
ConfigDiff
|
A ConfigDiff describing what changed. |
Raises:
| Type | Description |
|---|---|
ERPCNotRunning
|
If the process is not currently running. |
ValueError
|
If the endpoint is not found for the given chain. |