Skip to content

Commit

Permalink
Wrap around the Q score index (#935)
Browse files Browse the repository at this point in the history
## Describe your changes

Wrap around q score sample index if it overflows
  • Loading branch information
Gauthamastro authored Mar 25, 2024
2 parents 6c46f4a + 4112c11 commit ef58440
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 1 addition & 4 deletions pallets/ocex/src/lmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ pub fn store_q_score_and_uptime(
Some(encoded_q_scores_map) => {
let mut map = BTreeMap::<u16, Decimal>::decode(&mut &encoded_q_scores_map[..])
.map_err(|_| "Unable to decode decimal")?;
if map.insert(index, score).is_some() {
log::error!(target:"ocex","Overwriting q score with index: {:?}, epoch: {:?}, main: {:?}, market: {:?}",index,epoch,main,trading_pair);
return Err("Overwriting q score");
}
map.insert(index, score); // We overwrite on wrapping around
log::info!(target: "ocex","Writing Q score and uptime for main: {:?}",main);
state.insert(key, map.encode());
},
Expand Down
3 changes: 2 additions & 1 deletion pallets/ocex/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ impl<T: Config> Pallet<T> {
current_on_chain_epoch: u16,
) -> Result<(), &'static str> {
let mut config = get_lmp_config(state, current_on_chain_epoch)?;
let next_index = config.index.saturating_add(1);
// We wrap around the index if we overflow
let next_index = config.index.checked_add(1).unwrap_or(0);
for (main, score) in scores {
store_q_score_and_uptime(
state,
Expand Down

0 comments on commit ef58440

Please sign in to comment.