smartcontractkit / smartcontractkit/chainlink

[NODE] Support Hardhat node for development when running Chainlink node

Open
#5,468 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

investigating
Dominant language
Go
Stars
8.2k
Forks
2k
Avg merge
1d 23h
Merged PRs (30d)
202

Description

Description
I'm using Hardhat node for development, but cannot use Chainlink node to connect to it. Executing sendChainlinkRequestTo fails with remote eth node timed out. According to @PatrickAlphaC in this video https://www.youtube.com/watch?v=ZB3GLtQvgME&t=1537s Hardhat/ganache is not supported.

I believe it's important for Chainlink node to work with Hardhat(and other local dev nodes), setting up Geth/Parity and having it running on local dev machine is simply not ideal. This forces developers with localhost dev to use remote test network which slows down the development process and is a waste.

Basic Information
Running Hardhat node
npx hardhat node --network hardhat --verbose --show-stack-traces
with following config:

...
defaultNetwork: "hardhat",
  networks: {
    hardhat: {
      forking: {
        url: "https://eth-kovan.alchemyapi.io/v2/[my api_key]",
        blockNumber: 28379367
      }
    }
  }
....

Starting the chainlink node like this
docker run -p 6688:6688 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink:1.0.0 local n
On startup, the chainlink node can connect to the Hardhat node

2021-11-18T14:39:00Z [INFO]  HeadListener: Connecting to ethereum node ws://host.docker.internal:8545 in 0s headtracker/head_listener.go:107 logger=head_tracker
2021-11-18T14:39:00Z [DEBUG] eth.Client#EthSubscribe                            eth/client.go:298       mode=websocket nodeName=eth-primary-0 nodeTier=primary
2021-11-18T14:39:00Z [DEBUG] eth.Client#ChainID(...)                            eth/client.go:205       mode=websocket nodeName=eth-primary-0 nodeTier=primary
2021-11-18T14:39:00Z [INFO]  HeadListener: Connected to ethereum node ws://host.docker.internal:8545 headtracker/head_listener.go:107 logger=head_tracker

In contract .sol file I have the following code

        bytes32 jobId = stringToBytes32("5733f3313a0f47a9b601680031841d12");
        Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.buyOrderExecuted.selector);
        req.add("symbol", symbol);
        req.addUint("amount", amount);
        req.add("accountId", accountId);
        uint oraclePayment = 0;

        bytes32 requestId = sendChainlinkRequestTo(oracleAddress, req, oraclePayment);

When this code executes, the following log appears in the Chainlink console log

[WARN]  BlockHistoryEstimator: error fetching blocks       gas/block_history_estimator.go:169 err=BlockHistoryEstimator#fetchBlocks error fetching blocks with BatchCallContext: primary websocket (ws://host.docker.internal:8545) call failed: remote eth node timed out: context deadline exceeded errVerbose=context deadline exceeded
remote eth node timed out
github.com/smartcontractkit/chainlink/core/services/eth.wrap
        /chainlink/core/services/eth/node.go:349
github.com/smartcontractkit/chainlink/core/services/eth.node.wrapWS
        /chainlink/core/services/eth/node.go:337
github.com/smartcontractkit/chainlink/core/services/eth.node.BatchCallContext
        /chainlink/core/services/eth/node.go:105
github.com/smartcontractkit/chainlink/core/services/eth.(*client).BatchCallContext
        /chainlink/core/services/eth/client.go:316
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).batchFetch
        /chainlink/core/services/gas/block_history_estimator.go:333
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).FetchBlocks
        /chainlink/core/services/gas/block_history_estimator.go:273
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).FetchBlocksAndRecalculate
        /chainlink/core/services/gas/block_history_estimator.go:178
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).runLoop
        /chainlink/core/services/gas/block_history_estimator.go:169
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1371
primary websocket (ws://host.docker.internal:8545) call failed
github.com/smartcontractkit/chainlink/core/services/eth.wrap
        /chainlink/core/services/eth/node.go:351
github.com/smartcontractkit/chainlink/core/services/eth.node.wrapWS
        /chainlink/core/services/eth/node.go:337
github.com/smartcontractkit/chainlink/core/services/eth.node.BatchCallContext
        /chainlink/core/services/eth/node.go:105
github.com/smartcontractkit/chainlink/core/services/eth.(*client).BatchCallContext
        /chainlink/core/services/eth/client.go:316
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).batchFetch
        /chainlink/core/services/gas/block_history_estimator.go:333
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).FetchBlocks
        /chainlink/core/services/gas/block_history_estimator.go:273
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).FetchBlocksAndRecalculate
        /chainlink/core/services/gas/block_history_estimator.go:178
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).runLoop
        /chainlink/core/services/gas/block_history_estimator.go:169
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1371
BlockHistoryEstimator#fetchBlocks error fetching blocks with BatchCallContext
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).batchFetch
        /chainlink/core/services/gas/block_history_estimator.go:334
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).FetchBlocks
        /chainlink/core/services/gas/block_history_estimator.go:273
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).FetchBlocksAndRecalculate
        /chainlink/core/services/gas/block_history_estimator.go:178
