Skip to content

Commit 2efb4d5

Browse files
authored
Historical JS endpoints (#2285)
1 parent b54a28d commit 2efb4d5

File tree

20 files changed

+340
-119
lines changed

20 files changed

+340
-119
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Historical point query support has been added to JavaScript endpoints (#2285).
13+
14+
### Changed
15+
16+
- `"readonly"` has been replaced by `"mode"` in `app.json` in JavaScript apps (#2285).
17+
818
## [0.19.0]
919

1020
### Changed

cmake/quickjs.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ if("sgx" IN_LIST COMPILE_TARGETS)
2828
quickjs.enclave STATIC ${QUICKJS_SRC} ${CCF_DIR}/3rdparty/stub/time.c
2929
)
3030
target_compile_options(
31-
quickjs.enclave PUBLIC -nostdinc -DCONFIG_VERSION="${QUICKJS_VERSION}"
32-
-DEMSCRIPTEN -DCONFIG_STACK_CHECK
31+
quickjs.enclave
32+
PUBLIC -nostdinc -DCONFIG_VERSION="${QUICKJS_VERSION}" -DEMSCRIPTEN
33+
-DCONFIG_STACK_CHECK
34+
PRIVATE $<$<CONFIG:Debug>:-DDUMP_LEAKS>
3335
)
3436
target_link_libraries(quickjs.enclave PUBLIC ${OE_TARGET_LIBC})
3537
set_property(TARGET quickjs.enclave PROPERTY POSITION_INDEPENDENT_CODE ON)
@@ -40,7 +42,9 @@ endif()
4042

4143
add_library(quickjs.host STATIC ${QUICKJS_SRC})
4244
target_compile_options(
43-
quickjs.host PUBLIC -DCONFIG_VERSION="${QUICKJS_VERSION}"
45+
quickjs.host
46+
PUBLIC -DCONFIG_VERSION="${QUICKJS_VERSION}"
47+
PRIVATE $<$<CONFIG:Debug>:-DDUMP_LEAKS>
4448
)
4549
add_san(quickjs.host)
4650
set_property(TARGET quickjs.host PROPERTY POSITION_INDEPENDENT_CODE ON)

samples/apps/forum/app.tmpl.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
"forwarding_required": "always",
88
"execute_outside_consensus": "never",
99
"authn_policies": [],
10-
"readonly": false
10+
"mode": "readwrite"
1111
},
1212
"put": {
1313
"js_module": "build/PollControllerProxy.js",
1414
"js_function": "submitOpinion",
1515
"forwarding_required": "always",
1616
"execute_outside_consensus": "never",
1717
"authn_policies": [],
18-
"readonly": false
18+
"mode": "readwrite"
1919
},
2020
"get": {
2121
"js_module": "build/PollControllerProxy.js",
2222
"js_function": "getPoll",
2323
"forwarding_required": "always",
2424
"execute_outside_consensus": "never",
2525
"authn_policies": [],
26-
"readonly": true
26+
"mode": "readonly"
2727
}
2828
},
2929
"/polls": {
@@ -33,23 +33,23 @@
3333
"forwarding_required": "always",
3434
"execute_outside_consensus": "never",
3535
"authn_policies": [],
36-
"readonly": false
36+
"mode": "readwrite"
3737
},
3838
"put": {
3939
"js_module": "build/PollControllerProxy.js",
4040
"js_function": "submitOpinions",
4141
"forwarding_required": "always",
4242
"execute_outside_consensus": "never",
4343
"authn_policies": [],
44-
"readonly": false
44+
"mode": "readwrite"
4545
},
4646
"get": {
4747
"js_module": "build/PollControllerProxy.js",
4848
"js_function": "getPolls",
4949
"forwarding_required": "always",
5050
"execute_outside_consensus": "never",
5151
"authn_policies": [],
52-
"readonly": true
52+
"mode": "readonly"
5353
}
5454
},
5555
"/site": {
@@ -59,7 +59,7 @@
5959
"forwarding_required": "always",
6060
"execute_outside_consensus": "never",
6161
"authn_policies": [],
62-
"readonly": true
62+
"mode": "readonly"
6363
}
6464
},
6565
"/site/polls/create": {
@@ -69,7 +69,7 @@
6969
"forwarding_required": "always",
7070
"execute_outside_consensus": "never",
7171
"authn_policies": [],
72-
"readonly": true
72+
"mode": "readonly"
7373
}
7474
},
7575
"/site/opinions/submit": {
@@ -79,7 +79,7 @@
7979
"forwarding_required": "always",
8080
"execute_outside_consensus": "never",
8181
"authn_policies": [],
82-
"readonly": true
82+
"mode": "readonly"
8383
}
8484
},
8585
"/site/view": {
@@ -89,7 +89,7 @@
8989
"forwarding_required": "always",
9090
"execute_outside_consensus": "never",
9191
"authn_policies": [],
92-
"readonly": true
92+
"mode": "readonly"
9393
}
9494
},
9595
"/csv": {
@@ -99,7 +99,7 @@
9999
"forwarding_required": "always",
100100
"execute_outside_consensus": "never",
101101
"authn_policies": [],
102-
"readonly": true,
102+
"mode": "readonly",
103103
"openapi_merge_patch": {
104104
"responses": {
105105
"200": {
@@ -117,7 +117,7 @@
117117
"forwarding_required": "always",
118118
"execute_outside_consensus": "never",
119119
"authn_policies": [],
120-
"readonly": false,
120+
"mode": "readwrite",
121121
"openapi_merge_patch": {
122122
"requestBody": {
123123
"content": {

samples/apps/forum/src/types/ccf.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ export interface KVMap {
4848

4949
export type KVMaps = { [key: string]: KVMap };
5050

51+
export interface ProofElement {
52+
left?: string;
53+
right?: string;
54+
}
55+
56+
export type Proof = ProofElement[];
57+
58+
export interface Receipt {
59+
signature: string;
60+
root: string;
61+
proof: Proof;
62+
leaf: string;
63+
nodeId: string;
64+
}
65+
66+
export interface HistoricalState {
67+
transactionId: string;
68+
receipt: Receipt;
69+
}
70+
5171
interface WrapAlgoParams {
5272
name: string;
5373
}
@@ -61,6 +81,11 @@ export interface AESKWPParams extends WrapAlgoParams {
6181
name: "AES-KWP";
6282
}
6383

84+
export interface RsaOaepAESKWPParams extends WrapAlgoParams {
85+
name: "RSA-OAEP-AES-KWP";
86+
label?: ArrayBuffer;
87+
}
88+
6489
export interface CryptoKeyPair {
6590
privateKey: string;
6691
publicKey: string;
@@ -80,6 +105,7 @@ export interface CCF {
80105
): ArrayBuffer;
81106

82107
kv: KVMaps;
108+
historicalState?: HistoricalState;
83109
}
84110

85111
export const ccf = globalThis.ccf as CCF;

samples/apps/forum/tsoa-support/postprocess.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import SwaggerParser from "@apidevtools/swagger-parser";
44
import jsonmergepatch from "json-merge-patch";
55

66
// endpoint metadata defaults when first added to endpoints.json
7-
const metadataDefaults = (readonly) => ({
7+
const metadataDefaults = (mode) => ({
88
forwarding_required: "always",
99
execute_outside_consensus: "never",
1010
authn_policies: ["user_cert"],
11-
readonly: readonly,
11+
mode: mode,
1212
});
1313

1414
const distDir = "./dist";
@@ -116,8 +116,8 @@ const oldEndpoints = oldMetadata["endpoints"];
116116
const newEndpoints = newMetadata["endpoints"];
117117
for (const url in newEndpoints) {
118118
for (const method in newEndpoints[url]) {
119-
const readonly = method == "get";
120-
Object.assign(newEndpoints[url][method], metadataDefaults(readonly));
119+
const mode = method == "get" ? "readonly" : "readwrite";
120+
Object.assign(newEndpoints[url][method], metadataDefaults(mode));
121121
}
122122
}
123123
console.log(`Updating ${metadataPath} (if needed)`);

samples/apps/logging/js/app.json

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"forwarding_required": "always",
88
"execute_outside_consensus": "never",
99
"authn_policies": ["jwt", "user_cert"],
10-
"readonly": true,
10+
"mode": "readonly",
1111
"openapi": {}
1212
},
1313
"post": {
@@ -16,7 +16,7 @@
1616
"forwarding_required": "always",
1717
"execute_outside_consensus": "never",
1818
"authn_policies": ["jwt", "user_cert"],
19-
"readonly": false,
19+
"mode": "readwrite",
2020
"openapi": {}
2121
},
2222
"delete": {
@@ -25,7 +25,29 @@
2525
"forwarding_required": "always",
2626
"execute_outside_consensus": "never",
2727
"authn_policies": ["jwt", "user_cert"],
28-
"readonly": false,
28+
"mode": "readwrite",
29+
"openapi": {}
30+
}
31+
},
32+
"/log/private/historical": {
33+
"get": {
34+
"js_module": "logging.js",
35+
"js_function": "get_historical",
36+
"forwarding_required": "never",
37+
"execute_outside_consensus": "never",
38+
"authn_policies": ["jwt", "user_cert"],
39+
"mode": "historical",
40+
"openapi": {}
41+
}
42+
},
43+
"/log/private/historical_receipt": {
44+
"get": {
45+
"js_module": "logging.js",
46+
"js_function": "get_historical_with_receipt",
47+
"forwarding_required": "never",
48+
"execute_outside_consensus": "never",
49+
"authn_policies": ["jwt", "user_cert"],
50+
"mode": "historical",
2951
"openapi": {}
3052
}
3153
},
@@ -36,7 +58,7 @@
3658
"forwarding_required": "always",
3759
"execute_outside_consensus": "never",
3860
"authn_policies": ["jwt", "user_cert"],
39-
"readonly": true,
61+
"mode": "readonly",
4062
"openapi": {}
4163
},
4264
"post": {
@@ -45,7 +67,7 @@
4567
"forwarding_required": "always",
4668
"execute_outside_consensus": "never",
4769
"authn_policies": ["jwt", "user_cert"],
48-
"readonly": false,
70+
"mode": "readwrite",
4971
"openapi": {}
5072
},
5173
"delete": {
@@ -54,7 +76,7 @@
5476
"forwarding_required": "always",
5577
"execute_outside_consensus": "never",
5678
"authn_policies": ["jwt", "user_cert"],
57-
"readonly": false,
79+
"mode": "readwrite",
5880
"openapi": {}
5981
}
6082
}

samples/apps/logging/js/src/logging.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export function get_private(request) {
2929
return get_record(ccf.kv["records"], id);
3030
}
3131

32+
export function get_historical(request) {
33+
return get_private(request);
34+
}
35+
36+
export function get_historical_with_receipt(request) {
37+
const result = get_private(request);
38+
result.body.receipt = ccf.historicalState.receipt;
39+
return result;
40+
}
41+
3242
export function get_public(request) {
3343
const id = get_id_from_request_query(request);
3444
return get_record(ccf.kv["public:records"], id);

samples/apps/logging/logging.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -546,30 +546,8 @@ namespace loggingapp
546546
kv::Consensus::View view,
547547
kv::Consensus::SeqNo seqno,
548548
std::string& error_reason) {
549-
if (consensus == nullptr)
550-
{
551-
error_reason = "Node is not fully configured";
552-
return false;
553-
}
554-
555-
const auto tx_view = consensus->get_view(seqno);
556-
const auto committed_seqno = consensus->get_committed_seqno();
557-
const auto committed_view = consensus->get_view(committed_seqno);
558-
559-
const auto tx_status = ccf::evaluate_tx_status(
560-
view, seqno, tx_view, committed_view, committed_seqno);
561-
if (tx_status != ccf::TxStatus::Committed)
562-
{
563-
error_reason = fmt::format(
564-
"Only committed transactions can be queried. Transaction {}.{} is "
565-
"{}",
566-
view,
567-
seqno,
568-
ccf::tx_status_to_str(tx_status));
569-
return false;
570-
}
571-
572-
return true;
549+
return ccf::historical::is_tx_committed(
550+
consensus, view, seqno, error_reason);
573551
};
574552
make_endpoint(
575553
"log/private/historical",

0 commit comments

Comments
 (0)