From 1fb3c892d92b6256465e52706f142ff1d0b2d3c4 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 17:00:17 -0600 Subject: [PATCH 01/10] localContent returns '0x' when not found --- packages/cli/src/rpc/modules/portal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 5518f87e7..1b2d3c353 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -358,7 +358,7 @@ export class portal { const res = await this._history.findContentLocally(fromHexString(contentKey)) this.logger.extend(`historyLocalContent`)(`request returned ${res.length} bytes`) this.logger.extend(`historyLocalContent`)(`${toHexString(res)}`) - return res.length > 0 ? toHexString(res) : undefined + return res.length > 0 ? toHexString(res) : '0x' } async historyFindContent(params: [string, string]) { const [enr, contentKey] = params From 31c78037be5912b0a32c7aa34cd37751fd5d38fa Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 18:24:53 -0600 Subject: [PATCH 02/10] switch getEnr param to byte array --- packages/cli/src/rpc/modules/portal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 1b2d3c353..d952d269e 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -69,7 +69,7 @@ export class portal { this.historyLookupEnr = middleware(this.historyLookupEnr.bind(this), 1, [[validators.hex]]) this.historyAddBootNode = middleware(this.historyAddBootNode.bind(this), 1, [[validators.enr]]) this.historyAddEnr = middleware(this.historyAddEnr.bind(this), 1, [[validators.enr]]) - this.historyGetEnr = middleware(this.historyGetEnr.bind(this), 1, [[validators.hex]]) + this.historyGetEnr = middleware(this.historyGetEnr.bind(this), 1, [[validators.dstId]]) this.historyDeleteEnr = middleware(this.historyDeleteEnr.bind(this), 1, [[validators.hex]]) this.historyAddEnrs = middleware(this.historyAddEnrs.bind(this), 1, [ [validators.array(validators.enr)], From 4c414b069afb97d41aca0521efda8f97ba3ff966 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 19:40:13 -0600 Subject: [PATCH 03/10] fix getEnr param --- packages/cli/src/rpc/modules/portal.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index d952d269e..a16d7e90d 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -177,11 +177,14 @@ export class portal { } async historyGetEnr(params: [string]): Promise { const [nodeId] = params - this.logger(`portal_historyGetEnr request received for ${nodeId.slice(0, 10)}...`) - const enr = this._history.routingTable.getWithPending(nodeId.slice(2))?.value + this.logger.extend('portal_historyGetEnr')(` request received for ${nodeId.slice(0, 10)}...`) + const enr = this._history.routingTable.getWithPending(nodeId)?.value if (enr) { - return enr.encodeTxt() + const enrTxt = enr.encodeTxt() + this.logger.extend('portal_historyGetEnr')(enrTxt) + return enrTxt } + this.logger.extend('portal_historyGetEnr')('ENR not found') return '' } From d42060ef1f0183d3a5ecbbb3e4a3045f009d800e Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 19:49:51 -0600 Subject: [PATCH 04/10] return self enr if asked --- packages/cli/src/rpc/modules/portal.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index a16d7e90d..34b6622ef 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -177,6 +177,9 @@ export class portal { } async historyGetEnr(params: [string]): Promise { const [nodeId] = params + if (nodeId === this._client.discv5.enr.nodeId) { + return this._client.discv5.enr.encodeTxt() + } this.logger.extend('portal_historyGetEnr')(` request received for ${nodeId.slice(0, 10)}...`) const enr = this._history.routingTable.getWithPending(nodeId)?.value if (enr) { From f3d922b7274d3ee77a48118ee60d816c0c15b947 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 19:52:20 -0600 Subject: [PATCH 05/10] switch deleteEnr param to nodeID --- packages/cli/src/rpc/modules/portal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 34b6622ef..9dd91e156 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -70,7 +70,7 @@ export class portal { this.historyAddBootNode = middleware(this.historyAddBootNode.bind(this), 1, [[validators.enr]]) this.historyAddEnr = middleware(this.historyAddEnr.bind(this), 1, [[validators.enr]]) this.historyGetEnr = middleware(this.historyGetEnr.bind(this), 1, [[validators.dstId]]) - this.historyDeleteEnr = middleware(this.historyDeleteEnr.bind(this), 1, [[validators.hex]]) + this.historyDeleteEnr = middleware(this.historyDeleteEnr.bind(this), 1, [[validators.dstId]]) this.historyAddEnrs = middleware(this.historyAddEnrs.bind(this), 1, [ [validators.array(validators.enr)], ]) From 949c4c12fd86f2e7179640cfb4f0034d1a775c50 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 19:58:43 -0600 Subject: [PATCH 06/10] switch param for LookupENR to nodeID --- packages/cli/src/rpc/modules/portal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 9dd91e156..3c519921a 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -66,7 +66,7 @@ export class portal { this.methods = middleware(this.methods.bind(this), 0, []) this.historyNodeInfo = middleware(this.historyNodeInfo.bind(this), 0, []) this.historyRoutingTableInfo = middleware(this.historyRoutingTableInfo.bind(this), 0, []) - this.historyLookupEnr = middleware(this.historyLookupEnr.bind(this), 1, [[validators.hex]]) + this.historyLookupEnr = middleware(this.historyLookupEnr.bind(this), 1, [[validators.dstId]]) this.historyAddBootNode = middleware(this.historyAddBootNode.bind(this), 1, [[validators.enr]]) this.historyAddEnr = middleware(this.historyAddEnr.bind(this), 1, [[validators.enr]]) this.historyGetEnr = middleware(this.historyGetEnr.bind(this), 1, [[validators.dstId]]) From cb4a4bc2401581695c1412b1a68e60e9bec49003 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 20:02:30 -0600 Subject: [PATCH 07/10] remove slice from nodeID --- packages/cli/src/rpc/modules/portal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 3c519921a..6a817470c 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -233,7 +233,7 @@ export class portal { async historyLookupEnr(params: [string]) { const [nodeId] = params this.logger(`Looking up ENR for NodeId: ${shortId(nodeId)}`) - const enr = this._history.routingTable.getWithPending(nodeId.slice(2))?.value.encodeTxt() + const enr = this._history.routingTable.getWithPending(nodeId)?.value.encodeTxt() this.logger(`Found: ${enr}`) return enr ?? '' } From 1622a29870b4f0f2f912d800f8213fdd739293aa Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 22:11:57 -0600 Subject: [PATCH 08/10] return self ENR if asked --- packages/cli/src/rpc/modules/portal.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 6a817470c..88f7e8cbd 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -232,6 +232,9 @@ export class portal { } async historyLookupEnr(params: [string]) { const [nodeId] = params + if (nodeId === this._client.discv5.enr.nodeId) { + return this._client.discv5.enr.encodeTxt() + } this.logger(`Looking up ENR for NodeId: ${shortId(nodeId)}`) const enr = this._history.routingTable.getWithPending(nodeId)?.value.encodeTxt() this.logger(`Found: ${enr}`) From 0efa288587bc0adfd8775275086ea1b08c8113e0 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 22:15:09 -0600 Subject: [PATCH 09/10] remove slice from deleteENR --- packages/cli/src/rpc/modules/portal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/rpc/modules/portal.ts b/packages/cli/src/rpc/modules/portal.ts index 88f7e8cbd..2d03c498d 100644 --- a/packages/cli/src/rpc/modules/portal.ts +++ b/packages/cli/src/rpc/modules/portal.ts @@ -207,9 +207,9 @@ export class portal { } } async historyDeleteEnr(params: [string]): Promise { - this.logger(`portal_historyDeleteEnr request received.`) const [nodeId] = params - const remove = this._history.routingTable.removeById(nodeId.slice(2)) + this.logger(`portal_historyDeleteEnr request received for ${nodeId.slice(0, 10)}...`) + const remove = this._history.routingTable.removeById(nodeId) return remove !== undefined } async historyRoutingTableInfo(_params: []): Promise { From 7b2f2f764d476dae35a5b564fd78b425bfc4db1d Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Fri, 11 Aug 2023 22:23:13 -0600 Subject: [PATCH 10/10] let validator strip 0x if received --- packages/cli/src/rpc/validators.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/cli/src/rpc/validators.ts b/packages/cli/src/rpc/validators.ts index a9449a5de..f913b750a 100644 --- a/packages/cli/src/rpc/validators.ts +++ b/packages/cli/src/rpc/validators.ts @@ -115,10 +115,7 @@ export const validators = { } } if (params[index].startsWith('0x')) { - return { - code: INVALID_PARAMS, - message: `invalid argument ${index}: NodeId should be without 0x prefix`, - } + params[index] = params[index].slice(2) } } },