-
Notifications
You must be signed in to change notification settings - Fork 46
feat(committor): enforce per-account commit limit via MagicSys syscall #1024
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b469c5b
fix: address now possible race conditions in CacheTaskInfoFetcher
taco-paco b7b37d3
wip
taco-paco 420195f
fix: free locks of existing accs
taco-paco 6df5131
refactor: unnecessary comment
taco-paco 27d3062
fix: other parts
taco-paco 854c92a
feat: implementing MagicSysAdapter
taco-paco 3e05087
feat: support MagicSys through out validator
taco-paco cf4f7df
feat: return map into magic-validator instead of pure validation with…
taco-paco 0270391
fix: lint
taco-paco 78e2970
fix: compilation
taco-paco 31761e3
feat: add integration tests
taco-paco 251c8ed
feat: added docs
taco-paco 84a3af0
fix: COMMIT_LIMIT
taco-paco 2de4dc1
feat: separate cache and rpc task info fetchers
taco-paco fc18342
fix: tests
taco-paco 431630b
Merge branch 'master' into fix/committor/draining-intents
taco-paco 23268c4
fix: tests
taco-paco 977f430
fix: coderabbit
taco-paco 11b0a02
fix: pr comments
taco-paco c621d8c
fix: .lock
taco-paco 69946c1
Merge branch 'master' into fix/committor/draining-intents
taco-paco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| use std::{collections::HashMap, error::Error, sync::Arc}; | ||
|
|
||
| use magicblock_committor_service::{BaseIntentCommittor, CommittorService}; | ||
| use magicblock_core::{intent::CommittedAccount, traits::MagicSys}; | ||
| use magicblock_ledger::Ledger; | ||
| use solana_instruction::error::InstructionError; | ||
| use solana_pubkey::Pubkey; | ||
| use tracing::{enabled, error, trace, Level}; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct MagicSysAdapter { | ||
| ledger: Arc<Ledger>, | ||
| committor_service: Option<Arc<CommittorService>>, | ||
| } | ||
|
|
||
| impl MagicSysAdapter { | ||
| const RECV_ERR: u32 = 0xE000_0000; | ||
| const FETCH_ERR: u32 = 0xE001_0000; | ||
| const NO_COMMITTOR_ERR: u32 = 0xE002_0000; | ||
|
taco-paco marked this conversation as resolved.
Outdated
|
||
|
|
||
| pub fn new( | ||
| ledger: Arc<Ledger>, | ||
| committor_service: Option<Arc<CommittorService>>, | ||
| ) -> Self { | ||
| Self { | ||
| ledger, | ||
| committor_service, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl MagicSys for MagicSysAdapter { | ||
| fn persist(&self, id: u64, data: Vec<u8>) -> Result<(), Box<dyn Error>> { | ||
| trace!(id, data_len = data.len(), "Persisting data"); | ||
| self.ledger.write_account_mod_data(id, &data.into())?; | ||
|
taco-paco marked this conversation as resolved.
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn load(&self, id: u64) -> Result<Option<Vec<u8>>, Box<dyn Error>> { | ||
| let data = self.ledger.read_account_mod_data(id)?.map(|x| x.data); | ||
| if enabled!(Level::TRACE) { | ||
| if let Some(data) = &data { | ||
| trace!(id, data_len = data.len(), "Loading data"); | ||
| } else { | ||
| trace!(id, found = false, "Loading data"); | ||
| } | ||
| } | ||
| Ok(data) | ||
| } | ||
|
|
||
| fn fetch_current_commit_nonces( | ||
| &self, | ||
| commits: &[CommittedAccount], | ||
| ) -> Result<HashMap<Pubkey, u64>, InstructionError> { | ||
| let committor_service = | ||
| if let Some(committor_service) = &self.committor_service { | ||
| Ok(committor_service) | ||
| } else { | ||
| Err(InstructionError::Custom(Self::NO_COMMITTOR_ERR)) | ||
| }?; | ||
|
taco-paco marked this conversation as resolved.
|
||
|
|
||
| let min_context_slot = commits | ||
| .iter() | ||
| .map(|account| account.remote_slot) | ||
| .max() | ||
| .unwrap_or(0); | ||
| let pubkeys: Vec<_> = | ||
| commits.iter().map(|account| account.pubkey).collect(); | ||
|
|
||
| let receiver = committor_service | ||
| .fetch_current_commit_nonces(&pubkeys, min_context_slot); | ||
| // Tx execution is sync and runs on a tokio worker thread. handle.block_on | ||
| // would panic (nested runtime). futures::executor::block_on parks this | ||
| // thread independently of tokio — safe because the thread is already | ||
| // committed to this tx until execution completes. | ||
| futures::executor::block_on(receiver) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| .inspect_err(|err| { | ||
| error!(error = ?err, "Failed to receive nonces from CommittorService") | ||
| }) | ||
| .map_err(|_| InstructionError::Custom(Self::RECV_ERR))? | ||
|
taco-paco marked this conversation as resolved.
Outdated
|
||
| .inspect_err(|err| { | ||
| error!(error = ?err, "Failed to fetch current commit nonces") | ||
| }) | ||
| .map_err(|_| InstructionError::Custom(Self::FETCH_ERR)) | ||
|
taco-paco marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.