Skip to content

Commit 863f594

Browse files
committed
chore: fixed the previous version to match design proposal.
Signed-off-by: Aditya Arya <arya050411@gmail.com>
1 parent d91de45 commit 863f594

14 files changed

+179
-336
lines changed

src/sdk/main/include/Client.h

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -350,42 +350,23 @@ class Client
350350
[[nodiscard]] bool isAutoValidateChecksumsEnabled() const;
351351

352352
/**
353-
* Set whether receipt queries may fail over to other nodes when the submitting node is unavailable.
353+
* Set whether receipt and record queries may fail over to other nodes when the submitting node is unavailable.
354354
* When enabled, queries still start with the submitting node and advance
355355
* to other eligible nodes in deterministic order only on failure. When
356356
* disabled (default), strict single-node pinning is preserved.
357357
*
358-
* @param allow \c true to allow receipt query failover to other nodes.
359-
* @return A reference to this Client with the newly-set receipt failover policy.
358+
* @param allow \c true to allow receipt/record query failover to other nodes.
359+
* @return A reference to this Client with the newly-set failover policy.
360360
*/
361361
Client& setAllowReceiptNodeFailover(bool allow);
362362

363363
/**
364-
* Is receipt query node failover allowed for this Client?
364+
* Is receipt/record query node failover allowed for this Client?
365365
*
366-
* @return \c TRUE if node failover is allowed for receipt queries, otherwise \c FALSE.
366+
* @return \c TRUE if node failover is allowed for receipt/record queries, otherwise \c FALSE.
367367
*/
368368
[[nodiscard]] bool getAllowReceiptNodeFailover() const;
369369

370-
/**
371-
* Set whether record queries may fail over to other nodes when the submitting node is unavailable.
372-
* When enabled, queries still start with the submitting node and advance
373-
* to other eligible nodes in deterministic order only on failure. When
374-
* disabled (default), strict single-node pinning is
375-
* preserved.
376-
*
377-
* @param allow \c true to allow record query failover to other nodes.
378-
* @return A reference to this Client with the newly-set record failover policy.
379-
*/
380-
Client& setAllowRecordNodeFailover(bool allow);
381-
382-
/**
383-
* Is record query node failover allowed for this Client?
384-
*
385-
* @return \c TRUE if node failover is allowed for record queries, otherwise \c FALSE.
386-
*/
387-
[[nodiscard]] bool getAllowRecordNodeFailover() const;
388-
389370
/**
390371
* Replace the network being used by this Client with nodes contained in an address book.
391372
*

src/sdk/main/include/Query.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@ class Query : public Executable<SdkRequestType, proto::Query, proto::Response, S
180180
*/
181181
[[nodiscard]] bool isCostQuery() const;
182182

183-
/**
184-
* Derived from Executable. Perform any needed actions for this Query when it is being submitted.
185-
* Protected so that derived query classes (e.g. TransactionReceiptQuery) can call back into it
186-
* after performing their own pre-execution setup.
187-
*
188-
* @param client The Client being used to submit this Query.
189-
*/
190-
void onExecute(const Client& client) override;
191-
192183
private:
193184
/**
194185
* Build a Query protobuf object with this Query's data, with the input QueryHeader protobuf object.
@@ -231,6 +222,13 @@ class Query : public Executable<SdkRequestType, proto::Query, proto::Response, S
231222
*/
232223
[[nodiscard]] Status mapResponseStatus(const proto::Response& response) const override;
233224

225+
/**
226+
* Derived from Executable. Perform any needed actions for this Query when it is being submitted.
227+
*
228+
* @param client The Client being used to submit this Query.
229+
*/
230+
void onExecute(const Client& client) override;
231+
234232
/**
235233
* Derived from Executable. Get the ID of the payment transaction for this Query.
236234
*

src/sdk/main/include/TransactionReceiptQuery.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef HIERO_SDK_CPP_TRANSACTION_RECEIPT_QUERY_H_
33
#define HIERO_SDK_CPP_TRANSACTION_RECEIPT_QUERY_H_
44

5-
#include "AccountId.h"
65
#include "Query.h"
76
#include "TransactionId.h"
87

@@ -75,16 +74,6 @@ class TransactionReceiptQuery : public Query<TransactionReceiptQuery, Transactio
7574
*/
7675
[[nodiscard]] inline bool getIncludeDuplicates() const { return mIncludeDuplicates; }
7776

