1.0.0 • Published 3 years ago
forta-sharding v1.0.0
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...
};1.0.0
3 years ago