Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed the custom ip address logic and '@hashgraph/proto' #518

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading