Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/v1.5.x' into cbrumm/tend…
Browse files Browse the repository at this point in the history
…ermint-merkle-root
  • Loading branch information
christopherbrumm committed Jun 13, 2024
2 parents 3f522fc + 86d51e7 commit 7c19318
Show file tree
Hide file tree
Showing 172 changed files with 7,214 additions and 1,245 deletions.
4 changes: 2 additions & 2 deletions common/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@bundlr-network/client": "^0.8.9",
"@cosmjs/proto-signing": "^0.27.1",
"@cosmjs/stargate": "^0.27.1",
"@kyvejs/sdk": "1.1.1",
"@kyvejs/types": "1.2.0",
"@kyvejs/sdk": "1.2.0",
"@kyvejs/types": "1.3.0",
"@types/cli-progress": "^3.9.2",
"@types/jsonfile": "^6.0.1",
"arweave": "^1.10.17",
Expand Down
19 changes: 16 additions & 3 deletions common/protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ export class Validator {
"Specify the home directory of the node where logs and the cache should save their data. [default current directory]",
"./"
)
.option(
"--skip-data-availability-check",
"Skip data availability check and join pool instantly without waiting for the data source. WARNING: Only use this if you know what you are doing since this can lead to timeout slashes"
)
.action((options) => {
this.start(options);
});
Expand Down Expand Up @@ -326,9 +330,13 @@ export class Validator {
process.exit(1);
}

// until data is not available we wait and idle
while (!(await this.isDataAvailable())) {
await sleep(IDLE_TIME);
// by default we check if the first data items are available
// to protect the node operator from timeout slashes due to
// misconfiguration of the data source
if (!options.skipDataAvailabilityCheck) {
while (!(await this.isDataAvailable())) {
await sleep(IDLE_TIME);
}
}

await this.setupValidator();
Expand Down Expand Up @@ -356,3 +364,8 @@ export * from "./types";

// export utils
export * from "./utils";

// add this so we can JSON.stringify bignumbers
(BigInt.prototype as any).toJSON = function () {
return this.toString();
};
10 changes: 7 additions & 3 deletions common/protocol/src/methods/checks/isDataAvailable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import { Validator, standardizeError } from "../..";
* @return {Promise<boolean>}
*/
export async function isDataAvailable(this: Validator): Promise<boolean> {
let nextKey = "";

try {
// log debug method
if (this.pool.data!.current_key) {
this.logger.debug(`this.runtime.nextKey(${this.pool.data!.current_key})`);
}

// get the next key to node has to fetch
const nextKey = this.pool.data!.current_key
nextKey = this.pool.data!.current_key
? await this.runtime.nextKey(this, this.pool.data!.current_key)
: this.pool.data!.start_key;

Expand All @@ -45,8 +47,10 @@ export async function isDataAvailable(this: Validator): Promise<boolean> {

return true;
} catch (err) {
this.logger.warn(`Data not available for next key. Retrying in 60s ...`);
this.logger.debug(standardizeError(err));
this.logger.warn(
`Data not available for next key ${nextKey}. Retrying in 60s ...`
);
this.logger.warn(standardizeError(err));

return false;
}
Expand Down
3 changes: 3 additions & 0 deletions common/protocol/src/methods/checks/isPoolActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export function isPoolActive(this: Validator): boolean {
case PoolStatus.POOL_STATUS_UNSPECIFIED:
this.logger.info("Pool status is currently unspecified. Idling ...");
return false;
case PoolStatus.POOL_STATUS_END_KEY_REACHED:
this.logger.info("End key reached. Idling ...");
return false;
default:
this.logger.info("Pool status is currently unknown. Idling ...");
return false;
Expand Down
14 changes: 9 additions & 5 deletions common/protocol/src/methods/main/runCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export async function runCache(this: Validator): Promise<void> {
this.m.cache_index_tail.set(Math.max(0, currentIndex - 1));

for (let i = currentIndex; i < targetIndex; i++) {
// if the end key is not empty and we have reached the end key of the pool
// we do not sync past this key
if (this.pool.data?.end_key && this.pool.data.end_key === key) {
this.logger.info(
`Reached pool end key "${key}", the node will not continue collecting data past this key.`
);
break;
}

// check if data item was already collected. If it was
// already collected we don't need to retrieve it again
this.logger.debug(`this.cacheProvider.exists(${i.toString()})`);
Expand Down Expand Up @@ -223,11 +232,6 @@ export async function runCache(this: Validator): Promise<void> {
key = nextKey;
}

// indicate that current caching round is done
this.logger.debug(
`Finished caching from index ${currentIndex} to ${targetIndex}. Waiting for next round ...`
);

// wait until a new bundle proposal is available. We don't need
// to sync the pool here because the pool state already gets
// synced in the other main function "runNode" so we only listen
Expand Down
6 changes: 6 additions & 0 deletions common/protocol/src/methods/main/runNode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PoolStatus } from "@kyvejs/types/lcd/kyve/pool/v1beta1/pool";
import { Validator } from "../..";
import { IDLE_TIME, sleep } from "../../utils";

Expand Down Expand Up @@ -33,6 +34,11 @@ export async function runNode(this: Validator): Promise<void> {
process.exit(1);
}

if (this.pool.status === PoolStatus.POOL_STATUS_END_KEY_REACHED) {
this.logger.info(`Reached pool end key. Shutting down node ...`);
process.exit(0);
}

// log warnings if storage provider balance is low
await this.isStorageBalanceLow();

Expand Down
13 changes: 13 additions & 0 deletions common/protocol/src/methods/validate/validateBundleProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ export async function validateBundleProposal(
// validate each data item in bundle with custom runtime validation
for (let i = 0; i < proposedBundle.length; i++) {
if (valid) {
// if the pool has an end key and we find out that a data item
// has the end key and it is not the last data item in the bundle
// we consider the bundle invalid
if (this.pool.data?.end_key) {
if (
i < proposedBundle.length - 1 &&
proposedBundle[i].key === this.pool.data?.end_key
) {
valid = false;
break;
}
}

this.logger.debug(
`this.runtime.validateDataItem($THIS, $PROPOSED_DATA_ITEM, $VALIDATION_DATA_ITEM)`
);
Expand Down
Loading

0 comments on commit 7c19318

Please sign in to comment.