github.com/smartcontractkit/chainlink/core/services/gas.(*BlockHistoryEstimator).runLoop
        /chainlink/core/services/gas/block_history_estimator.go:169
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1371 head={"ID":56986,"Hash":"0x87815a4a373e0bb8f6bc575694503b47dba695bcbc92e58f8d7f339eb03849a8","Number":28379376,"L1BlockNumber":null,"ParentHash":"0xb321f135b403f2f17b2964be99226830c5103042f8a344cfe5be6f8bb4bceeed","Parent":{"hash":"0xb321f135b403f2f17b2964be99226830c5103042f8a344cfe5be6f8bb4bceeed","number":"0x1b108ef","parentHash":"0x19b9d3c573587d01fbbec254041341ef6ae6e324b6d1c8427418c09023a0d6d6","timestamp":"0x61915e28"},"Timestamp":"2021-11-14T19:07:09Z","CreatedAt":"2021-11-18T14:42:42.204589Z"} id=block_history_estimator
  • Network: localhost with fork from Kovan
  • Blockchain Client: Hardhat version 2.6.8
  • Go Version: n/a
  • Operating System: Windows 11, running in Docker
  • Commit:
2021-11-18T14:39:00Z [DEBUG] Starting service...                                cmd/local_client.go:145 serviceType=*services.balanceMonitor
2021-11-18T14:39:00Z [DEBUG] eth.Client#BalanceAt(...)                          eth/client.go:283       account=0xF5dF3EF33B1F0061e3876294c4d7f69CEF7F01b0 blockNumber=<nil> mode=websocket nodeName=eth-primary-0 nodeTier=primary   
2021-11-18T14:39:00Z [INFO]  ETH balance for 0xF5dF3EF33B1F0061e3876294c4d7f69CEF7F01b0: 0.005000000000000000 services/balance_monitor.go:166 address=0xF5dF3EF33B1F0061e3876294c4d7f69CEF7F01b0 chainId=31337 ethBalance=0.005000000000000000 id=balance_log weiBalance=5000000000000000
2021-11-18T14:39:00Z [DEBUG] Starting service...                                cmd/local_client.go:145 serviceType=*services.promReporter
2021-11-18T14:39:00Z [DEBUG] Starting service...                                cmd/local_client.go:145 serviceType=*job.spawner
2021-11-18T14:39:00Z [DEBUG] PromReporter: starting event loop                  services/prom_reporter.go:124 
2021-11-18T14:39:00Z [DEBUG] Starting service...                                cmd/local_client.go:145 serviceType=*pipeline.runner
2021-11-18T14:39:00Z [DEBUG] Starting service...                                cmd/local_client.go:145 serviceType=*headtracker.headBroadcaster
2021-11-18T14:39:00Z [DEBUG] Starting HeadTracker                               utils/utils.go:968      logger=head_tracker
2021-11-18T14:39:00Z [DEBUG] LogBroadcaster: Resubscribing and backfilling logs... runtime/asm_amd64.s:1371 chainId=31337
2021-11-18T14:39:00Z [DEBUG] LogBroadcaster: Using an override as a start of the backfill runtime/asm_amd64.s:1371 blockBackfillDepth=10 blockNumber=28379365 chainId=31337 highestNumConfirmations=0
2021-11-18T14:39:00Z [DEBUG] LogBroadcaster: No addresses to backfill for, returning log/broadcaster.go:281  chainId=31337
2021-11-18T14:39:00Z [DEBUG] LogBroadcaster: Starting the event loop            log/broadcaster.go:301  chainId=31337
2021-11-18T14:39:00Z [DEBUG] HeadTracker: Tracking logs from last block #28379375 (0x1b108ef) with hash 0x944ff1f108b6715541f99329737f63fcb5dde5a63dba56371d3199762bb31a0d utils/utils.go:968      blockHash=0x944ff1f108b6715541f99329737f63fcb5dde5a63dba56371d3199762bb31a0d blockNumber=28379375 logger=head_tracker
2021-11-18T14:39:00Z [DEBUG] eth.Client#Call(...)                               eth/client.go:268       args=["latest",false] method=eth_getBlockByNumber mode=websocket nodeName=eth-primary-0 nodeTier=primary
2021-11-18T14:39:00Z [DEBUG] HeadTracker: got initial current block             headtracker/head_tracker.go:123 blockHash=0x58dc40080f0abcd25fa69bc95ed91e93058d950ae333a73fd1830b0ec19ec120 blockNumber=28379372 head=28379372 logger=head_tracker
2021-11-18T14:39:00Z [DEBUG] HeadTracker: Received new head #28379372 (0x1b108ec) headtracker/head_tracker.go:127 blockHash=0x58dc40080f0abcd25fa69bc95ed91e93058d950ae333a73fd1830b0ec19ec120 blockHeight=28379372 logger=head_tracker parentHeadHash=0xb4d220457aa664d39ad2129672f77d522772b47a968eb7d9a1e3a37ea85dca50
2021-11-18T14:39:00Z [DEBUG] JobSpawner: Starting services for job              job/spawner.go:211      count=1 jobID=1
2021-11-18T14:39:00Z [DEBUG] JobSpawner: Starting services for job              job/spawner.go:211      count=1 jobID=6
2021-11-18T14:39:00Z [DEBUG] LogBroadcaster: Subscribing listener               log/broadcaster.go:339  address=0xEe8b316B0b682df35E3723F9A8d1a1719f52194D chainId=31337 requiredBlockConfirmations=3
2021-11-18T14:39:00Z [DEBUG] JobSpawner: Starting services for job              job/spawner.go:211      count=1 jobID=8
2021-11-18T14:39:00Z [INFO]  JobSpawner: all jobs running                       job/spawner.go:224      count=3    
2021-11-18T14:39:00Z [DEBUG] LogBroadcaster: Subscribing listener               log/broadcaster.go:339  address=0x879580935D01106fdaC4E62E7ca75a3Ba703a9a9 chainId=31337 requiredBlockConfirmations=3
2021-11-18T14:39:00Z [DEBUG] HeadTracker: got out of order head                 headtracker/head_tracker.go:127 blockNum=28379372 gotHead=0x58dc40080f0abcd25fa69bc95ed91e93058d950ae333a73fd1830b0ec19ec120 highestSeenHead=28379375 logger=head_tracker
2021-11-18T14:39:00Z [INFO]  Head sampling is enabled - sampling interval is set to: 1s runtime/asm_amd64.s:1371 logger=head_tracker
2021-11-18T14:39:00Z [INFO]  HeadListener: Connecting to ethereum node ws://host.docker.internal:8545 in 0s headtracker/head_listener.go:107 logger=head_tracker
2021-11-18T14:39:00Z [DEBUG] eth.Client#EthSubscribe                            eth/client.go:298       mode=websocket nodeName=eth-primary-0 nodeTier=primary
2021-11-18T14:39:00Z [DEBUG] eth.Client#ChainID(...)                            eth/client.go:205       mode=websocket nodeName=eth-primary-0 nodeTier=primary
2021-11-18T14:39:00Z [INFO]  HeadListener: Connected to ethereum node ws://host.docker.internal:8545 headtracker/head_listener.go:107 logger=head_tracker
2021-11-18T14:39:00Z [DEBUG] Environment variables
ALLOW_ORIGINS: *
BLOCK_BACKFILL_DEPTH: 10
BLOCK_HISTORY_ESTIMATOR_BLOCK_DELAY: 0
BLOCK_HISTORY_ESTIMATOR_BLOCK_HISTORY_SIZE: 0
BLOCK_HISTORY_ESTIMATOR_TRANSACTION_PERCENTILE: 0
BRIDGE_RESPONSE_URL:
ETH_CHAIN_ID: 31337
CLIENT_NODE_URL: http://localhost:6688
DATABASE_BACKUP_FREQUENCY: 1h0m0s
DATABASE_BACKUP_MODE: none
DATABASE_MAXIMUM_TX_DURATION: 30m0s
DATABASE_TIMEOUT:
DEFAULT_HTTP_LIMIT: 32768
DEFAULT_HTTP_TIMEOUT: 15s
CHAINLINK_DEV: false
ETH_DISABLED: false
ETH_HTTP_URL:
ETH_SECONDARY_URLS: []
ETH_URL: ws://host.docker.internal:8545
EXPLORER_URL:
FM_DEFAULT_TRANSACTION_QUEUE_DEPTH: 1
FEATURE_EXTERNAL_INITIATORS: true
FEATURE_OFFCHAIN_REPORTING: false
GAS_ESTIMATOR_MODE:
INSECURE_FAST_SCRYPT: false
JSON_CONSOLE: false
JOB_PIPELINE_REAPER_INTERVAL: 1h0m0s
JOB_PIPELINE_REAPER_THRESHOLD: 24h0m0s
KEEPER_DEFAULT_TRANSACTION_QUEUE_DEPTH: 1
KEEPER_MAXIMUM_GRACE_PERIOD: 0
KEEPER_MINIMUM_REQUIRED_CONFIRMATIONS: 0
KEEPER_REGISTRY_CHECK_GAS_OVERHEAD: 0
KEEPER_REGISTRY_PERFORM_GAS_OVERHEAD: 0
KEEPER_REGISTRY_SYNC_INTERVAL:
LINK_CONTRACT_ADDRESS:
FLAGS_CONTRACT_ADDRESS:
LAYER_2_TYPE:
LOG_LEVEL: debug
LOG_SQL_MIGRATIONS: true
LOG_SQL: false
LOG_TO_DISK: true
OCR_BOOTSTRAP_CHECK_INTERVAL: 20s
TRIGGER_FALLBACK_DB_POLL_INTERVAL: 30s
OCR_CONTRACT_TRANSMITTER_TRANSMIT_TIMEOUT: 10s
OCR_DATABASE_TIMEOUT: 10s
OCR_DEFAULT_TRANSACTION_QUEUE_DEPTH: 1
OCR_INCOMING_MESSAGE_BUFFER_SIZE: 10
P2P_BOOTSTRAP_PEERS: []
P2P_LISTEN_IP: 0.0.0.0
P2P_LISTEN_PORT:
P2P_NETWORKING_STACK: V1
P2P_PEER_ID:
P2PV2_ANNOUNCE_ADDRESSES: []
P2PV2_BOOTSTRAPPERS: []
P2PV2_DELTA_DIAL: 15s
P2PV2_DELTA_RECONCILE: 1m0s
P2PV2_LISTEN_ADDRESSES: []
OCR_OUTGOING_MESSAGE_BUFFER_SIZE: 10
OCR_NEW_STREAM_TIMEOUT: 10s
OCR_DHT_LOOKUP_INTERVAL: 10
OCR_TRACE_LOGGING: false
CHAINLINK_PORT: 6688
REAPER_EXPIRATION: 240h0m0s
REPLAY_FROM_BLOCK: -1
ROOT: /chainlink
SECURE_COOKIES: false
SESSION_TIMEOUT: 15m0s
TELEMETRY_INGRESS_LOGGING: false
TELEMETRY_INGRESS_SERVER_PUB_KEY:
TELEMETRY_INGRESS_URL:
CHAINLINK_TLS_HOST:
CHAINLINK_TLS_PORT: 0
CHAINLINK_TLS_REDIRECT: false
 cmd/local_client.go:235
