-
Notifications
You must be signed in to change notification settings - Fork 75
Improve shared state locations and other stylistic improvements #698
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
chrismaree
commented
Oct 28, 2024
- WIP
- WIP
|
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request |
…om:across-protocol/contracts into chrismaree/improve-state-locations
| let state = &ctx.accounts.state; | ||
| let current_time = get_current_time(state)?; | ||
|
|
||
| // Check if the fill status is filled |
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.
note that I changed the requires here! I think this check is redundant. the ONLY thing we care about is if the deposit is expired, not if it was filled (or not) to let us close the PDA. LMK if you'll agree.
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.
right, and this could even allow us to close fill accounts that have been requested slow fill but failed to execute before the deadline.
| #[derive(Accounts)] | ||
| pub struct Verify {} | ||
| pub fn verify(ctx: Context<Verify>, root: [u8; 32], leaf: [u8; 32], proof: Vec<[u8; 32]>) -> Result<()> { | ||
| let computed_root = process_proof(&proof, &leaf); |
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.
ctx parameter in verify above can be replaced with _ctx to avoid compile warnings
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{ error::CustomError, state::State }; | ||
| use crate::{ error::SvmError, state::State }; |
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.
nit: this still generates unused imports in test builds. Maybe we can avoid importing SvmError and instead reference it below using its full path crate::error::SvmError as it is used only in production builds?
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.
ye, that's great. or conditionally import the file. I've changed it to just use crate::error::SvmError when referencing the error.
| error::SvmError, | ||
| event::{ | ||
| EmergencyDeletedRootBundle, | ||
| EmergencyDeleteRootBundle, |
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.
Shall we not better fix it in EVM as EmergencyDeletedRootBundle seems more consistent with other event names?
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.
well then we break monitors and other things that depend on the EVM events rn, which is less ideal.
at least now they are consistent, which is better. I added a TODO to update both EVM and SVM.
|
|
||
| #[account( | ||
| mut, | ||
| #[account(mut, |
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 seems bit off. Either we can fit all parameters in one line or each has to be on its own line
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.
yes, you're right. I tried to see if I could fit all on one line & could not but messed up the formatting after the fact.
programs/svm-spoke/src/error.rs
Outdated
| pub enum CustomError { | ||
| #[msg("Only the owner can call this function!")] | ||
| NotOwner, | ||
| pub enum SharedError { |
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.
nit: maybe CommonError would be a better name?
| mint: Pubkey, | ||
| token_account: Pubkey | ||
| ) -> Result<()> { | ||
| pub fn initialize_claim_account(ctx: Context<InitializeClaimAccount>, _: Pubkey, _: Pubkey) -> Result<()> { |
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.
we can delete the unused props here and rename them to _mint and _token_account in the outer function.
| pub fn request_v3_slow_fill( | ||
| ctx: Context<SlowFillV3Relay>, | ||
| relay_hash: [u8; 32], // include in props, while not using it, to enable us to access it from the #Instruction Attribute within the accounts. This enables us to pass in the relay_hash PDA. | ||
| _: [u8; 32], // include in props, while not using it, to enable us to access it from the #Instruction Attribute within the accounts. This enables us to pass in the relay_hash PDA. |
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.
same comment as in others, rename it to _relay_hash in the outer call and not pass it to this inner function
| pub fn execute_v3_slow_relay_leaf( | ||
| ctx: Context<ExecuteV3SlowRelayLeaf>, | ||
| relay_hash: [u8; 32], | ||
| _token_account: [u8; 32], |
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.
there is no token_account param in the outer call
| _token_account: [u8; 32], | ||
| slow_fill_leaf: V3SlowFill, | ||
| root_bundle_id: u32, | ||
| _: u32, |
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.
better to skip passing unused params from the outer call
programs/svm-spoke/src/state/fill.rs
Outdated
| } | ||
|
|
||
| #[derive(AnchorSerialize, AnchorDeserialize, Clone)] | ||
| pub struct V3RelayData { |
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.
maybe better to have this under something like src/common/v3_relay_data? then we could also move RefundAccount to src/common/refund_account as it also does not strictly belong to the state
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.
ye, I think that's better. it's not really part of fill, and it's also not "state" in that it's not initialized. I'll update the way you've recommended.
I did not pull refund_account, though, as I think we might still end up changing this structure given the conversation we had last week where by we don't let the account be either TokenAccount OR ClaimAccount but rather pass in both of them to prevent relayers front running this set of methods.
test/svm/SvmSpoke.Fill.ts
Outdated
| const { recipient, initializeState, setCurrentTime, assertSE, assert } = common; | ||
|
|
||
| describe("svm_spoke.fill", () => { | ||
| describe.only("svm_spoke.fill", () => { |
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.
| describe.only("svm_spoke.fill", () => { | |
| describe("svm_spoke.fill", () => { |
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.
looking great!. just remove only mode in fill tests