From c248f3c2230f6bd3ed938d18ab3b27331d825363 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 28 May 2024 10:37:24 +0200 Subject: [PATCH] feat: add tool to query aggregates pending deal --- ...convert-piece-cid-v1-to-v2-with-height.yml | 2 +- ...vert-piece-cid-v1-to-v2-with-log2-size.yml | 2 +- .github/workflows/get-aggregate-deals.yml | 2 +- .../get-aggregates-pending-deals.yml | 23 ++++++++++ .github/workflows/test.yaml | 2 +- packages/tools/README.md | 46 +++++++++++++++++++ .../tools/get-aggregates-pending-deals.js | 23 ++++++++++ packages/tools/package.json | 3 +- 8 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/get-aggregates-pending-deals.yml create mode 100644 packages/tools/README.md create mode 100644 packages/tools/get-aggregates-pending-deals.js diff --git a/.github/workflows/convert-piece-cid-v1-to-v2-with-height.yml b/.github/workflows/convert-piece-cid-v1-to-v2-with-height.yml index b0eff01..8b14c75 100644 --- a/.github/workflows/convert-piece-cid-v1-to-v2-with-height.yml +++ b/.github/workflows/convert-piece-cid-v1-to-v2-with-height.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/setup-node@v3 with: registry-url: 'https://registry.npmjs.org' - node-version: 18 + node-version: 20 cache: 'npm' - run: npm install @web3-storage/pieces - name: Run job diff --git a/.github/workflows/convert-piece-cid-v1-to-v2-with-log2-size.yml b/.github/workflows/convert-piece-cid-v1-to-v2-with-log2-size.yml index e4f1a46..2f21401 100644 --- a/.github/workflows/convert-piece-cid-v1-to-v2-with-log2-size.yml +++ b/.github/workflows/convert-piece-cid-v1-to-v2-with-log2-size.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/setup-node@v3 with: registry-url: 'https://registry.npmjs.org' - node-version: 18 + node-version: 20 cache: 'npm' - run: npm install @web3-storage/pieces - name: Run job diff --git a/.github/workflows/get-aggregate-deals.yml b/.github/workflows/get-aggregate-deals.yml index 3ce5eb8..6798ea8 100644 --- a/.github/workflows/get-aggregate-deals.yml +++ b/.github/workflows/get-aggregate-deals.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/setup-node@v3 with: registry-url: 'https://registry.npmjs.org' - node-version: 18 + node-version: 20 cache: 'npm' - run: npm ci - name: Run job diff --git a/.github/workflows/get-aggregates-pending-deals.yml b/.github/workflows/get-aggregates-pending-deals.yml new file mode 100644 index 0000000..cf22e45 --- /dev/null +++ b/.github/workflows/get-aggregates-pending-deals.yml @@ -0,0 +1,23 @@ +name: Get Aggregates pending deals + +on: + workflow_dispatch: + +jobs: + getAggregatesOffered: + name: Get Aggregates pending deals + runs-on: ubuntu-latest + strategy: + matrix: + env: ['staging', 'production'] + timeout-minutes: 20 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + registry-url: 'https://registry.npmjs.org' + node-version: 20 + cache: 'npm' + - run: npm ci + - name: Run job + run: npm run get-aggregates-pending-deals -w packages/tools \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 81bc1d7..ef921c4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/setup-node@v3 with: registry-url: 'https://registry.npmjs.org' - node-version: 18 + node-version: 20 cache: 'npm' - run: npm ci - run: npm run lint diff --git a/packages/tools/README.md b/packages/tools/README.md new file mode 100644 index 0000000..e9fda42 --- /dev/null +++ b/packages/tools/README.md @@ -0,0 +1,46 @@ +# w3filecoin Tools + +> A set of tools to facilitate diagnosing and debugging incidents. + +## Getting Started + +Run in the main folder of this repo `npm install` to guarantee all the dependencies needed are properly installed. + +To be able to run these tools, an AWS account with the AWS CLI MUST be configured locally and have access to the resources of w3filecoin. + +## Tools + +### Get aggregate deals + +Get all known deals for a given aggregate. + +```sh +$ npm run get-aggregate-deals bafkz... +> @w3filecoin/tools@0.0.0 get-aggregate-deals +> node get-aggregate-deals.js bafkz... + +known information for aggregate bafkz...: +{ + deals: { + '123': { provider: '111' }, + '124': { provider: '222' } + } +} +``` + +### Get aggregates pending deals + +```sh +$ npm run get-aggregates-pending-deals + +> @w3filecoin/tools@0.0.0 get-aggregates-pending-deals +> node get-aggregates-pending-deals.js + +Offered aggregates page size: 4 + +Aggregate offer list: +bafkzcibcaapg... at 2024-05-28T06:52:25.779Z +bafkzcibcaapn... at 2024-05-28T07:12:45.567Z +bafkzcibcaapb... at 2024-05-28T07:48:21.420Z +bafkzcibcaapi... at 2024-05-28T08:23:59.203Z +``` diff --git a/packages/tools/get-aggregates-pending-deals.js b/packages/tools/get-aggregates-pending-deals.js new file mode 100644 index 0000000..b49e670 --- /dev/null +++ b/packages/tools/get-aggregates-pending-deals.js @@ -0,0 +1,23 @@ +import { createClient as createAggregateStoreClient } from '@w3filecoin/core/src/store/dealer-aggregate-store.js' + +const AWS_REGION = 'us-west-2' + +const aggregateStore = createAggregateStoreClient({ + region: AWS_REGION +}, { + tableName: 'prod-w3filecoin-dealer-aggregate-store' +}) + +// Get offered aggregates pending approval/rejection +const offeredAggregates = await aggregateStore.query({ + status: 'offered', +}) +if (offeredAggregates.error) { + throw offeredAggregates.error +} + +console.log('Offered aggregates page size:', offeredAggregates.ok.length, '\n') +console.log('Aggregate offer list:') +for (const aggregate of offeredAggregates.ok) { + console.log(`${aggregate.aggregate.link()} at ${aggregate.insertedAt}`) +} diff --git a/packages/tools/package.json b/packages/tools/package.json index 97d1146..f7e8986 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -3,7 +3,8 @@ "version": "0.0.0", "type": "module", "scripts": { - "get-aggregate-deals": "node get-aggregate-deals.js" + "get-aggregate-deals": "node get-aggregate-deals.js", + "get-aggregates-pending-deals": "node get-aggregates-pending-deals.js" }, "dependencies": {}, "devDependencies": {