-
Notifications
You must be signed in to change notification settings - Fork 37
fix: MagicContext's data reset on restart #986
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,6 @@ pub(crate) fn fund_account_with_data( | |
| ) { | ||
| let account = if let Some(mut acc) = accountsdb.get_account(pubkey) { | ||
| acc.set_lamports(lamports); | ||
| acc.set_data(vec![0; size]); | ||
| acc | ||
| } else { | ||
| AccountSharedData::new(lamports, size, &Default::default()) | ||
|
|
@@ -70,16 +69,20 @@ pub(crate) fn funded_faucet( | |
| } | ||
|
|
||
| pub(crate) fn fund_magic_context(accountsdb: &AccountsDb) { | ||
| const CONTEXT_LAMPORTS: u64 = u64::MAX; | ||
|
|
||
| fund_account_with_data( | ||
| accountsdb, | ||
| &magic_program::MAGIC_CONTEXT_PUBKEY, | ||
| u64::MAX, | ||
| CONTEXT_LAMPORTS, | ||
| MagicContext::SIZE, | ||
| ); | ||
| let mut magic_context = accountsdb | ||
| .get_account(&magic_program::MAGIC_CONTEXT_PUBKEY) | ||
| .unwrap(); | ||
| .expect("magic context should have been created"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After As per coding guidelines: "Treat any usage of 🔧 Sketch of error-propagating refactor-pub(crate) fn fund_magic_context(accountsdb: &AccountsDb) {
+pub(crate) fn fund_magic_context(accountsdb: &AccountsDb) -> ApiResult<()> {
const CONTEXT_LAMPORTS: u64 = u64::MAX;
- fund_account_with_data(
+ fund_account_with_data_result(
accountsdb,
&magic_program::MAGIC_CONTEXT_PUBKEY,
CONTEXT_LAMPORTS,
MagicContext::SIZE,
- );
+ )?;
let mut magic_context = accountsdb
.get_account(&magic_program::MAGIC_CONTEXT_PUBKEY)
- .expect("magic context should have been created");
+ .ok_or_else(|| /* appropriate ApiError variant */ ...)?;
magic_context.set_delegated(true);
magic_context.set_owner(magic_program::ID);
- let _ = accountsdb
+ accountsdb
.insert_account(&magic_program::MAGIC_CONTEXT_PUBKEY, &magic_context);
+ Ok(())
}🤖 Prompt for AI Agents |
||
| magic_context.set_delegated(true); | ||
| magic_context.set_owner(magic_program::ID); | ||
|
|
||
| let _ = accountsdb | ||
| .insert_account(&magic_program::MAGIC_CONTEXT_PUBKEY, &magic_context); | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 better to tweak the fund_account_with_data method to prevent any mutation if account already exists, all use cases assume that anyway.
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 that is the case, then it is better. Do we want to refill lamports for all of them tho?
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.
no, in case of EPHEMERAL VAULT account that would be a logic error, so we want to keep the state intact between restarts
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.
Done