-
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 4 commits
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 |
---|---|---|
|
@@ -554,6 +554,7 @@ export const CONTRACTS = { | |
HUB_CONTRACT: 'HubContract', | ||
COMMIT_MANAGER_V1_U1_CONTRACT: 'CommitManagerV1U1Contract', | ||
SERVICE_AGREEMENT_V1_CONTRACT: 'ServiceAgreementV1Contract', | ||
PARAMETERS_STORAGE_CONTRACT: 'ParametersStorageContract', | ||
}; | ||
|
||
export const CONTRACT_EVENTS = { | ||
|
@@ -563,6 +564,7 @@ export const CONTRACT_EVENTS = { | |
PROFILE: ['AskUpdated'], | ||
COMMIT_MANAGER_V1: ['StateFinalized'], | ||
SERVICE_AGREEMENT_V1: ['ServiceAgreementV1Extended', 'ServiceAgreementV1Terminated'], | ||
PARAMETERS_STORAGE: ['ParameterChanged'], | ||
}; | ||
|
||
export const NODE_ENVIRONMENTS = { | ||
|
@@ -586,3 +588,16 @@ export const BLOCK_TIME_MILLIS = { | |
}; | ||
|
||
export const TRANSACTION_CONFIRMATIONS = 1; | ||
|
||
export const CACHED_FUNCTIONS = { | ||
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', | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
HTTP_RPC_PROVIDER_PRIORITY, | ||
FALLBACK_PROVIDER_QUORUM, | ||
RPC_PROVIDER_STALL_TIMEOUT, | ||
CACHED_FUNCTIONS, | ||
} from '../../../constants/constants.js'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
@@ -51,6 +52,7 @@ const ABIs = { | |
const SCORING_FUNCTIONS = { | ||
1: 'Log2PLDSF', | ||
}; | ||
const resultCache = {}; | ||
|
||
class Web3Service { | ||
async initialize(config, logger) { | ||
|
@@ -269,6 +271,14 @@ class Web3Service { | |
} | ||
} | ||
|
||
cacheParameter(parameterName, parameterValue) { | ||
resultCache[parameterName] = parameterValue; | ||
} | ||
|
||
getCachedValue(parameterName) { | ||
return resultCache[parameterName]; | ||
} | ||
|
||
initializeContract(contractName, contractAddress) { | ||
if (ABIs[contractName] != null) { | ||
this[`${contractName}Contract`] = new ethers.Contract( | ||
|
@@ -406,10 +416,16 @@ 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; | ||
while (result === undefined) { | ||
if (CACHED_FUNCTIONS.ParametersStorage.includes(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); | ||
} | ||
} 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.
Could you also please move the cached values from the scoring function ?