Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance refactors #45

Merged
merged 10 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"lint": "yarn eslint .",
"lint-fix": "eslint . --fix",
"prettier": "prettier '**/*.ts'",
"test": "graph test -v 0.6.0-rc.2",
"prettier-write": "prettier --write '**/*.ts'"
},
"devDependencies": {
Expand All @@ -47,7 +48,8 @@
"eslint": "^7.2.0",
"mustache": "^4.0.1",
"prettier": "^2.0.5",
"typescript": "^3.9.3"
"typescript": "^3.9.3",
"matchstick-as": "0.6.0-beta.2"
},
"author": "",
"bugs": {
Expand Down
107 changes: 47 additions & 60 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Graph Network global parameters and contract addresses
"""
type GraphNetwork @entity {
"ID is set to 1"
id: ID!
id: Bytes!

"Ratio of max staked delegation tokens to indexers stake that earns rewards"
delegationRatio: Int!
Expand Down Expand Up @@ -89,7 +89,7 @@ delegating, curating, and indexing.
"""
type GraphAccount @entity {
"Graph account ID"
id: ID!
id: Bytes!

"All names this graph account has claimed from all name systems"
names: [GraphAccountName!]! @derivedFrom(field: "graphAccount")
Expand Down Expand Up @@ -154,7 +154,7 @@ type GraphAccount @entity {

type GraphAccountMetadata @entity(immutable:true) {
"IPFS hash with account metadata details"
id: ID!
id: Bytes!
"Account that reference this metadata file. For compatibility purposes. For the full list use graphAccounts"
graphAccount: GraphAccount @derivedFrom(field:"metadata")
"Accounts that reference this metadata file"
Expand Down Expand Up @@ -205,7 +205,7 @@ subgraph is stored on IPFS.
"""
type Subgraph @entity {
"Subgraph ID - which is derived from the Organization/Individual graph accountID"
id: ID!
id: Bytes!

"Graph account that owns this subgraph"
owner: GraphAccount!
Expand Down Expand Up @@ -249,12 +249,9 @@ type Subgraph @entity {
"Subgraph number used to create the ID. Only available for Subgraphs created pre-migration"
subgraphNumber: BigInt

"Version of the entity. Subgraph entities are changing the way their ID is generated when the new GNS v2 rolls out so we need to differnetiate them"
"[DEPRECATED] Version of the entity. Subgraph entities are changing the way their ID is generated when the new GNS v2 rolls out so we need to differnetiate them"
entityVersion: Int!

"Subgraph entities might have 'duplicate' entities so that old IDs can be persisted and still queried properly. If that happens we have to link both duplicate entities to be able to update them properly."
linkedEntity: Subgraph

# Name curation data for bonding curve
# Note that the Subgraphs V signal is actually stored in a Signal entity, which
# considers the GNS as a Curator
Expand Down Expand Up @@ -290,23 +287,23 @@ type Subgraph @entity {
"Block number for the L1 -> L2 Transfer. Null if the transfer hasn't started yet"
startedTransferToL2AtBlockNumber: BigInt
"Transaction hash for the L1 -> L2 Transfer. Null if the transfer hasn't started yet"
startedTransferToL2AtTx: String
startedTransferToL2AtTx: Bytes
"Whether the subgraph has been fully transferred from L1 to L2. Subgraphs published on L2 will have this as false unless they were published through a transfer"
transferredToL2: Boolean!
"Timestamp for the L1 -> L2 Transfer. Null if it's not fully transferred or if it's an L1 deployment"
transferredToL2At: BigInt
"Block number for the L1 -> L2 Transfer. Null if it's not fully transferred or if it's an L1 deployment"
transferredToL2AtBlockNumber: BigInt
"Transaction hash for the L1 -> L2 Transfer. Null if it's not fully transferred or if it's an L1 deployment"
transferredToL2AtTx: String
transferredToL2AtTx: Bytes
"Amount of GRT transferred to L2"
signalledTokensSentToL2: BigInt!
"Amount of GRT received on L2"
signalledTokensReceivedOnL2: BigInt!
"ID of the subgraph on L2. Null if it's not transferred"
idOnL2: String
idOnL2: Bytes
"ID of the subgraph on L1. Null if it's not transferred"
idOnL1: String
idOnL1: Bytes
}

"""
Expand All @@ -319,7 +316,7 @@ just a counter than increases each time a new SubgraphVersion is created for a S
"""
type SubgraphVersion @entity {
"Concatenation of subgraph, subgraph deployment, and version ID"
id: ID!
id: Bytes!

"Subgraph of this version"
subgraph: Subgraph!
Expand All @@ -342,8 +339,6 @@ type SubgraphVersion @entity {
# label: String!

entityVersion: Int!

linkedEntity: SubgraphVersion
}

"""
Expand All @@ -355,7 +350,7 @@ related to a SubgraphVersion.
"""
type SubgraphDeployment @entity {
"Subgraph Deployment ID. The IPFS hash with Qm removed to fit into 32 bytes"
id: ID!
id: Bytes!

"The versions this subgraph deployment relates to"
versions: [SubgraphVersion!]! @derivedFrom(field: "subgraphDeployment")
Expand Down Expand Up @@ -428,7 +423,7 @@ type SubgraphDeployment @entity {
"Block number for the L1 -> L2 Transfer. Null if it's not fully transferred or if it's an L1 deployment"
transferredToL2AtBlockNumber: BigInt
"Transaction hash for the L1 -> L2 Transfer. Null if it's not fully transferred or if it's an L1 deployment"
transferredToL2AtTx: String
transferredToL2AtTx: Bytes
"Amount of GRT transferred to L2"
signalledTokensSentToL2: BigInt!
"Amount of GRT received on L2"
Expand All @@ -440,7 +435,7 @@ Metadata for the Indexer along with parameters and staking data
"""
type Indexer @entity {
"Eth address of Indexer"
id: ID!
id: Bytes!
"Time this indexer was created"
createdAt: Int!
"Service registry URL for the indexer"
Expand Down Expand Up @@ -510,6 +505,9 @@ type Indexer @entity {
"Delegators to this Indexer"
delegators: [DelegatedStake!]! @derivedFrom(field: "indexer")

"Delegator relation entities. For internal usage for performance reasons"
relations: [IndexerDelegatedStakeRelation!]! @derivedFrom(field: "indexer")

"CURRENT tokens delegated to the indexer"
delegatedTokens: BigInt!

Expand Down Expand Up @@ -563,27 +561,27 @@ type Indexer @entity {
"Block number for the FIRST L1 -> L2 Transfer"
firstTransferredToL2AtBlockNumber: BigInt
"Transaction hash for the FIRST L1 -> L2 Transfer"
firstTransferredToL2AtTx: String
firstTransferredToL2AtTx: Bytes
"Timestamp for the latest L1 -> L2 Transfer"
lastTransferredToL2At: BigInt
"Block number for the latest L1 -> L2 Transfer"
lastTransferredToL2AtBlockNumber: BigInt
"Transaction hash for the latest L1 -> L2 Transfer"
lastTransferredToL2AtTx: String
lastTransferredToL2AtTx: Bytes
"Amount of GRT transferred to L2. Only visible from L1, as there's no events for it on L2"
stakedTokensTransferredToL2: BigInt!
"ID of the indexer on L2. Null if it's not transferred"
idOnL2: String
idOnL2: Bytes
"ID of the indexer on L1. Null if it's not transferred"
idOnL1: String
idOnL1: Bytes
}

"""
A state channel Allocation representing a single Indexer-SubgraphDeployment stake
"""
type Allocation @entity {
"Channel Address"
id: ID!
id: Bytes!

"Indexer of this allocation"
indexer: Indexer!
Expand Down Expand Up @@ -676,7 +674,7 @@ hence why they share the same IDs.
"""
type Pool @entity {
"Epoch number of the pool"
id: ID!
id: Bytes!

"Total effective allocation tokens from all allocations closed in this epoch"
allocation: BigInt!
Expand All @@ -699,7 +697,7 @@ Delegator with all their delegated stakes towards Indexers
"""
type Delegator @entity {
"Delegator address"
id: ID!
id: Bytes!

account: GraphAccount!
defaultDisplayName: String
Expand Down Expand Up @@ -762,7 +760,7 @@ Delegator stake for a single Indexer
"""
type DelegatedStake @entity {
"Concatenation of Delegator address and Indexer address"
id: ID!
id: Bytes!

"Index the stake is delegated to"
indexer: Indexer!
Expand Down Expand Up @@ -826,21 +824,21 @@ type DelegatedStake @entity {
"Block number for the L1 -> L2 Transfer"
transferredToL2AtBlockNumber: BigInt
"Transaction hash for the L1 -> L2 Transfer"
transferredToL2AtTx: String
transferredToL2AtTx: Bytes
"Amount of GRT transferred to L2. Only visible from L1, as there's no events for it on L2"
stakedTokensTransferredToL2: BigInt!
"ID of the delegation on L2. Null if it's not transferred"
idOnL2: String
idOnL2: Bytes
"ID of the delegation on L1. Null if it's not transferred"
idOnL1: String
idOnL1: Bytes
}

"""
Curator with all Signals and metrics
"""
type Curator @entity {
"Eth address of the Curator"
id: ID!
id: Bytes!

"Time this curator was created"
createdAt: Int!
Expand Down Expand Up @@ -894,7 +892,7 @@ Curator Signal for a single SubgraphDeployment
"""
type Signal @entity {
"Eth address + subgraph deployment ID"
id: ID!
id: Bytes!

"Eth address of the curator"
curator: Curator!
Expand Down Expand Up @@ -926,7 +924,7 @@ Curator Name Signal for a single Subgraph
"""
type NameSignal @entity {
"Eth address + subgraph ID"
id: ID!
id: Bytes!

"Eth address of the curator"
curator: Curator!
Expand Down Expand Up @@ -965,8 +963,6 @@ type NameSignal @entity {

entityVersion: Int!

linkedEntity: NameSignal

"Amount of GRT transferred to L2"
signalledTokensSentToL2: BigInt!
"Amount of GRT received on L2"
Expand All @@ -978,19 +974,19 @@ type NameSignal @entity {
"Block number for the L1 -> L2 Transfer."
transferredToL2AtBlockNumber: BigInt
"Transaction hash for the L1 -> L2 Transfer."
transferredToL2AtTx: String
transferredToL2AtTx: Bytes
"ID of the NameSignal entity on L2. Null if it's not transferred"
idOnL2: String
idOnL2: Bytes
"ID of the NameSignal entity on L1. Null if it's not transferred"
idOnL1: String
idOnL1: Bytes
}

"""
A generic transaction in The Graph Network
"""
interface Transaction {
"Transaction hash concatenated with event log index"
id: ID!
id: Bytes!

"Block number for the transaction"
blockNumber: Int!
Expand All @@ -1010,8 +1006,8 @@ interface Transaction {
"""
All relevant data for a Name Signal Transaction in The Graph Network
"""
type NameSignalTransaction implements Transaction @entity {
id: ID!
type NameSignalTransaction implements Transaction @entity(immutable: true) {
id: Bytes!

blockNumber: Int!

Expand All @@ -1037,8 +1033,8 @@ type NameSignalTransaction implements Transaction @entity {
"""
All relevant data for a Signal Transaction in The Graph Network
"""
type SignalTransaction implements Transaction @entity {
id: ID!
type SignalTransaction implements Transaction @entity(immutable: true) {
id: Bytes!

blockNumber: Int!

Expand Down Expand Up @@ -1075,24 +1071,15 @@ Analytics
"""
type IndexerDelegatedStakeRelation @entity {
"Auxiliary entity to DelegatedStake to make it easier to batch update those delegations"
id: ID!
id: Bytes!

"Indexer entity where the delegation resides"
indexer: Indexer!

"Delegator entity owner of said delegation stake"
delegator: Delegator!

"DelegatedStake entity that represents the delegation"
stake: DelegatedStake!

"Whether the delegation is active or not. Useful to avoid updating non-active delegations without deleting the entity."
active: Boolean!
indexer: Indexer
}

type IndexerDailyData @entity {
"<INDEXER ADDRESS>-<DAY NUMBER>"
id: ID!
id: Bytes!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1147,7 +1134,7 @@ type IndexerDailyData @entity {

type DelegatorDailyData @entity {
"<DELEGATOR ADDRESS>-<DAY NUMBER>"
id: ID!
id: Bytes!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1185,7 +1172,7 @@ type DelegatorDailyData @entity {

type DelegatedStakeDailyData @entity {
"<DELEGATOR ADDRESS>-<INDEXER ADDRESS>-<DAY NUMBER>"
id: ID!
id: Bytes!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1235,7 +1222,7 @@ type DelegatedStakeDailyData @entity {

type DelegatorDelegatedStakeDailyRelation @entity {
"Auxiliary entity to avoid using arrays for many-to-many relation tracking. Compounds the delegator id with an autoincremental number."
id: ID!
id: Bytes!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand All @@ -1261,7 +1248,7 @@ type DelegatorDelegatedStakeDailyRelation @entity {

type SubgraphDeploymentDailyData @entity {
"<SUBGRAPH ID>-<DAY NUMBER>"
id: ID!
id: Bytes!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1311,7 +1298,7 @@ type SubgraphDeploymentDailyData @entity {

type GraphNetworkDailyData @entity {
"<SUBGRAPH ID>-<DAY NUMBER>"
id: ID!
id: Bytes!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1409,5 +1396,5 @@ type _Schema_
name: "delegatorSearch"
language: en
algorithm: rank
include: [{ entity: "Delegator", fields: [{ name: "defaultDisplayName" }, { name: "id" }] }]
include: [{ entity: "Delegator", fields: [{ name: "defaultDisplayName" }] }]
)
Loading
Loading