Skip to content

Commit

Permalink
fix node update invalid account issue
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
jeromy-cannon committed Nov 22, 2024
1 parent 98a031a commit d65f89b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
27 changes: 14 additions & 13 deletions src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1090,37 +1090,37 @@ export class NodeCommandTasks {
}

sendNodeUpdateTransaction () {
const self = this
return new Task('Send node update transaction', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
const config: NodeUpdateConfigClass = ctx.config

const nodeId = Templates.nodeIdFromNodeAlias(config.nodeAlias) - 1
this.logger.info(`nodeId: ${nodeId}`)
this.logger.info(`config.newAccountNumber: ${config.newAccountNumber}`)
self.logger.info(`nodeId: ${nodeId}, config.newAccountNumber: ${config.newAccountNumber}`)

try {
const nodeUpdateTx = new NodeUpdateTransaction().setNodeId(nodeId)

if (config.tlsPublicKey && config.tlsPrivateKey) {
this.logger.info(`config.tlsPublicKey: ${config.tlsPublicKey}`)
const tlsCertDer = this._loadPermCertificate(config.tlsPublicKey)
self.logger.info(`config.tlsPublicKey: ${config.tlsPublicKey}`)
const tlsCertDer = self._loadPermCertificate(config.tlsPublicKey)
const tlsCertHash = crypto.createHash('sha384').update(tlsCertDer).digest()
nodeUpdateTx.setCertificateHash(tlsCertHash)

const publicKeyFile = Templates.renderTLSPemPublicKeyFile(config.nodeAlias)
const privateKeyFile = Templates.renderTLSPemPrivateKeyFile(config.nodeAlias)
renameAndCopyFile(config.tlsPublicKey, publicKeyFile, config.keysDir, this.logger)
renameAndCopyFile(config.tlsPrivateKey, privateKeyFile, config.keysDir, this.logger)
renameAndCopyFile(config.tlsPublicKey, publicKeyFile, config.keysDir, self.logger)
renameAndCopyFile(config.tlsPrivateKey, privateKeyFile, config.keysDir, self.logger)
}

if (config.gossipPublicKey && config.gossipPrivateKey) {
this.logger.info(`config.gossipPublicKey: ${config.gossipPublicKey}`)
const signingCertDer = this._loadPermCertificate(config.gossipPublicKey)
self.logger.info(`config.gossipPublicKey: ${config.gossipPublicKey}`)
const signingCertDer = self._loadPermCertificate(config.gossipPublicKey)
nodeUpdateTx.setGossipCaCertificate(signingCertDer)

const publicKeyFile = Templates.renderGossipPemPublicKeyFile(config.nodeAlias)
const privateKeyFile = Templates.renderGossipPemPrivateKeyFile(config.nodeAlias)
renameAndCopyFile(config.gossipPublicKey, publicKeyFile, config.keysDir, this.logger)
renameAndCopyFile(config.gossipPrivateKey, privateKeyFile, config.keysDir, this.logger)
renameAndCopyFile(config.gossipPublicKey, publicKeyFile, config.keysDir, self.logger)
renameAndCopyFile(config.gossipPrivateKey, privateKeyFile, config.keysDir, self.logger)
}

if (config.newAccountNumber) {
Expand All @@ -1141,10 +1141,11 @@ export class NodeCommandTasks {
const signedTx = await nodeUpdateTx.sign(config.adminKey)
const txResp = await signedTx.execute(config.nodeClient)
const nodeUpdateReceipt = await txResp.getReceipt(config.nodeClient)
this.logger.debug(`NodeUpdateReceipt: ${nodeUpdateReceipt.toString()}`)
self.logger.debug(`NodeUpdateReceipt: ${nodeUpdateReceipt.toString()}`)
await self.accountManager.refreshNodeClient(config.namespace, config.nodeAlias)
} catch (e) {
this.logger.error(`Error updating node to network: ${e.message}`, e)
this.logger.error(e.stack)
self.logger.error(`Error updating node to network: ${e.message}`, e)
self.logger.error(e.stack)
throw new SoloError(`Error updating node to network: ${e.message}`, e)
}
})
Expand Down
10 changes: 5 additions & 5 deletions src/core/account_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ export class AccountManager {
/**
* loads and initializes the Node Client
* @param namespace - the namespace of the network
* @param skipNodeAlias - the node alias to skip
*/
async refreshNodeClient (namespace: string) {
async refreshNodeClient (namespace: string, skipNodeAlias? : NodeAlias) {
await this.close()
const treasuryAccountInfo = await this.getTreasuryAccountKeys(namespace)
const networkNodeServicesMap = await this.getNodeServiceMap(namespace)

this._nodeClient = await this._getNodeClient(namespace,
networkNodeServicesMap, treasuryAccountInfo.accountId, treasuryAccountInfo.privateKey)
networkNodeServicesMap, treasuryAccountInfo.accountId, treasuryAccountInfo.privateKey, skipNodeAlias)
}

/**
Expand Down Expand Up @@ -216,14 +217,13 @@ export class AccountManager {
* @param operatorKey - the private key of the operator of the transactions
* @returns a node client that can be used to call transactions
*/
async _getNodeClient (namespace: string, networkNodeServicesMap: Map<string, NetworkNodeServices>, operatorId: string,
operatorKey: string) {
async _getNodeClient (namespace: string, networkNodeServicesMap: Map<string, NetworkNodeServices>, operatorId: string, operatorKey: string, skipNodeAlias: string) {
let nodes = {}
try {
let localPort = constants.LOCAL_NODE_START_PORT

for (const networkNodeService of networkNodeServicesMap.values()) {
if (networkNodeService.accountId !== IGNORED_NODE_ACCOUNT_ID) {
if (networkNodeService.accountId !== IGNORED_NODE_ACCOUNT_ID && networkNodeService.nodeAlias !== skipNodeAlias) {
const addlNode = await this.configureNodeAccess(networkNodeService, localPort, networkNodeServicesMap.size)
nodes = { ...nodes, ...addlNode }
localPort++
Expand Down

0 comments on commit d65f89b

Please sign in to comment.