perf: unnecessary call to arweave.networkInfo when block height is request from client #70
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
15f9bff17f
commit
a91f379e85
@@ -86,7 +86,6 @@
|
|||||||
"2caOW6ol9T8LHCMO8tVAx4GHRwv1q3fFc79KzKOtoww",
|
"2caOW6ol9T8LHCMO8tVAx4GHRwv1q3fFc79KzKOtoww",
|
||||||
"HdZBZa0GfOEUYCubwvoSyxGUUgPmgy7RJb5l77T21bE",
|
"HdZBZa0GfOEUYCubwvoSyxGUUgPmgy7RJb5l77T21bE",
|
||||||
"7Dp5r-UpZLDvHqsDbZbqWhCBwbYdJMKBuC3tFC-FF7U",
|
"7Dp5r-UpZLDvHqsDbZbqWhCBwbYdJMKBuC3tFC-FF7U",
|
||||||
"YLVpmhSq5JmLltfg6R-5fL04rIRPrlSU22f6RQ6VyYE",
|
|
||||||
"EOtTxCGktZe_J2DTM0D5h04crjlpjgeygA1R6Pmo_qM",
|
"EOtTxCGktZe_J2DTM0D5h04crjlpjgeygA1R6Pmo_qM",
|
||||||
"92Tq6BKm6pvVkKW8_6Fb13QWTdUzBRLnG9scMBNWYZ4",
|
"92Tq6BKm6pvVkKW8_6Fb13QWTdUzBRLnG9scMBNWYZ4",
|
||||||
"w27141UQGgrCFhkiw9tL7A0-qWMQjbapU3mq2TfI4Cg",
|
"w27141UQGgrCFhkiw9tL7A0-qWMQjbapU3mq2TfI4Cg",
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ export interface Contract<State = unknown> {
|
|||||||
* "root" contract network info - so that the whole execution is performed with the
|
* "root" contract network info - so that the whole execution is performed with the
|
||||||
* same network info)
|
* same network info)
|
||||||
*/
|
*/
|
||||||
getNetworkInfo(): NetworkInfoInterface;
|
getNetworkInfo(): Partial<NetworkInfoInterface>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block height requested by user for the given interaction with contract
|
* Get the block height requested by user for the given interaction with contract
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
* Only the 'root' contract call should read this data from Arweave - all the inner calls ("child" contracts)
|
* Only the 'root' contract call should read this data from Arweave - all the inner calls ("child" contracts)
|
||||||
* should reuse this data from the parent ("calling") contract.
|
* should reuse this data from the parent ("calling") contract.
|
||||||
*/
|
*/
|
||||||
private _networkInfo?: NetworkInfoInterface = null;
|
private _networkInfo?: Partial<NetworkInfoInterface> = null;
|
||||||
|
|
||||||
private _rootBlockHeight: number = null;
|
private _rootBlockHeight: number = null;
|
||||||
|
|
||||||
@@ -98,10 +98,10 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
contractTxId: this._contractTxId,
|
contractTxId: this._contractTxId,
|
||||||
currentTx
|
currentTx
|
||||||
});
|
});
|
||||||
|
const initBenchmark = Benchmark.measure();
|
||||||
this.maybeResetRootContract(blockHeight);
|
this.maybeResetRootContract(blockHeight);
|
||||||
|
|
||||||
const { stateEvaluator } = this.smartweave;
|
const { stateEvaluator } = this.smartweave;
|
||||||
const benchmark = Benchmark.measure();
|
|
||||||
const executionContext = await this.createExecutionContext(this._contractTxId, blockHeight);
|
const executionContext = await this.createExecutionContext(this._contractTxId, blockHeight);
|
||||||
this.logger.info('Execution Context', {
|
this.logger.info('Execution Context', {
|
||||||
blockHeight: executionContext.blockHeight,
|
blockHeight: executionContext.blockHeight,
|
||||||
@@ -109,10 +109,16 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
missingInteractions: executionContext.sortedInteractions.length,
|
missingInteractions: executionContext.sortedInteractions.length,
|
||||||
cachedStateHeight: executionContext.cachedState?.cachedHeight
|
cachedStateHeight: executionContext.cachedState?.cachedHeight
|
||||||
});
|
});
|
||||||
this.logger.debug('context', benchmark.elapsed());
|
initBenchmark.stop();
|
||||||
benchmark.reset();
|
|
||||||
|
const stateBenchmark = Benchmark.measure();
|
||||||
const result = await stateEvaluator.eval(executionContext, currentTx || []);
|
const result = await stateEvaluator.eval(executionContext, currentTx || []);
|
||||||
this.logger.debug('state', benchmark.elapsed());
|
stateBenchmark.stop();
|
||||||
|
|
||||||
|
this.logger.info('Benchmark', {
|
||||||
|
'init time': initBenchmark.elapsed(),
|
||||||
|
'evaluation time': stateBenchmark.elapsed()
|
||||||
|
});
|
||||||
return result as EvalStateResult<State>;
|
return result as EvalStateResult<State>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +238,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
return this._callStack;
|
return this._callStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
getNetworkInfo(): NetworkInfoInterface {
|
getNetworkInfo(): Partial<NetworkInfoInterface> {
|
||||||
return this._networkInfo;
|
return this._networkInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,9 +287,15 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
const benchmark = Benchmark.measure();
|
const benchmark = Benchmark.measure();
|
||||||
// if this is a "root" call (ie. original call from SmartWeave's client)
|
// if this is a "root" call (ie. original call from SmartWeave's client)
|
||||||
if (this._parentContract == null) {
|
if (this._parentContract == null) {
|
||||||
this.logger.debug('Reading network info for root call');
|
if (blockHeight) {
|
||||||
currentNetworkInfo = await arweave.network.getInfo();
|
this._networkInfo = {
|
||||||
this._networkInfo = currentNetworkInfo;
|
height: blockHeight
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.logger.debug('Reading network info for root call');
|
||||||
|
currentNetworkInfo = await arweave.network.getInfo();
|
||||||
|
this._networkInfo = currentNetworkInfo;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// if that's a call from within contract's source code
|
// if that's a call from within contract's source code
|
||||||
this.logger.debug('Reusing network info from the calling contract');
|
this.logger.debug('Reusing network info from the calling contract');
|
||||||
@@ -300,7 +312,6 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
blockHeight = currentNetworkInfo.height;
|
blockHeight = currentNetworkInfo.height;
|
||||||
}
|
}
|
||||||
this.logger.debug('network info', benchmark.elapsed());
|
this.logger.debug('network info', benchmark.elapsed());
|
||||||
|
|
||||||
benchmark.reset();
|
benchmark.reset();
|
||||||
|
|
||||||
const cachedState = await stateEvaluator.latestAvailableState<State>(contractTxId, blockHeight);
|
const cachedState = await stateEvaluator.latestAvailableState<State>(contractTxId, blockHeight);
|
||||||
@@ -309,6 +320,9 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
cachedBlockHeight = cachedState.cachedHeight;
|
cachedBlockHeight = cachedState.cachedHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.debug('cache lookup', benchmark.elapsed());
|
||||||
|
benchmark.reset();
|
||||||
|
|
||||||
let contractDefinition,
|
let contractDefinition,
|
||||||
interactions = [],
|
interactions = [],
|
||||||
sortedInteractions = [],
|
sortedInteractions = [],
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
import { ContractDefinition, DefinitionLoader, getTag, LoggerFactory, SmartWeaveTags, SwCache } from '@smartweave';
|
import {
|
||||||
|
Benchmark,
|
||||||
|
ContractDefinition,
|
||||||
|
DefinitionLoader,
|
||||||
|
getTag,
|
||||||
|
LoggerFactory,
|
||||||
|
SmartWeaveTags,
|
||||||
|
SwCache
|
||||||
|
} from '@smartweave';
|
||||||
import Arweave from 'arweave';
|
import Arweave from 'arweave';
|
||||||
import Transaction from 'arweave/web/lib/transaction';
|
import Transaction from 'arweave/web/lib/transaction';
|
||||||
|
|
||||||
@@ -8,7 +16,7 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly arweave: Arweave,
|
private readonly arweave: Arweave,
|
||||||
// TODO: cache should be removed from the core layer and implemented in a wrapper of the core implementation
|
// TODO: cache should be removed from the core layer and implemented in a wrapper of the core implementation
|
||||||
private readonly cache?: SwCache<string, ContractDefinition<unknown>>
|
protected readonly cache?: SwCache<string, ContractDefinition<unknown>>
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async load<State>(contractTxId: string, forcedSrcTxId?: string): Promise<ContractDefinition<State>> {
|
async load<State>(contractTxId: string, forcedSrcTxId?: string): Promise<ContractDefinition<State>> {
|
||||||
@@ -16,23 +24,33 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
|||||||
this.logger.debug('ContractDefinitionLoader: Hit from cache!');
|
this.logger.debug('ContractDefinitionLoader: Hit from cache!');
|
||||||
return Promise.resolve(this.cache?.get(contractTxId) as ContractDefinition<State>);
|
return Promise.resolve(this.cache?.get(contractTxId) as ContractDefinition<State>);
|
||||||
}
|
}
|
||||||
|
const benchmark = Benchmark.measure();
|
||||||
const contract = await this.doLoad<State>(contractTxId, forcedSrcTxId);
|
const contract = await this.doLoad<State>(contractTxId, forcedSrcTxId);
|
||||||
|
this.logger.info(`Contract definition loaded in: ${benchmark.elapsed()}`);
|
||||||
this.cache?.put(contractTxId, contract);
|
this.cache?.put(contractTxId, contract);
|
||||||
|
|
||||||
return contract;
|
return contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
async doLoad<State>(contractTxId: string, forcedSrcTxId?: string): Promise<ContractDefinition<State>> {
|
async doLoad<State>(contractTxId: string, forcedSrcTxId?: string): Promise<ContractDefinition<State>> {
|
||||||
|
const benchmark = Benchmark.measure();
|
||||||
const contractTx = await this.arweave.transactions.get(contractTxId);
|
const contractTx = await this.arweave.transactions.get(contractTxId);
|
||||||
const owner = await this.arweave.wallets.ownerToAddress(contractTx.owner);
|
const owner = await this.arweave.wallets.ownerToAddress(contractTx.owner);
|
||||||
|
this.logger.debug('Contract tx and owner', benchmark.elapsed());
|
||||||
|
benchmark.reset();
|
||||||
|
|
||||||
const contractSrcTxId = forcedSrcTxId ? forcedSrcTxId : getTag(contractTx, SmartWeaveTags.CONTRACT_SRC_TX_ID);
|
const contractSrcTxId = forcedSrcTxId ? forcedSrcTxId : getTag(contractTx, SmartWeaveTags.CONTRACT_SRC_TX_ID);
|
||||||
|
|
||||||
const minFee = getTag(contractTx, SmartWeaveTags.MIN_FEE);
|
const minFee = getTag(contractTx, SmartWeaveTags.MIN_FEE);
|
||||||
|
this.logger.debug('Tags decoding', benchmark.elapsed());
|
||||||
|
benchmark.reset();
|
||||||
|
|
||||||
const contractSrcTx = await this.arweave.transactions.get(contractSrcTxId);
|
const contractSrcTx = await this.arweave.transactions.get(contractSrcTxId);
|
||||||
|
this.logger.debug('Contract src tx load', benchmark.elapsed());
|
||||||
|
benchmark.reset();
|
||||||
|
|
||||||
const src = contractSrcTx.get('data', { decode: true, string: true });
|
const src = contractSrcTx.get('data', { decode: true, string: true });
|
||||||
const initState = JSON.parse(await this.evalInitialState(contractTx));
|
const initState = JSON.parse(await this.evalInitialState(contractTx));
|
||||||
|
this.logger.debug('Parsing src and init state', benchmark.elapsed());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
txId: contractTxId,
|
txId: contractTxId,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
} from '@smartweave';
|
} from '@smartweave';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import * as clarity from '@weavery/clarity';
|
import * as clarity from '@weavery/clarity';
|
||||||
|
import * as v8 from "v8";
|
||||||
|
|
||||||
export class ContractHandlerApi<State> implements HandlerApi<State> {
|
export class ContractHandlerApi<State> implements HandlerApi<State> {
|
||||||
private readonly contractLogger: RedStoneLogger;
|
private readonly contractLogger: RedStoneLogger;
|
||||||
@@ -63,11 +64,7 @@ export class ContractHandlerApi<State> implements HandlerApi<State> {
|
|||||||
this.assignWrite(executionContext, currentTx);
|
this.assignWrite(executionContext, currentTx);
|
||||||
this.assignRefreshState(executionContext);
|
this.assignRefreshState(executionContext);
|
||||||
|
|
||||||
// strangely - state is for some reason modified for some contracts (eg. YLVpmhSq5JmLltfg6R-5fL04rIRPrlSU22f6RQ6VyYE)
|
const handlerResult = await Promise.race([timeoutPromise, handler(stateCopy, interaction)]);
|
||||||
// when calling any async (even simple timeout) function here...
|
|
||||||
// that's (ie. deepCopy) a dumb workaround for this issue
|
|
||||||
// see https://github.com/ArweaveTeam/SmartWeave/pull/92 for more details
|
|
||||||
const handlerResult = deepCopy(await Promise.race([timeoutPromise, handler(stateCopy, interaction)]));
|
|
||||||
|
|
||||||
if (handlerResult && (handlerResult.state || handlerResult.result)) {
|
if (handlerResult && (handlerResult.state || handlerResult.result)) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
|||||||
let lastEvaluatedInteraction = null;
|
let lastEvaluatedInteraction = null;
|
||||||
let errorMessage = null;
|
let errorMessage = null;
|
||||||
|
|
||||||
for (const missingInteraction of missingInteractions) {
|
const missingInteractionsLength = missingInteractions.length;
|
||||||
|
for (let i = 0; i < missingInteractionsLength; i++) {
|
||||||
|
const missingInteraction = missingInteractions[i];
|
||||||
const singleInteractionBenchmark = Benchmark.measure();
|
const singleInteractionBenchmark = Benchmark.measure();
|
||||||
|
|
||||||
const interactionTx: GQLNodeInterface = missingInteraction.node;
|
const interactionTx: GQLNodeInterface = missingInteraction.node;
|
||||||
@@ -81,7 +83,6 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
|||||||
}/${missingInteractions.length} [of all:${sortedInteractions.length}]`
|
}/${missingInteractions.length} [of all:${sortedInteractions.length}]`
|
||||||
);
|
);
|
||||||
|
|
||||||
// verifying whether state isn't already available for this exact interaction.
|
|
||||||
const isInteractWrite = this.tagsParser.isInteractWrite(missingInteraction, contractDefinition.txId);
|
const isInteractWrite = this.tagsParser.isInteractWrite(missingInteraction, contractDefinition.txId);
|
||||||
|
|
||||||
this.logger.debug('interactWrite?:', isInteractWrite);
|
this.logger.debug('interactWrite?:', isInteractWrite);
|
||||||
@@ -163,8 +164,6 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
|||||||
caller: interactionTx.owner.address
|
caller: interactionTx.owner.address
|
||||||
};
|
};
|
||||||
|
|
||||||
const intermediaryCacheHit = false;
|
|
||||||
|
|
||||||
const interactionData = {
|
const interactionData = {
|
||||||
interaction,
|
interaction,
|
||||||
interactionTx,
|
interactionTx,
|
||||||
@@ -199,7 +198,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
|||||||
|
|
||||||
interactionCall.update({
|
interactionCall.update({
|
||||||
cacheHit: false,
|
cacheHit: false,
|
||||||
intermediaryCacheHit,
|
intermediaryCacheHit: false,
|
||||||
outputState: stackTrace.saveState ? currentState : undefined,
|
outputState: stackTrace.saveState ? currentState : undefined,
|
||||||
executionTime: singleInteractionBenchmark.elapsed(true) as number,
|
executionTime: singleInteractionBenchmark.elapsed(true) as number,
|
||||||
valid: validity[interactionTx.id],
|
valid: validity[interactionTx.id],
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
GQLNodeInterface
|
GQLNodeInterface
|
||||||
} from '@smartweave';
|
} from '@smartweave';
|
||||||
import 'isomorphic-fetch';
|
import 'isomorphic-fetch';
|
||||||
|
|
||||||
interface Paging {
|
interface Paging {
|
||||||
total: string;
|
total: string;
|
||||||
limit: number;
|
limit: number;
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ export class Benchmark {
|
|||||||
this.end = null;
|
this.end = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public stop() {
|
||||||
|
this.end = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
public elapsed(rawValue = false): string | number {
|
public elapsed(rawValue = false): string | number {
|
||||||
if (this.end === null) {
|
if (this.end === null) {
|
||||||
this.end = Date.now();
|
this.end = Date.now();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Benchmark,
|
||||||
BlockHeightKey,
|
BlockHeightKey,
|
||||||
BlockHeightSwCache,
|
BlockHeightSwCache,
|
||||||
EvaluationOptions,
|
EvaluationOptions,
|
||||||
@@ -26,6 +27,7 @@ export class CacheableContractInteractionsLoader implements InteractionsLoader {
|
|||||||
toBlockHeight: number,
|
toBlockHeight: number,
|
||||||
evaluationOptions?: EvaluationOptions
|
evaluationOptions?: EvaluationOptions
|
||||||
): Promise<GQLEdgeInterface[]> {
|
): Promise<GQLEdgeInterface[]> {
|
||||||
|
const benchmark = Benchmark.measure();
|
||||||
this.logger.debug('Loading interactions', {
|
this.logger.debug('Loading interactions', {
|
||||||
contractId,
|
contractId,
|
||||||
fromBlockHeight,
|
fromBlockHeight,
|
||||||
@@ -73,6 +75,8 @@ export class CacheableContractInteractionsLoader implements InteractionsLoader {
|
|||||||
// - that's why "result" variable is not used here
|
// - that's why "result" variable is not used here
|
||||||
await this.cache.put(new BlockHeightKey(contractId, toBlockHeight), valueToCache);
|
await this.cache.put(new BlockHeightKey(contractId, toBlockHeight), valueToCache);
|
||||||
|
|
||||||
|
this.logger.debug(`Interactions loaded in ${benchmark.elapsed()}`);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
|
|
||||||
|
const isNode = new Function('try {return this===global;}catch(e){return false;}');
|
||||||
|
|
||||||
|
let v8 = null;
|
||||||
|
if (isNode()) {
|
||||||
|
v8 = require('v8');
|
||||||
|
}
|
||||||
|
|
||||||
export const sleep = (ms: number): Promise<void> => {
|
export const sleep = (ms: number): Promise<void> => {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deepCopy = (input: unknown): any => {
|
export const deepCopy = (input: unknown): any => {
|
||||||
|
if (v8) {
|
||||||
|
return v8.deserialize(v8.serialize(input));
|
||||||
|
}
|
||||||
return cloneDeep(input);
|
return cloneDeep(input);
|
||||||
// note: parse/stringify combination is slooow: https://jsben.ch/bWfk9
|
// note: parse/stringify combination is slooow: https://jsben.ch/bWfk9
|
||||||
//return JSON.parse(JSON.stringify(input, mapReplacer), mapReviver);
|
//return JSON.parse(JSON.stringify(input, mapReplacer), mapReviver);
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ import {SmartWeaveNodeFactory} from '../src/core/node/SmartWeaveNodeFactory';
|
|||||||
|
|
||||||
const logger = LoggerFactory.INST.create('Contract');
|
const logger = LoggerFactory.INST.create('Contract');
|
||||||
|
|
||||||
LoggerFactory.use(new TsLogFactory());
|
// LoggerFactory.use(new TsLogFactory());
|
||||||
LoggerFactory.INST.logLevel('info');
|
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() {
|
async function main() {
|
||||||
@@ -23,35 +28,35 @@ async function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const contractTxId = 'Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY';
|
const contractTxId = 'Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY';
|
||||||
|
//const contractTxId = 't9T7DIOGxx4VWXoCEeYYarFYeERTpWIC1V3y-BPZgKE';
|
||||||
|
|
||||||
//const interactionsLoader = new FromFileInteractionsLoader(path.join(__dirname, 'data', 'interactions.json'));
|
//const interactionsLoader = new FromFileInteractionsLoader(path.join(__dirname, 'data', 'interactions.json'));
|
||||||
|
|
||||||
// const smartweave = SmartWeaveWebFactory.memCachedBased(arweave).setInteractionsLoader(interactionsLoader).build();
|
// const smartweave = SmartWeaveWebFactory.memCachedBased(arweave).setInteractionsLoader(interactionsLoader).build();
|
||||||
const smartweaveR = SmartWeaveWebFactory
|
const smartweaveR = SmartWeaveWebFactory
|
||||||
.memCachedBased(arweave, 1)
|
.memCachedBased(arweave, 1).build();
|
||||||
.setInteractionsLoader(new RedstoneGatewayInteractionsLoader(
|
|
||||||
'https://gateway.redstone.finance')
|
|
||||||
).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 contractR = smartweaveR.contract(contractTxId);
|
||||||
const {state, validity} = await contractR.readState();
|
const {state, validity} = await contractR.readState();
|
||||||
const usedAfter = Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100
|
const usedAfter = Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100
|
||||||
logger.warn("Heap used in MB", {
|
logger.warn("Heap used in MB", {
|
||||||
usedBefore,
|
usedBefore,
|
||||||
usedAfter
|
usedAfter
|
||||||
});
|
});*/
|
||||||
|
|
||||||
const smartweave = SmartWeaveWebFactory.memCached(arweave, 1);
|
const smartweave = SmartWeaveWebFactory.memCached(arweave);
|
||||||
const contract = smartweave.contract(contractTxId);
|
const contract = smartweave.contract(contractTxId).setEvaluationOptions({
|
||||||
|
updateCacheForEachInteraction: false
|
||||||
|
});
|
||||||
const result = await contract.readState();
|
const result = await contract.readState();
|
||||||
|
|
||||||
|
|
||||||
//fs.writeFileSync(path.join(__dirname, 'data', 'validity.json'), JSON.stringify(validity));
|
//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', '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_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_arweave.json'), JSON.stringify(result.state));
|
||||||
|
|
||||||
// console.log('second read');
|
// console.log('second read');
|
||||||
// await lootContract.readState();
|
// await lootContract.readState();
|
||||||
|
|||||||
14
yarn.lock
14
yarn.lock
@@ -2108,13 +2108,6 @@ cli-spinners@^2.5.0:
|
|||||||
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.1.tgz#adc954ebe281c37a6319bfa401e6dd2488ffb70d"
|
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.1.tgz#adc954ebe281c37a6319bfa401e6dd2488ffb70d"
|
||||||
integrity sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==
|
integrity sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==
|
||||||
|
|
||||||
cli-table@^0.3.11:
|
|
||||||
version "0.3.11"
|
|
||||||
resolved "https://registry.yarnpkg.com/cli-table/-/cli-table-0.3.11.tgz#ac69cdecbe81dccdba4889b9a18b7da312a9d3ee"
|
|
||||||
integrity sha512-IqLQi4lO0nIB4tcdTpN4LCB9FI3uqrJZK7RC515EnhZ6qBaglkIgICb1wjeAqpdoOabm1+SuQtkXIPdYC93jhQ==
|
|
||||||
dependencies:
|
|
||||||
colors "1.0.3"
|
|
||||||
|
|
||||||
cli-width@^3.0.0:
|
cli-width@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6"
|
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6"
|
||||||
@@ -2212,12 +2205,7 @@ colorette@2.0.16:
|
|||||||
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da"
|
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da"
|
||||||
integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==
|
integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==
|
||||||
|
|
||||||
colors@1.0.3:
|
colors@^1.3.3:
|
||||||
version "1.0.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
|
|
||||||
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
|
|
||||||
|
|
||||||
colors@^1.3.3, colors@^1.4.0:
|
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
|
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
|
||||||
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
|
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
|
||||||
|
|||||||
Reference in New Issue
Block a user