Skip to content

Commit

Permalink
Merge pull request #976 from Chia-Network/release/1.7.4
Browse files Browse the repository at this point in the history
release 1.7.4 - fix: invalid generation handling
  • Loading branch information
MichaelTaylor3D authored Dec 7, 2023
2 parents c49bb88 + 59be263 commit 2511591
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt",
"version": "1.7.3",
"version": "1.7.4",
"_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2",
"private": true,
"bin": "build/server.js",
Expand Down
78 changes: 42 additions & 36 deletions src/tasks/sync-audit-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ async function createTransaction(callback, afterCommitCallbacks) {
}
}

const tryParseJSON = (jsonString, defaultValue) => {
try {
return JSON.parse(jsonString);
} catch (error) {
return defaultValue;
}
};

const syncOrganizationAudit = async (organization) => {
try {
let afterCommitCallbacks = [];
Expand Down Expand Up @@ -295,9 +303,7 @@ const syncOrganizationAudit = async (organization) => {
logger.info(' ');
logger.info(`Syncing Registry: ${_.get(organization, 'name')}`);
logger.info(
`${organization.name} is ${
syncRemaining + 1
} DataLayer generations away from being fully synced.`,
`${organization.name} is ${syncRemaining} DataLayer generations away from being fully synced.`,
);

if (!CONFIG.USE_SIMULATOR) {
Expand Down Expand Up @@ -357,31 +363,31 @@ const syncOrganizationAudit = async (organization) => {
const key = decodeHex(diff.key);
const modelKey = key.split('|')[0];

if (!['comment', 'author'].includes(key)) {
const auditData = {
orgUid: organization.orgUid,
registryId: organization.registryId,
rootHash: root2.root_hash,
type: diff.type,
table: modelKey,
change: decodeHex(diff.value),
onchainConfirmationTimeStamp: root2.timestamp,
comment: _.get(
JSON.parse(
decodeHex(_.get(comment, '[0].value', encodeHex('{}'))),
),
'comment',
'',
const auditData = {
orgUid: organization.orgUid,
registryId: organization.registryId,
rootHash: root2.root_hash,
type: diff.type,
table: modelKey,
change: decodeHex(diff.value),
onchainConfirmationTimeStamp: root2.timestamp,
comment: _.get(
tryParseJSON(
decodeHex(_.get(comment, '[0].value', encodeHex('{}'))),
),
author: _.get(
JSON.parse(
decodeHex(_.get(author, '[0].value', encodeHex('{}'))),
),
'author',
'',
'comment',
'',
),
author: _.get(
tryParseJSON(
decodeHex(_.get(author, '[0].value', encodeHex('{}'))),
),
};
'author',
'',
),
};

if (Object.keys(ModelKeys).includes(modelKey)) {
if (modelKey) {
const record = JSON.parse(decodeHex(diff.value));
const primaryKeyValue =
Expand Down Expand Up @@ -425,18 +431,18 @@ const syncOrganizationAudit = async (organization) => {
}
}
}

// Create the Audit record
await Audit.create(auditData, { transaction, mirrorTransaction });
await Organization.update(
{ registryHash: root2.root_hash },
{
where: { orgUid: organization.orgUid },
transaction,
mirrorTransaction,
},
);
}

// Create the Audit record
await Audit.create(auditData, { transaction, mirrorTransaction });
await Organization.update(
{ registryHash: root2.root_hash },
{
where: { orgUid: organization.orgUid },
transaction,
mirrorTransaction,
},
);
}
};

Expand Down

0 comments on commit 2511591

Please sign in to comment.