Skip to content

Commit ef779af

Browse files
committed
fix: poi metadata handling
Signed-off-by: Tomás Migone <[email protected]>
1 parent d7f9a7d commit ef779af

File tree

6 files changed

+47
-50
lines changed

6 files changed

+47
-50
lines changed

abis/SubgraphService.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,9 @@
805805
},
806806
{
807807
"indexed": false,
808-
"internalType": "bytes32",
809-
"name": "publicPoi",
810-
"type": "bytes32"
808+
"internalType": "bytes",
809+
"name": "poiMetadata",
810+
"type": "bytes"
811811
},
812812
{
813813
"indexed": false,

config/localNetworkAddressScript.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export let addresses: Addresses = {
1616
controller: '{{horizon.Controller.address}}',
1717
graphToken: '{{horizon.L2GraphToken.address}}',
1818
epochManager: '{{horizon.EpochManager.address}}',
19-
disputeManager: '{{subgraphService.DisputeManager.address}}',
20-
horizonDisputeManager: '{{subgraphService.HorizonDisputeManager.address}}',
19+
disputeManager: '{{subgraphService.LegacyDisputeManager.address}}',
20+
horizonDisputeManager: '{{subgraphService.DisputeManager.address}}',
2121
staking: '{{horizon.HorizonStaking.address}}',
2222
stakingExtension: '{{horizon.HorizonStaking.address}}',
2323
curation: '{{horizon.L2Curation.address}}',
@@ -52,15 +52,8 @@ const main = (): void => {
5252
if(output.ethereumDIDRegistry == '') {
5353
output.ethereumDIDRegistry = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
5454
}
55-
// TODO: Remove this once subgraph service scripts deploy GNS and SubgraphNFT
56-
if(output.gns == '') {
57-
output.gns = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
58-
}
59-
if(output.subgraphNFT == '') {
60-
output.subgraphNFT = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
61-
}
62-
if(output.horizonDisputeManager == '') {
63-
output.horizonDisputeManager = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
55+
if(output.disputeManager == '') {
56+
output.disputeManager = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
6457
}
6558
fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2))
6659
} catch (e) {

schema.graphql

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,6 @@ type Allocation @entity(immutable: false) {
11081108
poi: Bytes
11091109
"POIs submitted when collecting payments in Horizon"
11101110
pois: [PoiSubmission!]! @derivedFrom(field: "allocation")
1111-
"Public POIs submitted when collecting payments in Horizon"
1112-
publicPois: [PublicPoiSubmission!]! @derivedFrom(field: "allocation")
11131111
"Number of POIs submitted for this allocation. Only available for Horizon allocations"
11141112
poiCount: BigInt
11151113
"Timestamp for the latest POI presentation"
@@ -1139,26 +1137,14 @@ type Allocation @entity(immutable: false) {
11391137

11401138
type PoiSubmission @entity(immutable: true) {
11411139
id: ID!
1142-
11431140
allocation: Allocation!
1144-
11451141
poi: Bytes!
1146-
1147-
submittedAtEpoch: Int!
1148-
1149-
presentedAtTimestamp: Int!
1150-
}
1151-
1152-
type PublicPoiSubmission @entity(immutable: true) {
1153-
id: ID!
1154-
1155-
allocation: Allocation!
1156-
11571142
publicPoi: Bytes!
1158-
11591143
submittedAtEpoch: Int!
1160-
11611144
presentedAtTimestamp: Int!
1145+
indexingStatus: Int!
1146+
blockNumber: Int!
1147+
metadataDecoded: Boolean!
11621148
}
11631149

11641150
enum AllocationStatus {

src/mappings/gns.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,14 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void {
625625
* call the contract directly to get the updated value
626626
*/
627627
export function handleParameterUpdated(event: ParameterUpdated): void {
628-
let parameter = event.params.param
629-
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
630-
let gns = GNS.bind(event.address)
631-
632-
if (parameter == 'ownerTaxPercentage') {
633-
graphNetwork.ownerTaxPercentage = gns.ownerTaxPercentage().toI32()
634-
}
635-
graphNetwork.save()
628+
// let parameter = event.params.param
629+
// let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
630+
// let gns = GNS.bind(event.address)
631+
632+
// if (parameter == 'ownerTaxPercentage') {
633+
// graphNetwork.ownerTaxPercentage = gns.ownerTaxPercentage().toI32()
634+
// }
635+
// graphNetwork.save()
636636
}
637637

638638
// - event: SubgraphPublished(indexed uint256,indexed bytes32,uint32)

src/mappings/subgraphService.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { BigDecimal, BigInt, ethereum, log } from "@graphprotocol/graph-ts"
1+
import { BigDecimal, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts"
22
import { AllocationClosed, AllocationCreated, AllocationResized, CurationCutSet, DelegationRatioSet, IndexingRewardsCollected, MaxPOIStalenessSet, ProvisionTokensRangeSet, QueryFeesCollected, RewardsDestinationSet, ServiceProviderRegistered, StakeToFeesRatioSet, ThawingPeriodRangeSet, VerifierCutRangeSet } from "../types/SubgraphService/SubgraphService"
33
import { batchUpdateSubgraphSignalledTokens, calculatePricePerShare, createOrLoadDataService, createOrLoadEpoch, createOrLoadGraphNetwork, createOrLoadIndexerQueryFeePaymentAggregation, createOrLoadPaymentSource, createOrLoadProvision, createOrLoadSubgraphDeployment, joinID, updateDelegationExchangeRate } from "./helpers/helpers"
4-
import { Allocation, PublicPoiSubmission, Indexer, PoiSubmission, SubgraphDeployment } from "../types/schema"
4+
import { Allocation, Indexer, PoiSubmission, SubgraphDeployment } from "../types/schema"
55
import { addresses } from "../../config/addresses"
66
import { tuplePrefixBytes } from "./helpers/decoder"
77
import { createOrLoadIndexer } from "./helpers/helpers"
@@ -255,22 +255,40 @@ export function handleIndexingRewardsCollected(event: IndexingRewardsCollected):
255255
allocation.poiCount = allocation.poiCount!.plus(BigInt.fromI32(1))
256256
allocation.save()
257257

258+
// Decode poi metadata
259+
let poiBlockNumber = 0
260+
let poiIndexingStatus = 0 // 0 is unknown, 1 is healthy, 2 is unhealthy, 3 is failed
261+
let publicPoi = Bytes.fromHexString('0x')
262+
let poiMetadataDecoded = false
263+
264+
let poiMetadata = ethereum.decode('(uint256,bytes32,uint8,uint8,uint256)', event.params.poiMetadata)
265+
if (poiMetadata != null && poiMetadata.kind == ethereum.ValueKind.TUPLE) {
266+
poiMetadataDecoded = true
267+
268+
let tupleData = poiMetadata.toTuple()
269+
poiBlockNumber = tupleData[0].toI32()
270+
publicPoi = tupleData[1].toBytes()
271+
poiIndexingStatus = tupleData[2].toI32()
272+
273+
// TODO: implement error code handling
274+
// let errorCode = tupleData[3].toBigInt()
275+
// let errorBlockNumber = tupleData[4].toBigInt()
276+
} else {
277+
log.error("IndexingRewardsCollected failed to decode poi metadata: {}", [event.params.poiMetadata.toHexString()])
278+
}
279+
258280
// Create PoI submission
259281
let poiSubmission = new PoiSubmission(joinID([event.transaction.hash.toHexString(), event.logIndex.toString()]))
260282
poiSubmission.allocation = allocation.id
261283
poiSubmission.poi = event.params.poi
284+
poiSubmission.publicPoi = publicPoi
262285
poiSubmission.submittedAtEpoch = event.params.currentEpoch.toI32()
263286
poiSubmission.presentedAtTimestamp = event.block.timestamp.toI32()
287+
poiSubmission.indexingStatus = poiIndexingStatus
288+
poiSubmission.blockNumber = poiBlockNumber
289+
poiSubmission.metadataDecoded = poiMetadataDecoded
264290
poiSubmission.save()
265291

266-
// Create public PoI submission
267-
let publicPoiSubmission = new PublicPoiSubmission(joinID([event.transaction.hash.toHexString(), event.logIndex.toString()]))
268-
publicPoiSubmission.allocation = allocation.id
269-
publicPoiSubmission.publicPoi = event.params.publicPoi
270-
publicPoiSubmission.submittedAtEpoch = event.params.currentEpoch.toI32()
271-
publicPoiSubmission.presentedAtTimestamp = event.block.timestamp.toI32()
272-
publicPoiSubmission.save()
273-
274292
// Update latest POI in allocation
275293
allocation.poi = event.params.poi
276294
allocation.latestPoiPresentedAt = event.block.timestamp.toI32()

subgraph.template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ dataSources:
477477
handler: handleAllocationResized
478478
- event: AllocationClosed(indexed address,indexed address,indexed bytes32,uint256,bool)
479479
handler: handleAllocationClosed
480-
- event: IndexingRewardsCollected(indexed address,indexed address,indexed bytes32,uint256,uint256,uint256,bytes32,bytes32,uint256)
480+
- event: IndexingRewardsCollected(indexed address,indexed address,indexed bytes32,uint256,uint256,uint256,bytes32,bytes,uint256)
481481
handler: handleIndexingRewardsCollected
482482
- event: QueryFeesCollected(indexed address,indexed address,indexed address,bytes32,uint256,uint256)
483483
handler: handleQueryFeesCollected

0 commit comments

Comments
 (0)