Skip to content

Conversation

@chrismaree
Copy link
Member

  • WIP
  • WIP

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@socket-security
Copy link

socket-security bot commented Oct 28, 2024

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

Signed-off-by: chrismaree <christopher.maree@gmail.com>
…om:across-protocol/contracts into chrismaree/improve-state-locations
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree changed the title Improve shared state locations Improve shared state locations and other stylistic improvements Oct 28, 2024
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree marked this pull request as ready for review October 28, 2024 12:50
@chrismaree chrismaree requested review from Reinis-FRP and md0x and removed request for Reinis-FRP October 28, 2024 13:18
let state = &ctx.accounts.state;
let current_time = get_current_time(state)?;

// Check if the fill status is filled
Copy link
Member Author

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.

Copy link
Contributor

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.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
#[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);
Copy link
Contributor

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 };
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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

Copy link
Member Author

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.

pub enum CustomError {
#[msg("Only the owner can call this function!")]
NotOwner,
pub enum SharedError {
Copy link
Contributor

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<()> {
Copy link
Contributor

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.
Copy link
Contributor

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],
Copy link
Contributor

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,
Copy link
Contributor

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

}

#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct V3RelayData {
Copy link
Contributor

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

Copy link
Member Author

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.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
const { recipient, initializeState, setCurrentTime, assertSE, assert } = common;

describe("svm_spoke.fill", () => {
describe.only("svm_spoke.fill", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe.only("svm_spoke.fill", () => {
describe("svm_spoke.fill", () => {

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Copy link
Contributor

@Reinis-FRP Reinis-FRP left a 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

@chrismaree chrismaree merged commit 3cfd778 into master Oct 29, 2024
9 checks passed
@chrismaree chrismaree deleted the chrismaree/improve-state-locations branch October 29, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants