Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Improvements on env variables awareness and update of the related documentation #1843

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
113 changes: 113 additions & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Default configuration if not overridden.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the existing Configuration.md not satisfy this or does it need further emphasis.
This file would be a dupe of that and would require extra effort to maintain on top of that README

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is another approach to note the Config README in the env.sample file?

# For a detailed description of all the fields see ./docs/configuration.md
# Some configuration can be overridden with a corresponding env variable.
# If you don't override a parameter, a default value is used instead, sometimes derived from the SDK.
# Here you can see all th possible override.
# The value you see here is the default used by the application if not overriding.
# Using this env file means settings all values equals to their default

CACHE_MAX=1_000 # Number of entries
CACHE_TTL=3_600_000 # Seconds
CHAIN_ID=298 # Hex or decimal. Default value is 298 (0x12a) commonly used for a "local-node" network.
CLIENT_TRANSPORT_SECURITY="false" # Use "true" to enable. Any other value means "false"
CONSENSUS_MAX_EXECUTION_TIME=10000 # Milliseconds. Default derived by @hashgraph/sdk if not defined.
CONTRACT_QUERY_TIMEOUT_RETRIES=1 # Number of retries
DEBUG_API_ENABLED="false" # Use "true" to enable. Any other value means "false"
DEFAULT_RATE_LIMIT=200 # Total amount of requests available per IP
ESTIMATE_GAS_THROWS="true" # Use "true" to enable. Any other value means "false"
ETH_CALL_ACCEPTED_ERRORS="false" # Use "true" to enable. Any other value means "false"
ETH_CALL_DEFAULT_TO_CONSENSUS_NODE="false" # Use "false" to disable. Any other value means "true"
ETH_FEE_HISTORY_FIXED="true" # Use "true" to enable. Any other value means "false"
ETH_GET_LOGS_BLOCK_RANGE_LIMIT=1000 # Number of blocks
ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE=1000 # Number of transactions
ETH_POPULATE_SYNTHETIC_CONTRACT_RESULTS="true" # Use "true" to enable. Any other value means "false"
FEE_HISTORY_MAX_RESULTS=10 # Number of results
FILE_APPEND_MAX_CHUNKS=20 # number of chunks
FILTER_API_ENABLED="false" # Use "true" to enable. Any other value means "false"
FILTER_TTL=300000 # Milliseconds.
GAS_PRICE_TINY_BAR_BUFFER=10000000000 # Tinybars
HAPI_CLIENT_DURATION_RESET=0 # Milliseconds. 0 means the client never resets based on time
HAPI_CLIENT_ERROR_RESET="[50]" # Array of protobuf status codes
HAPI_CLIENT_TRANSACTION_RESET=0 # Number of transactions.


HAVEGED_IMAGE_TAG
HBAR_RATE_LIMIT_DURATION
HBAR_RATE_LIMIT_TINYBAR
HEDERA_NETWORK
INPUT_SIZE_LIMIT
LIMIT_DURATION
LOCAL_NODE
LOG_LEVEL
MIRROR_IMAGE_TAG
MIRROR_NODE_AGENT_CACHEABLE_DNS
MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX
MIRROR_NODE_CONTRACT_RESULTS_PG_MAX
MIRROR_NODE_HTTP_KEEP_ALIVE
MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS
MIRROR_NODE_HTTP_MAX_SOCKETS
MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS
MIRROR_NODE_HTTP_SOCKET_TIMEOUT
MIRROR_NODE_LIMIT_PARAM
MIRROR_NODE_LIMIT_PARAM
MIRROR_NODE_MAX_REDIRECTS
MIRROR_NODE_RETRIES
MIRROR_NODE_RETRIES_DEVMODE
MIRROR_NODE_RETRY_CODES
MIRROR_NODE_RETRY_DELAY
MIRROR_NODE_RETRY_DELAY_DEVMODE
MIRROR_NODE_TIMEOUT
MIRROR_NODE_URL
MIRROR_NODE_URL
MIRROR_NODE_URL_HEADER_X_API_KEY
NETWORK_NODE_IMAGE_TAG
OPERATOR_ID
OPERATOR_ID_ETH_SENDRAWTRANSACTION
OPERATOR_ID_MAIN
OPERATOR_KEY
OPERATOR_KEY_ETH_SENDRAWTRANSACTION
OPERATOR_KEY_MAIN
PRIVATE_KEY
RATE_LIMIT_DISABLED
REDIS_ENABLED
REDIS_RECONNECT_DELAY_MS
REDIS_URL
RELAY_BASE_URL
REQUEST_ID_IS_OPTIONAL
SDK_REQUEST_TIMEOUT
SEND_RAW_TRANSACTION_SIZE_LIMIT
SERVER_PORT
SIGNED_TXS
SMART_CONTRACTS_AMOUNT
SUBSCRIPTIONS_ENABLED
TEST_ONLY_ENV_VAR_EMPTYSTRING
TEST_ONLY_ENV_VAR_NONNUMERICSTRING
TEST_ONLY_ENV_VAR_NUMERICSTRING
TEST_WS_SERVER
TIER_1_RATE_LIMIT
TIER_2_RATE_LIMIT
TIER_3_RATE_LIMIT
TX_DEFAULT_GAS
WALLETS_AMOUNT
WEB_SOCKET_HTTP_PORT
WEB_SOCKET_PORT
WS_CACHE_TTL
WS_CONNECTION_LIMIT
WS_CONNECTION_LIMIT_PER_IP
WS_MAX_INACTIVITY_TTL
WS_MULTIPLE_ADDRESSES_ENABLED
WS_PING_INTERVAL
WS_POLLING_INTERVAL
WS_RELAY_URL
WS_SUBSCRIPTION_LIMIT

