Skip to content

Commit da00000

Browse files
authored
Master fix node country decoding (#145)
* check if node country/city includes '\x00' Signed-off-by: mario <[email protected]> * add --start-block flag to substrate-ingest Signed-off-by: mario <[email protected]> * add setBlockRange to processor to enable modifying start/end blocks Signed-off-by: mario <[email protected]> * bump version to 2.11.5 Signed-off-by: mario <[email protected]> * validate all strings before saving to db Signed-off-by: mario <[email protected]> --------- Signed-off-by: mario <[email protected]>
1 parent 4990d79 commit da00000

File tree

13 files changed

+173
-193
lines changed

13 files changed

+173
-193
lines changed

indexer/chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: tfchainindexer
22
description: Helm Chart for the tfchain hydra indexer
33
version: 2.7.7
44
apiVersion: v2
5-
appVersion: '2.11.3'
5+
appVersion: '2.11.5'

indexer/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ services:
2727
"--out",
2828
"postgres://root@db:26257/defaultdb",
2929
"--types-bundle",
30-
"/configs/typesBundle.json"
30+
"/configs/typesBundle.json",
31+
"--start-block",
32+
"${START_HEIGHT}"
3133
]
3234

3335
gateway:

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "graphql_tfgrid",
33
"private": "true",
4-
"version": "2.11.3",
4+
"version": "2.11.5",
55
"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
66
"author": "",
77
"license": "ISC",

processor-chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ apiVersion: v2
22
name: tfchain-processor
33
description: A chart for the tfchain graphql processor and query node
44
version: 1.0.6
5-
appVersion: '2.11.3'
5+
appVersion: '2.11.5'

src/mappings/contracts.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
SmartContractModuleNruConsumptionReportReceivedEvent, SmartContractModuleRentContractCanceledEvent,
1616
SmartContractModuleContractGracePeriodStartedEvent, SmartContractModuleContractGracePeriodEndedEvent
1717
} from "../types/events";
18+
import { validateString } from "./nodes"
1819

