Skip to content

Commit 9b3a9ce

Browse files
majabbourtompntn
andauthored
Syncing account sizes between c and rust (#197)
* defined size in oracle.h and asserted it in rust * added docstring for the test * updated the doc * updated the error message * Update comment in program/c/src/oracle/oracle.h Co-authored-by: Tom Pointon <tom@teepeestudios.net> * updated time machine size name Co-authored-by: Tom Pointon <tom@teepeestudios.net>
1 parent 0fc4caf commit 9b3a9ce

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

program/c/src/oracle/oracle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ extern "C" {
1313
// defines to u32 (even with ULL suffix)
1414
const uint64_t SUCCESSFULLY_UPDATED_AGGREGATE = 1000ULL;
1515

16+
// The size of the "time machine" account defined in the
17+
// Rust portion of the codebase.
18+
const uint64_t TIME_MACHINE_STRUCT_SIZE = 1864ULL;
19+
1620
// magic number at head of account
1721
#define PC_MAGIC 0xa1b2c3d4
1822

program/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//c_oracle_header is auto generated by build_bpf.sh
22
//to reflect the current status of oracle.h
33
mod c_oracle_header;
4+
mod time_machine_types;
45

56
//do not link with C during unit tests (which are built in native architecture, unlike libpyth.o)
67
#[cfg(target_arch = "bpf")]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use super::c_oracle_header;
2+
#[derive(Debug, Clone)]
3+
#[repr(C)]
4+
/// this wraps multiple SMA and tick trackers, and includes all the state
5+
/// used by the time machine
6+
pub struct TimeMachineWrapper{
7+
//Place holder with the size of the fields I am planning to add
8+
place_holder: [u8;1864],
9+
}
10+
11+
#[test]
12+
///test that the size defined in C matches that
13+
///defined in Rust
14+
fn c_time_machine_size_is_correct() {
15+
assert_eq!(
16+
::std::mem::size_of::<TimeMachineWrapper>(),
17+
c_oracle_header::TIME_MACHINE_STRUCT_SIZE.try_into().unwrap(),
18+
"expected TIME_MACHINE_STRUCT_SIZE in oracle.h to the same as the size of TimeMachineWrapper"
19+
);
20+
}

0 commit comments

Comments
 (0)