@@ -352,119 +352,125 @@ bool CSigSharesManager::VerifySigSharesInv(Consensus::LLMQType llmqType, const C
352352
353353bool CSigSharesManager::ProcessMessageSigSharesInv (const CNode& pfrom, const CSigSharesInv& inv)
354354{
355- if ( auto sessionInfo = GetSessionInfoByRecvId (pfrom.GetId (), inv.sessionId )) {
356- if (!VerifySigSharesInv ( sessionInfo-> llmqType , inv) ) {
357- return false ;
358- }
355+ auto sessionInfo = GetSessionInfoByRecvId (pfrom.GetId (), inv.sessionId );
356+ if (!sessionInfo) {
357+ return true ;
358+ }
359359
360- // TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
361- if (sigman.HasRecoveredSigForSession (sessionInfo->signHash .Get ())) {
362- return true ;
363- }
360+ if (!VerifySigSharesInv (sessionInfo->llmqType , inv)) {
361+ return false ;
362+ }
364363
365- LogPrint (BCLog::LLMQ_SIGS, " CSigSharesManager::%s -- signHash=%s, inv={%s}, node=%d\n " , __func__,
366- sessionInfo->signHash .ToString (), inv.ToString (), pfrom.GetId ());
364+ // TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
365+ if (sigman.HasRecoveredSigForSession (sessionInfo->signHash .Get ())) {
366+ return true ;
367+ }
367368
368- if (!sessionInfo->quorum ->HasVerificationVector ()) {
369- // TODO we should allow to ask other nodes for the quorum vvec if we missed it in the DKG
370- LogPrint (BCLog::LLMQ_SIGS, /* Continued */
371- " CSigSharesManager::%s -- we don't have the quorum vvec for %s, not requesting sig shares. node=%d\n " ,
372- __func__, sessionInfo->quorumHash .ToString (), pfrom.GetId ());
373- return true ;
374- }
369+ LogPrint (BCLog::LLMQ_SIGS, " CSigSharesManager::%s -- signHash=%s, inv={%s}, node=%d\n " , __func__,
370+ sessionInfo->signHash .ToString (), inv.ToString (), pfrom.GetId ());
375371
376- LOCK (cs);
377- auto & nodeState = nodeStates[pfrom.GetId ()];
378- auto * session = nodeState.GetSessionByRecvId (inv.sessionId );
379- if (session == nullptr ) {
380- return true ;
381- }
382- session->announced .Merge (inv);
383- session->knows .Merge (inv);
372+ if (!sessionInfo->quorum ->HasVerificationVector ()) {
373+ // TODO we should allow to ask other nodes for the quorum vvec if we missed it in the DKG
374+ LogPrint (BCLog::LLMQ_SIGS, /* Continued */
375+ " CSigSharesManager::%s -- we don't have the quorum vvec for %s, not requesting sig shares. node=%d\n " ,
376+ __func__, sessionInfo->quorumHash .ToString (), pfrom.GetId ());
384377 return true ;
385378 }
379+
380+ LOCK (cs);
381+ auto & nodeState = nodeStates[pfrom.GetId ()];
382+ auto * session = nodeState.GetSessionByRecvId (inv.sessionId );
383+ if (session == nullptr ) {
384+ return true ;
385+ }
386+ session->announced .Merge (inv);
387+ session->knows .Merge (inv);
386388 return true ;
387389}
388390
389391bool CSigSharesManager::ProcessMessageGetSigShares (const CNode& pfrom, const CSigSharesInv& inv)
390392{
391- if ( auto sessionInfo = GetSessionInfoByRecvId (pfrom.GetId (), inv.sessionId )) {
392- if (!VerifySigSharesInv ( sessionInfo-> llmqType , inv) ) {
393- return false ;
394- }
393+ auto sessionInfo = GetSessionInfoByRecvId (pfrom.GetId (), inv.sessionId );
394+ if (!sessionInfo) {
395+ return true ;
396+ }
395397
396- // TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
397- if (sigman.HasRecoveredSigForSession (sessionInfo->signHash .Get ())) {
398- return true ;
399- }
398+ if (!VerifySigSharesInv (sessionInfo->llmqType , inv)) {
399+ return false ;
400+ }
400401
401- LogPrint (BCLog::LLMQ_SIGS, " CSigSharesManager::%s -- signHash=%s, inv={%s}, node=%d\n " , __func__,
402- sessionInfo->signHash .ToString (), inv.ToString (), pfrom.GetId ());
402+ // TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
403+ if (sigman.HasRecoveredSigForSession (sessionInfo->signHash .Get ())) {
404+ return true ;
405+ }
403406
404- LOCK (cs);
405- auto & nodeState = nodeStates[pfrom.GetId ()];
406- auto * session = nodeState.GetSessionByRecvId (inv.sessionId );
407- if (session == nullptr ) {
408- return true ;
409- }
410- session->requested .Merge (inv);
411- session->knows .Merge (inv);
407+ LogPrint (BCLog::LLMQ_SIGS, " CSigSharesManager::%s -- signHash=%s, inv={%s}, node=%d\n " , __func__,
408+ sessionInfo->signHash .ToString (), inv.ToString (), pfrom.GetId ());
409+
410+ LOCK (cs);
411+ auto & nodeState = nodeStates[pfrom.GetId ()];
412+ auto * session = nodeState.GetSessionByRecvId (inv.sessionId );
413+ if (session == nullptr ) {
412414 return true ;
413415 }
416+ session->requested .Merge (inv);
417+ session->knows .Merge (inv);
414418 return true ;
415419}
416420
417421bool CSigSharesManager::ProcessMessageBatchedSigShares (const CNode& pfrom, const CBatchedSigShares& batchedSigShares)
418422{
419- if ( auto sessionInfo = GetSessionInfoByRecvId (pfrom.GetId (), batchedSigShares.sessionId )) {
420- if (bool ban{ false }; ! PreVerifyBatchedSigShares (m_mn_activeman, qman, * sessionInfo, batchedSigShares, ban) ) {
421- return !ban ;
422- }
423+ auto sessionInfo = GetSessionInfoByRecvId (pfrom.GetId (), batchedSigShares.sessionId );
424+ if (! sessionInfo) {
425+ return true ;
426+ }
423427
424- std::vector<CSigShare> sigSharesToProcess;
425- sigSharesToProcess.reserve (batchedSigShares.sigShares .size ());
428+ if (bool ban{false }; !PreVerifyBatchedSigShares (m_mn_activeman, qman, *sessionInfo, batchedSigShares, ban)) {
429+ return !ban;
430+ }
426431
427- {
428- LOCK (cs);
429- auto & nodeState = nodeStates[pfrom.GetId ()];
432+ std::vector<CSigShare> sigSharesToProcess;
433+ sigSharesToProcess.reserve (batchedSigShares.sigShares .size ());
430434
431- for ( const auto & sigSharetmp : batchedSigShares. sigShares ) {
432- CSigShare sigShare = RebuildSigShare (*sessionInfo, sigSharetmp );
433- nodeState. requestedSigShares . Erase (sigShare. GetKey ()) ;
435+ {
436+ LOCK (cs );
437+ auto & nodeState = nodeStates[pfrom. GetId ()] ;
434438
435- // TODO track invalid sig shares received for PoSe?
436- // It's important to only skip seen *valid* sig shares here. If a node sends us a
437- // batch of mostly valid sig shares with a single invalid one and thus batched
438- // verification fails, we'd skip the valid ones in the future if received from other nodes
439- if (sigShares.Has (sigShare.GetKey ())) {
440- continue ;
441- }
439+ for (const auto & sigSharetmp : batchedSigShares.sigShares ) {
440+ CSigShare sigShare = RebuildSigShare (*sessionInfo, sigSharetmp);
441+ nodeState.requestedSigShares .Erase (sigShare.GetKey ());
442442
443- // TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
444- if (sigman. HasRecoveredSigForId (sigShare. getLlmqType (), sigShare. getId ())) {
445- continue ;
446- }
447-
448- sigSharesToProcess. emplace_back (sigShare) ;
443+ // TODO track invalid sig shares received for PoSe?
444+ // It's important to only skip seen *valid* sig shares here. If a node sends us a
445+ // batch of mostly valid sig shares with a single invalid one and thus batched
446+ // verification fails, we'd skip the valid ones in the future if received from other nodes
447+ if (sigShares. Has (sigShare. GetKey ())) {
448+ continue ;
449449 }
450- }
451450
452- LogPrint (BCLog::LLMQ_SIGS, /* Continued */
453- " CSigSharesManager::%s -- signHash=%s, shares=%d, new=%d, inv={%s}, node=%d \n " ,
454- __func__, sessionInfo-> signHash . ToString (), batchedSigShares. sigShares . size (),
455- sigSharesToProcess. size (), batchedSigShares. ToInvString (), pfrom. GetId ());
451+ // TODO for PoSe, we should consider propagating shares even if we already have a recovered sig
452+ if (sigman. HasRecoveredSigForId (sigShare. getLlmqType (), sigShare. getId ())) {
453+ continue ;
454+ }
456455
457- if (sigSharesToProcess.empty ()) {
458- return true ;
456+ sigSharesToProcess.emplace_back (sigShare);
459457 }
458+ }
460459
461- LOCK (cs);
462- auto & nodeState = nodeStates[pfrom.GetId ()];
463- for (const auto & s : sigSharesToProcess) {
464- nodeState.pendingIncomingSigShares .Add (s.GetKey (), s);
465- }
460+ LogPrint (BCLog::LLMQ_SIGS, /* Continued */
461+ " CSigSharesManager::%s -- signHash=%s, shares=%d, new=%d, inv={%s}, node=%d\n " ,
462+ __func__, sessionInfo->signHash .ToString (), batchedSigShares.sigShares .size (),
463+ sigSharesToProcess.size (), batchedSigShares.ToInvString (), pfrom.GetId ());
464+
465+ if (sigSharesToProcess.empty ()) {
466466 return true ;
467467 }
468+
469+ LOCK (cs);
470+ auto & nodeState = nodeStates[pfrom.GetId ()];
471+ for (const auto & s : sigSharesToProcess) {
472+ nodeState.pendingIncomingSigShares .Add (s.GetKey (), s);
473+ }
468474 return true ;
469475}
470476
0 commit comments