fix: init state from wasm contracts when state fully cached
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
b529e7bc7c
commit
459a28f059
Binary file not shown.
@@ -15,6 +15,7 @@ let contract: Contract<ExampleContractState>;
|
||||
interface ExampleContractState {
|
||||
counter: number;
|
||||
}
|
||||
|
||||
describe('Testing the SmartWeave client', () => {
|
||||
let contractSrc: string;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import { addFunds, mineBlock } from './_helpers';
|
||||
|
||||
interface ExampleContractState {
|
||||
counter: number;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
}
|
||||
|
||||
describe('Testing the SmartWeave client for WASM contract', () => {
|
||||
@@ -36,8 +38,6 @@ describe('Testing the SmartWeave client for WASM contract', () => {
|
||||
});
|
||||
|
||||
LoggerFactory.INST.logLevel('error');
|
||||
LoggerFactory.INST.logLevel('debug', 'WasmContractHandlerApi');
|
||||
LoggerFactory.INST.logLevel('debug', 'WASM');
|
||||
|
||||
smartweave = SmartWeaveNodeFactory.memCached(arweave);
|
||||
|
||||
@@ -79,7 +79,10 @@ describe('Testing the SmartWeave client for WASM contract', () => {
|
||||
});
|
||||
|
||||
it('should properly read initial state', async () => {
|
||||
expect((await contract.readState()).state.counter).toEqual(0);
|
||||
const contractState = (await contract.readState()).state;
|
||||
expect(contractState.counter).toEqual(0);
|
||||
expect(contractState.firstName).toEqual("first_ppe");
|
||||
expect(contractState.lastName).toEqual("last_ppe");
|
||||
});
|
||||
|
||||
it('should properly register interactions', async () => {
|
||||
@@ -105,7 +108,7 @@ describe('Testing the SmartWeave client for WASM contract', () => {
|
||||
function: 'increment'
|
||||
});
|
||||
|
||||
expect(result.gasUsed).toEqual(9079017);
|
||||
expect(result.gasUsed).toEqual(9053274);
|
||||
});
|
||||
|
||||
it('should return stable gas results', async () => {
|
||||
@@ -120,7 +123,7 @@ describe('Testing the SmartWeave client for WASM contract', () => {
|
||||
}
|
||||
|
||||
results.forEach((result) => {
|
||||
expect(result.gasUsed).toEqual(9079017);
|
||||
expect(result.gasUsed).toEqual(9053274);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
|
||||
|
||||
const cachedState = executionContext.cachedState;
|
||||
if (cachedState?.cachedHeight === requestedBlockHeight) {
|
||||
executionContext.handler?.initState(cachedState.cachedValue.state);
|
||||
return cachedState.cachedValue;
|
||||
}
|
||||
|
||||
@@ -93,6 +94,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
|
||||
// if cache is up-to date - return immediately to speed-up the whole process
|
||||
if (missingInteractions.length === 0 && cachedState) {
|
||||
this.cLogger.debug(`State up to requested height [${requestedBlockHeight}] fully cached!`);
|
||||
executionContext.handler?.initState(cachedState.cachedValue.state);
|
||||
return cachedState.cachedValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export class DefaultCreateContract implements CreateContract {
|
||||
throw new Error(`No info about source type in wasm binary. Did you forget to export global "type" value?`);
|
||||
}
|
||||
// @ts-ignore
|
||||
const type = module.instance.exports.type.value;
|
||||
const type = module.instance.exports.type();
|
||||
if (!wasmTypeMapping.has(type)) {
|
||||
throw new Error(`Unknown wasm source type ${type}`);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
||||
let currentState = baseState.state;
|
||||
const validity = baseState.validity;
|
||||
|
||||
executionContext.handler.initState(currentState);
|
||||
executionContext?.handler.initState(currentState);
|
||||
|
||||
this.logger.info(
|
||||
`Evaluating state for ${contractDefinition.txId} [${missingInteractions.length} non-cached of ${sortedInteractions.length} all]`
|
||||
|
||||
Binary file not shown.
BIN
tools/data/wasm/optimized.wasm
Normal file
BIN
tools/data/wasm/optimized.wasm
Normal file
Binary file not shown.
Reference in New Issue
Block a user