diff --git a/packages/codegen/README.md b/packages/codegen/README.md index 5c816823..d5f8c163 100644 --- a/packages/codegen/README.md +++ b/packages/codegen/README.md @@ -163,7 +163,7 @@ Steps: * Reset job-queue: ```bash - yarn reset job-queue --block-number + yarn reset job-queue ``` * To export the watcher state: diff --git a/packages/codegen/package.json b/packages/codegen/package.json index 2a4adf33..5930de16 100644 --- a/packages/codegen/package.json +++ b/packages/codegen/package.json @@ -37,6 +37,7 @@ "yargs": "^17.1.1" }, "devDependencies": { + "@openzeppelin/contracts": "^4.3.2", "@types/js-yaml": "^4.0.3", "@types/node": "^16.9.0", "@typescript-eslint/eslint-plugin": "^4.25.0", diff --git a/packages/codegen/src/templates/readme-template.handlebars b/packages/codegen/src/templates/readme-template.handlebars index 6dea60ab..70ee21cc 100644 --- a/packages/codegen/src/templates/readme-template.handlebars +++ b/packages/codegen/src/templates/readme-template.handlebars @@ -163,7 +163,7 @@ To enable GQL requests caching: * Reset job-queue: ```bash - yarn reset job-queue --block-number + yarn reset job-queue ``` * Reset state: diff --git a/packages/codegen/subgraph-demo.md b/packages/codegen/subgraph-demo.md index 0e956bf3..b8bc0fc7 100644 --- a/packages/codegen/subgraph-demo.md +++ b/packages/codegen/subgraph-demo.md @@ -26,7 +26,7 @@ git checkout v1.10.26-statediff-4.2.2-alpha ``` -* Update to use latest images for ipld-eth-db and ipld-eth-server +* Update docker compose file to use latest images for ipld-eth-db and ipld-eth-server * In [docker/latest/docker-compose-db-sharding.yml](https://github.com/vulcanize/stack-orchestrator/blob/main/docker/latest/docker-compose-db-sharding.yml) update image version diff --git a/packages/eden-watcher/README.md b/packages/eden-watcher/README.md index 0800c0cf..6b449a3c 100644 --- a/packages/eden-watcher/README.md +++ b/packages/eden-watcher/README.md @@ -149,7 +149,7 @@ * Reset job-queue: ```bash - yarn reset job-queue --block-number + yarn reset job-queue ``` * Reset state: diff --git a/packages/erc20-watcher/package.json b/packages/erc20-watcher/package.json index 3d78364b..61b481fa 100644 --- a/packages/erc20-watcher/package.json +++ b/packages/erc20-watcher/package.json @@ -58,6 +58,7 @@ "@ethersproject/abi": "^5.3.0", "@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-waffle": "^2.0.1", + "@openzeppelin/contracts": "^4.3.2", "@types/json-bigint": "^1.0.0", "@typescript-eslint/eslint-plugin": "^4.25.0", "@typescript-eslint/parser": "^4.25.0", diff --git a/packages/erc721-watcher/README.md b/packages/erc721-watcher/README.md index e616d858..a08deb16 100644 --- a/packages/erc721-watcher/README.md +++ b/packages/erc721-watcher/README.md @@ -151,7 +151,7 @@ Follow the steps below or follow the [Demo](./demo.md) * Reset job-queue: ```bash - yarn reset job-queue --block-number + yarn reset job-queue ``` * Reset state: diff --git a/packages/erc721-watcher/demo.md b/packages/erc721-watcher/demo.md index 881ab183..6e81f92c 100644 --- a/packages/erc721-watcher/demo.md +++ b/packages/erc721-watcher/demo.md @@ -15,13 +15,31 @@ ./setup-repositories.sh -p ssh ``` -* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.19-statediff-4.0.2-alpha) in go-ethereum repo. The path for go-ethereum is specified by `vulcanize_go_ethereum` variable in `config.sh` file created in stack-orchestrator repo. +* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.26-statediff-4.2.2-alpha) in go-ethereum repo. The path for go-ethereum is specified by `vulcanize_go_ethereum` variable in `config.sh` file created in stack-orchestrator repo. ```bash # In go-ethereum repo. - git checkout v1.10.19-statediff-4.0.2-alpha + git checkout v1.10.26-statediff-4.2.2-alpha ``` +* Update docker compose file to use latest images for ipld-eth-db and ipld-eth-server + + * In [docker/latest/docker-compose-db-sharding.yml](https://github.com/vulcanize/stack-orchestrator/blob/main/docker/latest/docker-compose-db-sharding.yml) update image version + + ```yml + services: + migrations: + image: git.vdb.to/cerc-io/ipld-eth-db/ipld-eth-db:v4.2.3-alpha + ``` + + * In [docker/latest/docker-compose-ipld-eth-server.yml](https://github.com/vulcanize/stack-orchestrator/blob/main/docker/latest/docker-compose-ipld-eth-server.yml) update image version + + ```yml + services: + ipld-eth-server: + image: git.vdb.to/cerc-io/ipld-eth-server/ipld-eth-server:v4.2.3-alpha + ``` + * To run the stack-orchestrator, the docker-compose version used is: ```bash diff --git a/packages/erc721-watcher/package.json b/packages/erc721-watcher/package.json index 741da00b..059c24ec 100644 --- a/packages/erc721-watcher/package.json +++ b/packages/erc721-watcher/package.json @@ -65,6 +65,7 @@ "@ethersproject/abi": "^5.3.0", "@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-waffle": "^2.0.1", + "@openzeppelin/contracts": "^4.3.2", "@types/yargs": "^17.0.0", "@typescript-eslint/eslint-plugin": "^4.25.0", "@typescript-eslint/parser": "^4.25.0", diff --git a/packages/erc721-watcher/src/database.ts b/packages/erc721-watcher/src/database.ts index 37b763fa..03af99ec 100644 --- a/packages/erc721-watcher/src/database.ts +++ b/packages/erc721-watcher/src/database.ts @@ -3,7 +3,7 @@ // import assert from 'assert'; -import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions, FindOneOptions, LessThanOrEqual, EntityTarget } from 'typeorm'; +import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions, FindOneOptions, LessThanOrEqual, EntityTarget, UpdateResult } from 'typeorm'; import path from 'path'; import { Database as BaseDatabase, DatabaseInterface, QueryOptions, StateKind, Where } from '@cerc-io/util'; @@ -504,6 +504,15 @@ export class Database implements DatabaseInterface { return this._baseDatabase.getAncestorAtDepth(blockHash, depth); } + async updateEntity (queryRunner: QueryRunner, entityType: new () => Entity, criteria: any, update: any): Promise { + const repo = queryRunner.manager.getRepository(entityType); + return repo.createQueryBuilder() + .update() + .set(update) + .where(criteria) + .execute(); + } + _getPropertyColumnMapForEntity (entityName: string): Map { return this._conn.getMetadata(entityName).ownColumns.reduce((acc, curr) => { return acc.set(curr.propertyName, curr.databaseName); diff --git a/packages/erc721-watcher/src/entity/TransferCount.ts b/packages/erc721-watcher/src/entity/TransferCount.ts index 01d07ba2..c40e0b7a 100644 --- a/packages/erc721-watcher/src/entity/TransferCount.ts +++ b/packages/erc721-watcher/src/entity/TransferCount.ts @@ -17,4 +17,7 @@ export class TransferCount { @Column('integer') count!: number; + + @Column('boolean', { default: false }) + isPruned!: boolean } diff --git a/packages/erc721-watcher/src/indexer.ts b/packages/erc721-watcher/src/indexer.ts index 19024d72..a5ec1ce3 100644 --- a/packages/erc721-watcher/src/indexer.ts +++ b/packages/erc721-watcher/src/indexer.ts @@ -4,7 +4,7 @@ import assert from 'assert'; import debug from 'debug'; -import { DeepPartial, FindConditions, FindManyOptions } from 'typeorm'; +import { DeepPartial, FindConditions, FindManyOptions, In } from 'typeorm'; import JSONbig from 'json-bigint'; import { ethers } from 'ethers'; @@ -870,7 +870,36 @@ export class Indexer implements IndexerInterface { } async markBlocksAsPruned (blocks: BlockProgress[]): Promise { - return this._baseIndexer.markBlocksAsPruned(blocks); + await this._baseIndexer.markBlocksAsPruned(blocks); + + await this._pruneEntities(blocks); + } + + // Prune custom entities. + async _pruneEntities (blocks: BlockProgress[]): Promise { + const entityTypes = [TransferCount]; + const blockHashes = blocks.map(block => block.blockHash); + + const dbTx = await this._db.createTransactionRunner(); + + try { + const updatePromises = entityTypes.map(async entityType => { + await this._db.updateEntity( + dbTx, + entityType, + { blockHash: In(blockHashes) }, + { isPruned: true } + ); + }); + + await Promise.all(updatePromises); + await dbTx.commitTransaction(); + } catch (error) { + await dbTx.rollbackTransaction(); + throw error; + } finally { + await dbTx.release(); + } } async updateBlockProgress (block: BlockProgress, lastProcessedEventIndex: number): Promise { diff --git a/packages/graph-test-watcher/README.md b/packages/graph-test-watcher/README.md index aa5a0426..fff50bfa 100644 --- a/packages/graph-test-watcher/README.md +++ b/packages/graph-test-watcher/README.md @@ -149,7 +149,7 @@ * Reset job-queue: ```bash - yarn reset job-queue --block-number + yarn reset job-queue ``` * Reset state: diff --git a/packages/mobymask-watcher/README.md b/packages/mobymask-watcher/README.md index bbc66634..66cd1143 100644 --- a/packages/mobymask-watcher/README.md +++ b/packages/mobymask-watcher/README.md @@ -141,7 +141,7 @@ Follow the steps below or follow the [Demo](./demo.md) * Reset job-queue: ```bash - yarn reset job-queue --block-number + yarn reset job-queue ``` * Reset state: diff --git a/yarn.lock b/yarn.lock index e1e010fe..bfc592cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2322,6 +2322,11 @@ dependencies: "@octokit/openapi-types" "^7.2.3" +"@openzeppelin/contracts@^4.3.2": + version "4.3.2" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.2.tgz#ff80affd6d352dbe1bbc5b4e1833c41afd6283b6" + integrity sha512-AybF1cesONZStg5kWf6ao9OlqTZuPqddvprc0ky7lrUVOjXeKpmQ2Y9FK+6ygxasb+4aic4O5pneFBfwVsRRRg== + "@poanet/solidity-flattener@https://github.com/vulcanize/solidity-flattener.git": version "3.0.6" resolved "https://github.com/vulcanize/solidity-flattener.git#144ef6cda8823f4a5e48cb4f615be87a32e2dcbc"