78-
/**
79-
* Set the account ID of the node that originally submitted the transaction. When the failover flag
80-
* is enabled on the Client, this node will be tried first and others will follow in deterministic
81-
* order on failure. When the flag is disabled (default), only this node will be targeted.
82-
*
83-
* @param nodeId The account ID of the submitting node.
84-
* @return A reference to this TransactionReceiptQuery object with the newly-set submitting node ID.
85-
*/
86-
TransactionReceiptQuery& setSubmittingNodeId(const AccountId& nodeId);
87-
8877
private:
8978
/**
9079
* Derived from Executable. Construct a TransactionReceipt object from a Response protobuf object.
@@ -156,14 +145,6 @@ class TransactionReceiptQuery : public Query<TransactionReceiptQuery, Transactio
156145
*/
157146
[[nodiscard]] inline bool isPaymentRequired() const override { return false; }
158147

159-
/**
160-
* Derived from Query. Populate node account IDs based on the submitting node and client failover
161-
* settings, then delegate the rest of pre-execution setup to the base Query.
162-
*
163-
* @param client The Client that will execute this query.
164-
*/
165-
void onExecute(const Client& client) override;
166-
167148
/**
168149
* The ID of the transaction of which this query should get the receipt.
169150
*/
@@ -178,12 +159,6 @@ class TransactionReceiptQuery : public Query<TransactionReceiptQuery, Transactio
178159
* Should the receipts of any duplicates transactions be retrieved as well?
179160
*/
180161
bool mIncludeDuplicates = false;
181-
182-
/**
183-
* The account ID of the node that originally submitted the transaction. Used to implement
184-
* submitting-node-first ordering when failover is enabled.
185-
*/
186-
std::optional<AccountId> mSubmittingNodeId;
187162
};
188163

189164
} // namespace Hiero

src/sdk/main/include/TransactionRecordQuery.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef HIERO_SDK_CPP_TRANSACTION_RECORD_QUERY_H_
33
#define HIERO_SDK_CPP_TRANSACTION_RECORD_QUERY_H_
44

5-
#include "AccountId.h"
65
#include "Query.h"
76
#include "TransactionId.h"
87

@@ -77,16 +76,6 @@ class TransactionRecordQuery : public Query<TransactionRecordQuery, TransactionR
7776
*/
7877
[[nodiscard]] inline bool getIncludeDuplicates() const { return mIncludeDuplicates; }
7978

80-
/**
81-
* Set the account ID of the node that originally submitted the transaction. When the failover flag
82-
* is enabled on the Client, this node will be tried first and others will follow in deterministic
83-
* order on failure. When the flag is disabled (default), only this node will be targeted.
84-
*
85-
* @param nodeId The account ID of the submitting node.
86-
* @return A reference to this TransactionRecordQuery object with the newly-set submitting node ID.
87-
*/
88-
TransactionRecordQuery& setSubmittingNodeId(const AccountId& nodeId);
89-
9079
private:
9180
/**
9281
* Derived from Executable. Construct a TransactionRecord object from a Response protobuf object.
@@ -150,14 +139,6 @@ class TransactionRecordQuery : public Query<TransactionRecordQuery, TransactionR
150139
*/
151140
[[nodiscard]] proto::ResponseHeader mapResponseHeader(const proto::Response& response) const override;
152141

153-
/**
154-
* Derived from Query. Populate node account IDs based on the submitting node and client failover
155-
* settings, then delegate the rest of pre-execution setup to the base Query.
156-
*
157-
* @param client The Client that will execute this query.
158-
*/
159-
void onExecute(const Client& client) override;
160-
161142
/**
162143
* The ID of the transaction of which this query should get the record.
163144
*/
@@ -172,12 +153,6 @@ class TransactionRecordQuery : public Query<TransactionRecordQuery, TransactionR
172153
* Should the records of any duplicates transactions be retrieved as well?
173154
*/
174155
bool mIncludeDuplicates = false;
175-
176-
/**
177-
* The account ID of the node that originally submitted the transaction. Used to implement
178-
* submitting-node-first ordering when failover is enabled.
179-
*/
180-
std::optional<AccountId> mSubmittingNodeId;
181156
};
182157

183158
} // namespace Hiero

