Skip to content

Commit

Permalink
Merge branch 'master' into joncinque-min-dele-merged
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-at-planetariummusic committed Nov 7, 2023
2 parents 10a7e94 + aca4dd4 commit 53239bc
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 24 deletions.
60 changes: 38 additions & 22 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,13 @@ fn classify(
|| too_many_poor_block_producers
{
notes.push("Stake adjustments skipped this epoch".to_string());

if env::var("SEND_SLACK_MESSAGES").is_ok() {
if let Err(e) = send_slack_channel_message(&notes.join("\n")) {
info!("Could not send slack message: {:?}", e);
};
}

None
} else {
let mut validator_classifications = HashMap::new();
Expand Down Expand Up @@ -1860,17 +1867,19 @@ fn classify(
let insufficent_testnet_participation: Option<String> = testnet_participation
.as_ref()
.and_then(|testnet_participation| {
testnet_participation.get(&identity).and_then(|passed| {
if !passed {
let note = "Insufficient testnet participation".to_string();
if config.enforce_testnet_participation {
return Some(note);
} else {
validator_notes.push(note);
}
let passed = testnet_participation
.get(&identity)
.map_or(false, |found_passed| *found_passed);

if !passed {
let note = "Insufficient testnet participation".to_string();
if config.enforce_testnet_participation {
return Some(note);
} else {
validator_notes.push(note);
}
None
})
}
None
});

let performance_requirements_waived =
Expand Down Expand Up @@ -2754,13 +2763,16 @@ fn calculate_commission_at_end_of_epoch(
Some(records) => {
// First check if there is a commission change record in `epoch`. The last one will
// give us the commision at the end of the epoch.
let mut rs: Vec<&CommissionChangeIndexHistoryEntry> =
records.iter().filter(|r| r.epoch <= epoch).collect();
let mut rs: Vec<&CommissionChangeIndexHistoryEntry> = records
.iter()
.filter(|r| r.epoch.is_some() && r.epoch.unwrap() <= epoch)
.collect();

if !rs.is_empty() {
rs.sort_by(|a, b| {
a.epoch
.cmp(&b.epoch)
.unwrap()
.cmp(&b.epoch.unwrap())
.then(a.epoch_completion.partial_cmp(&b.epoch_completion).unwrap())
});
rs.last().unwrap().commission_after.unwrap() as u8
Expand All @@ -2769,7 +2781,11 @@ fn calculate_commission_at_end_of_epoch(
// `epoch + 1`. The first one will give us the commission at the end of `epoch`.
let mut rs: Vec<&CommissionChangeIndexHistoryEntry> = records
.iter()
.filter(|r| r.commission_before.is_some() && r.epoch > epoch)
.filter(|r| {
r.commission_before.is_some()
&& r.epoch.is_some()
&& r.epoch.unwrap() > epoch
})
.collect();
if rs.is_empty() {
// no commission changes in epoch `epoch + 1`; commission is the current
Expand Down Expand Up @@ -2915,7 +2931,7 @@ mod test {
CommissionChangeIndexHistoryEntry {
commission_before: Some(expected_commission as f32),
commission_after: Some(10.0),
epoch: epoch + 2,
epoch: Some(epoch + 2),
epoch_completion: 50.0,
..Default::default()
},
Expand Down Expand Up @@ -2944,31 +2960,31 @@ mod test {
CommissionChangeIndexHistoryEntry {
commission_before: Some(50.0),
commission_after: Some(40.0),
epoch: epoch + 1,
epoch: Some(epoch + 1),
epoch_completion: 50.0,
..Default::default()
},
// first
CommissionChangeIndexHistoryEntry {
commission_before: None,
commission_after: Some(10.0),
epoch: 120,
epoch: Some(120),
epoch_completion: 10.0,
..Default::default()
},
// second
CommissionChangeIndexHistoryEntry {
commission_before: Some(10.0),
commission_after: Some(expected_commission),
epoch,
epoch: Some(epoch),
epoch_completion: 99.0,
..Default::default()
},
// third
CommissionChangeIndexHistoryEntry {
commission_before: Some(expected_commission),
commission_after: Some(50.0),
epoch: epoch + 1,
epoch: Some(epoch + 1),
epoch_completion: 10.0,
..Default::default()
},
Expand All @@ -2991,7 +3007,7 @@ mod test {
let history = [CommissionChangeIndexHistoryEntry {
commission_before: Some(expected_commission),
commission_after: Some(current_commission),
epoch: epoch + 1,
epoch: Some(epoch + 1),
epoch_completion: 50.0,
..Default::default()
}]
Expand All @@ -3015,14 +3031,14 @@ mod test {
CommissionChangeIndexHistoryEntry {
commission_before: Some(expected_commission),
commission_after: Some(10.0),
epoch: epoch + 1,
epoch: Some(epoch + 1),
epoch_completion: 50.0,
..Default::default()
},
CommissionChangeIndexHistoryEntry {
commission_before: Some(10.0),
commission_after: Some(50.0),
epoch: epoch + 1,
epoch: Some(epoch + 1),
epoch_completion: 60.0,
..Default::default()
},
Expand Down
4 changes: 4 additions & 0 deletions bot/src/rpc_client_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ pub fn send_and_confirm_transactions_with_spinner(
if Instant::now().duration_since(last_resend) > transaction_resend_interval {
for (index, (_i, transaction)) in pending_transactions.values().enumerate() {
let method = if dry_run {
client
.simulate_transaction(transaction)
.map_err(|e| transaction_errors.push(e.get_transaction_error()))
.ok();
"DRY RUN"
} else {
client.send_transaction(transaction)
Expand Down
Loading

0 comments on commit 53239bc

Please sign in to comment.