-
Notifications
You must be signed in to change notification settings - Fork 18
Lock free chainlink #591
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?
Lock free chainlink #591
Changes from all commits
ecd8f75
b0513e5
8f92284
00287a4
5073887
0b4e516
d21d0e2
960490b
7f8e45b
7dfc4ad
a297272
d27b6cc
a2f39d1
8ee7304
e28ea80
0fe90b1
27eaf78
0b87bae
c0863b1
bcb7553
93a2b1d
3006231
d306eed
e606575
43277ec
04730fd
2a8bf01
6b443e8
e6e0aff
4c1b478
863644f
aef1606
459b58b
d5d6f88
f0e0305
b6b7506
2548e79
1f92a44
0d1e771
5c54a9f
a74077c
928547e
a8b4d15
5607063
da9a10e
5fecca1
662944b
4cfac7b
d15e29e
4a67d01
f5d5bbc
fc585a3
9ad32f3
14f1bc8
19738c0
cadc7cd
fe02829
35d05e3
84546a1
9fd489b
f83120b
b66e8d5
41d59b5
e8ca627
b7201f1
b7efced
014c7e3
32ad8a9
8a2eae5
c3834ee
de8e5e3
429b33f
17dd52b
9eee79d
9766794
a962537
aee453d
d18fe12
82edc21
7a19b24
0f1f25a
f5523fb
cf227fb
e2426cd
6a3f27b
4061362
0603ee0
04443c3
676f49d
1c01030
a031b7d
8da42fc
ec0976e
74e8f09
0e499ea
ae87eb6
03bc653
a6bff5d
3af00bc
c722016
766d161
8d8cf49
21b953c
d632a57
7fa6dc7
ee55cba
3664298
b31f32a
70d9c43
65365a1
c1688ee
6cfca11
ce235d0
f2bcc6c
722f806
0f61748
6928135
071bfb0
5ce2cbd
16a46e8
873e040
7b17d39
3e345a0
a50cbaa
6f52e37
7c7d175
4b7b474
b3d922e
7405eb3
6fc6071
2507acf
17e6207
1e316c4
d96cac9
3f45f40
0f40459
aef5e32
cf87239
8b0cd87
18d26f4
fe0a789
057f93d
cfd45f7
c234448
3173865
c6e425d
530205d
879cadd
4d6c53d
66f2309
0dea41d
61369e8
8ad7de1
8e85ea9
cf0deb3
8e18721
38b27f4
424d251
b67dd24
5039e8f
342c64e
6956b13
92d36e1
84a69e7
74be01b
20bbc39
30226c8
12fc8b2
10543f1
4fc0d58
9ae040e
168a386
9de3825
46e3436
600400b
8f110f4
88c4a6e
69a3946
bf40f37
44a9990
1d0f537
7e1980f
2541953
3d4ef66
ff870af
39e6eef
39bc75a
f33f131
d49c0f4
fdacb09
5f90396
10c0f46
149bb3d
b924032
3637e10
74d9a5e
1d457e4
eda7c40
984a1c2
0f91b12
27709b9
33985ab
1cacaf8
c00fa4b
6b5f196
f13fbd9
6ac66b0
7c94e1f
74a505c
15c5faf
b7a4566
d5c03df
6d855f3
47d18a4
44089e2
6d05032
602ec16
c5b1efb
d609e63
eb3cffd
96c3098
84b288d
91a11e3
bb745fc
79d3df3
9c04c09
dfe86ee
d0c8fe9
5a6a24e
750e5be
77aed49
0826927
62db6bb
2cc4470
b09e9c2
f955f74
0a9194c
9d604e9
79b4f97
65628d9
ffb5f99
ba48d31
19a65c4
29ff17f
1a37103
6b1a67e
248ee2b
23e9867
bae911f
7edf7b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,33 @@ | ||
| #[cfg(any(test, feature = "dev-context"))] | ||
| pub mod mock { | ||
| use std::{collections::HashMap, fmt, sync::Mutex}; | ||
| use std::fmt; | ||
|
|
||
| use log::*; | ||
| use magicblock_core::traits::AccountsBank; | ||
| use scc::HashMap; | ||
| use solana_account::{AccountSharedData, WritableAccount}; | ||
| use solana_pubkey::Pubkey; | ||
|
|
||
| use crate::blacklisted_accounts; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct AccountsBankStub { | ||
| pub accounts: Mutex<HashMap<Pubkey, AccountSharedData>>, | ||
| pub accounts: HashMap<Pubkey, AccountSharedData>, | ||
| } | ||
|
|
||
| impl AccountsBankStub { | ||
| pub fn insert(&self, pubkey: Pubkey, account: AccountSharedData) { | ||
| trace!("Inserting account: {pubkey}"); | ||
| self.accounts.lock().unwrap().insert(pubkey, account); | ||
| self.accounts.upsert(pubkey, account); | ||
| } | ||
|
|
||
| pub fn get(&self, pubkey: &Pubkey) -> Option<AccountSharedData> { | ||
| self.accounts.lock().unwrap().get(pubkey).cloned() | ||
| self.accounts.get(pubkey).map(|acc| acc.get().clone()) | ||
| } | ||
|
|
||
| pub fn set_owner(&self, pubkey: &Pubkey, owner: Pubkey) -> &Self { | ||
| trace!("Setting owner for account: {pubkey} to {owner}"); | ||
| let mut accounts = self.accounts.lock().unwrap(); | ||
| if let Some(account) = accounts.get_mut(pubkey) { | ||
| if let Some(mut account) = self.accounts.get(pubkey) { | ||
| account.set_owner(owner); | ||
| } else { | ||
| panic!("Account not found in bank: {pubkey}"); | ||
|
|
@@ -37,8 +37,7 @@ pub mod mock { | |
|
|
||
| fn set_delegated(&self, pubkey: &Pubkey, delegated: bool) -> &Self { | ||
| trace!("Setting delegated for account: {pubkey} to {delegated}"); | ||
| let mut accounts = self.accounts.lock().unwrap(); | ||
| if let Some(account) = accounts.get_mut(pubkey) { | ||
| if let Some(mut account) = self.accounts.get(pubkey) { | ||
| account.set_delegated(delegated); | ||
| } else { | ||
| panic!("Account not found in bank: {pubkey}"); | ||
|
|
@@ -70,51 +69,42 @@ pub mod mock { | |
| output.push_str("AccountsBank {\n"); | ||
| let blacklisted_accounts = | ||
| blacklisted_accounts(&Pubkey::default(), &Pubkey::default()); | ||
| for pubkey in self.accounts.lock().unwrap().keys() { | ||
| if !include_blacklisted && blacklisted_accounts.contains(pubkey) | ||
| { | ||
| continue; | ||
| self.accounts.scan(|pk, _| { | ||
| if !include_blacklisted && blacklisted_accounts.contains(pk) { | ||
| return; | ||
| } | ||
| output.push_str(&format!("{pubkey},\n")); | ||
| } | ||
| output.push_str(&format!("{pk},\n")); | ||
| }); | ||
| output.push_str("} "); | ||
| output.push_str(&format!( | ||
| "{} total", | ||
| self.accounts.lock().unwrap().len() | ||
| )); | ||
| output.push_str(&format!("{} total", self.accounts.len())); | ||
| output | ||
| } | ||
| } | ||
|
|
||
| impl AccountsBank for AccountsBankStub { | ||
| fn get_account(&self, pubkey: &Pubkey) -> Option<AccountSharedData> { | ||
| self.accounts.lock().unwrap().get(pubkey).cloned() | ||
| self.get(pubkey) | ||
| } | ||
| fn remove_account(&self, pubkey: &Pubkey) { | ||
| self.accounts.lock().unwrap().remove(pubkey); | ||
| self.accounts.remove(pubkey); | ||
| } | ||
| fn remove_where( | ||
| &self, | ||
| predicate: impl Fn(&Pubkey, &AccountSharedData) -> bool, | ||
| ) -> usize { | ||
| let mut accounts = self.accounts.lock().unwrap(); | ||
| let initial_len = accounts.len(); | ||
| accounts.retain(|k, v| !predicate(k, v)); | ||
| initial_len - accounts.len() | ||
| let initial_len = self.accounts.len(); | ||
| self.accounts.retain(|k, v| !predicate(k, v)); | ||
| initial_len - self.accounts.len() | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for AccountsBankStub { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "AccountsBankStub {{")?; | ||
| for (pubkey, acc) in self.accounts.lock().unwrap().iter() { | ||
| write!(f, "\n - {pubkey}{acc:?}")?; | ||
| } | ||
| write!( | ||
| f, | ||
| "}}\nTotal {} accounts", | ||
| self.accounts.lock().unwrap().len() | ||
| ) | ||
| self.accounts.scan(|pubkey, acc| { | ||
| let _ = write!(f, "\n - {pubkey}{acc:?}"); | ||
| }); | ||
| write!(f, "}}\nTotal {} accounts", self.accounts.len()) | ||
| } | ||
|
Comment on lines
+104
to
108
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. 🧹 Nitpick | 🔵 Trivial fmt using scan is OK, but avoid heavy work in scan if it becomes parallel later. If scan ever becomes parallel, writing to fmt::Formatter inside the closure would be unsafe. Today it’s synchronous; to future‑proof, collect into a String in scan and write once afterward. 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
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.
Fix scc::HashMap insertion: use insert or proper upsert signature.
scc::HashMap::upsert typically requires an update closure; the 2‑arg form is invalid. Use insert or the 3‑arg upsert variant.
Apply one of these:
Or, if you truly want upsert semantics with an update:
📝 Committable suggestion
🤖 Prompt for AI Agents