Skip to content

🛠️ Helper library for effortless implementation of custom sharding logic in Forta bots.

Notifications You must be signed in to change notification settings

kovart/forta-sharding

Repository files navigation

Forta Custom Sharding

Description

Helper library for effortless implementation of custom sharding logic in Forta bots.

Installation

$ npm install forta-sharding

Usage

An example project of how to use the library can be found here.

First of all, you need to specify the number of scanners you need to run. This should be done through the package.json configuration by specifying shards: 1 and target: NUM_SCANNERS:

  "chainSettings": {
    "default": {
      "shards": 1,
      "target": 6
    }
  }

To specify the number of duplicate scanners, you need to specify the redundancy property when initializing BotSharding. For example, with 6 scanners, specifying redundancy as 2 would create 3 shards.

import { BotSharding } from 'bot-sharding'; 

const sharding = new BotSharding({
  redundancy: 2,
  isDevelopment: process.env.NODE_ENV !== 'production',
});

The following example shows how sharding can be implemented using the library:

const handleTransaction: HandleTransaction = async (txEvent: TransactionEvent) => {
  const findings: Finding[] = [];

  if (!sharding.isSynced || txEvent.blockNumber % 100 === 0) {
    await sharding.sync(txEvent.network);
  }
  
  // Non-sharded logic...

  if (txEvent.blockNumber % sharding.getShardCount() !== sharding.getShardIndex()) return findings;

  // Sharded logic...
};

About

🛠️ Helper library for effortless implementation of custom sharding logic in Forta bots.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published