Skip to content

Commit

Permalink
feat(mu): modify push endpoint to go by blockheight after config #1093
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Dec 20, 2024
1 parent 7a11e5e commit 1d14e9b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions servers/mu/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const domainConfigSchema = z.object({
TASK_QUEUE_MAX_RETRIES: positiveIntSchema,
TASK_QUEUE_RETRY_DELAY: positiveIntSchema,
DISABLE_TRACE: z.boolean(),
SPAWN_PUSH_ENABLED: z.boolean()
SPAWN_PUSH_ENABLED: z.boolean(),
ALLOW_PUSHES_AFTER: z.number()
})

/**
Expand Down Expand Up @@ -102,7 +103,8 @@ const CONFIG_ENVS = {
TASK_QUEUE_MAX_RETRIES: process.env.TASK_QUEUE_MAX_RETRIES || 5,
TASK_QUEUE_RETRY_DELAY: process.env.TASK_QUEUE_RETRY_DELAY || 1000,
DISABLE_TRACE: process.env.DISABLE_TRACE !== 'false',
SPAWN_PUSH_ENABLED: process.env.SPAWN_PUSH_ENABLED === 'true'
SPAWN_PUSH_ENABLED: process.env.SPAWN_PUSH_ENABLED === 'true',
ALLOW_PUSHES_AFTER: process.env.ALLOW_PUSHES_AFTER || 1572103
},
production: {
MODE,
Expand All @@ -124,7 +126,8 @@ const CONFIG_ENVS = {
TASK_QUEUE_MAX_RETRIES: process.env.TASK_QUEUE_MAX_RETRIES || 5,
TASK_QUEUE_RETRY_DELAY: process.env.TASK_QUEUE_RETRY_DELAY || 1000,
DISABLE_TRACE: process.env.DISABLE_TRACE !== 'false',
SPAWN_PUSH_ENABLED: process.env.SPAWN_PUSH_ENABLED === 'true'
SPAWN_PUSH_ENABLED: process.env.SPAWN_PUSH_ENABLED === 'true',
ALLOW_PUSHES_AFTER: process.env.ALLOW_PUSHES_AFTER || 1572103
}
}

Expand Down
7 changes: 3 additions & 4 deletions servers/mu/src/domain/api/pushMsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Rejected, Resolved, fromPromise, of } from 'hyper-async'

import { getCuAddressWith } from '../lib/get-cu-address.js'
import { pullResultWith } from '../lib/pull-result.js'
import { graphqlReturnSchema } from '../dal.js'

export function pushMsgWith ({
selectNode,
fetchResult,
fetchTransactions,
crank,
logger,
ALLOW_PUSHES_AFTER
}) {
const getCuAddress = getCuAddressWith({ selectNode, logger })
const pullResult = pullResultWith({ fetchResult, logger })
Expand All @@ -22,9 +22,8 @@ export function pushMsgWith ({
})
.chain(res => {
if(res?.data?.transactions?.edges?.length >= 1) {
if(res.data.transactions.edges[0].block?.timestamp) {
const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000;
if (res.data.transactions.edges[0].block.timestamp >= oneDayAgo) {
if(res.data.transactions.edges[0].block?.height) {
if (res.data.transactions.edges[0].block.height >= ALLOW_PUSHES_AFTER) {
return Resolved(ctx)
}
}
Expand Down
3 changes: 2 additions & 1 deletion servers/mu/src/domain/api/pushMsg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('pushMsgWith', () => {
transactions: {
edges: [
{
block: { timestamp: Date.now() }
block: { height: 1572105 }
}
]
}
Expand All @@ -42,6 +42,7 @@ describe('pushMsgWith', () => {
return Resolved()
},
logger,
ALLOW_PUSHES_AFTER: 1572103
})

const { crank } = await pushMsg({
Expand Down
4 changes: 3 additions & 1 deletion servers/mu/src/domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const createApis = async (ctx) => {
const PROC_FILE_PATH = ctx.PROC_FILE_PATH
const CRON_CURSOR_DIR = ctx.CRON_CURSOR_DIR
const SPAWN_PUSH_ENABLED = ctx.SPAWN_PUSH_ENABLED
const ALLOW_PUSHES_AFTER = ctx.ALLOW_PUSHES_AFTER

const logger = ctx.logger
const fetch = ctx.fetch
Expand Down Expand Up @@ -300,7 +301,8 @@ export const createApis = async (ctx) => {
fetchResult: cuClient.resultWith({ fetch: fetchWithCache, histogram, CU_URL, logger: sendDataItemLogger }),
crank,
logger: pushMsgItemLogger,
fetchTransactions: gatewayClient.fetchTransactionDetailsWith({ fetch, GRAPHQL_URL })
fetchTransactions: gatewayClient.fetchTransactionDetailsWith({ fetch, GRAPHQL_URL }),
ALLOW_PUSHES_AFTER
})

return {
Expand Down

0 comments on commit 1d14e9b

Please sign in to comment.