perf: unnecessary call to arweave.networkInfo when block height is request from client #70

This commit is contained in:
ppedziwiatr
2022-01-03 01:46:49 +01:00
committed by Piotr Pędziwiatr
parent 15f9bff17f
commit a91f379e85
12 changed files with 90 additions and 51 deletions

View File

@@ -9,8 +9,13 @@ import {SmartWeaveNodeFactory} from '../src/core/node/SmartWeaveNodeFactory';
const logger = LoggerFactory.INST.create('Contract');
LoggerFactory.use(new TsLogFactory());
LoggerFactory.INST.logLevel('info');
// LoggerFactory.use(new TsLogFactory());
LoggerFactory.INST.logLevel("error");
LoggerFactory.INST.logLevel("debug", "ArweaveGatewayInteractionsLoader");
LoggerFactory.INST.logLevel("debug", "HandlerBasedContract");
LoggerFactory.INST.logLevel("debug", "ContractDefinitionLoader");
LoggerFactory.INST.logLevel("debug", "CacheableContractInteractionsLoader");
async function main() {
@@ -23,35 +28,35 @@ async function main() {
});
const contractTxId = 'Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY';
//const contractTxId = 't9T7DIOGxx4VWXoCEeYYarFYeERTpWIC1V3y-BPZgKE';
//const interactionsLoader = new FromFileInteractionsLoader(path.join(__dirname, 'data', 'interactions.json'));
// const smartweave = SmartWeaveWebFactory.memCachedBased(arweave).setInteractionsLoader(interactionsLoader).build();
const smartweaveR = SmartWeaveWebFactory
.memCachedBased(arweave, 1)
.setInteractionsLoader(new RedstoneGatewayInteractionsLoader(
'https://gateway.redstone.finance')
).build();
.memCachedBased(arweave, 1).build();
const usedBefore = Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100
/* const usedBefore = Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100
const contractR = smartweaveR.contract(contractTxId);
const {state, validity} = await contractR.readState();
const usedAfter = Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100
logger.warn("Heap used in MB", {
usedBefore,
usedAfter
});
});*/
const smartweave = SmartWeaveWebFactory.memCached(arweave, 1);
const contract = smartweave.contract(contractTxId);
const smartweave = SmartWeaveWebFactory.memCached(arweave);
const contract = smartweave.contract(contractTxId).setEvaluationOptions({
updateCacheForEachInteraction: false
});
const result = await contract.readState();
//fs.writeFileSync(path.join(__dirname, 'data', 'validity.json'), JSON.stringify(validity));
//fs.writeFileSync(path.join(__dirname, 'data', 'validity_old.json'), JSON.stringify(result.validity));
fs.writeFileSync(path.join(__dirname, 'data', 'state_redstone.json'), JSON.stringify(state));
fs.writeFileSync(path.join(__dirname, 'data', 'state_arweave.json'), JSON.stringify(result.state));
//fs.writeFileSync(path.join(__dirname, 'data', 'state_redstone.json'), JSON.stringify(state));
//fs.writeFileSync(path.join(__dirname, 'data', 'state_arweave.json'), JSON.stringify(result.state));
// console.log('second read');
// await lootContract.readState();