Skip to content

Commit

Permalink
moonbeam staking fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrvano committed Dec 5, 2023
1 parent e02542a commit c7392d9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion main/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const preEnv = cleanEnv(process.env, {
NETWORK_ID: num(),
MODE: str({ choices: Object.values(MODE) }),
BATCH_INSERT_CHUNK_SIZE: num({ default: 1000 }),
MAX_ATTEMPTS: num({ default: 200 }),
MAX_ATTEMPTS: num({ default: 100 }),
PG_SSL_CA_PATH: str({ default: '' }),
PG_SSL_KEY_PATH: str({ default: '' }),
PG_SSL_CERT_PATH: str({ default: '' }),
Expand Down
5 changes: 0 additions & 5 deletions main/src/modules/Monitoring/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ export class MonitoringService {

await this.sliMetrics.add({ entity: 'queue', name: 'not_processed_count', value: missedTasks.length })

console.log('environment.RESTART_BLOCKS_URI', environment.RESTART_BLOCKS_URI)
console.log('environment.RESTART_ROUNDS_URI', environment.RESTART_ROUNDS_URI)
console.log('environment.RESTART_ERAS_URI', environment.RESTART_ERAS_URI)
console.log('environment.RESTART_BALANCES_URI', environment.RESTART_BALANCES_URI)

try {
if (environment.RESTART_BLOCKS_URI) await needle('get', environment.RESTART_BLOCKS_URI)
if (environment.RESTART_ROUNDS_URI) await needle('get', environment.RESTART_ROUNDS_URI)
Expand Down
31 changes: 21 additions & 10 deletions main/src/modules/MoonbeamStakingProcessor/round-payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ export class MoonbeamStakingProcessorRoundPayout {
const originalRound: any = await apiAtOriginal.query.parachainStaking.round()
const originalRoundNumber = originalRound.current
const runtime: any = await apiAtOriginal.query.system.lastRuntimeUpgrade()
this.specVersion = runtime.unwrap().specVersion.toNumber()
const specVersion: any = runtime.unwrap().specVersion.toNumber()
this.specVersion = specVersion

logger.info({
event: `Round Stake ${originalRoundNumber.toString(10)} runtime version is ${this.specVersion}.`,
event: `Round Stake ${originalRoundNumber.toString(10)} runtime version is ${specVersion}.`,
})

await this.getCollatorsAndDelegators(apiAtOriginal, apiAtOriginal, /*apiAtPriorRewarded, */ originalRoundNumber)
Expand Down Expand Up @@ -95,7 +96,8 @@ export class MoonbeamStakingProcessorRoundPayout {
const rewardDelay = apiAtRewarded.consts.parachainStaking?.rewardPaymentDelay || new BN(2)
const priorRewardedBlockHash: BlockHash = await this.api.rpc.chain.getBlockHash(nowRoundFirstBlock.subn(1))
const runtime: any = await apiAtRewarded.query.system.lastRuntimeUpgrade()
this.specVersion = runtime.unwrap().specVersion.toNumber()
const specVersion: any = runtime.unwrap().specVersion.toNumber()
this.specVersion = specVersion

// obtain data from original round
const rewardRound: any = await apiAtRewarded.query.parachainStaking.round()
Expand All @@ -112,7 +114,7 @@ export class MoonbeamStakingProcessorRoundPayout {
}

logger.info({
event: `Round ${originalRoundNumber.toString(10)} runtime version is ${this.specVersion}.`,
event: `Round ${originalRoundNumber.toString(10)} runtime version is ${specVersion}.`,
})

if (originalRoundBlock.toNumber() === 0) {
Expand Down Expand Up @@ -162,13 +164,13 @@ export class MoonbeamStakingProcessorRoundPayout {

// compute max rounds respecting the current block number and the number of awarded collators
let maxRoundChecks = 1
if (this.specVersion > 1002) {
if (specVersion > 1002) {
if (awardedCollatorCount > latestBlockNumber - nowBlockNumber + 1) {
await sleep(1000 * awardedCollatorCount * 15)
}
maxRoundChecks = awardedCollatorCount
}
if (this.specVersion >= 2000 && maxRoundChecks === 68) {
if (specVersion >= 2000 && maxRoundChecks === 68) {
maxRoundChecks = 72
}

Expand Down Expand Up @@ -202,15 +204,23 @@ export class MoonbeamStakingProcessorRoundPayout {
//apiAtPriorRewarded: ApiPromise,
roundNumber: number,
): Promise<void> {
const specVersion: any = (await apiAtOriginal.query.system.lastRuntimeUpgrade()).unwrap().specVersion.toNumber()

const atStake: any = await apiAtOriginal.query.parachainStaking.atStake.entries(roundNumber)

console.log('getCollatorsAndDelegators AFTER')
for (const [
{
args: [_, accountId],
},
value,
] of atStake) {
const { bond, total, delegations, nominators } = this.specVersion < 2600 ? value : value.unwrap()
//console.log("VALUE", value)
const { bond, total, delegations, nominators } = specVersion < 2600 ? value : value.unwrap()
console.log('BOND', bond)
console.log('total', total)
console.log('delegations', delegations.length)
//console.log("nominators", nominators.length)

const collatorId = accountId.toHex()
this.collators.add(collatorId)
Expand Down Expand Up @@ -318,6 +328,7 @@ export class MoonbeamStakingProcessorRoundPayout {
const apiAtBlock = await this.api.at(nowRoundRewardBlockHash)
const apiAtPreviousBlock = await this.api.at(await this.api.rpc.chain.getBlockHash(rewardedBlockNumber.toNumber() - 1))
const round: any = await apiAtBlock.query.parachainStaking.round()
const specVersion: any = (await apiAtBlock.query.system.lastRuntimeUpgrade()).unwrap().specVersion.toNumber()

logger.info({
event: 'RoundPayoutProcessor.getRewardedFromEventsAtBlock',
Expand Down Expand Up @@ -358,7 +369,7 @@ export class MoonbeamStakingProcessorRoundPayout {
})
}

if (this.specVersion >= 2000) {
if (specVersion >= 2000) {
// Now orbiters have their own event. To replicate previous behavior,
// we take the collator associated and mark rewards as if they were
// to the collator
Expand Down Expand Up @@ -416,14 +427,14 @@ export class MoonbeamStakingProcessorRoundPayout {
return
}

if (this.specVersion === 1001 || this.specVersion === 1002) {
if (specVersion === 1001 || specVersion === 1002) {
if (reward.collator_id) {
//runtime 1001, otherwise it should be defined in previous step.
collatorInfo = this.stakedValue[reward.collator_id]
} else {
return
}
} else if (this.specVersion <= 900) {
} else if (specVersion <= 900) {
for (const collator of Object.values(this.stakedValue)) {
if (
!collator.rewardCollator.isZero() &&
Expand Down
12 changes: 7 additions & 5 deletions main/src/modules/MoonbeamStakingProcessor/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ENTITY, ProcessingTaskModel, PROCESSING_STATUS } from '@/models/process
/**
* Please check this repo
* https://github.com/PureStake/moonbeam.git
*
*
* and test scripts like:
* test/suites/smoke/test-staking-round-cleanup.ts
*/
Expand Down Expand Up @@ -132,8 +132,9 @@ export class MoonbeamStakingProcessorService {
}

logger.info({
event: `Round ${round.id.toString(10)} staking processing finished in ${(Date.now() - startProcessingTime) / 1000
} seconds.`,
event: `Round ${round.id.toString(10)} staking processing finished in ${
(Date.now() - startProcessingTime) / 1000
} seconds.`,
})

await this.sliMetrics.add({
Expand Down Expand Up @@ -279,8 +280,9 @@ export class MoonbeamStakingProcessorService {
}

logger.info({
event: `Round ${round.id.toString(10)} staking processing finished in ${(Date.now() - startProcessingTime) / 1000
} seconds.`,
event: `Round ${round.id.toString(10)} staking processing finished in ${
(Date.now() - startProcessingTime) / 1000
} seconds.`,
})

await this.sliMetrics.add({
Expand Down

0 comments on commit c7392d9

Please sign in to comment.