Skip to content

Commit 421c6f9

Browse files
Merge branch 'develop' into 'master'
Develop See merge request in3/c/in3-core!310
2 parents a0a0e68 + bac6eb0 commit 421c6f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1077
-864
lines changed

Diff for: .gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ bin/
3333
*.class
3434
target/
3535
.cproject
36-
rust/in3-sys/in3-core/*
37-
rust/Cargo.lock
3836
.overcommit.yml
3937
c/src/third-party/hidapi/config*
4038
c/src/third-party/hidapi/autom4te.cache/*
@@ -49,5 +47,3 @@ c/src/third-party/hidapi/missing
4947
c/src/third-party/hidapi/depcomp
5048
c/src/third-party/hidapi/compile
5149
c/src/third-party/hidapi/aclocal.m4
52-
53-
rust/in3-sys/pre_generated/in3.rs

Diff for: .vscode/launch.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
"name": "in3 cmd",
3030
"program": "${workspaceFolder}/build/bin/in3",
3131
"cwd": "${workspaceFolder}",
32+
"externalConsole": true,
3233
"args": [
33-
"-c",
34-
"btc",
35-
"getblock",
36-
"000000000000000000103b2395f6cd94221b10d02eb9be5850303c0534307220",
34+
"-ccache",
35+
"-a",
36+
"3",
37+
"call",
38+
"totalNodes():uint",
39+
"-to",
40+
"0x6c095a05764a23156efd9d603eada144a9b1af33",
3741
"-debug"
3842
]
3943
},
@@ -60,7 +64,8 @@
6064
"name": "run test",
6165
"program": "${workspaceFolder}/build/test/runner",
6266
"args": [
63-
"../c/test/testdata/requests/in3_invalid_block.json",
67+
"../c/test/testdata/requests/in3_total_nodes.json",
68+
"-d",
6469
"-t",
6570
"1"
6671
],
@@ -77,7 +82,7 @@
7782
"type": "lldb",
7883
"request": "launch",
7984
"name": "run rpcapi test",
80-
"program": "${workspaceFolder}/build/test/test_rpc_api",
85+
"program": "${workspaceFolder}/build/test/test_request",
8186
"cwd": "${workspaceFolder}/build"
8287
},
8388
{

Diff for: c/ci-deploy.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ release_mac_and_wasm:
9797
- cp -r ../wasm_build/module wasm/release-wasm
9898
- cp -r ../asmjs_build/module wasm/release-asmjs
9999
- cp ../java_build/lib/in3.jar lib/in3.jar
100-
- cp ../python_multilib/in3/libin3/shared/* python/in3/libin3/shared/
100+
- cp -r ../python_multilib/in3/libin3/shared python/in3/libin3/
101101
- cd ..
102102
- tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_mac.tar.gz in3-mac-wasm/
103103
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_mac.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_mac.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
@@ -137,7 +137,7 @@ release_x64:
137137
- cp -r ../wasm_build/module wasm/release-wasm
138138
- cp -r ../asmjs_build/module wasm/release-asmjs
139139
- cp ../java_build/lib/in3.jar lib/in3.jar
140-
- cp ../python_multilib/in3/libin3/shared/* python/in3/libin3/shared/
140+
- cp -r ../python_multilib/in3/libin3/shared python/in3/libin3/
141141
- cd ..
142142
- tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_x64.tar.gz in3-x64/
143143
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_x64.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_mac.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
@@ -174,7 +174,7 @@ release_x86:
174174
- cp -r ../wasm_build/module wasm/release-wasm
175175
- cp -r ../asmjs_build/module wasm/release-asmjs
176176
- cp ../java_build/lib/in3.jar lib/in3.jar
177-
- cp ../python_multilib/in3/libin3/shared/* python/in3/libin3/shared/
177+
- cp -r ../python_multilib/in3/libin3/shared python/in3/libin3/
178178
- cd ..
179179
- tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_x86.tar.gz in3-x86/
180180
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_x86.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_x86.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
@@ -211,7 +211,7 @@ release_arm7:
211211
- cp -r ../wasm_build/module wasm/release-wasm
212212
- cp -r ../asmjs_build/module wasm/release-asmjs
213213
- cp ../java_build/lib/in3.jar lib/in3.jar
214-
- cp ../python_multilib/in3/libin3/shared/* python/in3/libin3/shared/
214+
- cp -r ../python_multilib/in3/libin3/shared python/in3/libin3/
215215
- cd ..
216216
- tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_arm7.tar.gz in3-arm7/
217217
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_arm7.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_arm7.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
@@ -252,7 +252,7 @@ release_win:
252252
- cp -r ../wasm_build/module wasm/release-wasm
253253
- cp -r ../asmjs_build/module wasm/release-asmjs
254254
- cp ../java_build/lib/in3.jar lib/in3.jar
255-
- cp ../python_multilib/in3/libin3/shared/* python/in3/libin3/shared/
255+
- cp -r ../python_multilib/in3/libin3/shared python/in3/libin3/
256256
- cd ..
257257
- tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_windows.tar.gz in3-win/
258258
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_windows.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_windows.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')

Diff for: c/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ gcc_legacy:
106106
image: docker.slock.it/build-images/cmake:gcc-legacy
107107
extends: .conanbuild
108108
before_script:
109-
- curl -sSL https://cmake.org/files/v3.6/cmake-3.6.1-Linux-x86_64.tar.gz | tar -xzC /opt
110109
- export PATH="/opt/cmake-3.6.1-Linux-x86_64/bin/:$PATH"
111110
variables:
112111
CONAN_OPTS: "-DUSE_CURL=false"

Diff for: c/include/in3/client.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ typedef struct in3_chain {
227227
chain_id_t chain_id; /**< chain_id, which could be a free or based on the public ethereum networkId*/
228228
in3_chain_type_t type; /**< chaintype */
229229
uint64_t last_block; /**< last blocknumber the nodeList was updated, which is used to detect changed in the nodelist*/
230-
int nodelist_length; /**< number of nodes in the nodeList */
230+
unsigned int nodelist_length; /**< number of nodes in the nodeList */
231231
in3_node_t* nodelist; /**< array of nodes */
232232
in3_node_weight_t* weights; /**< stats and weights recorded for each node */
233233
bytes_t** init_addresses; /**< array of addresses of nodes that should always part of the nodeList */
@@ -615,8 +615,8 @@ NONULL in3_ret_t in3_cache_init(
615615
* My return NULL if not found.
616616
*/
617617
NONULL in3_chain_t* in3_find_chain(
618-
in3_t* c /**< the incubed client */,
619-
chain_id_t chain_id /**< chain_id */
618+
const in3_t* c /**< the incubed client */,
619+
chain_id_t chain_id /**< chain_id */
620620
);
621621

622622
/**

Diff for: c/include/in3/context.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ typedef enum ctx_type {
6262
* This will be used when picking the nodes to send the request to. A linked list of these structs desribe the result.
6363
*/
6464
typedef struct weight {
65-
in3_node_t* node; /**< the node definition including the url */
66-
in3_node_weight_t* weight; /**< the current weight and blacklisting-stats */
67-
float s; /**< The starting value */
68-
float w; /**< weight value */
69-
struct weight* next; /**< next in the linkedlist or NULL if this is the last element*/
65+
unsigned int index; /**< index of the node in the nodelist */
66+
bool blocked; /**< if true this node has been blocked for sending wrong responses */
67+
uint32_t s; /**< The starting value */
68+
uint32_t w; /**< weight value */
69+
struct weight* next; /**< next in the linkedlist or NULL if this is the last element*/
7070
} node_match_t;
7171

7272
/**
@@ -445,4 +445,11 @@ NONULL void in3_ctx_add_response(
445445
int data_len /**< the length of the data or the the string (use -1 if data is a null terminated string)*/
446446
);
447447

