Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ RUN apt-get install -qq \
qtchooser \
qt5-qmake \
qtbase5-dev-tools \
libqt5websockets5-dev
libqt5websockets5-dev\
llvm-dev\
libclang-dev\
clang

# Install jcon-cpp library
RUN git clone https://github.com/joncol/jcon-cpp.git /jcon-cpp && cd /jcon-cpp && git checkout 2235654e39c7af505d7158bf996e47e37a23d6e3 && mkdir build && cd build && cmake .. && make -j4 && make install
Expand Down
6 changes: 5 additions & 1 deletion program/c/src/oracle/oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,11 @@ static uint64_t upd_price( SolParameters *prm, SolAccountInfo *ka )
cptr->pub_slot_ <= fptr->pub_slot_ ) {
return ERROR_INVALID_ARGUMENT;
}

bool updated_aggregate = false;
// update aggregate price as necessary
if ( sptr->slot_ > pptr->agg_.pub_slot_ ) {
upd_aggregate( pptr, sptr->slot_, sptr->unix_timestamp_ );
updated_aggregate = true;
}

// update component price if required
Expand All @@ -511,6 +512,9 @@ static uint64_t upd_price( SolParameters *prm, SolAccountInfo *ka )
fptr->status_ = status;
fptr->pub_slot_ = cptr->pub_slot_;
}
if (updated_aggregate){
return SUCCESSFULLY_UPDATED_AGGREGATE;
}
return SUCCESS;
}

Expand Down
7 changes: 7 additions & 0 deletions program/c/src/oracle/oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
extern "C" {
#endif

//a new custom return value to indicate to rust that aggregate was updated
//this triggers SMA trackers to update
//values 0-14 are defined in solana_sdk.h
//used consts instead of define because bingen always turns
// defines to u32 (even with ULL suffix)
const uint64_t SUCCESSFULLY_UPDATED_AGGREGATE = 15ULL;

// magic number at head of account
#define PC_MAGIC 0xa1b2c3d4

Expand Down
12 changes: 6 additions & 6 deletions program/c/src/oracle/test_oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ Test( oracle, upd_price ) {
.data_len = sizeof( idata ),
.program_id = &p_id
};
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 42L );
cr_assert( sptr->comp_[0].latest_.conf_ == 2L );
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 1 );
Expand All @@ -426,7 +426,7 @@ Test( oracle, upd_price ) {
idata.price_ = 81;
idata.pub_slot_ = 2;
cvar.slot_ = 3;
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 81L );
cr_assert( sptr->comp_[0].agg_.price_ == 42L );
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 2 );
Expand All @@ -436,7 +436,7 @@ Test( oracle, upd_price ) {
// next price doesnt change but slot does
cvar.slot_ = 4;
idata.pub_slot_ = 3;
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 81L );
cr_assert( sptr->comp_[0].agg_.price_ == 81L );
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 3 );
Expand All @@ -446,7 +446,7 @@ Test( oracle, upd_price ) {
// next price doesnt change and neither does aggregate but slot does
idata.pub_slot_ = 4;
cvar.slot_ = 5;
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 81L );
cr_assert( sptr->comp_[0].agg_.price_ == 81L );
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 4 );
Expand All @@ -466,7 +466,7 @@ Test( oracle, upd_price ) {
cvar.slot_ = 6;
idata.price_ = 50;
idata.conf_ = 6;
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 50L );
cr_assert( sptr->comp_[0].latest_.conf_ == 6L );
cr_assert( sptr->comp_[0].latest_.status_ == PC_STATUS_UNKNOWN );
Expand All @@ -478,7 +478,7 @@ Test( oracle, upd_price ) {
// Crank one more time and aggregate should be unknown
idata.pub_slot_ = 6;
cvar.slot_ = 7;
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( sptr->agg_.status_ == PC_STATUS_UNKNOWN );
}

Expand Down
14 changes: 14 additions & 0 deletions program/rust/src/bindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#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 "../../c/src/oracle/oracle.h"
12 changes: 10 additions & 2 deletions program/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
//this is auto generated by build_bpf.sh
mod c_oracle_header;

#[link(name = "cpyth")]
extern "C" {
fn c_entrypoint(input: *mut u8) -> u64;
}

#[no_mangle]
pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
unsafe{
return c_entrypoint(input);
let c_ret_val = unsafe{c_entrypoint(input)};
if c_ret_val == c_oracle_header::SUCCESSFULLY_UPDATED_AGGREGATE{
return 0;
} else {
return c_ret_val;
}


}
2 changes: 2 additions & 0 deletions scripts/build-bpf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ rm ./target/*-keypair.json

#build Rust and link it with C
cd "${RUST_DIR}"
cargo install bindgen
bindgen ./src/bindings.h -o ./src/c_oracle_header.rs
cargo clean
cargo build-bpf
sha256sum ./target/**/*.so
Expand Down