feat: uncommitte state - removing 'currentTx' inf. loop hack

This commit is contained in:
ppe
2022-12-12 11:52:58 +01:00
committed by just_ppe
parent 773f7c54bc
commit f57423e887
9 changed files with 27 additions and 89 deletions

View File

@@ -123,12 +123,10 @@ export class HandlerBasedContract<State> implements Contract<State> {
async readState(
sortKeyOrBlockHeight?: string | number,
currentTx?: CurrentTx[],
interactions?: GQLNodeInterface[]
): Promise<SortKeyCacheResult<EvalStateResult<State>>> {
this.logger.info('Read state for', {
contractTxId: this._contractTxId,
currentTx,
sortKeyOrBlockHeight
});
const initBenchmark = Benchmark.measure();
@@ -153,7 +151,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
initBenchmark.stop();
const stateBenchmark = Benchmark.measure();
const result = await stateEvaluator.eval(executionContext, currentTx || []);
const result = await stateEvaluator.eval(executionContext);
stateBenchmark.stop();
const total = (initBenchmark.elapsed(true) as number) + (stateBenchmark.elapsed(true) as number);
@@ -207,13 +205,9 @@ export class HandlerBasedContract<State> implements Contract<State> {
return await this.callContract<Input>(input, caller, undefined, tags, transfer);
}
async dryWriteFromTx<Input>(
input: Input,
transaction: GQLNodeInterface,
currentTx?: CurrentTx[]
): Promise<InteractionResult<State, unknown>> {
async dryWriteFromTx<Input>(input: Input, transaction: GQLNodeInterface): Promise<InteractionResult<State, unknown>> {
this.logger.info(`Dry-write from transaction ${transaction.id} for ${this._contractTxId}`);
return await this.callContractForTx<Input>(input, transaction, currentTx || []);
return await this.callContractForTx<Input>(input, transaction);
}
async writeInteraction<Input>(
@@ -627,7 +621,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
};
// eval current state
const evalStateResult = await stateEvaluator.eval<State>(executionContext, []);
const evalStateResult = await stateEvaluator.eval<State>(executionContext);
this.logger.info('Current state', evalStateResult.cachedValue.state);
// create interaction transaction
@@ -665,8 +659,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
const handleResult = await this.evalInteraction<Input, View>(
{
interaction,
interactionTx: dummyTx,
currentTx: []
interactionTx: dummyTx
},
executionContext,
evalStateResult.cachedValue
@@ -684,13 +677,12 @@ export class HandlerBasedContract<State> implements Contract<State> {
private async callContractForTx<Input, View = unknown>(
input: Input,
interactionTx: GQLNodeInterface,
currentTx?: CurrentTx[]
interactionTx: GQLNodeInterface
): Promise<InteractionResult<State, View>> {
this.maybeResetRootContract();
const executionContext = await this.createExecutionContextFromTx(this._contractTxId, interactionTx);
const evalStateResult = await this.warp.stateEvaluator.eval<State>(executionContext, currentTx);
const evalStateResult = await this.warp.stateEvaluator.eval<State>(executionContext);
this.logger.debug('callContractForTx - evalStateResult', {
result: evalStateResult.cachedValue.state,
@@ -704,8 +696,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
const interactionData: InteractionData<Input> = {
interaction,
interactionTx,
currentTx
interactionTx
};
const result = await this.evalInteraction<Input, View>(