Skip to content

Commit

Permalink
indexer-cli, -common: allow latestBlock and chainHeadBlock to be null…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
hopey1118@gmail.com committed Aug 3, 2022
1 parent 0bdbcc4 commit d579000
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/indexer-cli/src/commands/indexer/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ module.exports = {
: '-',
node: deployment.node,
network: chain.network,
latestBlockNumber: chain.latestBlock.number,
chainHeadBlockNumber: chain.chainHeadBlock.number,
latestBlockNumber: chain.latestBlock?.number,
chainHeadBlockNumber: chain.chainHeadBlock?.number,
earliestBlockNumber: chain.earliestBlock?.number,
})),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const defaults: IndexerManagementDefaults = {
},
}

const subgraphDeployment1 = 'QmbFK3kfmeNXyQ2zzvysAkduAFb68S7a6heaFxnJizSAqD'
const subgraphDeployment1 = 'QmZsXh48bDVNVvrkweZRoGJrXbvbXzTE5M8ztZYc46dPRx'
const subgraphDeployment2 = 'Qmav8jkmAeKBLyxmngJVwprN3ZsJA9A57jeoikdCU2Dyrv'
const subgraphDeployment3 = 'Qmdpkd8yvD4XR3mQMZQmY5nqBQtjEac8gb8RoFFcWan7xE'
const notPublishedSubgraphDeployment = 'QmeqJ6hsdyk9dVbo1tvRgAxWrVS3rkERiEMsxzPShKLco6'
Expand Down Expand Up @@ -245,7 +245,7 @@ const setup = async () => {
})
networkSubgraph = await NetworkSubgraph.create({
logger,
endpoint: 'https://gateway.testnet.thegraph.com/network',
endpoint: 'https://gateway.thegraph.com/network',
deployment: undefined,
})
transactionManager = new TransactionManager(
Expand Down Expand Up @@ -500,7 +500,7 @@ describe('Actions', () => {
new CombinedError({
graphQLErrors: [
new GraphQLError(
'Failed to queue action: Invalid action input, actionInput: {"status":"queued","type":"reallocate","deploymentID":"QmbFK3kfmeNXyQ2zzvysAkduAFb68S7a6heaFxnJizSAqD","allocationID":"0x8f63930129e585c69482b56390a09b6b176f4a4c","force":false,"source":"indexerAgent","reason":"indexingRule","priority":0}',
'Failed to queue action: Invalid action input, actionInput: {"status":"queued","type":"reallocate","deploymentID":"QmZsXh48bDVNVvrkweZRoGJrXbvbXzTE5M8ztZYc46dPRx","allocationID":"0x8f63930129e585c69482b56390a09b6b176f4a4c","force":false,"source":"indexerAgent","reason":"indexingRule","priority":0}',
),
],
}),
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('Actions', () => {
new CombinedError({
graphQLErrors: [
new GraphQLError(
`Duplicate action found in queue that effects 'QmbFK3kfmeNXyQ2zzvysAkduAFb68S7a6heaFxnJizSAqD' but NOT overwritten because it has a different source and/or status. If you ` +
`Duplicate action found in queue that effects 'QmZsXh48bDVNVvrkweZRoGJrXbvbXzTE5M8ztZYc46dPRx' but NOT overwritten because it has a different source and/or status. If you ` +
`would like to replace the item currently in the queue please cancel it and then queue the proposed action`,
),
],
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-common/src/indexer-management/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ const SCHEMA_SDL = gql`
type ChainIndexingStatus {
network: String!
latestBlock: BlockPointer!
chainHeadBlock: BlockPointer!
latestBlock: BlockPointer
chainHeadBlock: BlockPointer
earliestBlock: BlockPointer
}
Expand Down
15 changes: 8 additions & 7 deletions packages/indexer-common/src/indexing-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ export const parseGraphQLChain = (chain: any): ChainIndexingStatus => ({
network: chain.network,
latestBlock: parseGraphQLBlockPointer(chain.latestBlock),
chainHeadBlock: parseGraphQLBlockPointer(chain.chainHeadBlock),
earliestBlock: chain.earliestBlock
? parseGraphQLBlockPointer(chain.earliestBlock)
: null,
earliestBlock: parseGraphQLBlockPointer(chain.earliestBlock),
})

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const parseGraphQLBlockPointer = (block: any): BlockPointer => ({
number: +block.number,
hash: block.hash,
})
export const parseGraphQLBlockPointer = (block: any): BlockPointer | null =>
block
? {
number: +block.number,
hash: block.hash,
}
: null

export class IndexingStatusResolver {
logger: Logger
Expand Down
10 changes: 5 additions & 5 deletions packages/indexer-common/src/network-subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface NetworkSubgraphCreateOptions {
interface DeploymentStatus {
health: string
synced: boolean
latestBlock?: BlockPointer
chainHeadBlock?: BlockPointer
latestBlock?: BlockPointer | null
chainHeadBlock?: BlockPointer | null
fatalError?: IndexingError
}

Expand Down Expand Up @@ -222,13 +222,13 @@ const monitorDeployment = async ({
const status = {
health: indexingStatus.health,
synced: indexingStatus.synced,
latestBlock: indexingStatus.chains[0].latestBlock,
chainHeadBlock: indexingStatus.chains[0].chainHeadBlock,
latestBlock: indexingStatus.chains[0]?.latestBlock,
chainHeadBlock: indexingStatus.chains[0]?.chainHeadBlock,
fatalError: indexingStatus.fatalError,
}

// If failed for the first time, log an error
if (!lastStatus.fatalError && status.fatalError) {
if (!lastStatus || (!lastStatus.fatalError && status.fatalError)) {
logger.error(`Failed to index network subgraph deployment`, {
err: status.fatalError,
latestBlock: status.latestBlock,
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface BlockPointer {

export interface EthereumIndexingStatus {
network: string
latestBlock: BlockPointer
chainHeadBlock: BlockPointer
latestBlock: BlockPointer | null
chainHeadBlock: BlockPointer | null
earliestBlock: BlockPointer | null
}

Expand Down

0 comments on commit d579000

Please sign in to comment.