forta-sharding
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Forta Custom Sharding

Description

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

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.

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...
};

Readme

Keywords

Package Sidebar

Install

npm i forta-sharding

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

144 kB

Total Files

22

Last publish

Collaborators

  • kovart