Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.

Commit 5281c80

Browse files
Merge pull request #238 from acompany-develop/feature/sakamoto/fix_getShares_size0
Supported the case where the length of share_ids is 0 in getShares.
2 parents edf3655 + 2731d6e commit 5281c80

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/server/computation_container/server/computation_to_computation_container/server.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@ std::string Server::getShare(int party_id, qmpc::Share::AddressId share_id)
157157

158158
// 複数シェアget用
159159
std::vector<std::string> Server::getShares(
160-
int party_id, const std::vector<qmpc::Share::AddressId> &share_ids, unsigned int length
160+
int party_id, const std::vector<qmpc::Share::AddressId> &share_ids
161161
)
162162
{
163+
const std::size_t length = share_ids.size();
164+
if (length == 0)
165+
{
166+
return std::vector<std::string>{};
167+
}
168+
163169
Config *conf = Config::getInstance();
164170
// std::cout << "party share job thread"
165171
// << " " << party_id << " " << share_ids[0].getShareId() << " "
@@ -173,14 +179,15 @@ std::vector<std::string> Server::getShares(
173179

174180
if (!cond.wait_for(
175181
lock,
176-
std::chrono::seconds(conf->getshare_time_limit),
182+
std::chrono::seconds(conf->getshare_time_limit * length),
177183
[&] { return shares_vec.count(key) == 1; }
178184
)) // 待機
179185
{
180186
qmpc::Log::throw_with_trace(std::runtime_error("getShares is timeout"));
181187
}
182188
auto local_str_shares = shares_vec[key];
183189
shares_vec.erase(key);
190+
assert(local_str_shares.size() == length);
184191
return local_str_shares;
185192
}
186193

packages/server/computation_container/server/computation_to_computation_container/server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Server final : public computationtocomputation::ComputationToComputation::
4747
// 受け取ったシェアをgetするメソッド
4848
std::string getShare(int party_id, qmpc::Share::AddressId share_id);
4949
std::vector<std::string> getShares(
50-
int party_id, const std::vector<qmpc::Share::AddressId> &share_ids, unsigned int length
50+
int party_id, const std::vector<qmpc::Share::AddressId> &share_ids
5151
);
5252
Server(Server &&) noexcept = delete;
5353
Server(const Server &) noexcept = delete;

packages/server/computation_container/share/networking.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ auto recons(const T &share)
207207
}
208208
else
209209
{
210-
std::vector<std::string> values = server->getShares(pt_id, ids_list, length);
210+
std::vector<std::string> values = server->getShares(pt_id, ids_list);
211211
for (unsigned int i = 0; i < length; i++)
212212
{
213213
if constexpr (std::is_same_v<Result, bool>)
@@ -253,7 +253,7 @@ std::vector<SV> receive(int sp_id, const std::vector<AddressId> &address_ids)
253253
ComputationToComputation::Server *server = ComputationToComputation::Server::getServer();
254254
int n = address_ids.size();
255255
std::vector<SV> ret(n);
256-
auto shares = server->getShares(sp_id, address_ids, address_ids.size());
256+
auto shares = server->getShares(sp_id, address_ids);
257257
for (int i = 0; i < n; ++i)
258258
{
259259
ret[i] = stosv<SV>(shares[i]);

packages/server/computation_container/test/unit_test/ctoc_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ TEST(CtoC_Test, EXCHANGESHARES)
9696
EXPECT_TRUE(status.ok());
9797

9898
auto server = qmpc::ComputationToComputation::Server::getServer();
99-
auto datas = server->getShares(conf->party_id, share_ids, length);
99+
auto datas = server->getShares(conf->party_id, share_ids);
100100
for (unsigned int i = 0; i < length; i++)
101101
{
102102
EXPECT_EQ(values[i], datas[i]);
@@ -119,7 +119,7 @@ TEST(CtoC_Test, GetSharesThrowExceptionTest)
119119
std::vector<qmpc::Share::AddressId> share_ids(length);
120120

121121
auto server = qmpc::ComputationToComputation::Server::getServer();
122-
EXPECT_ANY_THROW(server->getShares(conf->party_id, share_ids, length));
122+
EXPECT_ANY_THROW(server->getShares(conf->party_id, share_ids));
123123
}
124124
int main(int argc, char **argv)
125125
{

0 commit comments

Comments
 (0)