448+
NONULL static inline in3_node_t* ctx_get_node(const in3_chain_t* chain, const node_match_t* node) {
449+
return node->index < chain->nodelist_length ? chain->nodelist + node->index : NULL;
450+
}
451+
NONULL static inline in3_node_weight_t* ctx_get_node_weight(const in3_chain_t* chain, const node_match_t* node) {
452+
return node->index < chain->nodelist_length ? chain->weights + node->index : NULL;
453+
}
454+
448455
#endif

Diff for: c/include/in3/log.h

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef enum { LOG_TRACE,
4141
#define in3_log_set_prefix(prefix) in3_log_set_prefix_(prefix)
4242
#define in3_log_enable_prefix() in3_log_enable_prefix_()
4343
#define in3_log_disable_prefix() in3_log_disable_prefix_()
44+
#define in3_log_is_prefix_enabled() in3_log_is_prefix_enabled_()
4445
#define in3_log(...) in3_log_(__VA_ARGS__)
4546
#else
4647
#define in3_log_trace(...)
@@ -57,6 +58,7 @@ typedef enum { LOG_TRACE,
5758
#define in3_log_get_level() LOG_TRACE
5859
#define in3_log_set_quiet(enable)
5960
#define in3_log_set_prefix(prefix)
61+
#define in3_log_is_prefix_enabled() 0
6062
#define in3_log_enable_prefix()
6163
#define in3_log_disable_prefix()
6264
#define in3_log(level, file, function, line, ...) \
@@ -82,6 +84,7 @@ void in3_log_set_quiet_(int enable);
8284
void in3_log_set_prefix_(const char* prefix);
8385
void in3_log_enable_prefix_();
8486
void in3_log_disable_prefix_();
87+
int in3_log_is_prefix_enabled_();
8588

8689
/* in3_log() function can be made thread-safe using the in3_log_set_lock() function */
8790
void in3_log_(in3_log_level_t level, const char* file, const char* function, int line, const char* fmt, ...);

Diff for: c/include/in3/stringbuilder.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ sb_t* sb_add_bytes(sb_t* sb, const char* prefix, const bytes_t* bytes, int len,
7272
sb_t* sb_add_hexuint_l(sb_t* sb, uintmax_t uint, size_t l); /**< add a integer value as hexcoded, 0x-prefixed string*/
7373
sb_t* sb_add_escaped_chars(sb_t* sb, const char* chars); /**< add chars but escapes all quotes */
7474
sb_t* sb_add_int(sb_t* sb, uint64_t val); /**< adds a numeric value to the stringbuilder */
75+
char* format_json(const char* json); /**< format a json string and returns a new string, which needs to be freed */
7576

7677
#endif

Diff for: c/src/cmd/in3/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if (LEDGER_NANO)
4141
set(LIBS ${LIBS} ledger_signer)
4242
endif()
4343

44-
add_executable(in3 main.c in3_storage.c)
44+
add_executable(in3 main.c in3_storage.c recorder.c)
4545
target_compile_definitions(in3 PRIVATE _XOPEN_SOURCE=600)
4646

4747
target_link_libraries(in3 init pk_signer ${LIBS} -lm)

Diff for: c/src/cmd/in3/main.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "../../verifier/eth1/nano/chainspec.h"
7272
#include "../../verifier/in3_init.h"
7373
#include "in3_storage.h"
74+
#include "recorder.h"
7475
#include <inttypes.h>
7576
#include <math.h>
7677
#include <stdint.h>
@@ -766,6 +767,10 @@ int main(int argc, char* argv[]) {
766767
run_test_request = 1;
767768
else if (strcmp(argv[i], "-thr") == 0)
768769
run_test_request = 2;
770+
else if (strcmp(argv[i], "-fo") == 0)
771+
recorder_write_start(c, argv[++i]);
772+
else if (strcmp(argv[i], "-fi") == 0)
773+
recorder_read_start(c, argv[++i]);
769774
else if (strcmp(argv[i], "-nl") == 0)
770775
set_nodelist(c, argv[++i], false);
771776
else if (strcmp(argv[i], "-bn") == 0)
@@ -954,7 +959,7 @@ int main(int argc, char* argv[]) {
954959
if (run_test_request == 1) more = "WEIGHT : LAST_BLOCK";
955960
if (run_test_request == 2) more = "WEIGHT : NAME VERSION : RUNNING : HEALTH : LAST_BLOCK";
956961
printf(" : %-45s : %7s : %5s : %5s: %s\n------------------------------------------------------------------------------------------------\n", "URL", "BL", "CNT", "AVG", more);
957-
for (int i = 0; i < chain->nodelist_length; i++) {
962+
for (unsigned int i = 0; i < chain->nodelist_length; i++) {
958963
in3_ctx_t* ctx = NULL;
959964
char* health_s = NULL;
960965
if (run_test_request) {
@@ -1251,7 +1256,7 @@ int main(int argc, char* argv[]) {
12511256

12521257
// if the result is a string, we remove the quotes
12531258
if (result[0] == '"' && result[strlen(result) - 1] == '"') {
1254-
memmove(result, result + 1, strlen(result) + 1);
1259+
memmove(result, result + 1, strlen(result));
12551260
result[strlen(result) - 1] = 0;
12561261
}
12571262

0 commit comments

Comments
 (0)