Skip to content

Commit d3f9e3c

Browse files
authored
Feature/update schema to support migration changes (#54)
## Summary * Fixed supplierStakeAmount mapping in migration handler: Replaced incorrect reference to `applicationStake` with `supplierStake` for accurate mapping of supplier data. * Added support for MsgRecoverMorseAccount and handling migration-related updates. * Removed blockId from getParamId function and updated all usages accordingly. * Added transaction and claimedMsg to MorseClaimableAccount and replaced claimedAtHeight bigint with claimedAt block * Added database functions creation logic. * Added support for EventSupplierServiceConfigActivated to schema, mappings, and handlers to track supplier service activation events. Select one or more: - [x] New feature, functionality or library - [x] Bug fix - [ ] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Sanity Checklist - [x] I have tested my changes using the available tooling - [x] I have commented my code - [x] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable
1 parent 80a625d commit d3f9e3c

20 files changed

+644
-30
lines changed

.run/(VB) Index Alpha.run.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="(VB) Index Alpha" type="NodeJSConfigurationType" singleton="false" application-parameters="--force-clean --db-schema=testnet_alpha --unfinalized-blocks=true --batch-size=100 --timeout=360000 --scale-batch-size=false --store-cache-async=true --store-flush-interval=1 --enable-cache=false --kyve-endpoint=false --query-limit=1000 --pg-pool-min=300 --pg-pool-max=500 --pg-pool-acquire=30000 --pg-pool-idle=10000 --pg-pool-evict=12000" path-to-node="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node" node-parameters="--max-old-space-size=16384" path-to-js-file="node_modules/@subql/node-cosmos/bin/run" typescript-loader="bundled" working-dir="$PROJECT_DIR$">
3+
<envs>
4+
<env name="BATCH_SIZE" value="100" />
5+
<env name="CHAIN_ID" value="pocket_alpha" />
6+
<env name="DB_HOST" value="localhost" />
7+
<env name="DB_PASS" value="postgres" />
8+
<env name="DB_PORT" value="5432" />
9+
<env name="DB_USER" value="postgres" />
10+
<env name="ENDPOINT" value="https://shannon-testnet-grove-rpc.alpha.poktroll.com" />
11+
<env name="NODE_ENV" value="development" />
12+
<env name="NODE_OPTIONS" value="--max-old-space-size=8192" />
13+
<env name="POCKETDEX_DB_BATCH_SIZE" value="5000" />
14+
<env name="POCKETDEX_DB_PAGE_LIMIT" value="1000" />
15+
<env name="POCKETDEX_GENESIS" value="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/refs/heads/master/shannon/testnet-alpha/genesis.json" />
16+
<env name="TZ" value="utc" />
17+
</envs>
18+
<method v="2">
19+
<option name="NpmBeforeRunTask" enabled="true">
20+
<package-json value="$PROJECT_DIR$/package.json" />
21+
<command value="run" />
22+
<scripts>
23+
<script value="build" />
24+
</scripts>
25+
<arguments value="--mode=development" />
26+
<node-interpreter value="project" />
27+
<envs>
28+
<env name="CHAIN_ID" value="pocket-alpha" />
29+
<env name="DB_HOST" value="localhost" />
30+
<env name="DB_PASS" value="postgres" />
31+
<env name="DB_PORT" value="5432" />
32+
<env name="DB_USER" value="postgres" />
33+
<env name="DEBUG_BLOCK" value="false" />
34+
<env name="ENDPOINT" value="https://shannon-testnet-grove-rpc.alpha.poktroll.com" />
35+
<env name="NODE_ENV" value="development" />
36+
<env name="TZ" value="utc" />
37+
</envs>
38+
</option>
39+
</method>
40+
</configuration>
41+
</component>

.run/(VB) Index Beta.run.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
<env name="TZ" value="utc" />
2121
</envs>
2222
<method v="2">
23-
<option name="NpmBeforeRunTask" enabled="true">
24-
<package-json value="$PROJECT_DIR$/package.json"/>
25-
<command value="run"/>
26-
<scripts>
27-
<script value="vendors:build"/>
28-
</scripts>
29-
<node-interpreter value="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node"/>
30-
<envs/>
31-
</option>
3223
<option name="NpmBeforeRunTask" enabled="true">
3324
<package-json value="$PROJECT_DIR$/package.json" />
3425
<command value="run" />

.run/(VB) Index MainNet.run.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="(VB) Index MainNet" type="NodeJSConfigurationType" singleton="false" application-parameters="--force-clean --db-schema=mainnet --unfinalized-blocks=true --batch-size=1 --timeout=360000 --scale-batch-size=false --store-cache-async=true --store-flush-interval=1 --enable-cache=false --kyve-endpoint=false --query-limit=1000 --pg-pool-min=300 --pg-pool-max=500 --pg-pool-acquire=30000 --pg-pool-idle=10000 --pg-pool-evict=12000" path-to-node="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node" node-parameters="--max-old-space-size=8192" path-to-js-file="node_modules/@subql/node-cosmos/bin/run" typescript-loader="bundled" working-dir="$PROJECT_DIR$">
3+
<envs>
4+
<env name="BATCH_SIZE" value="100" />
5+
<env name="CHAIN_ID" value="pocket" />
6+
<env name="DB_HOST" value="localhost" />
7+
<env name="DB_PASS" value="postgres" />
8+
<env name="DB_PORT" value="5432" />
9+
<env name="DB_SCHEMA" value="mainnet" />
10+
<env name="DB_USER" value="postgres" />
11+
<env name="ENDPOINT" value="https://shannon-grove-rpc.mainnet.poktroll.com" />
12+
<env name="NODE_ENV" value="development" />
13+
<env name="NODE_OPTIONS" value="--max-old-space-size=8192" />
14+
<env name="POCKETDEX_DB_BATCH_SIZE" value="5000" />
15+
<env name="POCKETDEX_DB_PAGE_LIMIT" value="1000" />
16+
<env name="POCKETDEX_GENESIS" value="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/refs/heads/master/shannon/mainnet/genesis.json" />
17+
<env name="TZ" value="utc" />
18+
</envs>
19+
<method v="2">
20+
<option name="NpmBeforeRunTask" enabled="true">
21+
<package-json value="$PROJECT_DIR$/package.json" />
22+
<command value="run" />
23+
<scripts>
24+
<script value="build" />
25+
</scripts>
26+
<arguments value="--mode=development" />
27+
<node-interpreter value="project" />
28+
<envs>
29+
<env name="BATCH_SIZE" value="100" />
30+
<env name="CHAIN_ID" value="pocket" />
31+
<env name="DB_SCHEMA" value="mainnet" />
32+
<env name="DB_HOST" value="localhost" />
33+
<env name="DB_PASS" value="postgres" />
34+
<env name="DB_PORT" value="5432" />
35+
<env name="DB_USER" value="postgres" />
36+
<env name="DEBUG_BLOCK" value="false" />
37+
<env name="ENDPOINT" value="https://shannon-grove-rpc.mainnet.poktroll.com" />
38+
<env name="NODE_ENV" value="development" />
39+
<env name="TZ" value="utc" />
40+
</envs>
41+
</option>
42+
</method>
43+
</configuration>
44+
</component>

.run/FC Alpha.run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="FC Alpha" type="NodeJSConfigurationType" singleton="false"
3+
application-parameters="force-clean -f . --db-schema=testnet_alpha --profiler"
4+
path-to-node="$USER_HOME$/.nvm/versions/node/v18.20.3/bin/node"
5+
path-to-js-file="node_modules/@subql/node-cosmos/bin/run" typescript-loader="bundled"
6+
working-dir="$PROJECT_DIR$">
7+
<envs>
8+
<env name="CHAIN_ID" value="pocket-alpha"/>
9+
<env name="DB_HOST" value="localhost"/>
10+
<env name="DB_PASS" value="postgres"/>
11+
<env name="DB_PORT" value="5432"/>
12+
<env name="DB_USER" value="postgres"/>
13+
<env name="ENDPOINT" value="https://shannon-testnet-grove-rpc.alpha.poktroll.com"/>
14+
<env name="NODE_ENV" value="development"/>
15+
<env name="TZ" value="utc"/>
16+
</envs>
17+
<method v="2"/>
18+
</configuration>
19+
</component>

project.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ const project: CosmosProject = {
335335
"EventSupplierStaked",
336336
"EventSupplierUnbondingBegin",
337337
"EventSupplierUnbondingEnd",
338+
"EventSupplierServiceConfigActivated",
338339
],
339340
},
340341
],
@@ -399,6 +400,7 @@ const project: CosmosProject = {
399400
"EventMorseAccountClaimed",
400401
"EventMorseApplicationClaimed",
401402
"EventMorseSupplierClaimed",
403+
"EventMorseAccountRecovered",
402404
],
403405
},
404406
],
@@ -411,6 +413,7 @@ const project: CosmosProject = {
411413
"MsgClaimMorseAccount",
412414
"MsgClaimMorseApplication",
413415
"MsgClaimMorseSupplier",
416+
"MsgRecoverMorseAccount",
414417
],
415418
},
416419
],
@@ -420,6 +423,7 @@ const project: CosmosProject = {
420423
{
421424
startBlock: 1,
422425
// migration at 25507 on alpha
426+
// msg grants at 23196 on alpha
423427
kind: CosmosDatasourceKind.Runtime,
424428
mapping: {
425429
file: "./dist/index.js",

schema.graphql

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,33 @@ enum SettlementOpReason {
124124
TLM_GLOBAL_MINT_REIMBURSEMENT_REQUEST_ESCROW_MODULE_TRANSFER
125125
}
126126

127+
enum MorseSupplierClaimSignerType {
128+
# Unspecified signer type
129+
MORSE_SUPPLIER_CLAIM_SIGNER_TYPE_UNSPECIFIED
130+
131+
# signer === addr === operator === owner
132+
# Custodial signer type
133+
# - The Morse node address is NOT EMPTY (i.e. operator)
134+
# - The Morse output address is EMPTY (i.e. owner)
135+
# - Implies that the operator and owner are THE SAME offchain identity
136+
MORSE_SUPPLIER_CLAIM_CUSTODIAL_SIGNED_BY_NODE_ADDR
137+
138+
# signer === operator === addr && owner !== operator
139+
# Non-custodial signer type
140+
# - The Morse node address is NOT EMPTY (i.e. operator)
141+
# - The Morse output address is NOT EMPTY (i.e. owner)
142+
# - Implies that the operator and owner are MOST LIKELY DIFFERENT offchain identities
143+
# - The operator is the one signing the supplier claim
144+
MORSE_SUPPLIER_CLAIM_NON_CUSTODIAL_SIGNED_BY_NODE_ADDR
145+
# signer === owner && owner !== addr
146+
# Owner non-custodial signer type
147+
# - The Morse node address is EMPTY (i.e. operator)
148+
# - The Morse output address is NOT EMPTY (i.e. owner)
149+
# - Implies that the operator and owner are MOST LIKELY different offchain identities
150+
# - The owner is the one signing the supplier claim
151+
MORSE_SUPPLIER_CLAIM_NON_CUSTODIAL_SIGNED_BY_OWNER
152+
}
153+
127154
### JSON FIELDS
128155

129156
type EventAttribute @jsonField(indexed: false) {
@@ -717,6 +744,16 @@ type SupplierServiceConfig @entity {
717744
service: Service!
718745
revShare: [SupplierRevShare]!
719746
endpoints: [SupplierEndpoint]!
747+
# activation block per EventSupplierServiceConfigActivated event
748+
activatedAt: Block
749+
activatedEvent: EventSupplierServiceConfigActivated
750+
}
751+
752+
type EventSupplierServiceConfigActivated @entity {
753+
id: ID!
754+
event: Event!
755+
block: Block!
756+
activatedServicesConfig: [SupplierServiceConfig] @derivedFrom(field: "activatedEvent")
720757
}
721758

722759
type EventSupplierUnbondingBegin @entity {
@@ -1147,10 +1184,17 @@ type MorseClaimableAccount @entity {
11471184
supplierStakeAmount: BigInt!
11481185
applicationStakeAmount: BigInt!
11491186

1187+
# Only applicable to morse node/supplier accounts
1188+
morseOutputAddress: String
1189+
# the datetime after which the Morse node/supplier unbonding period will have elapsed.
1190+
unstakingTime: Date
1191+
11501192
# to be filled when claiming
11511193
shannonDestAddress: String
1152-
claimedAtHeight: BigInt
1194+
claimedAt: Block
11531195
claimed: Boolean!
1196+
transaction: Transaction
1197+
claimedMsg: Message
11541198

11551199
# TODO(@Alann27): the denominations are really needed? We know for sure that they are upokt
11561200
unstakedBalanceDenom: String!
@@ -1175,6 +1219,19 @@ type MsgClaimMorseAccount @entity {
11751219
message: Message!
11761220
}
11771221

1222+
type MsgRecoverMorseAccount @entity {
1223+
id: ID!
1224+
authority: ModuleAccount!
1225+
shannonDestAddress: Account!
1226+
morseSrcAddress: String!
1227+
recoveredBalanceAmount: BigInt!
1228+
recoveredBalanceDenom: String!
1229+
1230+
block: Block!
1231+
transaction: Transaction!
1232+
message: Message!
1233+
}
1234+
11781235
type MsgClaimMorseApplication @entity {
11791236
id: ID!
11801237
application: Application!
@@ -1211,6 +1268,9 @@ type MsgClaimMorseSupplier @entity {
12111268
morsePublicKey: String!
12121269
morseSrcAddress: String!
12131270
morseSignature: String!
1271+
morseNodeAddress: String
1272+
signerIsOutputAddress: Boolean
1273+
claimSignerType: MorseSupplierClaimSignerType
12141274
# Retrieved from the event
12151275
stakeAmount: BigInt!
12161276
stakeDenom: String!
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Used to get the proof, claim and slash data between blocks and for the list of delegator addresses
2+
export function getDataByDelegatorAddressesAndBlocksFn (dbSchema: string): string {
3+
return `CREATE OR REPLACE FUNCTION ${dbSchema}.get_data_by_delegator_addresses_and_blocks(
4+
addresses TEXT[],
5+
start_height BIGINT,
6+
end_height BIGINT
7+
)
8+
RETURNS jsonb
9+
LANGUAGE sql
10+
STABLE
11+
AS $$
12+
WITH matched_suppliers AS (
13+
SELECT DISTINCT ON (elem->>'address')
14+
ssc.supplier_id,
15+
elem->>'address' AS address
16+
FROM ${dbSchema}.supplier_service_configs ssc
17+
INNER JOIN ${dbSchema}.suppliers s ON s.id = ssc.supplier_id
18+
CROSS JOIN jsonb_array_elements(ssc.rev_share) AS elem
19+
WHERE elem->>'address' = ANY (addresses)
20+
AND upper_inf(ssc._block_range)
21+
AND s.stake_status = 'Staked'
22+
AND upper_inf(s._block_range)
23+
),
24+
25+
claim_agg AS (
26+
SELECT
27+
mcc.supplier_id,
28+
COUNT(DISTINCT mcc.id) AS claim_count,
29+
SUM(r.num_relays) AS claim_relays,
30+
SUM(r.num_claimed_computed_units) AS claim_computed_units,
31+
SUM(r.claimed_amount) AS claim_upokt
32+
FROM ${dbSchema}.msg_create_claims mcc
33+
INNER JOIN ${dbSchema}.relays r ON r.msg_create_claim_id = mcc.id
34+
WHERE mcc.block_id BETWEEN start_height AND end_height
35+
GROUP BY mcc.supplier_id
36+
),
37+
38+
proof_agg AS (
39+
SELECT
40+
ecs.supplier_id,
41+
COUNT(DISTINCT ecs.id) AS proof_count,
42+
SUM(ecs.num_relays) AS proof_relays,
43+
SUM(ecs.num_claimed_computed_units) AS proof_computed_units,
44+
SUM(ecs.claimed_amount) AS proof_upokt
45+
FROM ${dbSchema}.event_claim_settleds ecs
46+
WHERE ecs.block_id BETWEEN start_height AND end_height
47+
GROUP BY ecs.supplier_id
48+
),
49+
50+
slashed_agg AS (
51+
SELECT
52+
ess.supplier_id,
53+
SUM(ess.previous_stake_amount - ess.after_stake_amount) AS slashed
54+
FROM ${dbSchema}.event_supplier_slasheds ess
55+
WHERE ess.block_id BETWEEN start_height AND end_height
56+
GROUP BY ess.supplier_id
57+
)
58+
59+
SELECT jsonb_agg(
60+
jsonb_build_object(
61+
'address', ms.address,
62+
'proof_relays', COALESCE(p.proof_relays, 0),
63+
'proof_computed_units', COALESCE(p.proof_computed_units, 0),
64+
'proof_upokt', COALESCE(p.proof_upokt, 0),
65+
'proof_amount', COALESCE(p.proof_count, 0),
66+
'claim_relays', COALESCE(c.claim_relays, 0),
67+
'claim_computed_units', COALESCE(c.claim_computed_units, 0),
68+
'claim_upokt', COALESCE(c.claim_upokt, 0),
69+
'claim_amount', COALESCE(c.claim_count, 0),
70+
'slashed', COALESCE(s.slashed, 0)
71+
)
72+
)
73+
FROM matched_suppliers ms
74+
LEFT JOIN claim_agg c ON c.supplier_id = ms.supplier_id
75+
LEFT JOIN proof_agg p ON p.supplier_id = ms.supplier_id
76+
LEFT JOIN slashed_agg s ON s.supplier_id = ms.supplier_id;
77+
$$;
78+
`
79+
}

0 commit comments

Comments
 (0)