From 67b3499293e6a007776b6d350257b4aadb773b27 Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Mon, 18 Nov 2024 12:11:06 +0800 Subject: [PATCH] use uint64_t to record refInfo --- .../ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp | 10 +++------- .../ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.h | 3 ++- .../ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.cpp | 10 +++++++++- .../ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.h | 4 ++++ .../src/ecdh-multi-psi/core/EcdhMultiPSICalculator.cpp | 2 -- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp index bdc515af..8c0f2da1 100644 --- a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp +++ b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp @@ -78,13 +78,13 @@ void MasterCache::updateMasterDataRef( if (!m_masterDataRef.count(data)) { MasterCipherRef ref; - ref.refInfo.insert(_peerIndex); + ref.refInfo |= (1 << _peerIndex); ref.updateDataIndex(dataIndex); m_masterDataRef.insert(std::make_pair(std::move(data), ref)); return; } // existed data case - m_masterDataRef[data].refInfo.insert(_peerIndex); + m_masterDataRef[data].refInfo |= (1 << _peerIndex); m_masterDataRef[data].updateDataIndex(dataIndex); return; } @@ -157,15 +157,11 @@ void MasterCache::mergeMasterCipher(std::string const& peerId, unsigned short pe for (auto it = m_masterDataRef.begin(); it != m_masterDataRef.end();) { // not has intersect-element with the finished peer - if (!it->second.refInfo.count(peerIndex)) + if (!(it->second.refInfo & (1 << peerIndex))) { it = m_masterDataRef.erase(it); continue; } - // set the refCount - it->second.refCount = it->second.refInfo.size(); - // release the refInfo - std::set().swap(it->second.refInfo); it++; } m_peerMerged = true; diff --git a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.h b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.h index 1dabf793..13604d43 100644 --- a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.h +++ b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.h @@ -30,7 +30,8 @@ namespace ppc::psi { struct MasterCipherRef { - std::set refInfo; + // support at least 63 peers + uint64_t refInfo = 0; unsigned short refCount = 0; int32_t dataIndex = -1; diff --git a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.cpp b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.cpp index 139fb4a5..f47a405f 100644 --- a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.cpp +++ b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.cpp @@ -130,7 +130,15 @@ void EcdhMultiPSIImpl::asyncRunTask( psi->removePendingTask(taskID); }); addPendingTask(taskState); - + // over the peer limit + if (_task->getAllPeerParties().size() > c_max_peer_size) + { + auto error = std::make_shared( + -1, "at most support " + std::to_string(c_max_peer_size) + " peers, over the limit!"); + ECDH_MULTI_LOG(WARNING) << LOG_DESC("asyncRunTask failed") + << LOG_KV("msg", error->errorMessage()); + onSelfError(_task->id(), error, true); + } try { auto dataResource = _task->selfParty()->dataResource(); diff --git a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.h b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.h index be9933b4..df4e8034 100644 --- a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.h +++ b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.h @@ -147,6 +147,10 @@ class EcdhMultiPSIImpl : public std::enable_shared_from_this, void wakeupWorker() { m_signal.notify_all(); } const int c_popWaitMs = 5; + + // at most support 63 peers + const int c_max_peer_size = 63; + EcdhMultiPSIConfig::Ptr m_config; TaskState::Ptr m_taskMultiState; EcdhMultiPSIMsgQueuePtr m_msgQueue; diff --git a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/core/EcdhMultiPSICalculator.cpp b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/core/EcdhMultiPSICalculator.cpp index c4902603..d979fa88 100644 --- a/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/core/EcdhMultiPSICalculator.cpp +++ b/cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/core/EcdhMultiPSICalculator.cpp @@ -154,8 +154,6 @@ void EcdhMultiPSICalculator::blindData(std::string _taskID, bcos::bytes _randA) [self = weak_from_this(), master](bcos::Error::Ptr&& _error) { if (!_error) { - ECDH_CAL_LOG(INFO) - << LOG_KV("blindData success to Master: ", master.first); return; } auto psi = self.lock();