2021-11-18T14:39:00Z [INFO]  Chainlink booted in 20.171492434s                  cmd/local_client.go:154
2021-11-18T14:39:00Z [INFO]  Listening and serving HTTP on port 6688            cmd/client.go:136
  • Hosting Provider: self-hosted
  • Startup Command: docker run -p 6688:6688 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink:1.0.0 local n

Environment Variables

ROOT=/chainlink
LOG_LEVEL=debug
ETH_CHAIN_ID=31337
MIN_OUTGOING_CONFIRMATIONS=2
LINK_CONTRACT_ADDRESS=0xa36085F69e2889c224210F603D836748e7dC0088
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
GAS_UPDATER_ENABLED=true
ALLOW_ORIGINS=*
ETH_CONTAINER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -f name=eth -q))
ETH_URL=ws://host.docker.internal:8545
DATABASE_URL=postgresql://postgres:abc123@host.docker.internal:5432/postgres?sslmode=disable
FEATURE_EXTERNAL_INITIATORS=true
FEATURE_WEBHOOK_V2=true

Steps to Reproduce
I believe it's decribed in Basic info

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the setup with the Hardhat command, Docker command, and localhost fork described in the issue. Start by tracing the timeout through core/services/eth/node.go, core/services/eth/client.go, and core/services/gas/block_history_estimator.go. Done means the Chainlink node supports the Hardhat node and sendChainlinkRequestTo completes without the reported remote eth node timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
backend, blockchain
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.