Skip to content

Commit

Permalink
Harvester wait for partial diff at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
madMAx43v3r committed Oct 16, 2024
1 parent d999253 commit 478b74a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/mmx/Harvester.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Harvester : public HarvesterBase {
const uint32_t score, const int64_t time_begin_ms) const;

private:
bool is_ready = false;
hash_t harvester_id;
uint64_t total_bytes = 0;
uint64_t total_bytes_effective = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/Farmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ uint64_t Farmer::get_partial_diff(const addr_t& plot_nft) const
return stats.partial_diff;
}
}
return 1;
return 0;
}

std::map<addr_t, uint64_t> Farmer::get_partial_diffs(const std::vector<addr_t>& plot_nfts) const
{
std::map<addr_t, uint64_t> out;
for(const auto& addr : plot_nfts) {
out[addr] = get_partial_diff(addr);
if(auto diff = get_partial_diff(addr)) {
out[addr] = diff;
}
}
return out;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Harvester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void Harvester::check_queue()

void Harvester::handle(std::shared_ptr<const Challenge> value)
{
if(value->max_delay < 2) {
if(!is_ready || value->max_delay < 2) {
return;
}
if(!already_checked.insert(value->challenge).second) {
Expand Down Expand Up @@ -643,8 +643,8 @@ void Harvester::reload()
}
}
for(const auto& entry : plot_map) {
if(auto contract = entry.second->get_contract()) {
plot_contract_set[*contract]++;
if(const auto& addr = entry.second->get_contract()) {
plot_contract_set[*addr]++;
}
}

Expand All @@ -653,8 +653,14 @@ void Harvester::reload()

// check challenges again for new plots
if(plots.size()) {
is_ready = false;
already_checked.clear();
}
if(!is_ready) {
set_timeout_millis(3000, [this]() {
is_ready = true;
});
}
log(INFO) << "[" << my_name << "] Loaded " << plot_map.size() << " plots, "
<< total_bytes / pow(1000, 4) << " TB, " << total_bytes_effective / pow(1000, 4) << " TBe, "
<< virtual_map.size() << " virtual plots, " << total_balance / pow(10, params->decimals) << " MMX total, took "
Expand Down Expand Up @@ -742,6 +748,7 @@ void Harvester::update_nfts()
}
if(--(*job) == 0) {
update();
set_timeout_millis(2000, std::bind(&Harvester::update, this));
}
},
[this, address](const std::exception& ex) {
Expand Down

0 comments on commit 478b74a

Please sign in to comment.