# Testing

DEV_MODE="false" # Use "true" to enable. Any other value means "false"
E2E_RELAY_HOST="http://localhost:7546" # Remote JSON-RPC Relay URL to point to.
E2E_SERVER_PORT=7546 # Port for local testing, used in some acceptance tests.


# Development related
SEM_VER=
SNAPSHOT=
144 changes: 74 additions & 70 deletions docs/configuration.md

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions docs/dev-mode.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# Development mode

`Developer mode` is intended to be used by users when developing and testing smart contracts. It allows `hardhat-chai-matchers` and other similar libraries to correctly assert revert messages of non-pure contract methods.
It will also be expanded with special settings to speed up the [local node](https://github.com/hashgraph/hedera-local-node).
`Developer mode` is intended to be used by users when developing and testing smart contracts. It allows `hardhat-chai-matchers` and other similar libraries to correctly assert revert messages of non-pure contract methods. It will also be expanded with special settings to speed up the [local node](https://github.com/hashgraph/hedera-local-node).

## Enabling

To enable `dev mode` start the Relay with the environment variable `DEV_MODE` set to `true`.


## Rationale
## Rationale

In the example below `contract.call()` will make the following requests to the JSON RPC Relay: `eth_chainId, eth_estimateGas, eth_sendRawTransaction, eth_getTransactionByHash`

```typescript
await expect(contract.call()).to.be.revertedWith("Some revert message");
```

The asserting method expects to catch an error from any of the called API endpoints. Normally `eth_estimateGas` throws the error if the contract call is about to revert,
but that is currently not possible in the context of Hedera. Instead the error can be thrown by `eth_getTransactionByHash` after the transaction has gone through the consensus nodes.
Since that is not the normal desired behaviour it is only enabled in this mode.
The asserting method expects to catch an error from any of the called API endpoints. Normally `eth_estimateGas` throws the error if the contract call is about to revert, but that is currently not possible in the context of Hedera. Instead the error can be thrown by `eth_getTransactionByHash` after the transaction has gone through the consensus nodes.
Since that is not the normal desired behaviour it is only enabled in this mode.
4 changes: 2 additions & 2 deletions docs/examples/.env.mainnet.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HEDERA_NETWORK=mainnet
HEDERA_NETWORK="mainnet"
OPERATOR_ID_MAIN=<...redacted...>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: why was this needed? Isn't it inherently string already?

OPERATOR_KEY_MAIN=<...redacted...>
CHAIN_ID=0x127
MIRROR_NODE_URL=https://mainnet-public.mirrornode.hedera.com/
MIRROR_NODE_URL="https://mainnet-public.mirrornode.hedera.com/"
4 changes: 2 additions & 2 deletions docs/examples/.env.previewnet.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HEDERA_NETWORK=previewnet
HEDERA_NETWORK="previewnet"
OPERATOR_ID_MAIN=<...redacted...>
OPERATOR_KEY_MAIN=<...redacted...>
CHAIN_ID=0x129
MIRROR_NODE_URL=https://previewnet.mirrornode.hedera.com/
MIRROR_NODE_URL="https://previewnet.mirrornode.hedera.com/"
4 changes: 2 additions & 2 deletions docs/examples/.env.testnet.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HEDERA_NETWORK=testnet
HEDERA_NETWORK="testnet"
OPERATOR_ID_MAIN=<...redacted...>
OPERATOR_KEY_MAIN=<...redacted...>
CHAIN_ID=0x128
MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com/
MIRROR_NODE_URL="https://testnet.mirrornode.hedera.com/"
2 changes: 1 addition & 1 deletion packages/relay/src/lib/clients/mirrorNodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class MirrorNodeClient {
);
this.cacheService = cacheService;

// set up eth call accepted error codes.
// set up eth call accepted error codes.
if (process.env.ETH_CALL_ACCEPTED_ERRORS) {
MirrorNodeClient.acceptedErrorStatusesResponsePerRequestPathMap.set(
MirrorNodeClient.CONTRACT_CALL_ENDPOINT,
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ export class EthImpl implements Eth {
// ETH_CALL_DEFAULT_TO_CONSENSUS_NODE = false enables the use of Mirror node
if (
process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE === undefined ||
process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE == 'false'
process.env.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE === 'false'
) {
//temporary workaround until precompiles are implemented in Mirror node evm module
// Execute the call and get the response
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/lib/services/debugService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DebugService implements IDebugService {
* Checks if the Debug API is enabled
* @public
*/
public static readonly isDebugAPIEnabled = process.env.DEBUG_API_ENABLED;
public static readonly isDebugAPIEnabled = process.env.DEBUG_API_ENABLED || false;

static requireDebugAPIEnabled(): void {
if (!process.env.DEBUG_API_ENABLED || process.env.DEBUG_API_ENABLED !== 'true') {
Expand Down