Skip to content

Commit e4f241d

Browse files
committed
feat: added error message field into SentCommit
feat: trigger SentCommit on intent failure and failed retry
1 parent 438c527 commit e4f241d

File tree

7 files changed

+141
-74
lines changed

7 files changed

+141
-74
lines changed

magicblock-accounts/src/scheduled_commits_processor.rs

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use magicblock_chainlink::{
1616
Chainlink,
1717
};
1818
use magicblock_committor_service::{
19-
intent_execution_manager::{
20-
BroadcastedIntentExecutionResult, ExecutionOutputWrapper,
21-
},
19+
intent_execution_manager::BroadcastedIntentExecutionResult,
2220
intent_executor::ExecutionOutput,
2321
types::{ScheduledBaseIntentWrapper, TriggerType},
2422
BaseIntentCommittor, CommittorService,
@@ -241,79 +239,56 @@ impl ScheduledCommitsProcessorImpl {
241239
continue;
242240
};
243241

244-
match execution_result {
245-
Ok(value) => {
246-
Self::process_intent_result(
247-
intent_id,
248-
&internal_transaction_scheduler,
249-
value,
250-
intent_meta,
251-
)
252-
.await;
253-
}
254-
Err((_, _, err)) => {
255-
match err.as_ref() {
256-
&magicblock_committor_service::intent_executor::error::IntentExecutorError::EmptyIntentError => {
257-
warn!("Empty intent was scheduled!");
258-
Self::process_empty_intent(
259-
intent_id,
260-
&internal_transaction_scheduler,
261-
intent_meta
262-
).await;
263-
}
264-
_ => {
265-
error!(
266-
"Failed to commit in slot: {}, blockhash: {}. {:?}",
267-
intent_meta.slot, intent_meta.blockhash, err
268-
);
269-
}
270-
}
271-
}
272-
}
242+
Self::process_intent_result(
243+
intent_id,
244+
&internal_transaction_scheduler,
245+
execution_result,
246+
intent_meta,
247+
)
248+
.await;
273249
}
274250
}
275251

276252
async fn process_intent_result(
277253
intent_id: u64,
278254
internal_transaction_scheduler: &TransactionSchedulerHandle,
279-
execution_outcome: ExecutionOutputWrapper,
255+
result: BroadcastedIntentExecutionResult,
280256
mut intent_meta: ScheduledBaseIntentMeta,
281257
) {
282-
let chain_signatures = match execution_outcome.output {
283-
ExecutionOutput::SingleStage(signature) => vec![signature],
284-
ExecutionOutput::TwoStage {
285-
commit_signature,
286-
finalize_signature,
287-
} => vec![commit_signature, finalize_signature],
288-
};
289-
let intent_sent_transaction =
290-
std::mem::take(&mut intent_meta.intent_sent_transaction);
291-
let sent_commit =
292-
Self::build_sent_commit(intent_id, chain_signatures, intent_meta);
293-
register_scheduled_commit_sent(sent_commit);
294-
match internal_transaction_scheduler
295-
.execute(intent_sent_transaction)
296-
.await
297-
{
298-
Ok(signature) => debug!(
299-
"Signaled sent commit with internal signature: {:?}",
300-
signature
301-
),
302-
Err(err) => {
303-
error!("Failed to signal sent commit via transaction: {}", err);
258+
let error_message = result
259+
.as_ref()
260+
.err()
261+
.map(|(_, _, err)| format!("{:?}", err));
262+
let chain_signatures = match result {
263+
Ok(execution_outcome) => match execution_outcome.output {
264+
ExecutionOutput::SingleStage(signature) => vec![signature],
265+
ExecutionOutput::TwoStage {
266+
commit_signature,
267+
finalize_signature,
268+
} => vec![commit_signature, finalize_signature],
269+
},
270+
Err((_, _, err)) => {
271+
error!(
272+
"Failed to commit in slot: {}, blockhash: {}. {:?}",
273+
intent_meta.slot, intent_meta.blockhash, err
274+
);
275+
err.signatures()
276+
.map(|(commit, finalize)| {
277+
finalize
278+
.map(|finalize| vec![commit, finalize])
279+
.unwrap_or(vec![commit])
280+
})
281+
.unwrap_or(vec![])
304282
}
305-
}
306-
}
307-
308-
async fn process_empty_intent(
309-
intent_id: u64,
310-
internal_transaction_scheduler: &TransactionSchedulerHandle,
311-
mut intent_meta: ScheduledBaseIntentMeta,
312-
) {
283+
};
313284
let intent_sent_transaction =
314285
std::mem::take(&mut intent_meta.intent_sent_transaction);
315-
let sent_commit =
316-
Self::build_sent_commit(intent_id, vec![], intent_meta);
286+
let sent_commit = Self::build_sent_commit(
287+
intent_id,
288+
chain_signatures,
289+
intent_meta,
290+
error_message,
291+
);
317292
register_scheduled_commit_sent(sent_commit);
318293
match internal_transaction_scheduler
319294
.execute(intent_sent_transaction)
@@ -333,6 +308,7 @@ impl ScheduledCommitsProcessorImpl {
333308
intent_id: u64,
334309
chain_signatures: Vec<Signature>,
335310
intent_meta: ScheduledBaseIntentMeta,
311+
error_message: Option<String>,
336312
) -> SentCommit {
337313
SentCommit {
338314
message_id: intent_id,
@@ -343,6 +319,7 @@ impl ScheduledCommitsProcessorImpl {
343319
included_pubkeys: intent_meta.included_pubkeys,
344320
excluded_pubkeys: intent_meta.excluded_pubkeys,
345321
requested_undelegation: intent_meta.requested_undelegation,
322+
error_message,
346323
}
347324
}
348325
}

magicblock-committor-service/src/intent_executor/error.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ impl IntentExecutorError {
105105
}
106106
}
107107
}
108+
109+
pub fn signatures(&self) -> Option<(Signature, Option<Signature>)> {
110+
match self {
111+
IntentExecutorError::CpiLimitError(_, signature)
112+
| IntentExecutorError::ActionsError(_, signature)
113+
| IntentExecutorError::CommitIDError(_, signature)
114+
| IntentExecutorError::UndelegationError(_, signature)
115+
| IntentExecutorError::FailedToCommitError { signature, err: _ } => {
116+
signature.map(|el| (el, None))
117+
}
118+
IntentExecutorError::FailedCommitPreparationError(err)
119+
| IntentExecutorError::FailedFinalizePreparationError(err) => {
120+
err.signature().map(|el| (el, None))
121+
}
122+
IntentExecutorError::TaskBuilderError(err) => {
123+
err.signature().map(|el| (el, None))
124+
}
125+
IntentExecutorError::FailedToFinalizeError {
126+
err: _,
127+
commit_signature,
128+
finalize_signature,
129+
} => commit_signature.map(|el| (el, *finalize_signature)),
130+
IntentExecutorError::EmptyIntentError
131+
| IntentExecutorError::FailedToFitError
132+
| IntentExecutorError::SignerError(_) => None,
133+
}
134+
}
108135
}
109136

