Skip to content

Commit a7b4aa5

Browse files
committed
feat: limiting stale reallocs until we bail
1 parent 3cf473d commit a7b4aa5

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

magicblock-committor-service/src/commit/commit_using_buffer.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::{
5151
struct NextReallocs {
5252
missing_size: u64,
5353
start_idx: usize,
54+
err: Option<String>,
5455
}
5556

5657
impl CommittorProcessor {
@@ -826,11 +827,30 @@ impl CommittorProcessor {
826827
blockhash: ephemeral_blockhash,
827828
};
828829

830+
const MAX_STALE_REALLOCS: u8 = 10;
831+
let mut prev_missing_size = 0;
832+
let mut remaining_tries = MAX_STALE_REALLOCS;
829833
while let Some(NextReallocs {
830834
missing_size,
831835
start_idx,
836+
err,
832837
}) = next_reallocs
833838
{
839+
if missing_size == prev_missing_size {
840+
remaining_tries -= 1;
841+
if remaining_tries == 0 {
842+
return Err(
843+
CommitAccountError::ReallocBufferRanOutOfRetries(
844+
err.unwrap_or("No Error".to_string()),
845+
Arc::new(commit_info.clone()),
846+
commit_strategy,
847+
),
848+
);
849+
}
850+
} else {
851+
remaining_tries = MAX_STALE_REALLOCS;
852+
prev_missing_size = missing_size;
853+
}
834854
let realloc_ixs = {
835855
let realloc_ixs =
836856
create_realloc_buffer_ixs_to_add_remaining(
@@ -849,7 +869,6 @@ impl CommittorProcessor {
849869
start_idx,
850870
)
851871
.await;
852-
// TODO(thlorenz): give up at some point
853872
}
854873
}
855874
}
@@ -882,6 +901,7 @@ impl CommittorProcessor {
882901
return Some(NextReallocs {
883902
missing_size,
884903
start_idx,
904+
err: Some(format!("{:?}", err)),
885905
});
886906
}
887907
};
@@ -923,23 +943,27 @@ impl CommittorProcessor {
923943
if current_size as u64 >= desired_size {
924944
None
925945
} else {
926-
Some(desired_size - current_size as u64)
946+
Some((desired_size - current_size as u64, None))
927947
}
928948
}
929949
// NOTE: if we cannot get the account we must assume that
930950
// the entire size we just tried to alloc is still missing
931951
Ok(None) => {
932952
warn!("buffer account not found");
933-
Some(missing_size)
953+
Some((
954+
missing_size,
955+
Some("buffer account not found".to_string()),
956+
))
934957
}
935958
Err(err) => {
936959
warn!("Failed to get buffer account: {:?}", err);
937-
Some(missing_size)
960+
Some((missing_size, Some(format!("{:?}", err))))
938961
}
939962
}
940-
.map(|missing_size| NextReallocs {
963+
.map(|(missing_size, err)| NextReallocs {
941964
missing_size,
942965
start_idx: count,
966+
err,
943967
})
944968
}
945969

magicblock-committor-service/src/commit_stage.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ impl From<CommitAccountError> for CommitStage {
142142
commit_strategy,
143143
))
144144
}
145+
ReallocBufferRanOutOfRetries(err, commit_info, commit_strategy) => {
146+
warn!("Realloc buffer ran out of retries: {:?}", err);
147+
Self::BufferAndChunkPartiallyInitialized((
148+
ci!(commit_info),
149+
commit_strategy,
150+
))
151+
}
145152
WriteChunksRanOutOfRetries(err, commit_info, commit_strategy) => {
146153
warn!("Write chunks ran out of retries: {:?}", err);
147154
Self::BufferAndChunkPartiallyInitialized((

magicblock-committor-service/src/error.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,13 @@ pub enum CommitAccountError {
102102
#[error("Failed to deserialize chunks account: {0} ({0:?})")]
103103
DeserializeChunksAccount(std::io::Error, Arc<CommitInfo>, CommitStrategy),
104104

105+
#[error("Failed to affect remaining size via realloc buffer after max retries. Last error {0}")]
106+
ReallocBufferRanOutOfRetries(String, Arc<CommitInfo>, CommitStrategy),
107+
105108
#[error("Failed to write complete chunks of commit data after max retries. Last write error {0:?}")]
106109
WriteChunksRanOutOfRetries(
107110
Option<magicblock_rpc_client::MagicBlockRpcClientError>,
108111
Arc<CommitInfo>,
109112
CommitStrategy,
110113
),
111114
}
112-
113-
impl CommitAccountError {
114-
pub fn into_commit_info(self) -> CommitInfo {
115-
use CommitAccountError::*;
116-
let ci = match self {
117-
InitBufferAndChunkAccounts(_, commit_info, _) => {
118-
return *commit_info;
119-
}
120-
GetChunksAccount(_, commit_info, _) => commit_info,
121-
DeserializeChunksAccount(_, commit_info, _) => commit_info,
122-
WriteChunksRanOutOfRetries(_, commit_info, _) => commit_info,
123-
};
124-
Arc::<CommitInfo>::unwrap_or_clone(ci)
125-
}
126-
}

0 commit comments

Comments
 (0)