From fdc9657348745bf0f280f042270fe958f9ebf822 Mon Sep 17 00:00:00 2001 From: Alan Rojas Date: Wed, 20 Nov 2024 19:55:08 -0400 Subject: [PATCH] Feature/add reports and relays entities (#31) ## Summary - Added entities related to claims and proof - Added summarized data for each block - Added missing fields to blocks and transactions --- genesis/localnet.json | 32 +- project.ts | 62 ++++ schema.graphql | 254 +++++++++++++- src/mappings/bank/transfer.ts | 6 +- src/mappings/constants.ts | 6 + src/mappings/genesis.ts | 9 +- src/mappings/mappingHandlers.ts | 2 + src/mappings/poktroll/gateways.ts | 6 +- src/mappings/poktroll/relays.ts | 544 ++++++++++++++++++++++++++++++ src/mappings/poktroll/reports.ts | 348 +++++++++++++++++++ src/mappings/poktroll/services.ts | 2 +- src/mappings/primitives.ts | 34 +- src/mappings/utils/ids.ts | 15 + 13 files changed, 1285 insertions(+), 35 deletions(-) create mode 100644 src/mappings/poktroll/relays.ts create mode 100644 src/mappings/poktroll/reports.ts diff --git a/genesis/localnet.json b/genesis/localnet.json index e83ecc1..101ea1c 100644 --- a/genesis/localnet.json +++ b/genesis/localnet.json @@ -1,7 +1,7 @@ { "app_name": "poktrolld", - "app_version": "0.0.9-49290e3d", - "genesis_time": "2024-10-07T15:34:55.513335691Z", + "app_version": "0.0.9-06636795", + "genesis_time": "2024-10-30T14:44:47.056910596Z", "chain_id": "poktroll", "initial_height": 1, "app_hash": null, @@ -23,7 +23,7 @@ } ], "stake": { - "amount": "1000068", + "amount": "100000068", "denom": "upokt" } }, @@ -42,7 +42,7 @@ } ], "stake": { - "amount": "1000068", + "amount": "100000068", "denom": "upokt" } } @@ -51,7 +51,7 @@ "params": { "max_delegated_gateways": "7", "min_stake": { - "amount": "1000000", + "amount": "100000000", "denom": "upokt" } } @@ -180,7 +180,7 @@ ] }, "authz": { - "authorization": [{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.service.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.session.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.gateway.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.application.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.supplier.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.proof.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.tokenomics.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.shared.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.service.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.session.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.gateway.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.application.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.supplier.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.proof.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.tokenomics.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.shared.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.gateway.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.application.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.upgrade.v1beta1.MsgCancelUpgrade"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.auth.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.bank.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.distribution.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.mint.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.staking.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.slashing.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.gov.v1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.gov.v1.MsgCancelProposal"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.consensus.v1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"}] + "authorization": [{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.service.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.session.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.gateway.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.application.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.supplier.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.proof.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.tokenomics.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.shared.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.service.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.session.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.gateway.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.application.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.supplier.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.proof.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.tokenomics.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.shared.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.gateway.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.application.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/poktroll.supplier.MsgUpdateParam"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.upgrade.v1beta1.MsgCancelUpgrade"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.auth.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.bank.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.distribution.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.mint.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.staking.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.slashing.v1beta1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.gov.v1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.gov.v1.MsgCancelProposal"},"expiration":"2500-01-01T00:00:00Z"},{"granter":"pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t","grantee":"pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw","authorization":{"@type":"/cosmos.authz.v1beta1.GenericAuthorization","msg":"/cosmos.consensus.v1.MsgUpdateParams"},"expiration":"2500-01-01T00:00:00Z"}] }, "bank": { "params": { @@ -456,7 +456,7 @@ "validator_address": "poktvaloper18kk3aqe2pjz7x7993qp2pjt95ghurra9c5ef0t", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", - "key": "RpLYTCdsb89BmHpfOFMt07TmTwZME3O9GGlhgigC+Eo=" + "key": "tDyl89O4qlynjt/oGAlLniplbOFpZUtCuvqBZ3x3qOw=" }, "value": { "denom": "upokt", @@ -464,7 +464,7 @@ } } ], - "memo": "54c2e75f5689792684f79461acd83466cf889945@192.168.1.7:26656", + "memo": "5e0d633782ab6178d05de424c5a1ef44a50ee281@192.168.1.2:26656", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] @@ -493,7 +493,7 @@ "tip": null }, "signatures": [ - "7trDQdS9K6aLhG3BUfhJFUGwsq6AG//Dqn1pL0fQSQRudWzi/6PtsFQ2z9xfs122Jt08Qijj31in+r3fH3fYkw==" + "8UKjLXaBmEatazLosAcp+YwH88lac95YeLJL1DH8oEI32bcPK4M1YvG+FDhRoXlH//uufkvLeBZLf5lJ4XVgcw==" ] } ] @@ -576,8 +576,7 @@ "proof_submission_fee": { "amount": "1000000", "denom": "upokt" - }, - "relay_difficulty_target_hash": "//////////////////////////////////////////8=" + } }, "proof_list": [] }, @@ -589,6 +588,7 @@ "denom": "upokt" } }, + "relayMiningDifficultyList": [], "serviceList": [ { "compute_units_per_relay": 1, @@ -656,7 +656,12 @@ "validators": [] }, "supplier": { - "params": {}, + "params": { + "min_stake": { + "amount": "1000000", + "denom": "upokt" + } + }, "supplierList": [ { "operator_address": "pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj", @@ -719,8 +724,7 @@ ] }, "tokenomics": { - "params": {}, - "relayMiningDifficultyList": [] + "params": {} }, "upgrade": {}, "vesting": {} diff --git a/project.ts b/project.ts index af9fdae..12b885a 100644 --- a/project.ts +++ b/project.ts @@ -583,6 +583,68 @@ const project: CosmosProject = { type: "/cosmos.authz.v1beta1.MsgExec", } }, + // --- Relays + { + handler: "handleEventClaimSettled", + kind: CosmosHandlerKind.Event, + filter: { + type: "poktroll.tokenomics.EventClaimSettled", + } + }, + { + handler: "handleEventClaimExpired", + kind: CosmosHandlerKind.Event, + filter: { + type: "poktroll.tokenomics.EventClaimExpired", + } + }, + { + handler: "handleMsgCreateClaim", + kind: CosmosHandlerKind.Message, + filter: { + type: "/poktroll.proof.MsgCreateClaim", + } + }, + { + handler: "handleEventClaimUpdated", + kind: CosmosHandlerKind.Event, + filter: { + type: "poktroll.proof.EventClaimUpdated", + } + }, + { + handler: "handleEventProofUpdated", + kind: CosmosHandlerKind.Event, + filter: { + type: "poktroll.proof.EventProofUpdated", + } + }, + { + handler: "handleMsgSubmitProof", + kind: CosmosHandlerKind.Message, + filter: { + type: "/poktroll.proof.MsgSubmitProof", + } + }, + { + handler: "handleEventClaimCreated", + kind: CosmosHandlerKind.Event, + filter: { + type: "poktroll.proof.EventClaimCreated", + } + }, + { + handler: "handleEventProofSubmitted", + kind: CosmosHandlerKind.Event, + filter: { + type: "poktroll.proof.EventProofSubmitted", + } + }, + // --- Reports + { + handler: "handleAddBlockReports", + kind: CosmosHandlerKind.Block, + }, ], }, }, diff --git a/schema.graphql b/schema.graphql index 23d535e..63d0aec 100644 --- a/schema.graphql +++ b/schema.graphql @@ -77,7 +77,7 @@ type Block @entity { id: ID! # The block header hash chainId: String! @index height: BigInt! @index - timestamp: Date! + timestamp: Date! @index proposerAddress: String! metadata: BlockMetadata! size: Int! @@ -104,6 +104,31 @@ type Block @entity { supplierParams: [SupplierParam] @derivedFrom(field: "block") tokenomicsParams: [TokenomicsParam] @derivedFrom(field: "block") consensusParams: [ConsensusParam] @derivedFrom(field: "block") + # REPORTS + totalComputedUnits: BigInt + totalRelays: BigInt + failedTxs: Int + successfulTxs: Int + totalTxs: Int + stakedSuppliers: Int + stakedSuppliersTokens: BigInt + unstakingSuppliers: Int + unstakingSuppliersTokens: BigInt + # How much time (in ms) the block took to be produced. + # In fact this is the subtract of the timestamp of the current block against the previous one. + timeToBlock: Int + unstakedSuppliers: Int + unstakedSuppliersTokens: BigInt + stakedApps: Int + stakedAppsTokens: BigInt + unstakingApps: Int + unstakingAppsTokens: BigInt + unstakedApps: Int + unstakedAppsTokens: BigInt + stakedGateways: Int + stakedGatewaysTokens: BigInt + unstakedGateways: Int + unstakedGatewaysTokens: BigInt } type Transaction @entity { @@ -116,6 +141,8 @@ type Transaction @entity { # 0 = Success, 1 = Error status: Int! log: String + code: Int! + codespace: String timeoutHeight: BigInt @index # NB: only the first signer! signerAddress: String @index @@ -145,8 +172,8 @@ type Coin @jsonField { type NativeTransfer @entity { id: ID! - toAddress: String! @index - fromAddress: String! @index + recipient: Account! @index + sender: Account! @index amounts: [Coin]! denom: String! @index message: Message! @@ -258,7 +285,7 @@ type Application @entity { stakeAmount: BigInt! stakeDenom: String! # 0 = Staked, 1 = Unstaking, 2 = Unstaked - stakeStatus: Int! + stakeStatus: Int! @index # Block where the msg to unstake the application was received unstakingBeginBlock: Block # Height of the block where the application is going to be unstaked/unbonded. Received with the EventApplicationUnbondingBegin event. @@ -291,6 +318,7 @@ type Application @entity { # Account because the destination application is created on transfer end transferringTo: Account transferEndHeight: BigInt + relays: [Relay] @derivedFrom(field: "application") } type ApplicationGateway @entity { @@ -416,7 +444,7 @@ type Supplier @entity { unstakingBeginEvents: [EventSupplierUnbondingBegin] @derivedFrom(field: "supplier") unstakingEndEvents: [EventSupplierUnbondingEnd] @derivedFrom(field: "supplier") # 0 = Staked, 1 = Unstaking, 2 = Unstaked - stakeStatus: Int! + stakeStatus: Int! @index # Block where MsgUnstakeSupplier was received unstakingBeginBlock: Block # Height of the block where the supplier is going to be unstaked/unbonded. @@ -426,6 +454,7 @@ type Supplier @entity { # This is received with the EventSupplierUnbondingEnd event. unstakingEndBlock: Block serviceConfigs: [SupplierServiceConfig] @derivedFrom(field: "supplier") + relays: [Relay] @derivedFrom(field: "supplier") } type ConfigOption @jsonField { @@ -489,7 +518,7 @@ type Gateway @entity { stakeAmount: BigInt! stakeDenom: String! # 0 = Staked, 1 = Unstaking, 2 = Unstaked - stakeStatus: Int! + stakeStatus: Int! @index unstakingBeginBlock: Block unstakingEndBlock: Block stakeMsgs: [MsgStakeGateway] @derivedFrom(field: "gateway") @@ -655,6 +684,219 @@ type AuthzMsgExec @entity { message: Message! } +type MsgCreateClaim @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + transaction: Transaction! + block: Block! +} + +type MsgSubmitProof @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + proof: String + transaction: Transaction! + block: Block! +} + +type EventClaimCreated @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + transaction: Transaction + block: Block! +} + +type EventClaimUpdated @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + transaction: Transaction + block: Block! + relay: Relay +} + +enum ClaimExpirationReason { + EXPIRATION_REASON_UNSPECIFIED + PROOF_MISSING + PROOF_INVALID +} + +type EventClaimExpired @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + expirationReason: ClaimExpirationReason + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + transaction: Transaction + block: Block! +} + +enum ProofRequirementReason { + NOT_REQUIRED + PROBABILISTIC + THRESHOLD +} + + +type EventClaimSettled @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + proofRequirement: ProofRequirementReason + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + transaction: Transaction + block: Block! +} + +type Relay @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + closestMerkleProof: String + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + msgCreateClaim: MsgCreateClaim + eventClaimCreated: EventClaimCreated + eventsClaimUpdated: [EventClaimUpdated] @derivedFrom(field: "relay") + eventClaimExpired: EventClaimExpired + eventClaimSettled: EventClaimSettled + eventProofSubmitted: EventProofSubmitted + msgSubmitProof: MsgSubmitProof + eventsProofUpdated: [EventProofUpdated] @derivedFrom(field: "relay") + # 0 = PENDING, 1 = SUCCESSFUL, 2 = FAILED + status: Int! + failedCodeSpace: String + requiredProof: Boolean + # this must be a value of the enums ClaimErrors or ProofErrors. We are using Int because we can't define enums with numbers. + failedCode: Int +} + +type EventProofSubmitted @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + closestMerkleProof: String + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + transaction: Transaction + block: Block! +} + +type EventProofUpdated @entity { + id: ID! + supplier: Supplier! + application: Application! + service: Service! + sessionId: String! + sessionStartHeight: BigInt! + sessionEndHeight: BigInt! + rootHash: String + closestMerkleProof: String + numRelays: BigInt + numClaimedComputedUnits: BigInt + numEstimatedComputedUnits: BigInt + claimedAmount: BigInt + claimedDenom: String + transaction: Transaction + block: Block! + relay: Relay +} + +# Entity used to store summarized data related to relays by block and service +type RelayByBlockAndService @entity { + id: ID! + relays: BigInt! + computedUnits: BigInt! + claimedUpokt: BigInt! + amount: Int! + block: Block! + service: Service! +} + +# Entity used to store summarized data related to staked suppliers by block and service +type StakedSuppliersByBlockAndService @entity { + id: ID! + tokens: BigInt! + amount: Int! + block: Block! + service: Service! +} + +# Entity used to store summarized data related to staked apps by block and service +type StakedAppsByBlockAndService @entity { + id: ID! + tokens: BigInt! + amount: Int! + block: Block! + service: Service! +} + type Supply @entity { id: ID! denom: String! @index diff --git a/src/mappings/bank/transfer.ts b/src/mappings/bank/transfer.ts index b19f2b0..a3bb012 100644 --- a/src/mappings/bank/transfer.ts +++ b/src/mappings/bank/transfer.ts @@ -17,7 +17,7 @@ export async function handleNativeTransfer(event: CosmosEvent): Promise { async function _handleNativeTransfer(event: CosmosEvent): Promise { const msg: CosmosMessage = event.msg; - logger.info(`[handleNativeTransfer] (tx ${msg.tx.hash}): indexing message ${msg.idx + 1} / ${msg.tx.decodedTx.body.messages.length}`); + logger.debug(`[handleNativeTransfer] (tx ${msg.tx.hash}): indexing message ${msg.idx + 1} / ${msg.tx.decodedTx.body.messages.length}`); logger.debug(`[handleNativeTransfer] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); // const timeline = getTimeline(event); @@ -35,8 +35,8 @@ async function _handleNativeTransfer(event: CosmosEvent): Promise { const id = messageId(msg); const transferEntity = NativeTransfer.create({ id, - toAddress, - fromAddress, + senderId: toAddress, + recipientId: fromAddress, amounts, denom, // timeline, diff --git a/src/mappings/constants.ts b/src/mappings/constants.ts index f4f2010..3209a3b 100644 --- a/src/mappings/constants.ts +++ b/src/mappings/constants.ts @@ -18,3 +18,9 @@ export const ApplicationUnbondingReason = { ...ApplicationUnbondingReasonEnum, TRANSFERRED: 2, } as const + +export enum RelayStatus { + PENDING = 0, + SUCCESSFUL = 1, + FAILED = 2, +} diff --git a/src/mappings/genesis.ts b/src/mappings/genesis.ts index c8bd6a6..9dbf057 100644 --- a/src/mappings/genesis.ts +++ b/src/mappings/genesis.ts @@ -178,9 +178,9 @@ async function _handleGenesisSuppliers(genesis: Genesis, block: CosmosBlock): Pr const transactions: Array = []; for (let i = 0; i < genesis.app_state.supplier.supplierList.length; i++) { - const supplier = genesis.app_state.supplier.supplierList[i]; - const msgId = `genesis-${supplier.operator_address}`; - const transactionHash = getGenesisFakeTxHash("app", i); + const supplier = genesis.app_state.supplier.supplierList[i] + const msgId = `genesis-${supplier.operator_address}` + const transactionHash = getGenesisFakeTxHash('supplier', i) transactions.push({ id: transactionHash, @@ -189,6 +189,7 @@ async function _handleGenesisSuppliers(genesis: Genesis, block: CosmosBlock): Pr gasWanted: BigInt(0), fees: [], status: TxStatus.Success, + code: 0 }); supplierMsgStakes.push({ @@ -275,6 +276,7 @@ async function _handleGenesisApplications(genesis: Genesis, block: CosmosBlock): gasWanted: BigInt(0), fees: [], status: TxStatus.Success, + code: 0 }); if (app.delegatee_gateway_addresses.length > 0) { @@ -363,6 +365,7 @@ async function _handleGenesisGateways(genesis: Genesis, block: CosmosBlock): Pro gasWanted: BigInt(0), fees: [], status: TxStatus.Success, + code: 0 }); gatewayMsgStakes.push({ diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 8c8d8a9..4a2b0ea 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -4,5 +4,7 @@ export * from "./poktroll/applications"; export * from "./poktroll/services"; export * from "./poktroll/suppliers"; export * from "./poktroll/gateways"; +export * from "./poktroll/relays"; export * from "./genesis"; export * from "./authz/exec"; +export * from "./poktroll/reports"; diff --git a/src/mappings/poktroll/gateways.ts b/src/mappings/poktroll/gateways.ts index c6d26c6..2bb25d9 100644 --- a/src/mappings/poktroll/gateways.ts +++ b/src/mappings/poktroll/gateways.ts @@ -39,7 +39,7 @@ export async function handleGatewayUnstakeEvent(event: CosmosEvent): Promise, ) { - logger.info(`[handleGatewayMsgStake] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); + logger.debug(`[handleGatewayMsgStake] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); if (!msg.msg.decodedMsg.stake) { throw new Error(`[handleGatewayMsgStake] stake not provided in msg`); @@ -77,7 +77,7 @@ async function _handleGatewayMsgStake( async function _handleGatewayMsgUnstake( msg: CosmosMessage, ) { - logger.info(`[handleGatewayMsgUnstake] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); + logger.debug(`[handleGatewayMsgUnstake] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); const gateway = await Gateway.get(msg.msg.decodedMsg.address); if (!gateway) { @@ -105,7 +105,7 @@ async function _handleGatewayMsgUnstake( async function _handleGatewayUnstakeEvent( event: CosmosEvent, ) { - logger.info(`[handleGatewayUnstakeEvent] (event.event): ${stringify(event.event, undefined, 2)}`); + logger.debug(`[handleGatewayUnstakeEvent] (event.event): ${stringify(event.event, undefined, 2)}`); const gatewayStringified = event.event.attributes.find(attribute => attribute.key === "gateway")?.value as unknown as string; diff --git a/src/mappings/poktroll/relays.ts b/src/mappings/poktroll/relays.ts new file mode 100644 index 0000000..3a113c5 --- /dev/null +++ b/src/mappings/poktroll/relays.ts @@ -0,0 +1,544 @@ +import { CosmosEvent, CosmosMessage } from "@subql/types-cosmos"; +import { claimExpirationReasonFromJSON } from "../../client/poktroll/tokenomics/event"; +import { + ClaimExpirationReason, + EventClaimCreated, + EventClaimExpired, + EventClaimSettled, + EventClaimUpdated, + EventProofSubmitted, + EventProofUpdated, + MsgCreateClaim as MsgCreateClaimEntity, + MsgSubmitProof as MsgSubmitProofEntity, + ProofRequirementReason, + Relay +} from "../../types"; +import { CoinSDKType } from "../../types/proto-interfaces/cosmos/base/v1beta1/coin"; +import { MsgCreateClaim, MsgSubmitProof } from "../../types/proto-interfaces/poktroll/proof/tx"; +import { + ClaimSDKType, + proofRequirementReasonFromJSON, + ProofRequirementReasonSDKType, + ProofSDKType, +} from "../../types/proto-interfaces/poktroll/proof/types"; +import { ClaimExpirationReasonSDKType } from "../../types/proto-interfaces/poktroll/tokenomics/event"; +import { RelayStatus } from "../constants"; +import { getEventId, getRelayId, messageId } from "../utils/ids"; +import { stringify } from "../utils/json"; + +function parseAttribute(attribute: unknown): string { + return (attribute as string).replaceAll('"', '') +} + +function getAttributes(attributes: CosmosEvent['event']['attributes']) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + let proof: ProofSDKType = {}, + expirationReason: ClaimExpirationReason = ClaimExpirationReason.EXPIRATION_REASON_UNSPECIFIED, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + claim: ClaimSDKType = {}, + proofRequirement: ProofRequirementReason = ProofRequirementReason.NOT_REQUIRED, + numRelays = BigInt(0), + numClaimedComputedUnits = BigInt(0), + numEstimatedComputedUnits = BigInt(0), + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + claimed: CoinSDKType = {}; + + for (const attribute of attributes) { + if (attribute.key === 'proof') { + proof = JSON.parse(attribute.value as string) + } + + if (attribute.key === 'claim') { + claim = JSON.parse(attribute.value as string) + } + + if (attribute.key === 'num_relays') { + numRelays = BigInt(parseAttribute(attribute.value)) + } + + if (attribute.key === 'num_claimed_computed_units') { + numClaimedComputedUnits = BigInt(parseAttribute(attribute.value)) + } + + if (attribute.key === 'num_estimated_computed_units') { + numEstimatedComputedUnits = BigInt(parseAttribute(attribute.value)) + } + + if (attribute.key === 'claimed') { + claimed = JSON.parse(attribute.value as string) + } + + if (attribute.key === 'proof_requirement') { + switch (proofRequirementReasonFromJSON(parseAttribute(attribute.value))) { + case ProofRequirementReasonSDKType.THRESHOLD: + proofRequirement = ProofRequirementReason.THRESHOLD + break; + case ProofRequirementReasonSDKType.NOT_REQUIRED: + proofRequirement = ProofRequirementReason.NOT_REQUIRED + break; + case ProofRequirementReasonSDKType.PROBABILISTIC: + proofRequirement = ProofRequirementReason.PROBABILISTIC + break; + default: { + throw new Error(`Unknown ProofRequirementReason: ${attribute.value}`) + } + } + } + + if (attribute.key === 'expiration_reason') { + switch (claimExpirationReasonFromJSON(parseAttribute(attribute.value))) { + case ClaimExpirationReasonSDKType.EXPIRATION_REASON_UNSPECIFIED: + expirationReason = ClaimExpirationReason.EXPIRATION_REASON_UNSPECIFIED + break; + case ClaimExpirationReasonSDKType.PROOF_INVALID: + expirationReason = ClaimExpirationReason.PROOF_INVALID + break; + case ClaimExpirationReasonSDKType.PROOF_MISSING: + expirationReason = ClaimExpirationReason.PROOF_MISSING + break; + default: { + throw new Error(`Unknown ClaimExpirationReason: ${attribute.value}`) + } + } + } + } + + return { + claim, + proof, + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimed, + proofRequirement, + expirationReason + } +} + +// eslint-disable-next-line complexity +export async function handleEventClaimSettled(event: CosmosEvent): Promise { + logger.debug(`[handleEventClaimSettled] event.attributes: ${stringify(event.event.attributes, undefined,2 )}`); + + const { + claim, + claimed, + numClaimedComputedUnits, + numEstimatedComputedUnits, + numRelays, + proofRequirement + } = getAttributes(event.event.attributes) + + const {root_hash, session_header, supplier_operator_address} = claim + + const id = getRelayId({ + applicationId: session_header?.application_address || '', + supplierId: supplier_operator_address, + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + }); + + const shared = { + supplierId: supplier_operator_address, + applicationId: session_header?.application_address || '', + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + sessionStartHeight: BigInt(session_header?.session_start_block_height?.toString() || 0), + sessionEndHeight: BigInt(session_header?.session_end_block_height?.toString() || 0), + rootHash: stringify(root_hash), + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimedDenom: claimed?.denom || '', + claimedAmount: BigInt(claimed?.amount || '0'), + } as const + + const relay = await Relay.get(id) + + await Promise.all([ + Relay.create({ + ...relay, + ...shared, + id, + status: RelayStatus.SUCCESSFUL, + eventClaimSettledId: getEventId(event), + }).save(), + EventClaimSettled.create({ + ...shared, + transactionId: event.tx?.hash, + blockId: event.block.block.id, + id: getEventId(event), + proofRequirement + }).save() + ]) +} +// eslint-disable-next-line complexity +export async function handleEventClaimExpired(event: CosmosEvent): Promise { + logger.debug(`[handleEventClaimExpired] event.attributes: ${stringify(event.event.attributes, undefined,2 )}`); + + const { + claim, + claimed, + expirationReason, + numClaimedComputedUnits, + numEstimatedComputedUnits, + numRelays, + } = getAttributes(event.event.attributes) + + const {root_hash, session_header, supplier_operator_address} = claim + + const id = getRelayId({ + applicationId: session_header?.application_address || '', + supplierId: supplier_operator_address, + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + }); + + const shared = { + supplierId: supplier_operator_address, + applicationId: session_header?.application_address || '', + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + sessionStartHeight: BigInt(session_header?.session_start_block_height?.toString() || 0), + sessionEndHeight: BigInt(session_header?.session_end_block_height?.toString() || 0), + rootHash: stringify(root_hash), + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimedDenom: claimed?.denom || '', + claimedAmount: BigInt(claimed?.amount || '0'), + } as const + + const relay = await Relay.get(id) + + await Promise.all([ + Relay.create({ + ...relay, + ...shared, + id, + eventClaimExpiredId: getEventId(event), + status: RelayStatus.FAILED, + }).save(), + EventClaimExpired.create({ + ...shared, + id: getEventId(event), + expirationReason, + transactionId: event.tx?.hash, + blockId: event.block.block.id, + }).save() + ]) +} + +export async function handleMsgCreateClaim(msg: CosmosMessage): Promise { + logger.debug(`[handleMsgCreateClaim] msg.msg: ${stringify(msg.msg, undefined,2 )}`); + + const {rootHash, sessionHeader, supplierOperatorAddress} = msg.msg.decodedMsg; + + const applicationId = sessionHeader?.applicationAddress || ''; + const serviceId = sessionHeader?.serviceId || ''; + const sessionId = sessionHeader?.sessionId || ''; + + const id = getRelayId({ + applicationId, + supplierId: supplierOperatorAddress, + serviceId, + sessionId, + }); + + const shared = { + supplierId: supplierOperatorAddress, + applicationId, + serviceId, + sessionId, + sessionStartHeight: BigInt(sessionHeader?.sessionStartBlockHeight?.toString() || 0), + sessionEndHeight: BigInt(sessionHeader?.sessionEndBlockHeight?.toString() || 0), + rootHash: stringify(rootHash), + } + + await Promise.all([ + MsgCreateClaimEntity.create({ + id: messageId(msg), + ...shared, + transactionId: msg.tx.hash, + blockId: msg.block.block.id, + }).save(), + Relay.create({ + id, + ...shared, + status: RelayStatus.PENDING, + msgCreateClaimId: messageId(msg), + }).save() + ]) +} + +export async function handleEventClaimCreated(event: CosmosEvent): Promise { + logger.debug(`[handleEventClaimCreated] event.attributes: ${stringify(event.event.attributes, undefined,2 )}`); + + const { + claim, + claimed, + numClaimedComputedUnits, + numEstimatedComputedUnits, + numRelays, + } = getAttributes(event.event.attributes) + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const {root_hash, session_header, supplier_operator_address, } = claim + + const id = getRelayId({ + applicationId: session_header?.application_address || '', + supplierId: supplier_operator_address, + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + }); + + const relay = await Relay.get(id) + + const shared = { + supplierId: supplier_operator_address, + applicationId: session_header?.application_address || '', + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + sessionStartHeight: BigInt(session_header?.session_start_block_height?.toString() || 0), + sessionEndHeight: BigInt(session_header?.session_end_block_height?.toString() || 0), + rootHash: stringify(root_hash), + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimedDenom: claimed?.denom || '', + claimedAmount: BigInt(claimed?.amount || '0'), + } + + await Promise.all([ + Relay.create({ + ...relay, + ...shared, + id, + status: RelayStatus.PENDING, + eventClaimCreatedId: getEventId(event), + }).save(), + EventClaimCreated.create({ + id: getEventId(event), + ...shared, + transactionId: event.tx?.hash, + blockId: event.block.block.id, + }).save() + ]) +} + +export async function handleEventClaimUpdated(event: CosmosEvent): Promise { + logger.debug(`[handleEventClaimUpdated] event.attributes: ${stringify(event.event.attributes, undefined,2 )}`); + + const { + claim, + claimed, + numClaimedComputedUnits, + numEstimatedComputedUnits, + numRelays, + } = getAttributes(event.event.attributes) + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const {root_hash, session_header, supplier_operator_address, } = claim + + const id = getRelayId({ + applicationId: session_header?.application_address || '', + supplierId: supplier_operator_address, + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + }); + + const shared = { + supplierId: supplier_operator_address, + applicationId: session_header?.application_address || '', + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + sessionStartHeight: BigInt(session_header?.session_start_block_height?.toString() || 0), + sessionEndHeight: BigInt(session_header?.session_end_block_height?.toString() || 0), + rootHash: stringify(root_hash), + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimedDenom: claimed?.denom || '', + claimedAmount: BigInt(claimed?.amount || '0'), + } as const + + const relay = await Relay.get(id) + + await Promise.all([ + Relay.create({ + ...relay, + ...shared, + id, + status: RelayStatus.PENDING, + }).save(), + EventClaimUpdated.create({ + ...shared, + id: getEventId(event), + relayId: id, + transactionId: event.tx?.hash, + blockId: event.block.block.id, + }).save() + ]) +} + +export async function handleMsgSubmitProof(msg: CosmosMessage): Promise { + logger.debug(`[handleMsgSubmitProof] msg.msg: ${stringify(msg.msg, undefined,2 )}`); + + const { proof, sessionHeader, supplierOperatorAddress,} = msg.msg.decodedMsg + + const applicationId = sessionHeader?.applicationAddress || ''; + const serviceId = sessionHeader?.serviceId || ''; + const sessionId = sessionHeader?.sessionId || ''; + + const id = getRelayId({ + applicationId, + supplierId: supplierOperatorAddress, + serviceId, + sessionId, + }); + + const shared = { + id, + applicationId, + supplierId: supplierOperatorAddress, + sessionId, + serviceId, + sessionEndHeight: BigInt(sessionHeader?.sessionEndBlockHeight?.toString() || 0), + sessionStartHeight: BigInt(sessionHeader?.sessionStartBlockHeight?.toString() || 0), + } + + const relay = await Relay.get(id) + + await Promise.all([ + MsgSubmitProofEntity.create({ + ...shared, + proof: stringify(proof), + transactionId: msg.tx.hash, + blockId: msg.block.block.id, + }).save(), + Relay.create({ + ...relay, + ...shared, + id, + status: RelayStatus.PENDING, + msgSubmitProofId: id, + }).save() + ]) +} + +export async function handleEventProofSubmitted(event: CosmosEvent): Promise { + logger.debug(`[EventProofSubmitted] event.attributes: ${stringify(event.event.attributes, undefined,2 )}`); + + const { + claim, + claimed, + numClaimedComputedUnits, + numEstimatedComputedUnits, + numRelays, + proof + } = getAttributes(event.event.attributes) + + const {root_hash, session_header, supplier_operator_address, } = claim + + const shared = { + supplierId: supplier_operator_address, + applicationId: session_header?.application_address || '', + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + sessionStartHeight: BigInt(session_header?.session_start_block_height?.toString() || 0), + sessionEndHeight: BigInt(session_header?.session_end_block_height?.toString() || 0), + rootHash: stringify(root_hash), + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimedDenom: claimed?.denom || '', + claimedAmount: BigInt(claimed?.amount || '0'), + } as const + + const id = getRelayId({ + applicationId: session_header?.application_address || '', + supplierId: supplier_operator_address, + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + }) + + const relay = await Relay.get(id) + + await Promise.all([ + EventProofSubmitted.create({ + id: getEventId(event), + ...shared, + closestMerkleProof: proof ? stringify(proof.closest_merkle_proof) : undefined, + transactionId: event.tx?.hash, + blockId: event.block.block.id, + }).save(), + Relay.create({ + id, + ...relay, + ...shared, + status: RelayStatus.PENDING, + eventProofSubmittedId: getEventId(event), + }) + ]) +} + +export async function handleEventProofUpdated(event: CosmosEvent): Promise { + logger.debug(`[EventProofSubmitted] event.attributes: ${stringify(event.event.attributes, undefined,2 )}`); + + const { + claim, + claimed, + numClaimedComputedUnits, + numEstimatedComputedUnits, + numRelays, + proof + } = getAttributes(event.event.attributes) + + const {root_hash, session_header, supplier_operator_address, } = claim + + const shared = { + supplierId: supplier_operator_address, + applicationId: session_header?.application_address || '', + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + sessionStartHeight: BigInt(session_header?.session_start_block_height?.toString() || 0), + sessionEndHeight: BigInt(session_header?.session_end_block_height?.toString() || 0), + rootHash: stringify(root_hash), + numRelays, + numClaimedComputedUnits, + numEstimatedComputedUnits, + claimedDenom: claimed?.denom || '', + claimedAmount: BigInt(claimed?.amount || '0'), + } as const + + + const id = getRelayId({ + applicationId: session_header?.application_address || '', + supplierId: supplier_operator_address, + serviceId: session_header?.service_id || '', + sessionId: session_header?.session_id || '', + }) + + const relay = await Relay.get(id) + + await Promise.all([ + EventProofUpdated.create({ + id: getEventId(event), + ...shared, + closestMerkleProof: proof ? stringify(proof.closest_merkle_proof) : undefined, + relayId: id, + transactionId: event.tx?.hash, + blockId: event.block.block.id, + }).save(), + Relay.create({ + id, + ...relay, + ...shared, + status: RelayStatus.PENDING, + }) + ]) +} diff --git a/src/mappings/poktroll/reports.ts b/src/mappings/poktroll/reports.ts new file mode 100644 index 0000000..946f461 --- /dev/null +++ b/src/mappings/poktroll/reports.ts @@ -0,0 +1,348 @@ +import { CosmosBlock } from "@subql/types-cosmos"; +import { + Application, + ApplicationService, + Block, + EventClaimSettled, Gateway, + Supplier, + SupplierServiceConfig, + Transaction, +} from "../../types"; +import { RelayByBlockAndServiceProps } from "../../types/models/RelayByBlockAndService"; +import { StakedAppsByBlockAndServiceProps } from "../../types/models/StakedAppsByBlockAndService"; +import { StakedSuppliersByBlockAndServiceProps } from "../../types/models/StakedSuppliersByBlockAndService"; +import { StakeStatus } from "../constants"; + +export async function handleAddBlockReports(block: CosmosBlock): Promise { + const [ + {computedUnits, relays, relaysByService}, + {invalidTxs, validTxs}, + {stakedSuppliers, stakedSuppliersByService, stakedTokensBySupplier}, + {unstakingSuppliers, unstakingTokensBySupplier}, + took, + {unstakedSuppliers, unstakedTokensBySupplier}, + {stakedApps, stakedAppsByService, stakedTokensByApp}, + {unstakingApps, unstakingTokensByApp}, + {unstakedApps, unstakedTokensByApp}, + {stakedGateways, stakedTokensByGateway}, + {unstakedGateways, unstakedTokensByGateway}, + blockFromDB + ] = await Promise.all([ + getRelaysData(block), + getTransactionsData(block), + getStakedSuppliersData(), + getUnstakingSuppliersData(), + getTook(block), + getUnstakedSuppliersData(block.block.id), + getStakedAppsData(), + getUnstakingAppsData(), + getUnstakedAppssData(block.block.id), + getStakedGatewaysData(), + getUnstakedGatewaysData(block.block.id), + Block.get(block.block.id)! + ] as const) + + const blockEntity = blockFromDB as Block + + blockEntity.totalComputedUnits = computedUnits + blockEntity.totalRelays = relays + blockEntity.failedTxs = invalidTxs + blockEntity.successfulTxs = validTxs + blockEntity.timeToBlock = took + blockEntity.totalTxs = validTxs + invalidTxs + blockEntity.stakedSuppliers = stakedSuppliers + blockEntity.stakedSuppliersTokens = stakedTokensBySupplier + blockEntity.unstakingSuppliers = unstakingSuppliers + blockEntity.unstakingSuppliersTokens = unstakingTokensBySupplier + blockEntity.unstakedSuppliers = unstakedSuppliers + blockEntity.unstakedSuppliersTokens = unstakedTokensBySupplier + blockEntity.stakedApps = stakedApps + blockEntity.stakedAppsTokens = stakedTokensByApp + blockEntity.unstakingApps = unstakingApps + blockEntity.unstakingAppsTokens = unstakingTokensByApp + blockEntity.unstakedApps = unstakedApps + blockEntity.unstakedAppsTokens = unstakedTokensByApp + blockEntity.stakedGateways = stakedGateways + blockEntity.stakedGatewaysTokens = stakedTokensByGateway + blockEntity.unstakedGateways = unstakedGateways + blockEntity.unstakedGatewaysTokens = unstakedTokensByGateway + + await Promise.all([ + blockEntity.save(), + store.bulkCreate('RelayByBlockAndService', relaysByService.map(relay => ({ + id: `${block.block.id}-${relay.service}`, + relays: relay.relays, + amount: relay.amount, + computedUnits: relay.computedUnits, + claimedUpokt: relay.tokens, + blockId: block.block.id, + serviceId: relay.service, + } as RelayByBlockAndServiceProps))), + store.bulkCreate('StakedSuppliersByBlockAndService', stakedSuppliersByService.map(staked => ({ + id: `${block.block.id}-${staked.service}`, + tokens: staked.tokens, + amount: staked.amount, + blockId: block.block.id, + serviceId: staked.service, + } as StakedSuppliersByBlockAndServiceProps))), + store.bulkCreate('StakedAppsByBlockAndService', stakedAppsByService.map(staked => ({ + id: `${block.block.id}-${staked.service}`, + tokens: staked.tokens, + amount: staked.amount, + blockId: block.block.id, + serviceId: staked.service, + } as StakedAppsByBlockAndServiceProps))), + ]) +} + +async function getRelaysData(block: CosmosBlock){ + const relays: Array = []; + const limit = 100; + let offset = 0; + + // eslint-disable-next-line no-constant-condition + while (true) { + const items: Array = await EventClaimSettled.getByFields([["blockId", "=", block.block.id]], { limit, offset }); + + // eslint-disable-next-line + //@ts-ignore + if (items.length === 0) { + break; + } + + relays.push(...items); + offset += limit; + } + + const relaysByServiceMap: Record = {} + + let relaysAmount = BigInt(0), computedUnits = BigInt(0), claimedAmount = BigInt(0); + + for (const relay of relays) { + relaysAmount += relay.numRelays || BigInt(0) + computedUnits += relay.numClaimedComputedUnits || BigInt(0) + claimedAmount += relay.claimedAmount || BigInt(0) + + if (!relaysByServiceMap[relay.serviceId]) { + relaysByServiceMap[relay.serviceId] = { + tokens: BigInt(0), + computedUnits: BigInt(0), + amount: 0, + relays: BigInt(0), + } + } + + relaysByServiceMap[relay.serviceId].amount += 1 + relaysByServiceMap[relay.serviceId].relays += relay.numRelays || BigInt(0) + relaysByServiceMap[relay.serviceId].tokens += relay.claimedAmount || BigInt(0) + relaysByServiceMap[relay.serviceId].computedUnits += relay.numClaimedComputedUnits || BigInt(0) + } + + const relaysByService = Object.entries(relaysByServiceMap).map(([service, {amount, computedUnits, relays, tokens}]) => ({ + service, + tokens, + amount, + computedUnits, + relays + })) + + return { + relays: relaysAmount, + computedUnits, + claimedAmount, + relaysByService + } +} + +async function getTransactionsData(block: CosmosBlock){ + const transactions: Array = []; + const limit = 100; + let offset = 0; + + // eslint-disable-next-line no-constant-condition + while (true) { + const items: Array = await Transaction.getByFields([["blockId", "=", block.block.id]], { limit, offset }); + + // eslint-disable-next-line + //@ts-ignore + if (items.length === 0) { + break; + } + + transactions.push(...items); + offset += limit; + } + + let validTxs = 0, invalidTxs = 0; + + for (const tx of transactions) { + if (tx.code === 0) { + validTxs += 1 + } else { + invalidTxs += 1 + } + } + + return { + validTxs, + invalidTxs + } +} + +async function getStakedSuppliersData() { + const stakedSuppliers = await Supplier.getByFields([["stakeStatus", "=", StakeStatus.Staked]], {}) + const stakedSuppliersByServiceMap: Record = {} + + let stakedTokensBySupplier = BigInt(0) + + for (const supplier of stakedSuppliers) { + stakedTokensBySupplier += supplier.stakeAmount + + const services = await SupplierServiceConfig.getBySupplierId(supplier.id, {}) + + for (const {serviceId} of services) { + if (!stakedSuppliersByServiceMap[serviceId]) { + stakedSuppliersByServiceMap[serviceId] = { + tokens: BigInt(0), + amount: 0, + } + } else { + stakedSuppliersByServiceMap[serviceId].tokens += supplier.stakeAmount + stakedSuppliersByServiceMap[serviceId].amount += 1 + } + } + } + + const stakedSuppliersByService = Object.entries(stakedSuppliersByServiceMap).map(([service, {amount, tokens}]) => ({ + service, + tokens, + amount, + })) + + return { + stakedSuppliers: stakedSuppliers.length, + stakedTokensBySupplier, + stakedSuppliersByService + } +} + +async function getUnstakingSuppliersData() { + const unstakingSuppliers = await Supplier.getByFields([["stakeStatus", "=", StakeStatus.Unstaking]], {}) + const unstakingTokensBySupplier = unstakingSuppliers.reduce((acc, supplier) => acc + BigInt(supplier.stakeAmount), BigInt(0)) + + return { + unstakingSuppliers: unstakingSuppliers.length, + unstakingTokensBySupplier, + } +} + +async function getTook(block: CosmosBlock) { + if (block.header.height === 1) { + return 0 + } + + const previousHeight = BigInt(block.header.height - 1) + const previousBlock = (await Block.getByHeight(previousHeight, {}))[0] + + // took is the time between the previous block and the current block + return block.header.time.getTime() - previousBlock.timestamp.getTime() +} + +async function getUnstakedSuppliersData(blockId: string) { + const unstakedSuppliers = await Supplier.getByUnstakingEndBlockId(blockId, {}) + const unstakedTokensBySupplier = unstakedSuppliers.reduce((acc, supplier) => acc + BigInt(supplier.stakeAmount), BigInt(0)) + + return { + unstakedSuppliers: unstakedSuppliers.length, + unstakedTokensBySupplier, + } +} + +async function getStakedAppsData() { + const stakedApps = await Application.getByFields([["stakeStatus", "=", StakeStatus.Staked]], {}) + const stakedAppsByServiceMap: Record = {} + + let stakedTokensByApp = BigInt(0) + + for (const app of stakedApps) { + stakedTokensByApp += app.stakeAmount + + const services = await ApplicationService.getByApplicationId(app.id, {}) + + for (const {serviceId} of services) { + if (!stakedAppsByServiceMap[serviceId]) { + stakedAppsByServiceMap[serviceId] = { + tokens: BigInt(0), + amount: 0, + } + } else { + stakedAppsByServiceMap[serviceId].tokens += app.stakeAmount + stakedAppsByServiceMap[serviceId].amount += 1 + } + } + } + + const stakedAppsByService = Object.entries(stakedAppsByServiceMap).map(([service, {amount, tokens}]) => ({ + service, + tokens, + amount, + })) + + return { + stakedApps: stakedApps.length, + stakedTokensByApp, + stakedAppsByService + } +} + +async function getUnstakingAppsData() { + const unstakingApps = await Application.getByFields([["stakeStatus", "=", StakeStatus.Unstaking]], {}) + const unstakingTokensByApp = unstakingApps.reduce((acc, app) => acc + app.stakeAmount, BigInt(0)) + + return { + unstakingApps: unstakingApps.length, + unstakingTokensByApp, + } +} + +async function getUnstakedAppssData(blockId: string) { + const unstakedApps = await Application.getByUnstakingEndBlockId(blockId, {}) + const unstakedTokensByApp = unstakedApps.reduce((acc, app) => acc + BigInt(app.stakeAmount), BigInt(0)) + + return { + unstakedApps: unstakedApps.length, + unstakedTokensByApp, + } +} + +async function getStakedGatewaysData() { + const stakedGateways = await Gateway.getByFields([["stakeStatus", "=", StakeStatus.Staked]], {}) + const stakedTokensByGateway = stakedGateways.reduce((acc, gateway) => acc + BigInt(gateway.stakeAmount), BigInt(0)) + + return { + stakedGateways: stakedGateways.length, + stakedTokensByGateway, + } +} + + +async function getUnstakedGatewaysData(blockId: string) { + const unstakedGateways = await Gateway.getByUnstakingEndBlockId(blockId, {}) + const unstakedTokensByGateway = unstakedGateways.reduce((acc, gateway) => acc + BigInt(gateway.stakeAmount), BigInt(0)) + + return { + unstakedGateways: unstakedGateways.length, + unstakedTokensByGateway, + } +} diff --git a/src/mappings/poktroll/services.ts b/src/mappings/poktroll/services.ts index 82a13bb..7d12732 100644 --- a/src/mappings/poktroll/services.ts +++ b/src/mappings/poktroll/services.ts @@ -20,7 +20,7 @@ export async function handleMsgAddService( async function _handleMsgAddService( msg: CosmosMessage, ) { - logger.info(`[handleMsgAddService] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); + logger.debug(`[handleMsgAddService] (msg.msg): ${stringify(msg.msg, undefined, 2)}`); const { ownerAddress, service: { computeUnitsPerRelay, id, name } } = msg.msg.decodedMsg; diff --git a/src/mappings/primitives.ts b/src/mappings/primitives.ts index 16de932..77b2bd4 100644 --- a/src/mappings/primitives.ts +++ b/src/mappings/primitives.ts @@ -18,19 +18,17 @@ import { BlockLastCommit, BlockMetadata, BlockSupply, + SupplyDenom, Event, EventAttribute, Message, - SupplyDenom, Transaction, } from "../types"; import { _handleSupply, getSupplyId, } from "./bank/supply"; -import { - PREFIX, - TxStatus, +import { PREFIX, TxStatus, } from "./constants"; import { ConvertedBlockJson, @@ -126,6 +124,28 @@ async function _handleBlock(block: CosmosBlock): Promise { proposerAddress: processedBlock.header.proposerAddress as string, size, metadataId: id, + stakedSuppliers: 0, + totalComputedUnits: BigInt(0), + totalRelays: BigInt(0), + failedTxs: 0, + successfulTxs: 0, + totalTxs: 0, + stakedSuppliersTokens: BigInt(0), + unstakingSuppliers: 0, + unstakingSuppliersTokens: BigInt(0), + timeToBlock: 0, + unstakedSuppliers: 0, + unstakedSuppliersTokens: BigInt(0), + stakedApps: 0, + stakedAppsTokens: BigInt(0), + unstakingApps: 0, + unstakingAppsTokens: BigInt(0), + stakedGateways: 0, + stakedGatewaysTokens: BigInt(0), + unstakedGateways: 0, + unstakedGatewaysTokens: BigInt(0), + unstakedAppsTokens: BigInt(0), + unstakedApps: 0, }); await blockEntity.save(); @@ -135,6 +155,7 @@ async function _handleBlock(block: CosmosBlock): Promise { await _handleSupply(block); } + async function _handleTransaction(tx: CosmosTransaction): Promise { let status = tx.tx.code === 0 ? TxStatus.Success : TxStatus.Error; @@ -151,6 +172,7 @@ async function _handleTransaction(tx: CosmosTransaction): Promise { signerAddress = toBech32(PREFIX, addressBytes); } + logger.debug(`[handleTransaction] (block ${tx.block.block.header.height}): indexing transaction ${tx.idx + 1} / ${tx.block.txs.length} status=${status} signer=${signerAddress}`); logger.debug(`[handleTransaction] (tx.decodedTx): ${stringify(tx.decodedTx, undefined, 2)}`); if (!isNil(tx.tx.log)) logger.debug(`[handleTransaction] (tx.tx.log): ${tx.tx.log}`); @@ -169,6 +191,8 @@ async function _handleTransaction(tx: CosmosTransaction): Promise { log: tx.tx.log || "", status, signerAddress, + code: tx.tx.code, + codespace: tx.tx.codespace, }); await txEntity.save(); } @@ -204,7 +228,7 @@ async function _handleEvent(event: CosmosEvent): Promise { if (event.tx) { id = `${messageId(event)}-${event.idx}`; } else { - id = `${event.block.blockId}-${event.idx}`; + id = `${event.block.block.id}-${event.idx}`; } // NB: sanitize attribute values (may contain non-text characters) diff --git a/src/mappings/utils/ids.ts b/src/mappings/utils/ids.ts index 7b2b7e5..197079a 100644 --- a/src/mappings/utils/ids.ts +++ b/src/mappings/utils/ids.ts @@ -66,3 +66,18 @@ export function getMsgStakeServiceId(msgStakeId: string, serviceId: string): str export function getStakeServiceId(entityStakedId: string, serviceId: string): string { return `${entityStakedId}-${serviceId}`; } + +// Returns the id of the relay for claim and proof +export function getRelayId({ +applicationId, +serviceId, +sessionId, +supplierId +}: { + serviceId: string, + applicationId: string, + supplierId: string, + sessionId: string, +}): string { + return `${supplierId}-${applicationId}-${serviceId}-${sessionId}`; +}