From 33e70c88ad222c62ad3768820a2b232e5ee4d74a Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 12 Aug 2022 20:24:13 +0000 Subject: [PATCH 1/5] Export upd_aggregate --- program/c/makefile | 3 +++ .../c/src/oracle/for_cargo_test/cpyth_test.c | 23 +++++++++++++++++++ program/c/src/oracle/oracle.c | 4 ++++ scripts/build-bpf.sh | 3 ++- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 program/c/src/oracle/for_cargo_test/cpyth_test.c diff --git a/program/c/makefile b/program/c/makefile index 5bf090afe..cd54b55f9 100644 --- a/program/c/makefile +++ b/program/c/makefile @@ -3,3 +3,6 @@ SOLANA := ../../../solana include $(SOLANA)/sdk/bpf/c/bpf.mk cpyth: bash -c "ar rcs target/libcpyth.a target/**/*.o" +cpythtest: + gcc -c ./src/oracle/for_cargo_test/cpyth_test.c -o ./target/cpyth_test.o + ar rcs target/libcpythtest.a ./target/cpyth_test.o diff --git a/program/c/src/oracle/for_cargo_test/cpyth_test.c b/program/c/src/oracle/for_cargo_test/cpyth_test.c new file mode 100644 index 000000000..8826d4ac4 --- /dev/null +++ b/program/c/src/oracle/for_cargo_test/cpyth_test.c @@ -0,0 +1,23 @@ +/// The goal of this file is to provide the upd_aggregate function to local rust tests + +/// The heap address is different on solana runtime and locally, so here we need to allocate some heap space +/// In compilation to bpf, PC_HEAP_START is provided by +char heap_start[8192]; +#define PC_HEAP_START (heap_start) +#define static_assert _Static_assert + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long int int64_t; +typedef unsigned long int uint64_t; + +#include +#include "../upd_aggregate.h" + +extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){ + return upd_aggregate(ptr, slot, timestamp ); +} diff --git a/program/c/src/oracle/oracle.c b/program/c/src/oracle/oracle.c index 1f0a9d705..c82d56a85 100644 --- a/program/c/src/oracle/oracle.c +++ b/program/c/src/oracle/oracle.c @@ -171,3 +171,7 @@ extern uint64_t c_entrypoint(const uint8_t *input) } return dispatch( prm, ka ); } + +extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){ + return upd_aggregate(ptr, slot, timestamp ); +} diff --git a/scripts/build-bpf.sh b/scripts/build-bpf.sh index 15aaf503f..c49e5ab8b 100755 --- a/scripts/build-bpf.sh +++ b/scripts/build-bpf.sh @@ -30,13 +30,14 @@ export V="${V:-1}" make clean make "${@:2}" make cpyth +make cpythtest rm ./target/*-keypair.json #build Rust and link it with C cd "${PYTH_DIR}" cargo clean -cargo test +cargo test-bpf cargo clean cargo build-bpf From 63bcc423be632ef949079d77fa12af616337caa5 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 12 Aug 2022 20:30:37 +0000 Subject: [PATCH 2/5] Comment --- program/c/makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/program/c/makefile b/program/c/makefile index cd54b55f9..fa72b45cc 100644 --- a/program/c/makefile +++ b/program/c/makefile @@ -1,8 +1,12 @@ OUT_DIR := ./target SOLANA := ../../../solana include $(SOLANA)/sdk/bpf/c/bpf.mk + cpyth: +# Bundle C code compiled to bpf for use by rust bash -c "ar rcs target/libcpyth.a target/**/*.o" cpythtest: +# Compile C code to system architecture for use by rust's cargo test gcc -c ./src/oracle/for_cargo_test/cpyth_test.c -o ./target/cpyth_test.o +# Bundle C code compiled to system architecture for use by rust's cargo test ar rcs target/libcpythtest.a ./target/cpyth_test.o From d48957dc043bac2c948331f475f84893745a915f Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 12 Aug 2022 20:35:34 +0000 Subject: [PATCH 3/5] Cleanup --- program/c/src/oracle/for_cargo_test/cpyth_test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/program/c/src/oracle/for_cargo_test/cpyth_test.c b/program/c/src/oracle/for_cargo_test/cpyth_test.c index 8826d4ac4..488a0b06a 100644 --- a/program/c/src/oracle/for_cargo_test/cpyth_test.c +++ b/program/c/src/oracle/for_cargo_test/cpyth_test.c @@ -1,7 +1,7 @@ /// The goal of this file is to provide the upd_aggregate function to local rust tests -/// The heap address is different on solana runtime and locally, so here we need to allocate some heap space -/// In compilation to bpf, PC_HEAP_START is provided by +/// The heap address PC_HEAP_START is different on solana runtime and locally, so here we need to allocate some heap space +/// When compiling to bpf, PC_HEAP_START is provided by char heap_start[8192]; #define PC_HEAP_START (heap_start) #define static_assert _Static_assert @@ -15,7 +15,6 @@ typedef unsigned int uint32_t; typedef signed long int int64_t; typedef unsigned long int uint64_t; -#include #include "../upd_aggregate.h" extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){ From a8ae385074fc89e66b0c5d2db73821c6240992c4 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 12 Aug 2022 20:37:19 +0000 Subject: [PATCH 4/5] Better comment --- program/c/src/oracle/for_cargo_test/cpyth_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program/c/src/oracle/for_cargo_test/cpyth_test.c b/program/c/src/oracle/for_cargo_test/cpyth_test.c index 488a0b06a..72f21a49a 100644 --- a/program/c/src/oracle/for_cargo_test/cpyth_test.c +++ b/program/c/src/oracle/for_cargo_test/cpyth_test.c @@ -1,7 +1,7 @@ /// The goal of this file is to provide the upd_aggregate function to local rust tests -/// The heap address PC_HEAP_START is different on solana runtime and locally, so here we need to allocate some heap space -/// When compiling to bpf, PC_HEAP_START is provided by +/// We need to allocate some heap space for upd_aggregate +/// When compiling for the solana runtime, the heap space is preallocated and PC_HEAP_START is provided by char heap_start[8192]; #define PC_HEAP_START (heap_start) #define static_assert _Static_assert From aee34ef0e5417635f8293dfe79e65926739d5529 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 12 Aug 2022 21:57:32 +0000 Subject: [PATCH 5/5] Get the right gcc --- program/c/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/c/makefile b/program/c/makefile index fa72b45cc..a33fcc4dd 100644 --- a/program/c/makefile +++ b/program/c/makefile @@ -7,6 +7,6 @@ cpyth: bash -c "ar rcs target/libcpyth.a target/**/*.o" cpythtest: # Compile C code to system architecture for use by rust's cargo test - gcc -c ./src/oracle/for_cargo_test/cpyth_test.c -o ./target/cpyth_test.o + $(CC) -c ./src/oracle/for_cargo_test/cpyth_test.c -o ./target/cpyth_test.o # Bundle C code compiled to system architecture for use by rust's cargo test ar rcs target/libcpythtest.a ./target/cpyth_test.o