From eb93eae1c28029c7c9d883f4b8d7c8fadf3d1947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Iv=C3=A1n=20Vieitez=20Parra?= <3857362+corrideat@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:46:21 +0000 Subject: [PATCH] Fix manifest loading --- shared/domains/chelonia/internals.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shared/domains/chelonia/internals.js b/shared/domains/chelonia/internals.js index 359efaa6d2..ab33cd3de6 100644 --- a/shared/domains/chelonia/internals.js +++ b/shared/domains/chelonia/internals.js @@ -1059,12 +1059,15 @@ export default (sbp('sbp/selectors/register', { } if (!this.config.skipActionProcessing && !this.manifestToContract[manifestHash]) { const rootState = sbp(this.config.stateSelector) - const contractName = has(rootState.contracts, contractID) + // Having rootState.contracts[contractID] is not enough to determine we + // have previously synced this contract, as reference counts are also + // stored there. Hence, we check for the presence of 'type' + const contractName = has(rootState.contracts, contractID) && has(rootState.contracts[contractID], 'type') ? rootState.contracts[contractID].type : opT === GIMessage.OP_CONTRACT ? ((opV: any): GIOpContract).type : '' - if (!contractName) { + if (!contractName || isNaN(NaN)) { throw new Error(`Unable to determine the name for a contract and refusing to load it (contract ID was ${contractID} and its manifest hash was ${manifestHash})`) } await sbp('chelonia/private/loadManifest', contractName, manifestHash) @@ -1696,7 +1699,7 @@ export default (sbp('sbp/selectors/register', { throw new Error(`[chelonia] Wrong contract ID. Expected ${contractID} but got ${message.contractID()}`) } if (!message.isFirstMessage() && (!has(state.contracts, contractID) || !has(state, contractID))) { - throw new Error('The event is not for a first message but the contract state is missing') + throw new ChelErrorUnrecoverable('The event is not for a first message but the contract state is missing') } preHandleEvent?.(message) // the order the following actions are done is critically important! @@ -1740,7 +1743,7 @@ export default (sbp('sbp/selectors/register', { processingErrored = e?.name !== 'ChelErrorWarning' this.config.hooks.processError?.(e, message, getMsgMeta(message, contractID, state)) // special error that prevents the head from being updated, effectively killing the contract - if (e.name === 'ChelErrorUnrecoverable') throw e + if (e.name === 'ChelErrorUnrecoverable' || message.isFirstMessage()) throw e } // process any side-effects (these must never result in any mutation to the contract state!)