Skip to content
Permalink
Browse files

stratum result returns blockhash on valid solution

  • Loading branch information...
shrikus authored and oneevil committed Aug 14, 2019
1 parent 4bca6c7 commit 33f7d100455b6bbf20578c6e246ba8b1fc783bba
Showing with 26 additions and 3 deletions.
  1. +7 −1 node/node.cpp
  2. +12 −1 pow/external_pow.h
  3. +3 −1 pow/stratum.cpp
  4. +1 −0 pow/stratum.h
  5. +3 −0 pow/stratum_server.cpp
@@ -3743,10 +3743,16 @@ IExternalPOW::BlockFoundResult Node::Miner::OnMinedExternal()
return IExternalPOW::solution_rejected;
}

IExternalPOW::BlockFoundResult result(IExternalPOW::solution_accepted);
Merkle::Hash hv;
pTask->m_Hdr.get_Hash(hv);
result._blockhash = to_hex(hv.m_pData, hv.nBytes);

m_pTask = pTask;
*m_pTask->m_pStop = true;
m_pEvtMined->post();
return IExternalPOW::solution_accepted;

return result;
}

void Node::Miner::OnMined()
@@ -20,7 +20,18 @@ namespace beam {

class IExternalPOW {
public:
enum BlockFoundResult { solution_accepted, solution_rejected, solution_expired };
enum BlockFoundResultCode { solution_accepted, solution_rejected, solution_expired };

struct BlockFoundResult {
BlockFoundResult(BlockFoundResultCode code) : _code(code) {}
virtual ~BlockFoundResult() = default;

bool operator ==(BlockFoundResultCode code) { return _code == code; }
bool operator !=(BlockFoundResultCode code) { return _code != code; }

BlockFoundResultCode _code;
std::string _blockhash;
};

using BlockFound = std::function<BlockFoundResult()>;

@@ -68,6 +68,7 @@ namespace {
DEF_LABEL(height);
DEF_LABEL(nonceprefix);
DEF_LABEL(forkheight);
DEF_LABEL(blockhash);
#undef DEF_LABEL

ResultCode parse_json(const void* buf, size_t bufSize, json& o) {
@@ -203,7 +204,8 @@ bool append_json_msg(io::FragmentWriter& packer, const Result& m) {
o[l_code] = m.code;
o[l_description] = m.description;
if (!m.nonceprefix.empty()) o[l_nonceprefix] = m.nonceprefix;
if (m.forkheight != MaxHeight) o[l_forkheight] = m.forkheight;
if (m.forkheight != MaxHeight) o[l_forkheight] = m.forkheight;
if (!m.blockhash.empty()) o[l_blockhash] = m.blockhash;
return serialize_json_msg(packer, o);
}

@@ -124,6 +124,7 @@ struct Result : Message {
ResultCode code=no_error;
std::string description;
std::string nonceprefix;
std::string blockhash;
uint64_t forkheight = MaxHeight;

Result() = default;
@@ -176,6 +176,9 @@ bool Server::on_solution(uint64_t from, const Solution& sol) {
stratumCode = stratum::solution_expired;
}
Result res(sol.id, stratumCode);
if (result == IExternalPOW::solution_accepted) {
res.blockhash = result._blockhash;
}
append_json_msg(_fw, res);
bool sent = _connections[from]->send_msg(_currentMsg, true);
_currentMsg.clear();

0 comments on commit 33f7d10

Please sign in to comment.
You can’t perform that action at this time.