Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ jobs:
if: steps.changes.outputs.testChanges == 'true'
working-directory: scenarios/test_codegen
run: |
pnpm ts:test
pnpm test

- name: erc20_multichain_factory build
Expand All @@ -175,5 +174,4 @@ jobs:
if: steps.changes.outputs.testChanges == 'true'
working-directory: scenarios/fuel_test
run: |
pnpm ts:test
pnpm test
2 changes: 2 additions & 0 deletions codegenerator/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ update-schemas:
cargo run -- script print-config-json-schema evm > ./npm/envio/evm.schema.json
@echo "Updating schemas json schemas for fuel human config..."
cargo run -- script print-config-json-schema fuel > ./npm/envio/fuel.schema.json
@echo "Updating schemas json schemas for solana human config..."
cargo run -- script print-config-json-schema solana > ./npm/envio/solana.schema.json

# Target to update help
update-help:
Expand Down
26 changes: 14 additions & 12 deletions codegenerator/cli/npm/envio/evm.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"description": "Configuration of the blockchain chains that the project is deployed on.",
"type": "array",
"items": {
"$ref": "#/$defs/Network"
"$ref": "#/$defs/Chain"
}
},
"multichain": {
Expand Down Expand Up @@ -301,17 +301,17 @@
"mixHash"
]
},
"Network": {
"Chain": {
"type": "object",
"properties": {
"id": {
"description": "The public blockchain network ID.",
"description": "The public blockchain chain ID.",
"type": "integer",
"format": "uint64",
"minimum": 0
},
"rpc_config": {
"description": "RPC configuration for utilizing as the network's data-source. Typically optional for chains with HyperSync support, which is highly recommended. HyperSync dramatically enhances performance, providing up to a 1000x speed boost over traditional RPC.",
"description": "RPC configuration for utilizing as the chain's data-source. Typically optional for chains with HyperSync support, which is highly recommended. HyperSync dramatically enhances performance, providing up to a 1000x speed boost over traditional RPC.",
"anyOf": [
{
"$ref": "#/$defs/RpcConfig"
Expand All @@ -322,7 +322,7 @@
]
},
"rpc": {
"description": "RPC configuration for your indexer. If not specified otherwise, for networks supported by HyperSync, RPC serves as a fallback for added reliability. For others, it acts as the primary data-source. HyperSync offers significant performance improvements, up to a 1000x faster than traditional RPC.",
"description": "RPC configuration for your indexer. If not specified otherwise, for chains supported by HyperSync, RPC serves as a fallback for added reliability. For others, it acts as the primary data-source. HyperSync offers significant performance improvements, up to a 1000x faster than traditional RPC.",
"anyOf": [
{
"$ref": "#/$defs/NetworkRpc"
Expand Down Expand Up @@ -367,18 +367,20 @@
"minimum": 0
},
"contracts": {
"description": "All the contracts that should be indexed on the given network",
"type": "array",
"description": "All the contracts that should be indexed on the given chain",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/NetworkContract_for_ContractConfig"
"$ref": "#/$defs/ChainContract_for_ContractConfig"
}
}
},
"additionalProperties": false,
"required": [
"id",
"start_block",
"contracts"
"start_block"
]
},
"RpcConfig": {
Expand Down Expand Up @@ -594,7 +596,7 @@
"url"
]
},
"NetworkContract_for_ContractConfig": {
"ChainContract_for_ContractConfig": {
"type": "object",
"properties": {
"name": {
Expand All @@ -606,7 +608,7 @@
"$ref": "#/$defs/Addresses"
},
"start_block": {
"description": "The block at which the indexer should start ingesting data for this specific contract. If not specified, uses the network start_block. Can be greater than the network start_block for more specific indexing.",
"description": "The block at which the indexer should start ingesting data for this specific contract. If not specified, uses the chain start_block. Can be greater than the chain start_block for more specific indexing.",
"type": [
"integer",
"null"
Expand Down
22 changes: 12 additions & 10 deletions codegenerator/cli/npm/envio/fuel.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"description": "Configuration of the blockchain chains that the project is deployed on.",
"type": "array",
"items": {
"$ref": "#/$defs/Network"
"$ref": "#/$defs/Chain"
}
},
"raw_events": {
Expand Down Expand Up @@ -152,11 +152,11 @@
"call"
]
},
"Network": {
"Chain": {
"type": "object",
"properties": {
"id": {
"description": "Public chain/network id",
"description": "Public chain id",
"type": "integer",
"format": "uint64",
"minimum": 0
Expand Down Expand Up @@ -188,18 +188,20 @@
]
},
"contracts": {
"description": "All the contracts that should be indexed on the given network",
"type": "array",
"description": "All the contracts that should be indexed on the given chain",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/NetworkContract_for_ContractConfig"
"$ref": "#/$defs/ChainContract_for_ContractConfig"
}
}
},
"additionalProperties": false,
"required": [
"id",
"start_block",
"contracts"
"start_block"
]
},
"HyperfuelConfig": {
Expand All @@ -215,7 +217,7 @@
"url"
]
},
"NetworkContract_for_ContractConfig": {
"ChainContract_for_ContractConfig": {
"type": "object",
"properties": {
"name": {
Expand All @@ -227,7 +229,7 @@
"$ref": "#/$defs/Addresses"
},
"start_block": {
"description": "The block at which the indexer should start ingesting data for this specific contract. If not specified, uses the network start_block. Can be greater than the network start_block for more specific indexing.",
"description": "The block at which the indexer should start ingesting data for this specific contract. If not specified, uses the chain start_block. Can be greater than the chain start_block for more specific indexing.",
"type": [
"integer",
"null"
Expand Down
3 changes: 2 additions & 1 deletion codegenerator/cli/npm/envio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"rescript-schema": "9.3.4",
"viem": "2.21.0",
"rescript-envsafe": "5.0.0",
"dotenv": "16.4.5"
"dotenv": "16.4.5",
"date-fns": "3.3.1"
},
"files": [
"local-bin.mjs",
Expand Down
3 changes: 2 additions & 1 deletion codegenerator/cli/npm/envio/package.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"rescript-schema": "9.3.4",
"viem": "2.21.0",
"rescript-envsafe": "5.0.0",
"dotenv": "16.4.5"
"dotenv": "16.4.5",
"date-fns": "3.3.1"
},
"files": [
"bin.js",
Expand Down
8 changes: 8 additions & 0 deletions codegenerator/cli/npm/envio/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions codegenerator/cli/npm/envio/solana.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Envio Solana Config Schema",
"description": "Schema for a YAML config for an envio Solana indexer",
"type": "object",
"properties": {
"description": {
"description": "Description of the project",
"type": [
"string",
"null"
]
},
"name": {
"description": "Name of the project",
"type": "string"
},
"schema": {
"description": "Custom path to schema.graphql file",
"type": [
"string",
"null"
]
},
"output": {
"description": "Path where the generated directory will be placed. By default it's 'generated' relative to the current working directory. If set, it'll be a path relative to the config file location.",
"type": [
"string",
"null"
]
},
"handlers": {
"description": "Optional relative path to handlers directory for auto-loading. Defaults to 'src/handlers' if not specified.",
"type": [
"string",
"null"
]
},
"ecosystem": {
"description": "Ecosystem of the project.",
"$ref": "#/$defs/EcosystemTag"
}
},
"additionalProperties": false,
"required": [
"name",
"ecosystem"
],
"$defs": {
"EcosystemTag": {
"type": "string",
"enum": [
"solana"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ type t = {
fetchState: FetchState.t,
sourceManager: SourceManager.t,
chainConfig: Config.chain,
//The latest known block of the chain
currentBlockHeight: int,
isProgressAtHead: bool,
timestampCaughtUpToHeadOrEndblock: option<Js.Date.t>,
committedProgressBlockNumber: int,
Expand Down Expand Up @@ -157,6 +155,7 @@ let make = (
~endBlock,
~eventConfigs,
~targetBufferSize,
~knownHeight=0, // FIXME: Get it from db or fetch before creating FetchState
~chainId=chainConfig.id,
// FIXME: Shouldn't set with full history
~blockLag=Pervasives.max(
Expand Down Expand Up @@ -191,7 +190,6 @@ let make = (
~shouldRollbackOnReorg=config.shouldRollbackOnReorg,
~chainReorgCheckpoints,
),
currentBlockHeight: 0,
isProgressAtHead: false,
fetchState,
firstEventBlockNumber,
Expand Down Expand Up @@ -296,18 +294,14 @@ let runContractRegistersOrThrow = async (
let {blockNumber} = eventItem

// Use contract-specific start block if configured, otherwise fall back to registration block
let contractStartBlock = switch getContractStartBlock(
config,
~chain,
~contractName=(contractName: Enums.ContractType.t :> string),
) {
let contractStartBlock = switch getContractStartBlock(config, ~chain, ~contractName) {
| Some(configuredStartBlock) => configuredStartBlock
| None => blockNumber
}

let dc: Internal.indexingContract = {
address: contractAddress,
contractName: (contractName: Enums.ContractType.t :> string),
contractName,
startBlock: contractStartBlock,
registrationBlock: Some(blockNumber),
}
Expand Down Expand Up @@ -380,6 +374,7 @@ let handleQueryResult = (
~newItems,
~newItemsWithDcs,
~latestFetchedBlock,
~knownHeight,
) => {
let fs = switch newItemsWithDcs {
| [] => chainFetcher.fetchState
Expand All @@ -390,7 +385,7 @@ let handleQueryResult = (
->FetchState.handleQueryResult(~query, ~latestFetchedBlock, ~newItems)
->Result.map(fs => {
...chainFetcher,
fetchState: fs,
fetchState: fs->FetchState.updateKnownHeight(~knownHeight),
})
}

Expand All @@ -410,7 +405,7 @@ let hasNoMoreEventsToProcess = (self: t) => {
}

let getHighestBlockBelowThreshold = (cf: t): int => {
let highestBlockBelowThreshold = cf.currentBlockHeight - cf.chainConfig.maxReorgDepth
let highestBlockBelowThreshold = cf.fetchState.knownHeight - cf.chainConfig.maxReorgDepth
highestBlockBelowThreshold < 0 ? 0 : highestBlockBelowThreshold
}

Expand All @@ -431,7 +426,7 @@ let getLastKnownValidBlock = async (
let scannedBlockNumbers =
chainFetcher.reorgDetection->ReorgDetection.getThresholdBlockNumbersBelowBlock(
~blockNumber=reorgBlockNumber,
~currentBlockHeight=chainFetcher.currentBlockHeight,
~knownHeight=chainFetcher.fetchState.knownHeight,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is knownHeight essentially current height?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that known height is better since we have multiple sources and also source might have a different height than the one we know in hyperindex. This is why I decided to use the name. It's also internal only

)

let getBlockHashes = blockNumbers => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let createBatch = (chainManager: t, ~batchSizeTarget: int, ~isRollback: bool): B
fetchState: cf.fetchState,
progressBlockNumber: cf.committedProgressBlockNumber,
totalEventsProcessed: cf.numEventsProcessed,
sourceBlockNumber: cf.currentBlockHeight,
sourceBlockNumber: cf.fetchState.knownHeight,
reorgDetection: cf.reorgDetection,
}),
~multichain=chainManager.multichain,
Expand Down Expand Up @@ -162,7 +162,7 @@ let getSafeCheckpointId = (chainManager: t) => {
| Some(safeCheckpointTracking) => {
let safeCheckpointId =
safeCheckpointTracking->SafeCheckpointTracking.getSafeCheckpointId(
~sourceBlockNumber=chainFetcher.currentBlockHeight,
~sourceBlockNumber=chainFetcher.fetchState.knownHeight,
)
if safeCheckpointId < result.contents {
result := safeCheckpointId
Expand Down
Loading