Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 4b08dc7

Browse files
committed
fix(core): Limit the maximun response fetch by tag
Querying 'find_transasction_obj_by_tag' with a tag which has huge amount of relating transactions would cause cclient failed to deserialize the response. Now, tangle-accelerator would respond 100 transaction objects in maximum. This limitation refers to the implementation of TheTangle. Closes #656 Fixes #652
1 parent 9b00d70 commit 4b08dc7

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

accelerator/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern "C" {
6363
#define DONE_LIST_NAME "done_txn_buff_list"
6464
#define CACHE_MAX_CAPACITY 170 * 1024 * 1024 // default to 170MB
6565
#define HEALTH_TRACK_PERIOD 1800 // Check every half hour in default
66+
#define RESULT_SET_LIMIT 100 // The maximun returned transaction object number when querying transaction object by tag
6667

6768
/** @name Redis connection config */
6869
/** @{ */

accelerator/core/apis.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ status_t api_find_transaction_objects(const iota_client_service_t* const service
7878
goto done;
7979
}
8080

81+
// Limit the returned transaction objects less equal than 'RESULT_SET_LIMIT'
82+
while (hash243_queue_count(req->hashes) > RESULT_SET_LIMIT) {
83+
hash243_queue_pop(&req->hashes);
84+
}
85+
8186
ret = ta_find_transaction_objects(service, req, res);
8287
if (ret) {
8388
ta_log_error("%d\n", ret);

accelerator/core/core.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ status_t ta_find_transactions_obj_by_tag(const iota_client_service_t* const serv
239239
goto done;
240240
}
241241

242-
hash243_queue_copy(&obj_req->hashes, txn_res->hashes, hash243_queue_count(txn_res->hashes));
242+
int txn_res_len = hash243_queue_count(txn_res->hashes);
243+
for (int i = 0; i < RESULT_SET_LIMIT && i < txn_res_len; i++) {
244+
hash243_queue_entry_t* tmp_queue_entry = hash243_queue_pop(&txn_res->hashes);
245+
hash243_queue_push(&obj_req->hashes, tmp_queue_entry->hash);
246+
free(tmp_queue_entry);
247+
}
243248

244249
ret = ta_find_transaction_objects(service, obj_req, res);
245250
if (ret) {

0 commit comments

Comments
 (0)