From 7dd7949f61d3716f898f5f7072f34fa9239f56c4 Mon Sep 17 00:00:00 2001 From: christopherbrumm Date: Thu, 5 Oct 2023 14:27:58 +0200 Subject: [PATCH] update: voteBundleProposal return type. --- .../methods/validate/validateBundleProposal.ts | 17 ++++++++++++++++- .../src/types/interfaces/runtime.interface.ts | 4 ++-- integrations/tendermint-bsync/src/runtime.ts | 11 ++++++----- integrations/tendermint-ssync/src/runtime.ts | 11 ++++++----- integrations/tendermint/src/runtime.ts | 17 +++++++++++------ 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/common/protocol/src/methods/validate/validateBundleProposal.ts b/common/protocol/src/methods/validate/validateBundleProposal.ts index fda27a66..2e228c53 100644 --- a/common/protocol/src/methods/validate/validateBundleProposal.ts +++ b/common/protocol/src/methods/validate/validateBundleProposal.ts @@ -158,12 +158,27 @@ export async function validateBundleProposal( this.logger.debug( `this.runtime.validateDataItem($THIS, $PROPOSED_DATA_ITEM, $VALIDATION_DATA_ITEM)` ); - valid = await this.runtime.validateDataItem( + const vote = await this.runtime.validateDataItem( this, proposedBundle[i], validationBundle[i] ); + // vote abstain if data item validation returned abstain + if (vote === VOTE.ABSTAIN) { + const success = await this.voteBundleProposal( + this.pool.bundle_proposal!.storage_id, + VOTE.ABSTAIN + ); + return success; + } + + if (vote === VOTE.VALID) { + valid = true; + } else if (vote === VOTE.INVALID) { + valid = false; + } + // only log if data item validation returned invalid if (!valid) { this.logger.info( diff --git a/common/protocol/src/types/interfaces/runtime.interface.ts b/common/protocol/src/types/interfaces/runtime.interface.ts index 91f0d01b..a65028d7 100644 --- a/common/protocol/src/types/interfaces/runtime.interface.ts +++ b/common/protocol/src/types/interfaces/runtime.interface.ts @@ -103,13 +103,13 @@ export interface IRuntime { * @param {Validator} v the class of @kyvejs/protocol * @param {DataItem} proposedDataItem the data item proposed by the uploader * @param {DataItem} validationDataItem the data item which the validator created himself for validation again the proposed data item - * @return {Promise} returns whether the proposed data item is valid compared to the validation data item + * @return {Promise} returns whether the vote is valid, invalid or abstain compared against the proposed data item */ validateDataItem( v: Validator, proposedDataItem: DataItem, validationDataItem: DataItem - ): Promise; + ): Promise; /** * Gets a formatted value string from a bundle. This produces a "summary" of diff --git a/integrations/tendermint-bsync/src/runtime.ts b/integrations/tendermint-bsync/src/runtime.ts index d145a4c2..3964a776 100644 --- a/integrations/tendermint-bsync/src/runtime.ts +++ b/integrations/tendermint-bsync/src/runtime.ts @@ -1,4 +1,4 @@ -import { DataItem, IRuntime, Validator } from '@kyvejs/protocol'; +import { DataItem, IRuntime, Validator, VOTE } from "@kyvejs/protocol"; import { name, version } from '../package.json'; import axios from 'axios'; @@ -62,11 +62,12 @@ export default class TendermintBSync implements IRuntime { _: Validator, proposedDataItem: DataItem, validationDataItem: DataItem - ): Promise { + ): Promise { // apply equal comparison - return ( - JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem) - ); + if (JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)) { + return VOTE.VALID + } + return VOTE.INVALID } async summarizeDataBundle(_: Validator, bundle: DataItem[]): Promise { diff --git a/integrations/tendermint-ssync/src/runtime.ts b/integrations/tendermint-ssync/src/runtime.ts index 43b9ebe7..a93a73f6 100644 --- a/integrations/tendermint-ssync/src/runtime.ts +++ b/integrations/tendermint-ssync/src/runtime.ts @@ -1,4 +1,4 @@ -import { DataItem, IRuntime, Validator } from '@kyvejs/protocol'; +import { DataItem, IRuntime, Validator, VOTE } from "@kyvejs/protocol"; import { name, version } from '../package.json'; import axios from 'axios'; @@ -126,11 +126,12 @@ export default class TendermintSSync implements IRuntime { _: Validator, proposedDataItem: DataItem, validationDataItem: DataItem - ): Promise { + ): Promise { // apply equal comparison - return ( - JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem) - ); + if (JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)) { + return VOTE.VALID + } + return VOTE.INVALID } async summarizeDataBundle(_: Validator, bundle: DataItem[]): Promise { diff --git a/integrations/tendermint/src/runtime.ts b/integrations/tendermint/src/runtime.ts index f5cfbc09..3a0355cf 100644 --- a/integrations/tendermint/src/runtime.ts +++ b/integrations/tendermint/src/runtime.ts @@ -1,4 +1,4 @@ -import { DataItem, IRuntime, Validator } from '@kyvejs/protocol'; +import { DataItem, IRuntime, Validator, VOTE } from '@kyvejs/protocol'; import { name, version } from '../package.json'; import axios from 'axios'; import Ajv from 'ajv'; @@ -182,11 +182,16 @@ export default class Tendermint implements IRuntime { _: Validator, proposedDataItem: DataItem, validationDataItem: DataItem - ): Promise { - // apply equal comparison - return ( - JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem) - ); + ): Promise { + if (proposedDataItem.value.block_results.begin_block_events === validationDataItem.value.block_results.begin_block_events) { + // apply equal comparison + if (JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)) { + return VOTE.VALID + } + return VOTE.INVALID + } + // vote abstain if begin_block_events are not equal + return VOTE.ABSTAIN } async summarizeDataBundle(_: Validator, bundle: DataItem[]): Promise {