Skip to content

Syncing account sizes between c and rust #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions program/c/src/oracle/oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extern "C" {
// defines to u32 (even with ULL suffix)
const uint64_t SUCCESSFULLY_UPDATED_AGGREGATE = 1000ULL;

// The size of the "time machine" account defined in the
// Rust portion of the codebase.
const uint64_t TIME_MACHINE_STRUCT_SIZE = 1864ULL;

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

Expand Down
1 change: 1 addition & 0 deletions program/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//c_oracle_header is auto generated by build_bpf.sh
//to reflect the current status of oracle.h
mod c_oracle_header;
mod time_machine_types;

//do not link with C during unit tests (which are built in native architecture, unlike libpyth.o)
#[cfg(target_arch = "bpf")]
Expand Down
20 changes: 20 additions & 0 deletions program/rust/src/time_machine_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::c_oracle_header;
#[derive(Debug, Clone)]
#[repr(C)]
/// this wraps multiple SMA and tick trackers, and includes all the state
/// used by the time machine
pub struct TimeMachineWrapper{
//Place holder with the size of the fields I am planning to add
place_holder: [u8;1864],
}

#[test]
///test that the size defined in C matches that
///defined in Rust
fn c_time_machine_size_is_correct() {
assert_eq!(
::std::mem::size_of::<TimeMachineWrapper>(),
c_oracle_header::TIME_MACHINE_STRUCT_SIZE.try_into().unwrap(),
"expected TIME_MACHINE_STRUCT_SIZE in oracle.h to the same as the size of TimeMachineWrapper"
);
}