near / near-indexer-for-explorer

Watch NEAR network and store all the data from NEAR blockchain to PostgreSQL database
https://near-indexers.io/docs/projects/near-indexer-for-explorer
GNU General Public License v3.0
123 stars 56 forks source link

Near indexer setup issue #281

Closed TanyaSrivastava-Dipali closed 1 year ago

TanyaSrivastava-Dipali commented 2 years ago

how can I set up near-indexer for existing near localnet?

khorolets commented 2 years ago

This can be done with a few tweaks here and there.

Assuming you have an existing localnet node with the default config. It means you're already running an RPC on port :3030 and the nearcore node on :24567

Indexer for Explorer is a nearcore node too, and in order to be running close to another node on the same machine, it needs a separate set of config.

Initialize configs

Assuming your localnet consists of 1 nearcore node that uses a default path ~/.near you need to initialize another config for indexer-for-explorer.

./target/release/indexer --home-dir ~/.near-indexer init --chain-id localnet

Tweak configs

Remove validator_key.json

Your nearcore node that is already existing is a validator. If running a few validators locally is not your particular case, we should remove validator_key.json from the newly created config folder

rm ~/.near-indexer/validator_key.json

Copy genesis from an existing node

genesis.json file contains the data about the initial validator, it is generated on the fly and expects the validator_key.json key we have just deleted to be a validator. But you already have a validator.

We need to get the genesis.json file from the existed configs

cp ~/.near/genesis.json ~/.near-indexer/genesis.json

Change ports in config.json

First of all, we need to change a port for indexer provided RPC from default :3030

Open ~/.near-indexer/config.json

Change

"rpc": {
  "addr": "0.0.0.0:3030",

To

"rpc": {
  "addr": "0.0.0.0:8080",

Then we need to change network port

The same ~/.near-indexer/config.json

Change

"network": {
    "addr": "0.0.0.0:24567",

To

"network": {
    "addr": "0.0.0.0:24568",

Boot nodes

Boot nodes are the nodes your node will try to connect first to exchange all the necessary information in order to sync up with the network, set up the peer-to-peer connection, etc.

Boot node value looks like this:

ed25519:4k9csx6zMiXy4waBKMMPTkEtAS2RFKLVScocR5HwN53P@192.168.0.1:24567

Which is basically

ed25519:NODE_PUBLIC_KEY@IP:PORT

Take the public_key from the existing ~/.near/validator_key.json

~/.near-indexer/config.json

Change

"network": {
    "addr": "0.0.0.0:24568",
    "external_address": "",
    "boot_nodes": "",

TO

"network": {
    "addr": "0.0.0.0:24568",
    "external_address": "",
    "boot_nodes": ["ed25519:public_key@127.0.0.1:24567"],

Copy data to speed up the syncing process

cp -rf ~/.near/data ~/.near-indexer/data

Run

Start your previously existing localnet node before starting the indexer-for-explorer.

Now you can start the indexer-for-explorer

./target/release/indexer --home-dir ~/.near-indexer run --stream-while-syncing start-from-interruption

This should work.

P.S. Anyone who sees this instruction please react with a thumb up if you'd like to see it on https://near-indexers.io React with the heart if you want to see video instruction.

frol commented 2 years ago

@khorolets I feel the best place would be actually the README file, not the docs.

@TanyaSrivastava-Dipali BTW, you can run indexer as your validator node, and kill two birds with one stone. Just stop your localnet node and run indexer with the --home specified where the localnet validator node was previously.

Sushain96 commented 2 years ago

what to do when we are using nearcore version 1.26.1 which in turn is using protocol version 53 but none of the indexer tag is using nearcore 1.26.1 and logs are showing error.{ thread 'main' panicked at 'The client protocol version is older than the protocol version of the network. Please update nearcore', /home/ubuntu/.cargo/git/checkouts/nearcore-5bf7818cf2261fd0/4ac008b/chain/client/src/client.rs:1063:21}

khorolets commented 2 years ago

what to do when we are using nearcore version 1.26.1 which in turn is using protocol version 53 but none of the indexer tag is using nearcore 1.26.1 and logs are showing error.{ thread 'main' panicked at 'The client protocol version is older than the protocol version of the network. Please update nearcore', /home/ubuntu/.cargo/git/checkouts/nearcore-5bf7818cf2261fd0/4ac008b/chain/client/src/client.rs:1063:21}

nearcore 1.26.1 uses the same protocol version as 1.26.0, 0.10.16 version of the indexer is based on 1.26.0 and they work together.

Please, create a separate issue, your comment does not relate to this issue.