Skip to content

Commit

Permalink
fix: removed the custom ip address logic and '@hashgraph/proto' (#518)
Browse files Browse the repository at this point in the history
Signed-off-by: instamenta <instamenta@abv.bg>
  • Loading branch information
instamenta authored Aug 28, 2024
1 parent f11af20 commit c81c76a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 40 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"author": "Swirlds Labs",
"license": "Apache2.0",
"dependencies": {
"@hashgraph/proto": "^2.15.0-beta.3",
"@hashgraph/sdk": "^2.50.0",
"@kubernetes/client-node": "^0.21.0",
"@listr2/prompt-adapter-enquirer": "^2.0.11",
Expand Down
39 changes: 1 addition & 38 deletions src/core/account_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*
*/
import * as HashgraphProto from '@hashgraph/proto'
import * as Base64 from 'js-base64'
import os from 'os'
import * as constants from './constants.mjs'
Expand Down Expand Up @@ -626,43 +625,7 @@ export class AccountManager {
async prepareAddressBookBase64 (namespace) {
// fetch AddressBook
const fileQuery = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK)
let addressBookBytes = await fileQuery.execute(this._nodeClient)

/** @type {Map<string, NetworkNodeServices>} **/
const networkNodeServicesMap = await this.getNodeServiceMap(namespace)

// ensure serviceEndpoint.ipAddressV4 value for all nodes in the addressBook is a 4 bytes array instead of string
// See: https://github.com/hashgraph/hedera-protobufs/blob/main/services/basic_types.proto#L1309
// TODO: with v0.53 will mirror node no longer need this and we can remove @hashgraph/proto: https://github.com/hashgraph/solo/issues/493
const addressBook = HashgraphProto.proto.NodeAddressBook.decode(addressBookBytes)
const hasAlphaRegEx = /[a-zA-Z]+/
let modified = false
for (const nodeAddress of addressBook.nodeAddress) {
const address = nodeAddress.serviceEndpoint[0].ipAddressV4.toString()

if (hasAlphaRegEx.test(address)) {
const nodeId = Templates.nodeIdFromFullyQualifiedNetworkSvcName(address)
nodeAddress.serviceEndpoint[0].ipAddressV4 = Uint8Array.from(ip.toBuffer(networkNodeServicesMap.get(nodeId).nodeServiceClusterIp))
nodeAddress.ipAddress = Uint8Array.from(ip.toBuffer(networkNodeServicesMap.get(nodeId).nodeServiceClusterIp))
modified = true
continue
}
// overwrite ipAddressV4 as 4 bytes array if required, unless there is alpha, which means it is a domain name
if (nodeAddress.serviceEndpoint[0].ipAddressV4.byteLength !== 4) {
const parts = address.split('.')

if (parts.length !== 4) {
throw new FullstackTestingError(`expected node IP address to have 4 parts, found ${parts.length}: ${address}`)
}

nodeAddress.serviceEndpoint[0].ipAddressV4 = Uint8Array.from(parts)
modified = true
}
}

if (modified) {
addressBookBytes = HashgraphProto.proto.NodeAddressBook.encode(addressBook).finish()
}
const addressBookBytes = await fileQuery.execute(this._nodeClient)

// convert addressBook into base64
return Base64.encode(addressBookBytes)
Expand Down

0 comments on commit c81c76a

Please sign in to comment.