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: use one of preselected nodes to execute the transaction #2165

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
11 changes: 4 additions & 7 deletions src/Executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,13 @@ export default class Executable {
let nodeAccountId;
let node;

// If node account IDs is locked then use the node account IDs
// from the list, otherwise build a new list of one node account ID
// using the entire network
if (this._nodeAccountIds.locked) {
nodeAccountId = this._nodeAccountIds.current;
node = client._network.getNode(nodeAccountId);
} else {
if (this._nodeAccountIds.isEmpty) {
node = client._network.getNode();
nodeAccountId = node.accountId;
this._nodeAccountIds.setList([nodeAccountId]);
} else {
nodeAccountId = this._nodeAccountIds.current;
node = client._network.getNode(nodeAccountId);
}

if (node == null) {
Expand Down
8 changes: 6 additions & 2 deletions src/client/ManagedNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ export default class ManagedNetwork {

// Add the selected node in array for execution
nodes.push(selectedNode);
// Remove the selected node from array
healthyNodes.splice(nodeIndex, 1);
// Remove all nodes with the same account id as
// the selected node account id from the array
healthyNodes = healthyNodes.filter(
// eslint-disable-next-line ie11/no-loop-func
(node) => node.getKey() !== selectedNode.getKey(),
);
}

return nodes;
Expand Down
16 changes: 9 additions & 7 deletions src/transaction/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,14 @@ export default class Transaction extends Executable {
// be regenerated if more signatures are added
transaction._transactions.setList(transactions);

// Set the signed transactions accordingly, and lock the list since signed transaction
// will not be regenerated. Although, they can be manipulated if for instance more
// signatures are added
// Set the signed transactions accordingly. Although, they
// can be manipulated if for instance more signatures are added
transaction._signedTransactions.setList(signedTransactions);

// Set the transaction IDs accordingly, and lock the list. Transaction IDs should not
// be regenerated if we're deserializing a request from bytes
// Set the transaction IDs accordingly
transaction._transactionIds.setList(transactionIds);

// Set the node account IDs accordingly, and lock the list. Node account IDs should
// never be changed if we're deserializing a request from bytes
// Set the node account IDs accordingly
transaction._nodeAccountIds.setList(nodeIds);

// Make sure to update the rest of the fields
Expand Down Expand Up @@ -701,6 +698,11 @@ export default class Transaction extends Executable {
* @returns {Promise<this>}
*/
async signWith(publicKey, transactionSigner) {
// If signing on demand is disabled, we need to make sure
// the request is frozen
if (!this._signOnDemand) {
this._requireFrozen();
}
const publicKeyData = publicKey.toBytesRaw();

// note: this omits the DER prefix on purpose because Hedera doesn't
Expand Down