diff --git a/examples/js_client/hp-client-lib.js b/examples/js_client/hp-client-lib.js index a5d87f83..09c00f5f 100644 --- a/examples/js_client/hp-client-lib.js +++ b/examples/js_client/hp-client-lib.js @@ -806,12 +806,12 @@ throw "Max ledger seq no. or offset cannot be 0."; if (!isOffset && !maxLedger) throw "Max ledger seq. no not specified."; - if (nonce && (!Number.isInteger(nonce) || nonce < 0)) + if (nonce && (!Number.isInteger(nonce) || nonce <= 0)) throw "Input nonce must be a positive integer."; - // Use time-based incrementing nonce if not specified. + // Use epoch-based auto incrementing nonce if nonce is not specified. if (!nonce) - nonce = (new Date()).getTime(); + nonce = new Date().getTime(); // If max ledger is specified as offset, we need to get current ledger status and add the offset to it. if (isOffset) { @@ -859,7 +859,8 @@ if (connectionStatus != 2) return Promise.resolve(null); - const msg = msgHelper.createLedgerQuery("seq_no", { "seq_no": seqNo }, includeInputs, includeOutputs); + const queryParams = { "seq_no": msgHelper.serializeNumber(seqNo) }; + const msg = msgHelper.createLedgerQuery("seq_no", queryParams, includeInputs, includeOutputs); const p = new Promise(resolve => { ledgerQueryResolvers[msg.id] = { type: "seq_no", @@ -906,6 +907,12 @@ return protocol == protocols.json ? val : val.buffer; } + this.serializeNumber = (num) => { + // For standard javascript numbers, Bson library does not support serializing large numbers correctly. + // Hence we have to encode as special bson long type when using bson protocol. + return (protocol == protocols.json) ? num : bson.Long.fromNumber(num); + } + // Used for generating strings to hold values as js object keys. this.stringifyValue = (val) => { if (isString(val)) @@ -945,8 +952,8 @@ const inpContainer = { input: this.serializeInput(input), - nonce: nonce, - max_ledger_seq_no: maxLedgerSeqNo + nonce: this.serializeNumber(nonce), + max_ledger_seq_no: this.serializeNumber(maxLedgerSeqNo) } const serlializedInpContainer = this.serializeObject(inpContainer); diff --git a/src/ledger/ledger_query.cpp b/src/ledger/ledger_query.cpp index 98565ff8..2a4c0656 100644 --- a/src/ledger/ledger_query.cpp +++ b/src/ledger/ledger_query.cpp @@ -42,7 +42,7 @@ namespace ledger::query ledgers.push_back(std::move(ledger)); // Fill raw data if required. - if (seq_q.seq_no > 0 && (seq_q.inputs || seq_q.outputs)) + if (seq_q.inputs || seq_q.outputs) { for (ledger_record &ledger : ledgers) { @@ -51,7 +51,8 @@ namespace ledger::query if (seq_q.outputs) ledger.outputs = std::vector(); - if (get_ledger_raw_data(ledger, user_pubkey, fs_sess_name) != -1) + // No need to actually query raw data for genesis ledger. + if (seq_q.seq_no == 0 || get_ledger_raw_data(ledger, user_pubkey, fs_sess_name) != -1) res = ledgers; } } diff --git a/src/msg/bson/usrmsg_bson.cpp b/src/msg/bson/usrmsg_bson.cpp index 7957113f..59724452 100644 --- a/src/msg/bson/usrmsg_bson.cpp +++ b/src/msg/bson/usrmsg_bson.cpp @@ -397,11 +397,18 @@ namespace msg::usrmsg::bson return -1; } + nonce = d[msg::usrmsg::FLD_NONCE].as(); + if (nonce == 0) + { + LOG_DEBUG << "Input nonce must be a positive integer."; + return -1; + } + + max_ledger_seq_no = d[msg::usrmsg::FLD_MAX_LEDGER_SEQ_NO].as(); + const jsoncons::byte_string_view &bsv = d[msg::usrmsg::FLD_INPUT].as_byte_string_view(); input = std::string_view(reinterpret_cast(bsv.data()), bsv.size()); - nonce = d[msg::usrmsg::FLD_NONCE].as(); - max_ledger_seq_no = d[msg::usrmsg::FLD_MAX_LEDGER_SEQ_NO].as(); return 0; } diff --git a/src/msg/json/usrmsg_json.cpp b/src/msg/json/usrmsg_json.cpp index 1dde8796..e232ba22 100644 --- a/src/msg/json/usrmsg_json.cpp +++ b/src/msg/json/usrmsg_json.cpp @@ -745,8 +745,14 @@ namespace msg::usrmsg::json return -1; } - input = d[msg::usrmsg::FLD_INPUT].as(); nonce = d[msg::usrmsg::FLD_NONCE].as(); + if (nonce == 0) + { + LOG_DEBUG << "Input nonce must be a positive integer."; + return -1; + } + + input = d[msg::usrmsg::FLD_INPUT].as(); max_ledger_seq_no = d[msg::usrmsg::FLD_MAX_LEDGER_SEQ_NO].as(); return 0; diff --git a/test/local-cluster/Dockerfile b/test/local-cluster/Dockerfile index 03173f6d..9dcd76b0 100644 --- a/test/local-cluster/Dockerfile +++ b/test/local-cluster/Dockerfile @@ -20,5 +20,5 @@ COPY ./bin/hpws . ENTRYPOINT ["/hp/hpcore"] -# Run with vagrind +# Run with valgrind # ENTRYPOINT ["valgrind", "/hp/hpcore"] \ No newline at end of file diff --git a/test/metrics/metrics.js b/test/metrics/metrics.js index 2f844dcf..2eb82fd8 100644 --- a/test/metrics/metrics.js +++ b/test/metrics/metrics.js @@ -109,7 +109,7 @@ function singleUserInputOutput(payloadKB, requestCount) { timer.start(); for (let i = 0; i < requestCount; i++) { - const input = await hpc.submitContractInput(payload, i, 10); + const input = await hpc.submitContractInput(payload); input.submissionStatus.then(s => { if (s.status != "accepted") console.log(s.reason);