1920
export async function contractCreated(
2021
ctx: Ctx,
@@ -47,7 +48,7 @@ export async function contractCreated(
4748
let newNameContract = new NameContract()
4849
newNameContract.id = item.event.id
4950
contract = contractEvent.contractType.value
50-
newNameContract.name = contract.name.toString()
51+
newNameContract.name = validateString(ctx, contract.name.toString())
5152
newNameContract.contractID = contractEvent.contractId
5253
newNameContract.gridVersion = contractEvent.version
5354
newNameContract.twinID = contractEvent.twinId
@@ -71,16 +72,9 @@ export async function contractCreated(
7172
newNodeContract.nodeID = contract.nodeId
7273
newNodeContract.numberOfPublicIPs = contract.publicIps
7374

74-
if (contract.deploymentData.toString().indexOf('\x00') >= 0) {
75-
newNodeContract.deploymentData = ""
76-
} else {
77-
newNodeContract.deploymentData = contract.deploymentData.toString()
78-
}
79-
if (contract.deploymentHash.toString().indexOf('\x00') >= 0) {
80-
newNodeContract.deploymentHash = ""
81-
} else {
82-
newNodeContract.deploymentHash = contract.deploymentHash.toString()
83-
}
75+
76+
newNodeContract.deploymentData = validateString(ctx, contract.deploymentData.toString())
77+
newNodeContract.deploymentHash = validateString(ctx, contract.deploymentHash.toString())
8478

8579
// newNodeContract.deploymentHash = contract.deploymentHash.toString()
8680
newNodeContract.state = state
@@ -164,16 +158,16 @@ export async function contractUpdated(
164158

165159
const SavedNodeContract = await ctx.store.get(NodeContract, { where: { contractID: contractEvent.contractId } })
166160
if (SavedNodeContract) {
167-
await updateNodeContract(contractEvent, SavedNodeContract, ctx.store)
161+
await updateNodeContract(ctx, contractEvent, SavedNodeContract, ctx.store)
168162
}
169163

170164
const SavedNameContract = await ctx.store.get(NameContract, { where: { contractID: contractEvent.contractId } })
171165
if (SavedNameContract) {
172-
await updateNameContract(contractEvent, SavedNameContract, ctx.store)
166+
await updateNameContract(ctx, contractEvent, SavedNameContract, ctx.store)
173167
}
174168
}
175169

176-
async function updateNodeContract(ctr: any, contract: NodeContract, store: Store) {
170+
async function updateNodeContract(ctx: Ctx, ctr: any, contract: NodeContract, store: Store) {
177171
if (ctr.contractType.__kind !== "NodeContract") return
178172

179173
const parsedNodeContract = ctr.contractType.value
@@ -184,16 +178,9 @@ async function updateNodeContract(ctr: any, contract: NodeContract, store: Store
184178
contract.nodeID = parsedNodeContract.nodeId
185179
contract.numberOfPublicIPs = parsedNodeContract.publicIps
186180

187-
if (contract.deploymentData.toString().indexOf('\x00') >= 0) {
188-
contract.deploymentData = ""
189-
} else {
190-
contract.deploymentData = contract.deploymentData.toString()
191-
}
192-
if (contract.deploymentHash.toString().indexOf('\x00') >= 0) {
193-
contract.deploymentHash = ""
194-
} else {
195-
contract.deploymentHash = contract.deploymentHash.toString()
196-
}
181+
182+
contract.deploymentData = validateString(ctx, contract.deploymentData.toString())
183+
contract.deploymentHash = validateString(ctx, contract.deploymentHash.toString())
197184

198185
let state = ContractState.OutOfFunds
199186
switch (ctr.state.__kind) {
@@ -208,15 +195,15 @@ async function updateNodeContract(ctr: any, contract: NodeContract, store: Store
208195
await store.save<NodeContract>(contract)
209196
}
210197

211-
async function updateNameContract(ctr: any, contract: NameContract, store: Store) {
198+
async function updateNameContract(ctx: Ctx, ctr: any, contract: NameContract, store: Store) {
212199
if (ctr.contractType.__kind !== "NameContract") return
213200

214201
const parsedNameContract = ctr.contractType.value
215202

216203
contract.contractID = ctr.contractId
217204
contract.gridVersion = ctr.version
218205
contract.twinID = ctr.twinId
219-
contract.name = parsedNameContract.name.toString()
206+
contract.name = validateString(ctx, parsedNameContract.name.toString())
220207

221208
let state = ContractState.OutOfFunds
222209
switch (ctr.state.__kind) {

src/mappings/farms.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSele
44

55
import { Ctx } from '../processor'
66
import * as v63 from '../types/v63'
7+
import { validateString } from "./nodes"
78

89
export class FarmWithIPs {
910
constructor(farmID: number, ips: PublicIp[]) {
@@ -41,7 +42,7 @@ export async function farmStored(
4142
newFarm.id = item.event.id
4243
newFarm.gridVersion = farmStoredEventParsed.version
4344
newFarm.farmID = farmStoredEventParsed.id
44-
newFarm.name = farmStoredEventParsed.name.toString()
45+
newFarm.name = validateString(ctx, farmStoredEventParsed.name.toString())
4546
newFarm.twinID = farmStoredEventParsed.twinId
4647
newFarm.pricingPolicyID = farmStoredEventParsed.pricingPolicyId
4748
newFarm.dedicatedFarm = false
@@ -56,15 +57,8 @@ export async function farmStored(
5657

5758
newIP.id = item.event.id
5859

59-
if (ip.ip.toString().indexOf('\x00') >= 0) {
60-
return
61-
}
62-
newIP.ip = ip.ip.toString()
63-
64-
if (ip.gateway.toString().indexOf('\x00') >= 0) {
65-
return
66-
}
67-
newIP.gateway = ip.gateway.toString()
60+
newIP.ip = validateString(ctx, ip.ip.toString())
61+
newIP.gateway = validateString(ctx, ip.gateway.toString())
6862

6963
newIP.contractId = ip.contractId
7064
newIP.farm = newFarm
@@ -114,7 +108,7 @@ export async function farmUpdated(
114108
if (!savedFarm) return
115109

116110
savedFarm.gridVersion = farmUpdatedEventParsed.version
117-
savedFarm.name = farmUpdatedEventParsed.name.toString()
111+
savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString())
118112
savedFarm.twinID = farmUpdatedEventParsed.twinId
119113
savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId
120114
savedFarm.certification = certification
@@ -128,14 +122,14 @@ export async function farmUpdated(
128122
const savedIP = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() }, relations: { farm: true } })
129123
// ip is already there in storage, don't save it again
130124
if (savedIP) {
131-
savedIP.ip = ip.ip.toString()
132-
savedIP.gateway = ip.gateway.toString()
125+
savedIP.ip = validateString(ctx, ip.ip.toString()) // not effective, but for since we already check for \x00
126+
savedIP.gateway = validateString(ctx, ip.gateway.toString())
133127
await ctx.store.save<PublicIp>(savedIP)
134128
} else {
135129
const newIP = new PublicIp()
136130
newIP.id = item.event.id
137-
newIP.ip = ip.ip.toString()
138-
newIP.gateway = ip.gateway.toString()
131+
newIP.ip = validateString(ctx, ip.ip.toString())
132+
newIP.gateway = validateString(ctx, ip.gateway.toString())
139133
newIP.contractId = ip.contractId
140134
newIP.farm = savedFarm
141135

@@ -151,7 +145,7 @@ export async function farmUpdated(
151145

152146
const publicIPsOfFarm = await ctx.store.find<PublicIp>(PublicIp, { where: { farm: { id: savedFarm.id } }, relations: { farm: true } })
153147
publicIPsOfFarm.forEach(async ip => {
154-
if (eventPublicIPs.filter(eventIp => eventIp.ip.toString() === ip.ip).length === 0) {
148+
if (eventPublicIPs.filter(eventIp => validateString(ctx, eventIp.ip.toString()) === ip.ip).length === 0) {
155149
// IP got removed from farm
156150
await ctx.store.remove<PublicIp>(ip)
157151
}
@@ -188,7 +182,7 @@ export async function farmPayoutV2AddressRegistered(
188182
if (savedFarm) {
189183
let address = ''
190184
if (!stellarAddress.includes(0)) {
191-
address = stellarAddress.toString()
185+
address = validateString(ctx, stellarAddress.toString())
192186
}
193187

194188
savedFarm.stellarAddress = address
@@ -252,7 +246,7 @@ export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Far
252246
newFarm.id = eventID
253247
newFarm.gridVersion = farmStoredEventParsed.version
254248
newFarm.farmID = farmStoredEventParsed.id
255-
newFarm.name = farmStoredEventParsed.name.toString()
249+
newFarm.name = validateString(ctx, farmStoredEventParsed.name.toString())
256250
newFarm.twinID = farmStoredEventParsed.twinId
257251
newFarm.pricingPolicyID = farmStoredEventParsed.pricingPolicyId
258252
newFarm.dedicatedFarm = false
@@ -267,15 +261,8 @@ export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Far
267261

268262
newIP.id = eventID
269263

270-
if (ip.ip.toString().indexOf('\x00') >= 0) {
271-
return
272-
}
273-
newIP.ip = ip.ip.toString()
274-
275-
if (ip.gateway.toString().indexOf('\x00') >= 0) {
276-
return
277-
}
278-
newIP.gateway = ip.gateway.toString()
264+
newIP.ip = validateString(ctx, ip.ip.toString())
265+
newIP.gateway = validateString(ctx, ip.gateway.toString())
279266

280267
newIP.contractId = ip.contractId
281268
newIP.farm = newFarm
@@ -313,7 +300,7 @@ export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Far
313300
if (foundInNewListIndex != -1) {
314301
const savedFarm: Farm = newFarms[foundInNewListIndex]
315302
savedFarm.gridVersion = farmUpdatedEventParsed.version
316-
savedFarm.name = farmUpdatedEventParsed.name.toString()
303+
savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString())
317304
savedFarm.twinID = farmUpdatedEventParsed.twinId
318305
savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId
319306
// const pubIps = updatePublicIPs(ctx, farmUpdatedEventParsed.publicIps, eventID, savedFarm)
@@ -328,7 +315,7 @@ export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Far
328315
if (foundInUpdatedListIndex != -1) {
329316
let savedFarm: Farm = updatedFarms[foundInUpdatedListIndex]
330317
savedFarm.gridVersion = farmUpdatedEventParsed.version
331-
savedFarm.name = farmUpdatedEventParsed.name.toString()
318+
savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString())
332319
savedFarm.twinID = farmUpdatedEventParsed.twinId
333320
savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId
334321
updatedFarms[foundInUpdatedListIndex] = savedFarm
@@ -342,7 +329,7 @@ export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Far
342329
if (!savedFarm) continue
343330

344331
savedFarm.gridVersion = farmUpdatedEventParsed.version
345-
savedFarm.name = farmUpdatedEventParsed.name.toString()
332+
savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString())
346333
savedFarm.twinID = farmUpdatedEventParsed.twinId
347334
savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId
348335

@@ -379,13 +366,13 @@ function getPublicIPs(ctx: Ctx, farm: Farm, savedFarmIps: FarmWithIPs[], newIps:
379366
// console.log(`found index: ${foundIdx}`)
380367
if (foundIdx !== -1) {
381368
toModify[0].publicIPs[foundIdx].contractId = ip.contractId
382-
toModify[0].publicIPs[foundIdx].ip = ip.ip.toString()
383-
toModify[0].publicIPs[foundIdx].gateway = ip.gateway.toString()
369+
toModify[0].publicIPs[foundIdx].ip = validateString(ctx, ip.ip.toString())
370+
toModify[0].publicIPs[foundIdx].gateway = validateString(ctx, ip.gateway.toString())
384371
} else {
385372
const newIP = new PublicIp()
386373
newIP.id = eventID
387374
newIP.ip = ip.ip.toString()
388-
newIP.gateway = ip.gateway.toString()
375+
newIP.gateway = validateString(ctx, ip.gateway.toString())
389376
newIP.contractId = ip.contractId
390377
newIP.farm = farm
391378
// ctx.log.info(`saving new ip: ${newIP.ip}`)

0 commit comments

Comments
 (0)