Skip to content

Commit dac1f05

Browse files
committed
feat: performance improvements to batch delegator update
1 parent dd261be commit dac1f05

File tree

5 files changed

+137
-239
lines changed

5 files changed

+137
-239
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
},
3636
"devDependencies": {
3737
"@graphprotocol/contracts": "5.0.0",
38-
"@graphprotocol/graph-cli": "^0.49.0",
39-
"@graphprotocol/graph-ts": "^0.29.1",
38+
"@graphprotocol/graph-cli": "^0.51.0",
39+
"@graphprotocol/graph-ts": "^0.31.0",
4040
"@types/node": "^14.0.13",
4141
"@typescript-eslint/eslint-plugin": "^3.3.0",
4242
"@typescript-eslint/parser": "^3.3.0",

src/mappings/helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,11 @@ export function batchUpdateDelegatorsForIndexer(indexerId: string, timestamp: Bi
605605
let indexer = Indexer.load(indexerId)!
606606
// pre-calculates a lot of data for all delegators that exists for a specific indexer
607607
// using already existing links with the indexer-delegatedStake relations
608-
for (let i = 0; i < indexer.delegatorsCount.toI32(); i++) {
609-
let relationId = compoundId(indexer.id, BigInt.fromI32(i).toString())
610-
let relation = IndexerDelegatedStakeRelation.load(relationId)!
611-
if (relation.active) {
612-
let delegatedStake = DelegatedStake.load(relation.stake)!
608+
let delegators = indexer.delegators.load()
609+
610+
for (let i = 0; i < delegators.length; i++) {
611+
if (!delegators[i].shareAmount.isZero()) {
612+
let delegatedStake = delegators[i]
613613
let delegator = Delegator.load(delegatedStake.delegator)!
614614
// Only update core entities if there's a change in the exchange rate
615615
if (delegatedStake.latestIndexerExchangeRate != indexer.delegationExchangeRate) {

src/mappings/rewardsManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createOrLoadGraphNetwork,
1414
getAndUpdateIndexerDailyData,
1515
getAndUpdateSubgraphDeploymentDailyData,
16-
// batchUpdateDelegatorsForIndexer,
16+
batchUpdateDelegatorsForIndexer,
1717
getAndUpdateNetworkDailyData
1818
} from './helpers'
1919

@@ -82,7 +82,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void {
8282
)
8383
graphNetwork.save()
8484

85-
// batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)
85+
batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)
8686

8787
getAndUpdateIndexerDailyData(indexer as Indexer, event.block.timestamp)
8888
getAndUpdateSubgraphDeploymentDailyData(

src/mappings/staking.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747
getAndUpdateIndexerDailyData,
4848
calculatePricePerShare,
4949
getAndUpdateSubgraphDeploymentDailyData,
50-
// batchUpdateDelegatorsForIndexer,
50+
batchUpdateDelegatorsForIndexer,
5151
getAndUpdateNetworkDailyData,
5252
calculateCapacities,
5353
} from './helpers'
@@ -654,7 +654,7 @@ export function handleRebateClaimed(event: RebateClaimed): void {
654654
)
655655
graphNetwork.save()
656656

657-
// batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)
657+
batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)
658658

659659
getAndUpdateIndexerDailyData(indexer as Indexer, event.block.timestamp)
660660
getAndUpdateSubgraphDeploymentDailyData(

0 commit comments

Comments
 (0)