-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Solana Vault Swaps Elections #5355
Conversation
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
I just merged #5375 on top of this so it has the entire vault swap feature so it can be reviewed together (CCM, vaultSwapParameters). |
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
} else { | ||
sp_std::mem::take(&mut known_accounts.witnessed_open_accounts) | ||
}; | ||
match Hook::close_accounts(accounts_to_close.clone()) { |
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 still think all of the above logic could be in the close_accounts hook (could make it close_accounts(last_close_block_number, &mut known_accounts)
).
This would also make it easier to mock and test.
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.
depending on whether we were successfully able to close accounts, we have to set the unsynchronized state so it makes sense to have this logic here.
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.
If all the logic were in the close_accounts hook, then, we wouldn't need to have two separate hooks for get_number_of_available_sol_nonce_accounts
and close_accounts
- close accounts would already have access to it -> which makes it easier to mock and test, and for the writing of state, all you need is to return a result as is already the case, and just set the block number.
Then for testing this ElectoralSystem's on_finalize, it's very simple, you can just check "has hook been called" - we already have tests that do this for other ElectoralSystems so it would be very similar. Then you could also write tests for the close_accounts hook implementation itself, separately, and can do so just focussing on that logic, free from the needing to test everything in the context of the whole ElectoralSystem
Also if you pass in SolanaVaultSwapsVote
could just have one hook function provided, since the api call would be out too
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 considered moving all the logic concerning all three hooks inside one hook but realized it would not actually make testing easier. This is because in that case, writing the test for one big hook impl would then be difficult since the logic in hook impl calls external code (constructing apicall, accessing sol nonces etc). So we would have to mock those. So basically we are back where we started. We wanted to avoid create 3 mocks of 3 election hooks, instead we create one. However, that means we create those extra mocks while testing the hook impl so I dont think we gain anything. In fact, creating the mocks for the hook impl is even harder since we dont have a framework for it at the Runtime level. creating 3 mocks instead of one while writing tests for the on_finalize shouldnt be a big deal.
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.
Having the apicall construction be a separate trait function is probably reasonable, it's also kind of a different part of the flow, so conceptually could make things easier to follow. Though I think putting the get nonce and close accounts in one should definitely be simpler
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 am not sure I understand what you mean. The apicall construction is inside the close_accounts
function. trying to combine apicall construction and get nonces into one hook would mean we have to move the whole logic inside that hook which creates the problem of testability that I mentioned above.
In general, I think it is a pretty arbitrary and subjective choice here between having the logic in one place or splitting it. In the end logic is logic, one has to follow it to make sure it works. Its not like we don't have long pieces of logic inside single functions in other places in the codebase.
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.
Sorry, should've been clearer. I mean leaving initiate_vault_swap separate makes sense. But since the only reason we need the number of sol accounts is to decide whether we construct the close accounts call, seems to make sense to include it.
I'm not against having long pieces of logic, it's just about keeping conceptually similar things together and the boundaries between things clean. Happy to see how the tests look keeping it like this
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 of course but in this case we cant test the hook impl easily as i said before so it makes sense to keep it here since we want to test and keep the hook impl trivial.
For visibility, after the two last PRs I merged into this PR, these are the last items to get this done:
Afaik @ramizhasan111 is working on those 👌 . I will test the last item once completed. |
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.
Still going through it, but thought I'd drop some comments now is looking good so far 👍
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/solana_swap_accounts_tracking.rs
Outdated
Show resolved
Hide resolved
} else { | ||
sp_std::mem::take(&mut known_accounts.witnessed_open_accounts) | ||
}; | ||
match Hook::close_accounts(accounts_to_close.clone()) { |
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.
If all the logic were in the close_accounts hook, then, we wouldn't need to have two separate hooks for get_number_of_available_sol_nonce_accounts
and close_accounts
- close accounts would already have access to it -> which makes it easier to mock and test, and for the writing of state, all you need is to return a result as is already the case, and just set the block number.
Then for testing this ElectoralSystem's on_finalize, it's very simple, you can just check "has hook been called" - we already have tests that do this for other ElectoralSystems so it would be very similar. Then you could also write tests for the close_accounts hook implementation itself, separately, and can do so just focussing on that logic, free from the needing to test everything in the context of the whole ElectoralSystem
Also if you pass in SolanaVaultSwapsVote
could just have one hook function provided, since the api call would be out too
Apart from tests, which I am doing as another PR, this PR should be ready and I would like to merge it if there are no more open points. |
Just fyi, when this gets rebased I expect the Solana Vault swaps to fail because the encoding of |
For visibility @ramizhasan111 is going to do the missing migrations |
The upgrade test might pass without those version changes until you run it in the queue because it'll be put on top of main, which will then require them |
.github/workflows/ci-development.yml
Outdated
@@ -79,7 +79,7 @@ jobs: | |||
uses: ./.github/workflows/upgrade-test.yml | |||
secrets: inherit | |||
with: | |||
run-job: false |
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.
reminder: needs to be reverted before merge
I'm looking into the Vault swap failures after upgrade. |
* chore: update transcationInId and bouncer * chore: run CI * chore: add logging and decrease timeout * chore: not try runtime * chore: add more prints * chore: run only one Solana Vault swap * chore: use processed commitment * chore: use confirmed * chore: revert sendAndConfirmTransaction * chore: fix * chore: add print and extra swap * chore: remove unnecessary context transition * chore: log electoral settings * chore: readd missing line * chore: improve logging * chore: add fix to upgrade-test * chore: add missing SOLANA_PROGRAMS_VERSION * chore: replace nonces manually * chore: manually skip solana vault swaps * chore: revert logs * chore: run upgrade * chore: fix path * chore: refactor env * chore: restore files * chore: force initial sol nonces * chore: run upgrade ci * chore: fix reset --hard * chore: small refactor * chore: remove unnecessary reset * chore: revert files * chore: refactor
Pull Request
Closes: PRO-1521 , PRO-1522
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
note: please ignore some of the naming around Contract Swaps. That will be fixed before merging.Renaming done.