Skip to content

Commit 736678f

Browse files
committed
fix(V2): remove sync generation wait
Avoid fixed DataLayer waits during registry catch-up and retry later when local roots or diffs are not ready yet.
1 parent b5e3154 commit 736678f

3 files changed

Lines changed: 225 additions & 145 deletions

File tree

src/datalayer/persistance.js

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const getHomeOrg = async () => {
5151
}
5252

5353
// Neither V1 nor V2 is enabled or orgs don't exist
54-
logger.debug('[persistance]: No home org found - V1 and V2 both disabled or no orgs exist');
54+
logger.debug(
55+
'[persistance]: No home org found - V1 and V2 both disabled or no orgs exist',
56+
);
5557
return null;
5658
};
5759

@@ -107,7 +109,9 @@ const getMirrors = async (storeId) => {
107109

108110
// In simulator mode, return empty array (no mirrors in simulator)
109111
if (CONFIG.USE_SIMULATOR || CONFIG.USE_DEVELOPMENT_MODE) {
110-
logger.debug(`[MIRROR_DEBUG] Simulator mode - returning empty mirrors array`);
112+
logger.debug(
113+
`[MIRROR_DEBUG] Simulator mode - returning empty mirrors array`,
114+
);
111115
return [];
112116
}
113117

@@ -210,8 +214,8 @@ const checkWalletBalanceForMirror = async (coinAmount, fee) => {
210214
if (isSplitInProgress()) {
211215
logger.warn(
212216
`Wallet balance temporarily reduced by coin split in progress ` +
213-
`(have ${balanceMojos} mojos, need ${coinAmount} mojos). ` +
214-
`Skipping mirror creation - will retry after split confirms.`,
217+
`(have ${balanceMojos} mojos, need ${coinAmount} mojos). ` +
218+
`Skipping mirror creation - will retry after split confirms.`,
215219
);
216220
} else {
217221
logger.error(
@@ -318,7 +322,9 @@ const addMirrorInner = async (storeId, url, forceAddMirror) => {
318322

319323
// In simulator mode, return success without making RPC call
320324
if (CONFIG.USE_SIMULATOR || CONFIG.USE_DEVELOPMENT_MODE) {
321-
logger.debug(`[MIRROR_DEBUG] Simulator mode - returning success for addMirror`);
325+
logger.debug(
326+
`[MIRROR_DEBUG] Simulator mode - returning success for addMirror`,
327+
);
322328
return true;
323329
}
324330

@@ -448,10 +454,15 @@ const getRootDiff = async (storeId, root1, root2) => {
448454
return _.get(data, 'diff', []);
449455
}
450456

451-
return [];
457+
throw new Error(
458+
data.error ||
459+
`DataLayer get_kv_diff failed for store ${storeId} between roots ${root1} and ${root2}`,
460+
);
452461
} catch (error) {
453-
logger.error(error);
454-
return [];
462+
logger.error(
463+
`DataLayer get_kv_diff failed for store ${storeId} between roots ${root1} and ${root2}: ${error.message}`,
464+
);
465+
throw error;
455466
}
456467
};
457468

@@ -692,7 +703,11 @@ const getRoots = async (storeIds) => {
692703
}
693704
};
694705

695-
const pushChangeListToDataLayer = async (storeId, changelist, { skipTransactionWait = false } = {}) => {
706+
const pushChangeListToDataLayer = async (
707+
storeId,
708+
changelist,
709+
{ skipTransactionWait = false } = {},
710+
) => {
696711
let attempts = 0;
697712
const maxAttempts = 5;
698713

@@ -706,30 +721,33 @@ const pushChangeListToDataLayer = async (storeId, changelist, { skipTransactionW
706721
}
707722

708723
// Log the changelist being sent (with decoded keys/values for readability)
709-
logger.debug(`[DATALAYER_RPC] Sending changelist to storeId: ${storeId}`, {
710-
storeId,
711-
changelistSize: changelist.length,
712-
changelist: changelist.map((change) => {
713-
const decoded = {
714-
action: change.action,
715-
key: change.key ? decodeHex(change.key) : change.key,
716-
};
717-
if (change.value) {
718-
try {
719-
decoded.value = decodeHex(change.value);
720-
// Try to parse as JSON for better readability
724+
logger.debug(
725+
`[DATALAYER_RPC] Sending changelist to storeId: ${storeId}`,
726+
{
727+
storeId,
728+
changelistSize: changelist.length,
729+
changelist: changelist.map((change) => {
730+
const decoded = {
731+
action: change.action,
732+
key: change.key ? decodeHex(change.key) : change.key,
733+
};
734+
if (change.value) {
721735
try {
722-
decoded.valueParsed = JSON.parse(decoded.value);
723-
} catch {
724-
// Not JSON, that's fine
736+
decoded.value = decodeHex(change.value);
737+
// Try to parse as JSON for better readability
738+
try {
739+
decoded.valueParsed = JSON.parse(decoded.value);
740+
} catch {
741+
// Not JSON, that's fine
742+
}
743+
} catch (e) {
744+
decoded.value = change.value; // Keep hex if decode fails
725745
}
726-
} catch (e) {
727-
decoded.value = change.value; // Keep hex if decode fails
728746
}
729-
}
730-
return decoded;
731-
}),
732-
});
747+
return decoded;
748+
}),
749+
},
750+
);
733751

734752
const url = `${CONFIG.DATALAYER_URL}/batch_update`;
735753
const { cert, key, timeout } = getBaseOptions();
@@ -766,7 +784,9 @@ const pushChangeListToDataLayer = async (storeId, changelist, { skipTransactionW
766784
// Wait for confirmation then retry the push instead of failing to writeService.
767785
if (
768786
data.error &&
769-
data.error.includes('Already have a pending root waiting for confirmation')
787+
data.error.includes(
788+
'Already have a pending root waiting for confirmation',
789+
)
770790
) {
771791
logger.info(
772792
`Pending root for store ${storeId}; waiting for confirmation then retrying (attempt ${attempts + 1}/${maxAttempts})`,
@@ -831,21 +851,26 @@ const pushChangeListToDataLayer = async (storeId, changelist, { skipTransactionW
831851
// All data in CADT must come from datalayer, so DELETE operations should always find the keys
832852
// If keys are not found, it indicates a key format mismatch that needs to be fixed
833853
if (data.error && data.error.includes('unknown key')) {
834-
const isDeleteOnlyChangelist = changelist.every(change => change.action === 'delete');
854+
const isDeleteOnlyChangelist = changelist.every(
855+
(change) => change.action === 'delete',
856+
);
835857

836858
// Log detailed information about the keys we're trying to delete
837-
const deleteKeys = changelist.map(change => ({
859+
const deleteKeys = changelist.map((change) => ({
838860
hex: change.key,
839861
decoded: decodeHex(change.key),
840862
}));
841863

842-
logger.error(`[DELETE KEY MISMATCH ERROR] Unknown key error for ${isDeleteOnlyChangelist ? 'DELETE-only' : ''} changelist`, {
843-
storeId,
844-
deleteKeysCount: deleteKeys.length,
845-
deleteKeys,
846-
error: data.error,
847-
traceback: data.traceback,
848-
});
864+
logger.error(
865+
`[DELETE KEY MISMATCH ERROR] Unknown key error for ${isDeleteOnlyChangelist ? 'DELETE-only' : ''} changelist`,
866+
{
867+
storeId,
868+
deleteKeysCount: deleteKeys.length,
869+
deleteKeys,
870+
error: data.error,
871+
traceback: data.traceback,
872+
},
873+
);
849874

850875
if (isDeleteOnlyChangelist) {
851876
logger.error(
@@ -1208,7 +1233,8 @@ const getDataLayerStoreSyncStatus = async (storeId) => {
12081233
sync_status: {
12091234
generation: 10000,
12101235
target_generation: 10000,
1211-
target_root_hash: '0000000000000000000000000000000000000000000000000000000000000000',
1236+
target_root_hash:
1237+
'0000000000000000000000000000000000000000000000000000000000000000',
12121238
},
12131239
};
12141240
}

0 commit comments

Comments
 (0)