-
Notifications
You must be signed in to change notification settings - Fork 49
feat: schedule automatic undelegation on AML check failure #1300
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
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 |
|---|---|---|
|
|
@@ -19,8 +19,10 @@ use magicblock_aperture::{ | |
| state::{NodeContext, SharedState}, | ||
| }; | ||
| use magicblock_chainlink::{ | ||
| config::ChainlinkConfig, remote_account_provider::Endpoints, ProdChainlink, | ||
| ProdInnerChainlink, | ||
| config::ChainlinkConfig, | ||
| fetch_cloner::{UndelegationScheduleRequest, UndelegationScheduler}, | ||
| remote_account_provider::Endpoints, | ||
| ProdChainlink, ProdInnerChainlink, | ||
| }; | ||
| use magicblock_committor_service::{ | ||
| config::ChainConfig, BaseIntentCommittor, CommittorService, | ||
|
|
@@ -99,6 +101,29 @@ use crate::{ | |
| type InnerChainlinkImpl = ProdInnerChainlink<ChainlinkCloner>; | ||
|
|
||
| type ChainlinkImpl = ProdChainlink<ChainlinkCloner>; | ||
| /// Bridges chainlink's [`UndelegationScheduler`] to the committor service so a | ||
| /// delegated clone rejected by AML is undelegated on the base layer. | ||
| struct CommittorUndelegationScheduler(Arc<CommittorService>); | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl UndelegationScheduler for CommittorUndelegationScheduler { | ||
| async fn schedule_undelegation( | ||
| &self, | ||
| request: UndelegationScheduleRequest, | ||
| ) -> magicblock_chainlink::errors::ChainlinkResult<()> { | ||
| let pubkey = request.pubkey; | ||
| self.0 | ||
| .schedule_undelegation(pubkey, request.account) | ||
| .await | ||
| .map_err(|err| format!("committor response channel closed: {err}")) | ||
| .and_then(|result| result.map_err(|err| err.to_string())) | ||
| .map_err(|message| { | ||
|
Comment on lines
+115
to
+120
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. Add a timeout around committor scheduling await. Line 115 awaits the committor response without a deadline. If that actor stalls, this task can hang indefinitely and back up AML-rejection handling. Bound this external call with a timeout and map timeout to the same chainlink error variant. Suggested fix let pubkey = request.pubkey;
- self.0
- .schedule_undelegation(pubkey, request.account)
- .await
+ tokio::time::timeout(
+ Duration::from_secs(5),
+ self.0.schedule_undelegation(pubkey, request.account),
+ )
+ .await
+ .map_err(|_| "committor schedule_undelegation timed out".to_string())?
.map_err(|err| format!("committor response channel closed: {err}"))
.and_then(|result| result.map_err(|err| err.to_string()))
.map_err(|message| {
magicblock_chainlink::errors::ChainlinkError::FailedToScheduleUndelegationAfterAmlRejection(
pubkey, message,
)
})🤖 Prompt for AI Agents |
||
| magicblock_chainlink::errors::ChainlinkError::FailedToScheduleUndelegationAfterAmlRejection( | ||
| pubkey, message, | ||
| ) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // ----------------- | ||
| // MagicValidator | ||
|
|
@@ -238,6 +263,7 @@ impl MagicValidator { | |
| &ledger.latest_block().clone(), | ||
| &accountsdb, | ||
| shared_chain_slot.clone(), | ||
| committor_service.clone(), | ||
| ) | ||
| .await?, | ||
| ); | ||
|
|
@@ -495,6 +521,7 @@ impl MagicValidator { | |
| latest_block: &LatestBlock, | ||
| accountsdb: &Arc<AccountsDb>, | ||
| chain_slot: Option<Arc<AtomicU64>>, | ||
| committor_service: Option<Arc<CommittorService>>, | ||
| ) -> ApiResult<ChainlinkImpl> { | ||
| if Self::replication_mode_uses_disabled_chainlink( | ||
| &config.validator.replication_mode, | ||
|
|
@@ -550,6 +577,10 @@ impl MagicValidator { | |
| &config.chainlink, | ||
| config.storage.as_path(), | ||
| chain_slot.unwrap_or_default(), | ||
| committor_service.map(|committor_service| { | ||
| Arc::new(CommittorUndelegationScheduler(committor_service)) | ||
| as Arc<dyn UndelegationScheduler> | ||
| }), | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
||
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.
magic_validator.rsis already massive, let's extract this into separate file