src/sdk/main/include/TransactionResponse.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ class TransactionResponse
4040
* @param nodeId The ID of the node account to which this TransactionResponse's corresponding Transaction was sent.
4141
* @param transactionId The ID of this TransactionResponse's corresponding Transaction.
4242
* @param hash The hash of this TransactionResponse's corresponding Transaction.
43+
* @param transactionNodeAccountIds The list of node account IDs configured on the transaction at execution time.
4344
*/
44-
TransactionResponse(AccountId nodeId, TransactionId transactionId, std::vector<std::byte> hash);
45+
TransactionResponse(AccountId nodeId,
46+
TransactionId transactionId,
47+
std::vector<std::byte> hash,
48+
std::vector<AccountId> transactionNodeAccountIds);
4549

4650
/**
4751
* Get a TransactionReceipt for this TransactionResponse's corresponding Transaction.
@@ -74,10 +78,16 @@ class TransactionResponse
7478

7579
/**
7680
* Construct a TransactionReceiptQuery for this TransactionResponse's corresponding Transaction.
81+
* When a non-null Client is provided and its failover flag is
82+
* enabled, the query will target the submitting node first, then
83+
* other eligible nodes in deterministic order.
7784
*
85+
* @param client Optional pointer to the Client. When null or
86+
* failover is disabled, the query is pinned to the submitting
87+
* node only.
7888
* @return The constructed TransactionReceiptQuery.
7989
*/
80-
[[nodiscard]] TransactionReceiptQuery getReceiptQuery() const;
90+
[[nodiscard]] TransactionReceiptQuery getReceiptQuery(const Client* client = nullptr) const;
8191

8292
/**
8393
* Get a TransactionReceipt for this TransactionResponse's corresponding Transaction asynchronously.
@@ -214,10 +224,14 @@ class TransactionResponse
214224

215225
/**
216226
* Construct a TransactionRecordQuery for this TransactionResponse's corresponding Transaction.
227+
* When a non-null Client is provided and its failover flag is enabled, the query will target
228+
* the submitting node first, then other eligible nodes in deterministic order.
217229
*
230+
* @param client Optional pointer to the Client. When null or failover is disabled, the query is
231+
* pinned to the submitting node only.
218232
* @return The constructed TransactionRecordQuery.
219233
*/
220-
[[nodiscard]] TransactionRecordQuery getRecordQuery() const;
234+
[[nodiscard]] TransactionRecordQuery getRecordQuery(const Client* client = nullptr) const;
221235

222236
/**
223237
* Get a TransactionRecord for this TransactionResponse's corresponding Transaction asynchronously.
@@ -373,6 +387,11 @@ class TransactionResponse
373387
*/
374388
TransactionId mTransactionId;
375389