110137
impl metrics::LabelValue for IntentExecutorError {

magicblock-committor-service/src/intent_executor/task_info_fetcher.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use log::{error, warn};
1010
use lru::LruCache;
1111
use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient};
1212
use solana_pubkey::Pubkey;
13+
use solana_sdk::signature::Signature;
1314

1415
const NUM_FETCH_RETRIES: NonZeroUsize =
1516
unsafe { NonZeroUsize::new_unchecked(5) };
@@ -274,4 +275,14 @@ pub enum TaskInfoFetcherError {
274275
MagicBlockRpcClientError(#[from] MagicBlockRpcClientError),
275276
}
276277

278+
impl TaskInfoFetcherError {
279+
pub fn signature(&self) -> Option<Signature> {
280+
match self {
281+
Self::MetadataNotFoundError(_) => None,
282+
Self::InvalidAccountDataError(_) => None,
283+
Self::MagicBlockRpcClientError(err) => err.signature(),
284+
}
285+
}
286+
}
287+
277288
pub type TaskInfoFetcherResult<T, E = TaskInfoFetcherError> = Result<T, E>;

magicblock-committor-service/src/tasks/task_builder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use magicblock_program::magic_scheduled_base_intent::{
77
UndelegateType,
88
};
99
use solana_pubkey::Pubkey;
10+
use solana_sdk::signature::Signature;
1011

1112
use crate::{
1213
intent_executor::task_info_fetcher::{
@@ -206,4 +207,13 @@ pub enum TaskBuilderError {
206207
FinalizedTasksBuildError(#[source] TaskInfoFetcherError),
207208
}
208209

210+
impl TaskBuilderError {
211+
pub fn signature(&self) -> Option<Signature> {
212+
match self {
213+
Self::CommitTasksBuildError(err) => err.signature(),
214+
Self::FinalizedTasksBuildError(err) => err.signature(),
215+
}
216+
}
217+
}
218+
209219
pub type TaskBuilderResult<T, E = TaskBuilderError> = Result<T, E>;

magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ impl DeliveryPreparator {
7777
let (res1, res2) = join(task_preparations, alts_preparations).await;
7878
res1.into_iter()
7979
.collect::<Result<Vec<_>, _>>()
80-
.map_err(Error::FailedToPrepareBufferAccounts)?;
81-
let lookup_tables = res2.map_err(Error::FailedToCreateALTError)?;
80+
.map_err(DeliveryPreparatorError::FailedToPrepareBufferAccounts)?;
81+
let lookup_tables =
82+
res2.map_err(DeliveryPreparatorError::FailedToCreateALTError)?;
8283

8384
Ok(lookup_tables)
8485
}
@@ -524,12 +525,31 @@ pub enum InternalError {
524525
BaseTaskError(#[from] BaseTaskError),
525526
}
526527

528+
impl InternalError {
529+
pub fn signature(&self) -> Option<Signature> {
530+
match self {
531+
Self::MagicBlockRpcClientError(err) => err.signature(),
532+
_ => None,
533+
}
534+
}
535+
}
536+
527537
#[derive(thiserror::Error, Debug)]
528-
pub enum Error {
538+
pub enum DeliveryPreparatorError {
529539
#[error("FailedToPrepareBufferAccounts: {0}")]
530540
FailedToPrepareBufferAccounts(#[source] InternalError),
531541
#[error("FailedToCreateALTError: {0}")]
532542
FailedToCreateALTError(#[source] InternalError),
533543
}
534544

535-
pub type DeliveryPreparatorResult<T, E = Error> = Result<T, E>;
545+
impl DeliveryPreparatorError {
546+
pub fn signature(&self) -> Option<Signature> {
547+
match self {
548+
Self::FailedToCreateALTError(err)
549+
| Self::FailedToPrepareBufferAccounts(err) => err.signature(),
550+
}
551+
}
552+
}
553+
554+
pub type DeliveryPreparatorResult<T, E = DeliveryPreparatorError> =
555+
Result<T, E>;

magicblock-committor-service/src/transaction_preparator/error.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use solana_sdk::signer::SignerError;
1+
use solana_sdk::{signature::Signature, signer::SignerError};
22
use thiserror::Error;
33

4-
use crate::tasks::task_strategist::TaskStrategistError;
4+
use crate::{
5+
tasks::task_strategist::TaskStrategistError,
6+
transaction_preparator::delivery_preparator::DeliveryPreparatorError,
7+
};
58

69
#[derive(Error, Debug)]
710
pub enum TransactionPreparatorError {
@@ -10,9 +13,16 @@ pub enum TransactionPreparatorError {
1013
#[error("SignerError: {0}")]
1114
SignerError(#[from] SignerError),
1215
#[error("DeliveryPreparationError: {0}")]
13-
DeliveryPreparationError(
14-
#[from] crate::transaction_preparator::delivery_preparator::Error,
15-
),
16+
DeliveryPreparationError(#[from] DeliveryPreparatorError),
17+
}
18+
19+
impl TransactionPreparatorError {
20+
pub fn signature(&self) -> Option<Signature> {
21+
match self {
22+
Self::DeliveryPreparationError(err) => err.signature(),
23+
_ => None,
24+
}
25+
}
1626
}
1727

1828
impl From<TaskStrategistError> for TransactionPreparatorError {

programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct SentCommit {
2626
pub included_pubkeys: Vec<Pubkey>,
2727
pub excluded_pubkeys: Vec<Pubkey>,
2828
pub requested_undelegation: bool,
29+
pub error_message: Option<String>,
2930
}
3031

3132
/// This is a printable version of the SentCommit struct.
@@ -40,6 +41,7 @@ struct SentCommitPrintable {
4041
included_pubkeys: String,
4142
excluded_pubkeys: String,
4243
requested_undelegation: bool,
44+
error_message: Option<String>,
4345
}
4446

4547
impl From<SentCommit> for SentCommitPrintable {
@@ -67,6 +69,7 @@ impl From<SentCommit> for SentCommitPrintable {
6769
.collect::<Vec<_>>()
6870
.join(", "),
6971
requested_undelegation: commit.requested_undelegation,
72+
error_message: commit.error_message,
7073
}
7174
}
7275
}
@@ -210,6 +213,14 @@ pub fn process_scheduled_commit_sent(
210213
ic_msg!(invoke_context, "ScheduledCommitSent requested undelegation",);
211214
}
212215

216+
if let Some(error_message) = commit.error_message {
217+
ic_msg!(
218+
invoke_context,
219+
"ScheduledCommitSent error message: {}",
220+
error_message
221+
);
222+
}
223+
213224
Ok(())
214225
}
215226

@@ -245,6 +256,7 @@ mod tests {
245256
included_pubkeys: vec![acc],
246257
excluded_pubkeys: Default::default(),
247258
requested_undelegation: false,
259+
error_message: None,
248260
}
249261
}
250262

0 commit comments

Comments
 (0)