void doapplyvalidation(ledger::ref lastclosedledger, stobject& basevalidation) override { dividendmaster::pointer dividendmaster = getapp().getops().getdividendmaster(); if (dividendmaster->trylock()) { if (dividendmaster->isready()) { uint32_t dividendledger = lastclosedledger->getdividendbaseledger(); if (dividendledger == dividendmaster->getledgerseq()) { basevalidation.setfieldu32 (sfdividendledger, dividendledger); basevalidation.setfieldh256 (sfdividendresulthash, dividendmaster->getresulthash()); if (m_journal.info) m_journal.info << "voting for a dividend apply based " << dividendledger << " with hash "<< dividendmaster->getresulthash() << " in " << lastclosedledger->gethash(); } else { if (m_journal.warning) m_journal.warning << "wrong base ledger " << dividendmaster->getledgerseq() << " want "<< dividendledger; } } dividendmaster->unlock(); } }
bool doapplyvoting(ledger::ref lastclosedledger, shamap::ref initialposition) override { uint32_t dividendledger = lastclosedledger->getdividendbaseledger(); int weight = 0; std::map<uint256, int> votes; // get validations for validation ledger validationset const set = getapp().getvalidations ().getvalidations (lastclosedledger->gethash ()); for (auto const& e : set) { stvalidation const& val = *e.second; if (val.istrusted ()) { if (val.isfieldpresent (sfdividendledger) && val.isfieldpresent (sfdividendresulthash)) { uint32_t ledgerseq = val.getfieldu32 (sfdividendledger); if (ledgerseq != dividendledger) continue; const uint256 & dividendhash = val.getfieldh256 (sfdividendresulthash); ++votes[dividendhash]; // if (ledgerseq != dividendledger || dividendhash != dividendresulthash) { if (m_journal.debug) m_journal.debug << "recv dividend apply vote based " << ledgerseq << " hash " << dividendhash << " from validator " << val.getnodeid() << " in " << lastclosedledger->gethash(); // continue; // } // ++weight; } } } uint256 dividendresulthash; for (auto const& v : votes) { if (v.second > weight) { dividendresulthash = v.first; weight = v.second; } } dividendmaster::pointer dividendmaster = getapp().getops().getdividendmaster(); if (!dividendmaster->trylock()) { if (weight >=getapp().getledgermaster().getminvalidations()) return false; else return true; } if (!dividendmaster->isready() || dividendledger != dividendmaster->getledgerseq() || dividendresulthash != dividendmaster->getresulthash()) { if (dividendmaster->isready()) m_journal.warning << "we got mismatch dividend apply based " << dividendledger << " hash " << dividendresulthash << " ours " << dividendmaster->getresulthash() << " based " << dividendmaster->getledgerseq() << " in " << lastclosedledger->gethash(); dividendmaster->unlock(); if (weight >=getapp().getledgermaster().getminvalidations()) return false; else return true; } if (weight >= getapp().getledgermaster().getminvalidations()) { m_journal.warning << "we are voting for a dividend apply based " << dividendledger << " hash " << dividendresulthash << " with " << weight << " same votes in " << lastclosedledger->gethash(); dividendmaster->filldivresult(initialposition); dividendmaster->filldivready(initialposition); dividendmaster->setready(false); } else { m_journal.warning << "we are cancelling a dividend apply with only " << weight << " same votes in " << lastclosedledger->gethash(); dividendmaster->settotaldividend(0); dividendmaster->settotaldividendvbc(0); dividendmaster->setsumvrank(0); dividendmaster->setsumvspd(0); dividendmaster->setresulthash(uint256()); dividendmaster->filldivready(initialposition); dividendmaster->setready(false); } dividendmaster->unlock(); return true; }