Skip to content

Commit

Permalink
feat: performance improvements to batch delegator update
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Sep 18, 2023
1 parent dd261be commit dac1f05
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 239 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
},
"devDependencies": {
"@graphprotocol/contracts": "5.0.0",
"@graphprotocol/graph-cli": "^0.49.0",
"@graphprotocol/graph-ts": "^0.29.1",
"@graphprotocol/graph-cli": "^0.51.0",
"@graphprotocol/graph-ts": "^0.31.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.3.0",
"@typescript-eslint/parser": "^3.3.0",
Expand Down
10 changes: 5 additions & 5 deletions src/mappings/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ export function batchUpdateDelegatorsForIndexer(indexerId: string, timestamp: Bi
let indexer = Indexer.load(indexerId)!
// pre-calculates a lot of data for all delegators that exists for a specific indexer
// using already existing links with the indexer-delegatedStake relations
for (let i = 0; i < indexer.delegatorsCount.toI32(); i++) {
let relationId = compoundId(indexer.id, BigInt.fromI32(i).toString())
let relation = IndexerDelegatedStakeRelation.load(relationId)!
if (relation.active) {
let delegatedStake = DelegatedStake.load(relation.stake)!
let delegators = indexer.delegators.load()

for (let i = 0; i < delegators.length; i++) {
if (!delegators[i].shareAmount.isZero()) {
let delegatedStake = delegators[i]
let delegator = Delegator.load(delegatedStake.delegator)!
// Only update core entities if there's a change in the exchange rate
if (delegatedStake.latestIndexerExchangeRate != indexer.delegationExchangeRate) {
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/rewardsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createOrLoadGraphNetwork,
getAndUpdateIndexerDailyData,
getAndUpdateSubgraphDeploymentDailyData,
// batchUpdateDelegatorsForIndexer,
batchUpdateDelegatorsForIndexer,
getAndUpdateNetworkDailyData
} from './helpers'

Expand Down Expand Up @@ -82,7 +82,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void {
)
graphNetwork.save()

// batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)
batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)

getAndUpdateIndexerDailyData(indexer as Indexer, event.block.timestamp)
getAndUpdateSubgraphDeploymentDailyData(
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
getAndUpdateIndexerDailyData,
calculatePricePerShare,
getAndUpdateSubgraphDeploymentDailyData,
// batchUpdateDelegatorsForIndexer,
batchUpdateDelegatorsForIndexer,
getAndUpdateNetworkDailyData,
calculateCapacities,
} from './helpers'
Expand Down Expand Up @@ -654,7 +654,7 @@ export function handleRebateClaimed(event: RebateClaimed): void {
)
graphNetwork.save()

// batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)
batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)

getAndUpdateIndexerDailyData(indexer as Indexer, event.block.timestamp)
getAndUpdateSubgraphDeploymentDailyData(
Expand Down
Loading

0 comments on commit dac1f05

Please sign in to comment.