-
Notifications
You must be signed in to change notification settings - Fork 77
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
Implement caching for parameters and identity storage contracts #2834
Changes from 1 commit
a8c7806
d0870db
ade1090
3176845
829599f
4ac849d
d44ed6d
76ca352
04fbd45
962de73
4810571
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,15 +589,19 @@ export const BLOCK_TIME_MILLIS = { | |
|
||
export const TRANSACTION_CONFIRMATIONS = 1; | ||
|
||
export const CACHE_DATA_TYPES = { | ||
NUMBER: 'number', | ||
}; | ||
|
||
export const CACHED_FUNCTIONS = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also please move the cached values from the scoring function ? |
||
ParametersStorage: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make it an object, with If we remove types as I suggested in the comment above, we can just make it a |
||
'r0', | ||
'r1', | ||
'r2', | ||
'finalizationCommitsNumber', | ||
'updateCommitWindowDuration', | ||
'commitWindowDurationPerc', | ||
'proofWindowDurationPerc', | ||
'epochLength', | ||
{ name: 'r0', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'r1', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'r2', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'finalizationCommitsNumber', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'updateCommitWindowDuration', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'commitWindowDurationPerc', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'proofWindowDurationPerc', type: CACHE_DATA_TYPES.NUMBER }, | ||
{ name: 'epochLength', type: CACHE_DATA_TYPES.NUMBER }, | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { | |
FALLBACK_PROVIDER_QUORUM, | ||
RPC_PROVIDER_STALL_TIMEOUT, | ||
CACHED_FUNCTIONS, | ||
CACHE_DATA_TYPES, | ||
} from '../../../constants/constants.js'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
@@ -272,11 +273,28 @@ class Web3Service { | |
} | ||
|
||
cacheParameter(parameterName, parameterValue) { | ||
resultCache[parameterName] = parameterValue; | ||
console.log('PARAMETER IME', parameterName); | ||
const found = Object.values(CACHED_FUNCTIONS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just add |
||
.flat() | ||
.find((item) => item.name === parameterName); | ||
if (found) { | ||
console.log('NADJENO?', found); | ||
const { type } = found; | ||
|
||
switch (type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the suggestion to remove types from constants, I would make it a separate function somewhere in the |
||
case CACHE_DATA_TYPES.NUMBER: | ||
resultCache[parameterName] = Number(parameterValue); | ||
break; | ||
default: | ||
resultCache[parameterName] = parameterValue; | ||
} | ||
} | ||
} | ||
|
||
getCachedValue(parameterName) { | ||
return resultCache[parameterName]; | ||
if (CACHED_FUNCTIONS.ParametersStorage.some((item) => item.name === parameterName)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just add |
||
return resultCache[parameterName]; | ||
} | ||
} | ||
|
||
initializeContract(contractName, contractAddress) { | ||
|
@@ -416,16 +434,13 @@ class Web3Service { | |
|
||
async callContractFunction(contractInstance, functionName, args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're using this function for |
||
let result; | ||
if (CACHED_FUNCTIONS.ParametersStorage.includes(functionName)) { | ||
result = this.getCachedValue(functionName); | ||
} | ||
result = this.getCachedValue(functionName); | ||
|
||
while (!result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
try { | ||
// eslint-disable-next-line no-await-in-loop | ||
result = await contractInstance[functionName](...args); | ||
if (CACHED_FUNCTIONS.ParametersStorage.includes(functionName)) { | ||
this.cacheParameter(functionName, result); | ||
} | ||
this.cacheParameter(functionName, result); | ||
} catch (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why we don't call "handleError" in the catch block anymore ? This was previously used to switch RPCs in case the error was due to RPC being down. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We switched to a new provider implementation in the |
||
const decodedErrorData = this._decodeErrorData(error, contractInstance.interface); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I get why would we need this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't think it's needed, for the specific events we have predefined types in the ABI
e.g. for

ParametersStorage
it can't be anything else exceptNumber
, so I would just cast values based on the types in the ABI