mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Ledger consensus work.
This commit is contained in:
@@ -1,16 +1,169 @@
|
||||
|
||||
#include "LedgerConsensus.h"
|
||||
|
||||
TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, 1), mHaveRoot(false)
|
||||
{
|
||||
mMap = boost::make_shared<SHAMap>();
|
||||
mMap->setSynching();
|
||||
}
|
||||
|
||||
void TransactionAcquire::done()
|
||||
{
|
||||
// insert SHAMap in finished set (as valid or invalid), remove ourselves from current set
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
boost::weak_ptr<PeerSet> TransactionAcquire::pmDowncast()
|
||||
{
|
||||
return boost::shared_polymorphic_downcast<PeerSet, TransactionAcquire>(shared_from_this());
|
||||
}
|
||||
|
||||
void TransactionAcquire::trigger(Peer::pointer peer)
|
||||
{
|
||||
if (mComplete || mFailed)
|
||||
return;
|
||||
if (!mHaveRoot)
|
||||
{
|
||||
boost::shared_ptr<newcoin::TMGetLedger> tmGL = boost::make_shared<newcoin::TMGetLedger>();
|
||||
tmGL->set_ledgerhash(mHash.begin(), mHash.size());
|
||||
tmGL->set_itype(newcoin::liTS_CANDIDATE);
|
||||
*(tmGL->add_nodeids()) = SHAMapNode().getRawString();
|
||||
sendRequest(tmGL);
|
||||
}
|
||||
if (mHaveRoot)
|
||||
{
|
||||
std::vector<SHAMapNode> nodeIDs;
|
||||
std::vector<uint256> nodeHashes;
|
||||
mMap->getMissingNodes(nodeIDs, nodeHashes, 256);
|
||||
if (nodeIDs.empty())
|
||||
{
|
||||
if (mMap->isValid())
|
||||
mComplete = true;
|
||||
else
|
||||
mFailed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::shared_ptr<newcoin::TMGetLedger> tmGL = boost::make_shared<newcoin::TMGetLedger>();
|
||||
tmGL->set_ledgerhash(mHash.begin(), mHash.size());
|
||||
tmGL->set_itype(newcoin::liTS_CANDIDATE);
|
||||
for (std::vector<SHAMapNode>::iterator it = nodeIDs.begin(); it != nodeIDs.end(); ++it)
|
||||
*(tmGL->add_nodeids()) = it->getRawString();
|
||||
if (peer)
|
||||
sendRequest(tmGL, peer);
|
||||
else
|
||||
sendRequest(tmGL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mComplete || mFailed)
|
||||
done();
|
||||
else
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
bool TransactionAcquire::takeNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
const std::list< std::vector<unsigned char> >& data, Peer::pointer peer)
|
||||
{
|
||||
if (mComplete || mFailed)
|
||||
return true;
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin();
|
||||
std::list< std::vector<unsigned char> >::const_iterator nodeDatait = data.begin();
|
||||
while (nodeIDit != nodeIDs.end())
|
||||
{
|
||||
if (nodeIDit->isRoot())
|
||||
{
|
||||
if (!mMap->addRootNode(getHash(), *nodeDatait))
|
||||
return false;
|
||||
}
|
||||
else if (!mMap->addKnownNode(*nodeIDit, *nodeDatait))
|
||||
return false;
|
||||
++nodeIDit;
|
||||
++nodeDatait;
|
||||
}
|
||||
trigger(peer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LedgerConsensus::abort()
|
||||
{
|
||||
}
|
||||
|
||||
int LedgerConsensus::startup()
|
||||
{
|
||||
return 5;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LedgerConsensus::timerEntry()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool doAcquire)
|
||||
{
|
||||
boost::unordered_map<uint256, SHAMap::pointer>::iterator it = mComplete.find(hash);
|
||||
if (it == mComplete.end())
|
||||
{ // we have not completed acuiqiring this ledger
|
||||
if (doAcquire)
|
||||
{
|
||||
TransactionAcquire::pointer& acquiring = mAcquiring[hash];
|
||||
if (!acquiring)
|
||||
{
|
||||
acquiring = boost::make_shared<TransactionAcquire>(hash);
|
||||
startAcquiring(acquiring);
|
||||
}
|
||||
}
|
||||
return SHAMap::pointer();
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void LedgerConsensus::startAcquiring(TransactionAcquire::pointer acquire)
|
||||
{
|
||||
boost::unordered_map< uint256, std::vector< boost::weak_ptr<Peer> > >::iterator it =
|
||||
mPeerData.find(acquire->getHash());
|
||||
|
||||
if (it != mPeerData.end())
|
||||
{ // Add any peers we already know have his transaction set
|
||||
std::vector< boost::weak_ptr<Peer> >& peerList = it->second;
|
||||
std::vector< boost::weak_ptr<Peer> >::iterator pit = peerList.begin();
|
||||
while (pit != peerList.end())
|
||||
{
|
||||
Peer::pointer pr = pit->lock();
|
||||
if (!pr)
|
||||
pit = peerList.erase(pit);
|
||||
else
|
||||
{
|
||||
acquire->peerHas(pr);
|
||||
++pit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerConsensus::removePosition(LedgerProposal& position)
|
||||
{
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
void LedgerConsensus::addPosition(LedgerProposal& position)
|
||||
{
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
|
||||
{
|
||||
LedgerProposal::pointer& currentPosition = mPeerPositions[newPosition->getPeerID()];
|
||||
if (!currentPosition)
|
||||
{
|
||||
if (newPosition->getProposeSeq() <= currentPosition->getProposeSeq())
|
||||
return false;
|
||||
|
||||
// change in position
|
||||
removePosition(*currentPosition);
|
||||
}
|
||||
|
||||
currentPosition = newPosition;
|
||||
addPosition(*currentPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user