-
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: Open/Close Solana contract swap accounts #5321
feat: Open/Close Solana contract swap accounts #5321
Conversation
@@ -228,6 +242,21 @@ pub mod pallet { | |||
#[pallet::getter(fn solana_api_environment)] | |||
pub type SolanaApiEnvironment<T> = StorageValue<_, SolApiEnvironment, ValueQuery>; | |||
|
|||
#[pallet::storage] | |||
#[pallet::getter(fn solana_open_contract_swap_accounts)] |
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: no need to add the getters, they aren't used and I think are now considered deprecated.
#[pallet::storage] | ||
#[pallet::getter(fn solana_closed_contract_swap_accounts)] | ||
pub type SolanaClosedContractSwapAccounts<T> = | ||
StorageMap<_, Blake2_128Concat, ContractSwapAccountAndSender, ()>; |
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.
StorageMap<_, Blake2_128Concat, ContractSwapAccountAndSender, ()>; | |
StorageMap<_, Twox64_Concat, ContractSwapAccountAndSender, ()>; |
Simple hasher is enough 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.
But I don't understand why we need to store this as a map at all - we never need to look up a single account we always remove them in batches.
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 figured that we might have to close them one by one in some cases but I see that they will always be closed in batches. Will change to storage value.
@@ -272,6 +342,8 @@ pub mod pallet { | |||
StaleUtxosDiscarded { utxos: Vec<Utxo> }, | |||
/// Solana durable nonce is updated to a new nonce for the corresponding nonce account. | |||
DurableNonceSetForAccount { nonce_account: SolAddress, durable_nonce: SolHash }, | |||
/// apicall to close Solana Contract Swap Accounts has been initiated. |
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.
/// apicall to close Solana Contract Swap Accounts has been initiated. | |
/// Transaction broadcast to close Solana Contract Swap Accounts has been initiated. |
@@ -245,6 +274,47 @@ pub mod pallet { | |||
/// Contains the network environment for this runtime. | |||
pub type ChainflipNetworkEnvironment<T> = StorageValue<_, NetworkEnvironment, ValueQuery>; | |||
|
|||
#[pallet::hooks] | |||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { | |||
fn on_idle(block_number: BlockNumberFor<T>, _remaining_weight: Weight) -> Weight { |
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're using on_idle but we're not doing any weight calculations. If we don't care about weight (usually because we want to do something essential) then we can use on_finalize. If we want semantics of "only do this if we have enough weight to spare", then we should use on_idle, but we need to measure the weight.
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.
yeah, I left the benchmarking for later. I'll open an issue for it.
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.
Please do it in this PR - it's too easy to just kick all the 'boring parts' into a Linear ticket.
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.
the benchmarking ticket could have been assigned to me and I could've taken it up immediately after this (and the election ticket) but sure I can do it as part of this PR if you insist.
I will come back to it after working on election ticket. Since that is closely linked to the functionality in this PR, some of the functionality in this PR might change and so I would do the benchmarks once the functionality is final.
#[pallet::storage] | ||
#[pallet::getter(fn solana_last_closed_contract_swap_accounts_at)] | ||
pub type SolanaLastClosedContractSwapAccountsAt<T> = | ||
StorageValue<_, BlockNumberFor<T>, OptionQuery>; |
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 can be ValueQuery (by default we last closed at block 0) and then we can simplify the logic - no need to check for None case.
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 used Optionquery since it makes more conceptual sense. If there was no last apicall created, the value doesnt exist.
@@ -272,6 +342,8 @@ pub mod pallet { | |||
StaleUtxosDiscarded { utxos: Vec<Utxo> }, | |||
/// Solana durable nonce is updated to a new nonce for the corresponding nonce account. | |||
DurableNonceSetForAccount { nonce_account: SolAddress, durable_nonce: SolHash }, | |||
/// apicall to close Solana Contract Swap Accounts has been initiated. | |||
SolanaCloseContractSwapAccounts { broadcast_id: BroadcastId }, |
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.
The event could be more informative... why not add the details of the account being closed?
pub type SolanaOpenContractSwapAccounts<T> = | ||
StorageValue<_, Vec<ContractSwapAccountAndSender>, ValueQuery>; |
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 likely that this will be stored in the election that witnesses these.
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 the election pallet would store the new accounts (the ones not stored here stored here) which it will then report. The SC (here) stores the accounts that it already knows about. Depends of course also on how the witnessing is implemented.
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.
The witnessing needs to have access to this list, otherwise we will be querying like crazy and we want to avoid that. So I'm guessing that means it should be store in the election?! This information however is also needed here to know when to close accounts.
(I don't know enough details about the elections, just adding some info 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.
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.
Doesn't have to be solved here and now. My understanding was that the election pallet will maintain a list of the currently opened accounts: it basically tries to sync this state between Solana and the SC. The engine will vote on accounts that are opened and closed.
So the election pallet will be the source of truth for OPEN accounts.
The enviroment can track accounts that are CLOSING.
It needs periodically pull the set of open accounts and diff this with CLOSING:
- accounts that are OPEN and not CLOSING need to be closed
- accounts that are CLOSING and not OPEN can be removed from the set of CLOSING accounts.
- accounts that are CLOSING and OPEN can be ignored: we have already requested closure.
(But I get that the election side of things isn't implemented yet, so we need some placeholder for now.)
tx_hash: TransactionHash, | ||
) { | ||
let _ = SolanaIngressEgress::contract_swap_request( | ||
RuntimeOrigin::root(), |
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 you can do something like this:
RuntimeOrigin::root(), | |
pallet_cf_witnesser::Origin::CurrentEpochWitnessThreshold.into(), |
This PR is on hold for now since I am currently working on the elections for Solana contract swap accounts tracking as the functionality in this PR might change based on how the elections are implemented. I will come back to this PR and finalize it after the implementing the elections. |
@ramizhasan111 Can this be closed? All the functionality is now part of #5355, right? |
yes, this PR is not needed anymore and can be closed. |
closing since it is not needed as the functionality is now part of #5355. |
Pull Request
Closes: PRO-1522
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
Please include a succinct description of the purpose and content of the PR. What problem does it solve, and how? Link issues, discussions, other PRs, and anything else that will help the reviewer.
Non-Breaking changes
If this PR includes non-breaking changes, select the
non-breaking
label. On merge, CI will automatically cherry-pick the commit to a PR against the release branch.