Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): fix data verification test #285

Merged
merged 2 commits into from
Jan 24, 2025
Merged
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
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ export const BACKGROUND_DATA_VERIFICATION_INTERVAL_SECONDS = +env.varOrDefault(
'600', // 10 minutes
);

export const BACKGROUND_DATA_VERIFICATION_WORKER_COUNT = +env.varOrDefault(
'BACKGROUND_DATA_VERIFICATION_WORKER_COUNT',
'1',
);

export const BACKGROUND_DATA_VERIFICATION_STREAM_TIMEOUT_MS = +env.varOrDefault(
'BACKGROUND_DATA_VERIFICATION_STREAM_TIMEOUT_MS',
'1000 * 30', // 30 seconds
);

//
// GraphQL
//
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class DataRootComputer {
});
}

async computeDataRoot(id: string): Promise<Uint8Array | undefined> {
async computeDataRoot(id: string): Promise<string | undefined> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hlolli - the result of this is the toB64Url of the data root, lmk if i'm mistaken on this change. it was causing type warnings in the verifyDataRoot when trying to compare a string to Uint8Array

Copy link
Contributor

Choose a reason for hiding this comment

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

that is correct, initially it was that, but after my changes it's a string

const tempPath = 'data/tmp/data-root';
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
Expand Down
14 changes: 9 additions & 5 deletions src/workers/data-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import { ContiguousDataIndex, ContiguousDataSource } from '../types.js';
import { DataRootComputer } from '../lib/data-root.js';
import * as config from '../config.js';

const DEFAULT_STREAM_TIMEOUT = 1000 * 30; // 30 seconds
const DEFAULT_WORKER_COUNT = 1;

export class DataVerificationWorker {
// Dependencies
private log: winston.Logger;
Expand All @@ -41,8 +38,8 @@ export class DataVerificationWorker {
log,
contiguousDataIndex,
contiguousDataSource,
workerCount = DEFAULT_WORKER_COUNT,
streamTimeout = DEFAULT_STREAM_TIMEOUT,
workerCount = config.BACKGROUND_DATA_VERIFICATION_WORKER_COUNT,
streamTimeout = config.BACKGROUND_DATA_VERIFICATION_STREAM_TIMEOUT_MS,
interval = config.BACKGROUND_DATA_VERIFICATION_INTERVAL_SECONDS * 1000,
}: {
log: winston.Logger;
Expand Down Expand Up @@ -117,6 +114,13 @@ export class DataVerificationWorker {
return false;
}

if (dataAttributes.dataRoot === undefined) {
log.warn(
'Data root not found for id. Transaction must be indexed before it can be verified.',
);
return false;
}

const indexedDataRoot = dataAttributes.dataRoot;
const computedDataRoot = await this.dataRootComputer.computeDataRoot(id);

Expand Down
1 change: 0 additions & 1 deletion test/end-to-end/data-sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('DataSources', () => {

localStack = await new LocalstackContainer('localstack/localstack:3')
.withNetwork(network as any)
.withName('localstack')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was causing warnings/errors when attempting to spin up local stack. this will give it a dynamic name for each execution avoiding conflicts

Error: (HTTP code 409) unexpected - Conflict. The container name "/localstack" is already in use by container "420421cdc2b4abb71994d9034928ab0fd352c77cc1e0cc8fe05eff9112297135". You have to remove (or rename) that container to be able to reuse that name. 

.start();

// Create a bucket
Expand Down
24 changes: 20 additions & 4 deletions test/end-to-end/indexing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,10 @@ describe('Indexing', function () {
});
});

describe('Background data verification', function () {
describe('Background data verification', { timeout: 120_000 }, function () {
let dataDb: Database;
let compose: StartedDockerComposeEnvironment;
const bundleId = '-H3KW7RKTXMg5Miq2jHx36OHSVsXBSYuE2kxgsFj6OQ';

const waitForIndexing = async () => {
const getAll = () =>
Expand All @@ -862,7 +863,10 @@ describe('Indexing', function () {
dataDb.prepare('SELECT verified FROM contiguous_data_ids').all();

while (getAll().some((row) => row.verified === 0)) {
console.log('Waiting for data items to be verified...');
console.log('Waiting for data items to be verified...', {
verified: getAll().filter((row) => row.verified === 1).length,
total: getAll().length,
});

await wait(5000);
}
Expand All @@ -871,15 +875,27 @@ describe('Indexing', function () {
before(async function () {
compose = await composeUp({
ENABLE_BACKGROUND_DATA_VERIFICATION: 'true',
BACKGROUND_DATA_VERIFICATION_INTERVAL_SECONDS: '10',
BACKGROUND_DATA_VERIFICATION_INTERVAL_SECONDS: '1',
BACKGROUND_RETRIEVAL_ORDER: 'trusted-gateways',
});
dataDb = new Sqlite(`${projectRootPath}/data/sqlite/data.db`);

// queue the bundle tx to populate the data root
await axios({
method: 'post',
url: 'http://localhost:4000/ar-io/admin/queue-tx',
headers: {
Authorization: 'Bearer secret',
'Content-Type': 'application/json',
},
data: { id: bundleId },
});

// queue the bundle to index the data items, there should be 79 data items in this bundle, once the root tx is indexed and verified all associated data items should be marked as verified
await axios.post(
'http://localhost:4000/ar-io/admin/queue-bundle',
{
id: '-H3KW7RKTXMg5Miq2jHx36OHSVsXBSYuE2kxgsFj6OQ',
id: bundleId,
},
{
headers: {
Expand Down
Loading