From 3265e14a4975060df5816582b3e53045933b74b5 Mon Sep 17 00:00:00 2001 From: Vamsi Date: Thu, 15 Apr 2021 16:20:05 +0530 Subject: [PATCH 1/2] plasma exit counter introduced so that we know the queue position for the entity id when exitId is queried. --- root/schema.graphql | 7 +++++++ root/src/mappings/staking-info.ts | 3 --- root/src/mappings/withdraw-manager.ts | 26 ++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/root/schema.graphql b/root/schema.graphql index e856bdc..73a6911 100644 --- a/root/schema.graphql +++ b/root/schema.graphql @@ -38,6 +38,7 @@ type StateRegistration @entity { type PlasmaExit @entity { # id always created using `plasma-exit-${exitId}` id: ID! + counter: BigInt! # this field can be used to know where the exitStarted transaction happened. exitId: BigInt! exitInitiator: Bytes exitCompleter: Bytes @@ -108,6 +109,12 @@ type GlobalDelegatorCounter @entity { current: BigInt! } +# This can be used to get the count of the plasma exits and till where have the process exits been processed. +type GlobalPlasmaExitCounter @entity { + id: ID! + current: BigInt! +} + type Delegator @entity { id: ID! counter: BigInt! # this field can be used for traversing through large number of delegator list diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index 1e952a6..5a29506 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -198,7 +198,6 @@ export function handleUpdateCommissionRate(event: UpdateCommissionRate): void { // Sole purpose of this entity is to keep a global state variable // which can be used when new delegator comes into picture function getGlobalDelegatorCounter(): GlobalDelegatorCounter { - // Only one entry will be kept in this entity let id = 'global-delegator-counter' let entity = GlobalDelegatorCounter.load(id) @@ -208,9 +207,7 @@ function getGlobalDelegatorCounter(): GlobalDelegatorCounter { entity.current = BigInt.fromI32(0) } - return entity as GlobalDelegatorCounter - } function loadDelegator(validatorId: BigInt, delegator: Address): Delegator { diff --git a/root/src/mappings/withdraw-manager.ts b/root/src/mappings/withdraw-manager.ts index 61b3c2a..c0e8287 100644 --- a/root/src/mappings/withdraw-manager.ts +++ b/root/src/mappings/withdraw-manager.ts @@ -1,14 +1,36 @@ +import { BigInt } from '@graphprotocol/graph-ts' import { ExitStarted, ExitCancelled, Withdraw } from '../../generated/WithdrawManager/WithdrawManager' -import { PlasmaExit } from '../../generated/schema' +import { PlasmaExit, GlobalPlasmaExitCounter } from '../../generated/schema' +function getGlobalPlasmaExitCounter(): GlobalPlasmaExitCounter { + // Only one entry will be kept in this entity + let id = 'global-plasma-exit-counter' + let entity = GlobalPlasmaExitCounter.load(id) + if (entity == null) { + + entity = new GlobalPlasmaExitCounter(id) + entity.current = BigInt.fromI32(0) + + } + return entity as GlobalPlasmaExitCounter +} export function handleExitStarted(event: ExitStarted): void { let id = 'plasma-exit-' + event.params.exitId.toHexString() + + // Try to get what's current global delegator counter's state + // when called for very first time, it'll be `0` + let counter = getGlobalPlasmaExitCounter() + let updated = counter.current.plus(BigInt.fromI32(1)) + + // Updating global counter's state + counter.current = updated + counter.save() // this is first time this entity being created i.e. during plasma // exit start step let entity = new PlasmaExit(id) - + entity.counter = updated entity.exitId = event.params.exitId entity.exitInitiator = event.params.exitor entity.token = event.params.token From 23efc9467d1f26771111c1f90e02dd6195af78f9 Mon Sep 17 00:00:00 2001 From: Vamsi Date: Thu, 15 Apr 2021 16:24:15 +0530 Subject: [PATCH 2/2] comment corrected --- root/src/mappings/withdraw-manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/src/mappings/withdraw-manager.ts b/root/src/mappings/withdraw-manager.ts index c0e8287..f40e580 100644 --- a/root/src/mappings/withdraw-manager.ts +++ b/root/src/mappings/withdraw-manager.ts @@ -18,7 +18,7 @@ function getGlobalPlasmaExitCounter(): GlobalPlasmaExitCounter { export function handleExitStarted(event: ExitStarted): void { let id = 'plasma-exit-' + event.params.exitId.toHexString() - // Try to get what's current global delegator counter's state + // Try to get what's current global plasma counter's state // when called for very first time, it'll be `0` let counter = getGlobalPlasmaExitCounter() let updated = counter.current.plus(BigInt.fromI32(1))