390+
/**
391+
* The node account IDs that were configured on the transaction during execution.
392+
*/
393+
std::vector<AccountId> mTransactionNodeAccountIds;
394+
376395
private:
377396
/**
378397
* Did this TransactionResponse's corresponding Transaction have a successful pre-check?

src/sdk/main/src/Client.cc

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,11 @@ struct Client::ClientImpl
9696
// Should this Client automatically validate entity checksums?
9797
bool mAutoValidateChecksums = false;
9898

99-
// Should this Client allow receipt queries to fail over to other nodes when the submitting node
100-
// is unavailable? When true, queries start with the submitting node and advance to others on
99+
// Should this Client allow receipt/record queries to fail over to other nodes when the submitting
100+
// node is unavailable? When true, queries start with the submitting node and advance to others on
101101
// failure. Defaults to false (strict single-node pinning).
102102
bool mAllowReceiptNodeFailover = false;
103103

104-
// Should this Client allow record queries to fail over to other nodes when the submitting node
105-
// is unavailable? When true, queries start with the submitting node and advance to others on
106-
// failure. Defaults to false (strict single-node pinning).
107-
bool mAllowRecordNodeFailover = false;
108-
109104
// Has this Client made its initial network update? This is utilized in case
110105
// the user updates the network update period before the initial update is
111106
// made, as it prevents the update period from being overwritten.
@@ -696,21 +691,6 @@ bool Client::getAllowReceiptNodeFailover() const
696691
return mImpl->mAllowReceiptNodeFailover;
697692
}
698693

699-
//-----
700-
Client& Client::setAllowRecordNodeFailover(bool allow)
701-
{
702-
std::unique_lock lock(mImpl->mMutex);
703-
mImpl->mAllowRecordNodeFailover = allow;
704-
return *this;
705-
}
706-
707-
//-----
708-
bool Client::getAllowRecordNodeFailover() const
709-
{
710-
std::unique_lock lock(mImpl->mMutex);
711-
return mImpl->mAllowRecordNodeFailover;
712-
}
713-
714694
//-----
715695
Client& Client::setNetworkFromAddressBook(const NodeAddressBook& addressBook)
716696
{

src/sdk/main/src/Transaction.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,15 +1262,15 @@ TransactionId Transaction<SdkRequestType>::getCurrentTransactionId() const
12621262
template<typename SdkRequestType>
12631263
TransactionResponse Transaction<SdkRequestType>::mapResponse(const proto::TransactionResponse&) const
12641264
{
1265-
return TransactionResponse(
1266-
Executable<SdkRequestType, proto::Transaction, proto::TransactionResponse, TransactionResponse>::getNodeAccountIds()
1267-
.at(mImpl->mTransactionIndex %
1268-
Executable<SdkRequestType, proto::Transaction, proto::TransactionResponse, TransactionResponse>::
1269-
getNodeAccountIds()
1270-
.size()),
1271-
getCurrentTransactionId(),
1272-
internal::OpenSSLUtils::computeSHA384(internal::Utilities::stringToByteVector(
1273-
getTransactionProtobufObject(mImpl->mTransactionIndex).signedtransactionbytes())));
1265+
const auto& nodeAccountIds =
1266+
Executable<SdkRequestType, proto::Transaction, proto::TransactionResponse, TransactionResponse>::
1267+
getNodeAccountIds();
1268+
1269+
return TransactionResponse(nodeAccountIds.at(mImpl->mTransactionIndex % nodeAccountIds.size()),
1270+
getCurrentTransactionId(),
1271+
internal::OpenSSLUtils::computeSHA384(internal::Utilities::stringToByteVector(
1272+
getTransactionProtobufObject(mImpl->mTransactionIndex).signedtransactionbytes())),
1273+
nodeAccountIds);
12741274
}
12751275

12761276
//-----

src/sdk/main/src/TransactionReceiptQuery.cc

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
22
#include "TransactionReceiptQuery.h"
3-
#include "Client.h"
43
#include "Status.h"
54
#include "TransactionReceipt.h"
65
#include "impl/Node.h"
@@ -10,9 +9,6 @@
109
#include <services/response.pb.h>
1110
#include <services/transaction_get_receipt.pb.h>
1211

13-
#include <algorithm>
14-
#include <vector>
15-
1612
namespace Hiero
1713
{
1814
//-----
@@ -22,54 +18,6 @@ TransactionReceiptQuery& TransactionReceiptQuery::setTransactionId(const Transac
2218
return *this;
2319
}
2420

25-
//-----
26-
TransactionReceiptQuery& TransactionReceiptQuery::setSubmittingNodeId(const AccountId& nodeId)
27-
{
28-
mSubmittingNodeId = nodeId;
29-
return *this;
30-
}
31-
32-
//-----
33-
void TransactionReceiptQuery::onExecute(const Client& client)
34-
{
35-
if (getNodeAccountIds().empty() && mSubmittingNodeId.has_value())
36-
{
37-
if (client.getAllowReceiptNodeFailover())
38-
{
39-
// node list -> sorted order
40-
std::vector<AccountId> otherNodes;
41-
for (const auto& [url, accountId] : client.getNetwork())
42-
{
43-
if (!(accountId == *mSubmittingNodeId))
44-
{
45-
otherNodes.push_back(accountId);
46-
}
47-
}
48-
std::sort(otherNodes.begin(),
49-
otherNodes.end(),
50-
[](const AccountId& a, const AccountId& b)
51-
{
52-
if (a.mShardNum != b.mShardNum)
53-
return a.mShardNum < b.mShardNum;
54-
if (a.mRealmNum != b.mRealmNum)
55-
return a.mRealmNum < b.mRealmNum;
56-
return a.mAccountNum.value_or(0ULL) < b.mAccountNum.value_or(0ULL);
57-
});
58-
59-
std::vector<AccountId> nodeIds = { *mSubmittingNodeId };
60-
nodeIds.insert(nodeIds.end(), otherNodes.begin(), otherNodes.end());
61-
setNodeAccountIds(nodeIds);
62-
}
63-
else
64-
{
65-
// Default: single node pinning
66-
setNodeAccountIds({ *mSubmittingNodeId });
67-
}
68-
}
69-
70-
Query<TransactionReceiptQuery, TransactionReceipt>::onExecute(client);
71-
}
72-
7321
//-----
7422
TransactionReceiptQuery& TransactionReceiptQuery::setIncludeChildren(bool children)
7523
{

0 commit comments

Comments
 (0)