Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Do not skip block if no bid was placed #11

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/hunter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@ impl Hunter {
if bidders.is_empty() {
tracing::info!(" no bidders were found");

self.try_tender(auction.index, self.configuration.bid.increment, 0).await?;

*has_bid = true;
*has_bid = self.try_tender(auction.index, self.configuration.bid.increment, 0).await?;

return Ok(None);
}
Expand Down Expand Up @@ -455,15 +453,18 @@ impl Hunter {
let bid =
winning.minimum_bid_to_win(&leases, threshold) + self.configuration.bid.increment;

self.try_tender(auction.index, bid, self_bid).await?;

*has_bid = true;
*has_bid = self.try_tender(auction.index, bid, self_bid).await?;
}

Ok(())
}

async fn try_tender(&self, auction_index: u32, bid: Balance, self_bid: Balance) -> Result<()> {
async fn try_tender(
&self,
auction_index: u32,
bid: Balance,
self_bid: Balance,
) -> Result<bool> {
if self.watch_only() {
fn log(mode: &str, bid: String) {
tracing::warn!(" slothunter is running under the watch-only mode, {mode} {bid} manually to win");
Expand All @@ -475,12 +476,13 @@ impl Hunter {
log("contribute", self.configuration.token.fmt(bid - self_bid))
}

Ok(())
Ok(false)
} else {
fn log(mode: &str, bid: String, upper_limit: String) -> String {
format!(" skip {mode} {bid} because it exceeds the upper limit {upper_limit}")
}

let mut has_bid = false;
let notification;

if self.is_self_funded() {
Expand All @@ -496,6 +498,7 @@ impl Hunter {

tracing::info!("{n}");

has_bid = true;
notification = n.trim_start_matches(' ').to_string();
}
} else {
Expand Down Expand Up @@ -525,6 +528,7 @@ impl Hunter {

tracing::info!("{n}");

has_bid = true;
notification = n.trim_start_matches(' ').to_string();
}
} else {
Expand All @@ -543,7 +547,7 @@ impl Hunter {
self.notify_mail(&None::<()>, &notification);
self.notify_webhook(&None::<()>, &notification).await;

Ok(())
Ok(has_bid)
}
}
}