Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kovart/forta-sharding
🛠️ Helper library for effortless implementation of custom sharding logic in Forta bots.
https://github.com/kovart/forta-sharding
forta helper library sharding
Last synced: 4 days ago
JSON representation
🛠️ Helper library for effortless implementation of custom sharding logic in Forta bots.
- Host: GitHub
- URL: https://github.com/kovart/forta-sharding
- Owner: kovart
- Created: 2023-05-29T11:50:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-24T14:28:32.000Z (9 months ago)
- Last Synced: 2024-04-25T04:22:49.548Z (7 months ago)
- Topics: forta, helper, library, sharding
- Language: TypeScript
- Homepage:
- Size: 164 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Forta Custom Sharding
## Description
Helper library for effortless implementation of custom sharding logic in Forta bots.
## Installation
```bash
$ npm install forta-sharding
```### Usage
An example project of how to use the library can be found [here](./example).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`:```json
"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.```ts
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:
```ts
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...
};
```