Skip to content

Commit

Permalink
jobmaker: Error message will be acked when subpool update fails
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Mar 22, 2020
1 parent 4424121 commit 9926315
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions src/bitcoin/JobMakerBitcoin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,28 +659,63 @@ bool JobMakerHandlerBitcoin::updateSubPoolAddr(size_t index) {

auto json = JSON::parse(str);

JSON response = {
{"created_at", date("%F %T")},
{"host",
{
{"hostname", IpAddress::getHostName()},
{"ip", IpAddress::getInterfaceAddrs()},
}},
{"name", oldPool.name_},
{"old",
{
{"coinbaseInfo", oldPool.coinbaseInfo_},
{"payoutAddr",
BitcoinUtils::EncodeDestination(oldPool.payoutAddr_)},
}},
{"new", json},
};

auto sendResponse =
[this, &response, &oldPool](bool success, const string &errMsg) {
response["success"] = success;
response["err_msg"] = errMsg;

jobmaker_->zk()->setNode(
oldPool.zkUpdatePath_ + "/ack", response.dump());
};

string errMsg = "success";

if (!json.is_object() || !json["coinbaseInfo"].is_string() ||
!json["payoutAddr"].is_string()) {
errMsg = "field missing or wrong field type";
LOG(ERROR) << "JobMakerHandlerBitcoin::updateSubPoolAddr(): "
<< "[subpool " << oldPool.name_
<< "] wrong field type, raw json: " << str;
<< "[subpool " << oldPool.name_ << "] " << errMsg
<< ", raw json: " << str;

sendResponse(false, errMsg);
return false;
}

string payoutAddrStr = json["payoutAddr"].get<string>();
string coinbaseInfo = json["coinbaseInfo"].get<string>();

if (coinbaseInfo.size() > (size_t)def()->subPoolCoinbaseMaxLen_) {
coinbaseInfo.resize(def()->subPoolCoinbaseMaxLen_);
}

if (!BitcoinUtils::IsValidDestinationString(payoutAddrStr)) {
LOG(ERROR) << "[subpool " << oldPool.name_
<< "] update failed, invalid payout address: "
<< payoutAddrStr << ", raw json: " << str;
errMsg = "invalid payout address";
LOG(ERROR) << "[subpool " << oldPool.name_ << "] update failed, "
<< errMsg << ": " << payoutAddrStr << ", raw json: " << str;

sendResponse(false, errMsg);
return false;
}

if (coinbaseInfo.size() > (size_t)def()->subPoolCoinbaseMaxLen_) {
coinbaseInfo.resize(def()->subPoolCoinbaseMaxLen_);
errMsg = "coinbase info truncated to " +
std::to_string(def()->subPoolCoinbaseMaxLen_) + " bytes";
}

LOG(INFO) << "[subpool " << oldPool.name_
<< "] coinbase updated, coinbaseInfo: " << oldPool.coinbaseInfo_
<< " -> " << coinbaseInfo << ", payoutAddr: "
Expand All @@ -695,25 +730,7 @@ bool JobMakerHandlerBitcoin::updateSubPoolAddr(size_t index) {
pool.payoutAddr_ = payoutAddr;
}

JSON response = {
{"created_at", date("%F %T")},
{"host",
{
{"hostname", IpAddress::getHostName()},
{"ip", IpAddress::getInterfaceAddrs()},
}},
{"name", oldPool.name_},
{"old",
{
{"coinbaseInfo", oldPool.coinbaseInfo_},
{"payoutAddr",
BitcoinUtils::EncodeDestination(oldPool.payoutAddr_)},
}},
{"new", json},
};

jobmaker_->zk()->setNode(oldPool.zkUpdatePath_ + "/ack", response.dump());

sendResponse(true, errMsg);
return true;
}

Expand Down

0 comments on commit 9926315

Please sign in to comment.