mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Tx set exchange improvements.
This commit is contained in:
@@ -244,17 +244,15 @@ void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map)
|
||||
if (!peers.empty())
|
||||
adjustCount(map, peers);
|
||||
|
||||
std::vector<uint256> hashes;
|
||||
hashes.push_back(hash);
|
||||
sendHaveTxSet(hashes);
|
||||
sendHaveTxSet(hash, true);
|
||||
}
|
||||
|
||||
void LedgerConsensus::sendHaveTxSet(const std::vector<uint256>& hashes)
|
||||
void LedgerConsensus::sendHaveTxSet(const uint256& hash, bool direct)
|
||||
{
|
||||
newcoin::TMHaveTransactionSet set;
|
||||
for (std::vector<uint256>::const_iterator it = hashes.begin(), end = hashes.end(); it != end; ++it)
|
||||
set.add_hashes(it->begin(), 256 / 8);
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage>(set, newcoin::mtHAVE_SET);
|
||||
newcoin::TMHaveTransactionSet msg;
|
||||
msg.set_hash(hash.begin(), 256 / 8);
|
||||
msg.set_status(direct ? newcoin::tsHAVE : newcoin::tsCAN_GET);
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage>(msg, newcoin::mtHAVE_SET);
|
||||
theApp->getConnectionPool().relayMessage(NULL, packet);
|
||||
}
|
||||
|
||||
@@ -411,9 +409,7 @@ bool LedgerConsensus::updateOurPositions(int sinceClose)
|
||||
uint256 newHash = ourPosition->getHash();
|
||||
mOurPosition->changePosition(newHash);
|
||||
propose(addedTx, removedTx);
|
||||
std::vector<uint256> hashes;
|
||||
hashes.push_back(newHash);
|
||||
sendHaveTxSet(hashes);
|
||||
sendHaveTxSet(newHash, true);
|
||||
}
|
||||
|
||||
return stable;
|
||||
@@ -535,23 +531,20 @@ bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerConsensus::peerHasSet(Peer::pointer peer, const std::vector<uint256>& sets)
|
||||
bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, newcoin::TxSetStatus status)
|
||||
{
|
||||
for (std::vector<uint256>::const_iterator it = sets.begin(), end = sets.end(); it != end; ++it)
|
||||
{
|
||||
std::vector< boost::weak_ptr<Peer> >& set = mPeerData[*it];
|
||||
bool found = false;
|
||||
for (std::vector< boost::weak_ptr<Peer> >::iterator iit = set.begin(), iend = set.end(); iit != iend; ++iit)
|
||||
if (iit->lock() == peer)
|
||||
found = true;
|
||||
if (!found)
|
||||
{
|
||||
set.push_back(peer);
|
||||
boost::unordered_map<uint256, TransactionAcquire::pointer>::iterator acq = mAcquiring.find(*it);
|
||||
if (acq != mAcquiring.end())
|
||||
acq->second->peerHas(peer);
|
||||
}
|
||||
}
|
||||
if (status != newcoin::tsHAVE) // Indirect requests are for future support
|
||||
return true;
|
||||
|
||||
std::vector< boost::weak_ptr<Peer> >& set = mPeerData[hashSet];
|
||||
for (std::vector< boost::weak_ptr<Peer> >::iterator iit = set.begin(), iend = set.end(); iit != iend; ++iit)
|
||||
if (iit->lock() == peer)
|
||||
return false;
|
||||
|
||||
set.push_back(peer);
|
||||
boost::unordered_map<uint256, TransactionAcquire::pointer>::iterator acq = mAcquiring.find(hashSet);
|
||||
if (acq != mAcquiring.end())
|
||||
acq->second->peerHas(peer);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ protected:
|
||||
|
||||
void addPosition(LedgerProposal&, bool ours);
|
||||
void removePosition(LedgerProposal&, bool ours);
|
||||
void sendHaveTxSet(const std::vector<uint256>& txSetHashes);
|
||||
void sendHaveTxSet(const uint256& set, bool direct);
|
||||
void applyTransactions(SHAMap::pointer transactionSet, Ledger::pointer targetLedger,
|
||||
std::list<SerializedTransaction::pointer>& failedTransactions);
|
||||
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
|
||||
bool peerPosition(LedgerProposal::pointer);
|
||||
|
||||
bool peerHasSet(Peer::pointer peer, const std::vector<uint256>& sets);
|
||||
bool peerHasSet(Peer::pointer peer, const uint256& set, newcoin::TxSetStatus status);
|
||||
|
||||
bool peerGaveNodes(Peer::pointer peer, const uint256& setHash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData);
|
||||
|
||||
@@ -108,9 +108,15 @@ message TMProposeSet {
|
||||
repeated bytes removedTransactions = 6; // not required if number is large
|
||||
}
|
||||
|
||||
// Announce to a peer that we have fully acquired a transaction set
|
||||
enum TxSetStatus {
|
||||
tsHAVE = 1; // We have this set locally
|
||||
tsCAN_GET = 2; // We have a peer with this set
|
||||
tsNEED = 3; // We need this set and can't get it
|
||||
}
|
||||
|
||||
message TMHaveTransactionSet {
|
||||
repeated bytes hashes = 1;
|
||||
required TxSetStatus status = 1;
|
||||
required bytes hash = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -221,11 +227,12 @@ enum TMLedgerType {
|
||||
}
|
||||
|
||||
message TMGetLedger {
|
||||
optional TMLedgerType ltype = 1;
|
||||
optional bytes ledgerHash = 2; // Can also be the transaction set hash if liTS_CANDIDATE
|
||||
optional uint32 ledgerSeq = 3;
|
||||
required TMLedgerInfoType itype = 4;
|
||||
required TMLedgerInfoType itype = 1;
|
||||
optional TMLedgerType ltype = 2;
|
||||
optional bytes ledgerHash = 3; // Can also be the transaction set hash if liTS_CANDIDATE
|
||||
optional uint32 ledgerSeq = 4;
|
||||
repeated bytes nodeIDs = 5;
|
||||
optional uint32 requestCookie = 6;
|
||||
}
|
||||
|
||||
message TMLedgerData {
|
||||
@@ -233,6 +240,7 @@ message TMLedgerData {
|
||||
required uint32 ledgerSeq = 2;
|
||||
required TMLedgerInfoType type = 3;
|
||||
repeated TMLedgerNode nodes = 4;
|
||||
optional uint32 requestCookie = 5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user