Skip to content

Commit

Permalink
update: voteBundleProposal return type.
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherbrumm committed Oct 5, 2023
1 parent 34efcfb commit 7dd7949
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
17 changes: 16 additions & 1 deletion common/protocol/src/methods/validate/validateBundleProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions common/protocol/src/types/interfaces/runtime.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>} returns whether the proposed data item is valid compared to the validation data item
* @return {Promise<number>} returns whether the vote is valid, invalid or abstain compared against the proposed data item
*/
validateDataItem(
v: Validator,
proposedDataItem: DataItem,
validationDataItem: DataItem
): Promise<boolean>;
): Promise<number>;

/**
* Gets a formatted value string from a bundle. This produces a "summary" of
Expand Down
11 changes: 6 additions & 5 deletions integrations/tendermint-bsync/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -62,11 +62,12 @@ export default class TendermintBSync implements IRuntime {
_: Validator,
proposedDataItem: DataItem,
validationDataItem: DataItem
): Promise<boolean> {
): Promise<number> {
// 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<string> {
Expand Down
11 changes: 6 additions & 5 deletions integrations/tendermint-ssync/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -126,11 +126,12 @@ export default class TendermintSSync implements IRuntime {
_: Validator,
proposedDataItem: DataItem,
validationDataItem: DataItem
): Promise<boolean> {
): Promise<number> {
// 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<string> {
Expand Down
17 changes: 11 additions & 6 deletions integrations/tendermint/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -182,11 +182,16 @@ export default class Tendermint implements IRuntime {
_: Validator,
proposedDataItem: DataItem,
validationDataItem: DataItem
): Promise<boolean> {
// apply equal comparison
return (
JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)
);
): Promise<number> {
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<string> {
Expand Down

0 comments on commit 7dd7949

Please sign in to comment.