-
Notifications
You must be signed in to change notification settings - Fork 116
Extend upd_aggregate
and add/del_publisher
to support 64 price components on pythnet
#384
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
Conversation
program/c/src/oracle/oracle.h
Outdated
// Replace Solana component size's contribution with Pythnet's. | ||
// | ||
// Note: Make sure to account here for all PC_COMP_SIZE-sized arrays in the struct. | ||
#define PC_EXPECTED_CMD_UPD_TEST_T_SIZE_PYTHNET (560 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this instruction is no longer used, I'd just get rid of the test altogether
@@ -9,30 +9,50 @@ use { | |||
fn main() { | |||
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); | |||
|
|||
let has_feat_pythnet = std::env::var("CARGO_FEATURE_PYTHNET").is_ok(); | |||
|
|||
// OUT_DIR is the path cargo provides to a build directory under `target/` specifically for | |||
// isolated build artifacts. We use this to build the C program and then link against the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this file you need to update the bindings codegen as well
program/rust/src/accounts/price.rs
Outdated
@@ -41,7 +38,7 @@ mod price_pythnet { | |||
}; | |||
|
|||
/// Pythnet-only extended price account format. This is extension | |||
/// is an append-only change that adds extra publisher slots and | |||
/// is an append-only change that extra publisher slots and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment change is grammatically incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main comments :
- Fix CI
- I think the Pythnet rust oracle has the wrong PC_COMP_SIZE because you didn't update the bindgen code
Summary of changes (since last review pass)Build.rs bindgen
Sanity Checks
CI
Fortify
|
Remaining items
|
program/rust/src/tests/test_sizes.rs
Outdated
@@ -58,6 +59,9 @@ fn test_sizes() { | |||
c_oracle_header::PC_COMP_SIZE_PYTHNET, | |||
}; | |||
|
|||
// Sanity-check the Pythnet PC_COMP_SIZE | |||
assert_eq!(PC_COMP_SIZE, 64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's in a good state to merge. I'm still a bit scared we accidentally link the Solana smart contract to the Pythnet C library
program/c/src/oracle/oracle.h
Outdated
#define PC_COMP_SIZE 32 | ||
#define PC_COMP_SIZE_V2 128 | ||
#define PC_COMP_SIZE_SOLANA 32 | ||
#define PC_COMP_SIZE_PYTHNET 128 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest calling these PC_NUM_COMP_SOLANA to distinguish values which are numbers from those which are byte size lengths
program/rust/src/accounts/price.rs
Outdated
@@ -41,7 +38,7 @@ mod price_pythnet { | |||
}; | |||
|
|||
/// Pythnet-only extended price account format. This is extension | |||
/// is an append-only change that adds extra publisher slots and | |||
/// is an append-only change that extra publisher slots and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why you deleted the word "adds" here?
agree with @guibescos about accidentally linking mismatched binaries. There's probably an easy way to test that -- actually if we have a unit test that uses > 32 publishers in the simulator, then I think that will catch it. The simulator loads the built bpf artifact, so that should account for the linking too. |
Changes since last review
Failure modes for pythnet/solana C/Rust mismatch
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! this solution makes sense to me. thanks for digging into all the linking stuff.
Thank you! This will be followed up by an explicit 32/64 publisher test in a separate change. |
This change extends all methods that touch the price component array to use 64 publishers on Pythnet. This includes publisher addition/deletion and, notably, aggregation logic. The latter is the reason why we don't use all 128 publisher slots on Pythnet - the compiled size of
upd_aggregate
under 128 publishing slots breached the stack size limits, resulting in various tests failing withentered unreachable code
panics.Summary of changes
program/c/makefile
-CFLAGS
passthroughprogram/c/src/oracle/oracle.h
- Use aPC_PYTHNET
feature macro to decide the value ofPC_COMP_SIZE
, disambiguate intoPC_COMP_SIZE_SOLANA
andPC_COMP_SIZE_PYTHNET
.program/rust/build.rs
- detect thepythnet
feature and define `PC_PYTHNET`` for the make build if set.program/rust/src/accounts/price.rs
- use a single big array for price components on Pythnet.program/rust/src/tests/test_sizes.rs
- Adjust size constants.Testing
test_add_publisher
which saturates the component array.Review Highlights
oracle.h
- It's not crystal clear to me how to prevent misuse betweenPC_COMP_SIZE
,PC_COMP_SIZE_SOLANA
andPC_COMP_SIZE_PYTHNET
.PC_COMP_SIZE
is the used size of the array, while the other two are total space available. In case of Solana, the two coincide