Skip to content

onflow/flow-public-key-indexer

Repository files navigation

Flow Public Key Indexer

A observer service for indexing flow Accounts public keys and REST service that serves up public key data.

Run Parameters

KEYIDX_LOGLEVEL default: "info"
Log Level: Takes string log level value for zerolog, "debug", "info", ...

KEYIDX_PORT default: "8888"
Port: The port the REST service is hosted on

KEYIDX_FLOWURL1 default: "access.mainnet.nodes.onflow.org:9000"
Flow Url: Access node endpoint blockchain data is pulled from, needs to match up with Chain Id. Up to 4 access nodes can be provided, only one is required. The access nodes are cycled through each request to get public key data.

KEYIDX_FLOWURL2 default: none
Flow Url: Access node endpoint

KEYIDX_FLOWURL3 default: none
Flow Url: Access node endpoint

KEYIDX_FLOWURL4 default: none
Flow Url: Access node endpoint

KEYIDX_CHAINID default: "flow-mainnet"
Chain Id: target blockchain, valid values are "flow-testnet" and "flow-mainnet". Needs to match up with Flor Url

KEYIDX_MAXACCTKEYS default: 500
Max Acct Keys: maximum number of keys to index per account, accounts that have more public keys that exceed max do not get indexed. Accounts are logged out that exceed the max

KEYIDX_BATCHSIZE default: 500
Batch Size: max number of accounts in a batch sent to cadence script that access node executes. Cadence script can exceed execution if accounts have a lot of keys

KEYIDX_IGNOREZEROWEIGHT default: true
Ignore Zero Weight: tells the cadence script to ignore public keys with zero weight. These keys will not be indexed

KEYIDX_IGNOREREVOKED default: true
Ignroe Revoked: tells the cadenc escript to ignore public keys that have been revoked. These keys will not be indexed

KEYIDX_WAITNUMBLOCKS default: 500
Wait Num Blocks: number of blocks to wait before running an incremental data load

KEYIDX_BLOCKPOLINTERVALSEC default: 120
Block Pol Interval Sec: number of seconds to wait before checking current block height to determine to run an incremental data load

KEYIDX_MAXBLOCKRANGE default: 600
Max Block Range: number of blocks that will trigger a bulk load if services falls behind. If this happens try increasing Batch Size parameter to a safe amount and not to trigger max computation error when cadence script is executed. Also, the server can only query 600 blocks

KEYIDX_PURGEONSTART default: false
When changing the data structure or want to clear the database and start from scratch chnage this variable to true

KEYIDX_ENABLESYNCDATA default: true
It's possible to run this service only as rest service and not sync, this makes it easy to have many instances that serve up data but only one that syncs

Postgresql configurations

KEYIDX_POSTGRESQLHOST default: "localhost" KEYIDX_POSTGRESQLPORT default: 5432 KEYIDX_POSTGRESQLUSERNAME default: "postgres" KEYIDX_POSTGRESQLPASSWORD not required, no default KEYIDX_POSTGRESQLDATABASE default: "keyindexer" KEYIDX_POSTGRESQLSSL default: true KEYIDX_POSTGRESQLLOGQUERIES default: false KEYIDX_POSTGRESQLSETLOGGER default: false KEYIDX_POSTGRESQLRETRYNUMTIMES default: 30 KEYIDX_POSTGRESQLRETRYSLEEPTIME default: "1s" KEYIDX_POSTGRESQLPOOLSIZE default: 1 KEYIDX_POSTGRESLOGGERPREFIX default: "keyindexer" KEYIDX_POSTGRESPROMETHEUSSUBSYSTEM default: "keyindexer"

How to Run

Since this is a golang service there are many ways to run it. Below are two ways to run this service

Command line

go run .

Docker

Configuration: Run docker in default 10 gig memory size. Reducing the running memory size reduces performance, the lowest is 6 gig, bulk sync and public key query responses are reasonable compared to running with more memory.
Create a docker container
docker build -t key-indexer .

need to configure to use postgresql This service stores public key data and needs persistent storage in postgresql
Run the docker and map the rest service port
Notice that environmental variables can be passed in. See variables above
docker run -p 8888:8080 --env KEYIDX_POSTGRESQLHOST=localhost
To see the logs of the container, get the container id
docker container ls
View the containers logs
docker logs <container id>

REST service

Endpoints

  • <root>/key/{public key}

note: public key is in base64 format serves up json object

{
	"publicKey": string  // public key string in base64
	"accounts" : array of {address: string, keyId: int, weight: int} 
}
  • <root>/status

note: this endpoint gives ability to see if the server is active and updating

{
"publicKeyCount": int         // total unique public keys indexed
"currentBlockHeight": int     // current block of access node
"updatedToBlockHeight": int   // block data is updated against
"pendingLoadBlockHeight": int // block height loading data from 
"isBulkLoading": bool         // indicates if bulk loading data
}

About

A observer service for indexing flow Accounts and by their associated Keys.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages