From b6d5a6add70f61d6d4453e9e2e1cfce843069515 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 5 Oct 2024 13:49:54 -0400 Subject: [PATCH 1/2] fix: ping peer message --- src/DigNetwork/PropagationServer.ts | 55 +++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/DigNetwork/PropagationServer.ts b/src/DigNetwork/PropagationServer.ts index b6e99d3..14c8e59 100644 --- a/src/DigNetwork/PropagationServer.ts +++ b/src/DigNetwork/PropagationServer.ts @@ -118,8 +118,6 @@ export class PropagationServer { * @param rootHash - The root hash for the store update. */ async pingUpdate(rootHash: string): Promise { - const spinner = createSpinner(`Pinging peer ${this.ipAddress}...`).start(); - try { const httpsAgent = this.createHttpsAgent(); const url = `https://${formatHost(this.ipAddress)}:${ @@ -131,6 +129,10 @@ export class PropagationServer { headers: { "Content-Type": "application/json", }, + validateStatus: (status) => { + // Accept all status codes to handle them manually + return true; + }, }; // Data to send in the request (storeId and rootHash) @@ -142,20 +144,53 @@ export class PropagationServer { try { const response = await axios.post(url, data, config); - console.log(green(`✔ Successfully pinged peer: ${this.ipAddress}`)); - spinner.success({ - text: green( - `✔ Successfully pinged peer ${this.ipAddress} with rootHash ${rootHash}` - ), - }); - return response.data; + + if (response.status === 200) { + console.log(green(`✔ Peer was up to date: ${this.ipAddress}`)); + return; + } else if ( + response.status === 400 && + response.data?.error?.includes("does not exist") + ) { + console.log( + yellow( + `⚠ Peer ${this.ipAddress} does not have store ${this.storeId}. Notifying for update.` + ) + ); + // You can implement additional logic here if needed, such as retrying or logging + return; + } else { + console.error( + red( + `✖ Unexpected response from peer ${this.ipAddress}: ${response.status} ${response.statusText}` + ) + ); + throw new Error( + `Unexpected response: ${response.status} ${response.statusText}` + ); + } } catch (error: any) { + if (error.response) { + // Server responded with a status other than 2xx + if ( + error.response.status === 400 && + error.response.data?.error?.includes("does not exist") + ) { + console.log( + yellow( + `⚠ Peer ${this.ipAddress} does not have store ${this.storeId}. Notifying for update.` + ) + ); + // You can implement additional logic here if needed + return; + } + } + console.error(red(`✖ Failed to ping peer: ${this.ipAddress}`)); console.error(red(error.message)); throw error; } } catch (error: any) { - spinner.error({ text: red("✖ Error pinging network peer.") }); console.error(red(error.message)); } } From 9cf650bb42f90736c0e463f24874910251fed883 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 5 Oct 2024 13:50:35 -0400 Subject: [PATCH 2/2] chore(release): 0.0.1-alpha.134 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99f2897..d956854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.134](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.133...v0.0.1-alpha.134) (2024-10-05) + + +### Bug Fixes + +* ping peer message ([b6d5a6a](https://github.com/DIG-Network/dig-chia-sdk/commit/b6d5a6add70f61d6d4453e9e2e1cfce843069515)) + ### [0.0.1-alpha.133](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.132...v0.0.1-alpha.133) (2024-10-05) diff --git a/package-lock.json b/package-lock.json index 3463c7a..2e811cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.133", + "version": "0.0.1-alpha.134", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.133", + "version": "0.0.1-alpha.134", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index 4f9f334..bcb9117 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.133", + "version": "0.0.1-alpha.134", "description": "", "type": "commonjs", "main": "./dist/index.js",