Skip to content

Commit

Permalink
Merge pull request #37 from maticnetwork/plasma-exit-counter
Browse files Browse the repository at this point in the history
plasma exit counter introduced so that we know the queue position for…
  • Loading branch information
reddyismav authored Apr 15, 2021
2 parents 3da2867 + 23efc94 commit 1a5843d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
7 changes: 7 additions & 0 deletions root/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions root/src/mappings/staking-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -208,9 +207,7 @@ function getGlobalDelegatorCounter(): GlobalDelegatorCounter {
entity.current = BigInt.fromI32(0)

}

return entity as GlobalDelegatorCounter

}

function loadDelegator(validatorId: BigInt, delegator: Address): Delegator {
Expand Down
26 changes: 24 additions & 2 deletions root/src/mappings/withdraw-manager.ts
Original file line number Diff line number Diff line change
@@ -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 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))

// 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
Expand Down

0 comments on commit 1a5843d

Please sign in to comment.