From 67c9256c8cff3885a5a6a6b32215e055359d0202 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 28 Aug 2024 07:24:47 -0500 Subject: [PATCH] GH-646 Add try-catch-log-and-drop on bls_signature creation to avoid an exception killing the thread pool --- libraries/chain/finality/finalizer.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/chain/finality/finalizer.cpp b/libraries/chain/finality/finalizer.cpp index dd8eea076c..5a2ec84004 100644 --- a/libraries/chain/finality/finalizer.cpp +++ b/libraries/chain/finality/finalizer.cpp @@ -119,15 +119,17 @@ vote_message_ptr finalizer::maybe_vote(const bls_public_key& pub_key, const digest_type& digest) { finalizer::vote_decision decision = decide_vote(bsp).decision; if (decision == vote_decision::strong_vote || decision == vote_decision::weak_vote) { - bls_signature sig; - if (decision == vote_decision::weak_vote) { - // if voting weak, the digest to sign should be a hash of the concatenation of the finalizer_digest - // and the string "WEAK" - sig = priv_key.sign(create_weak_digest(digest)); - } else { - sig = priv_key.sign({(uint8_t*)digest.data(), (uint8_t*)digest.data() + digest.data_size()}); - } - return std::make_shared(bsp->id(), decision == vote_decision::strong_vote, pub_key, sig); + try { + bls_signature sig; + if (decision == vote_decision::weak_vote) { + // if voting weak, the digest to sign should be a hash of the concatenation of the finalizer_digest + // and the string "WEAK" + sig = priv_key.sign(create_weak_digest(digest)); + } else { + sig = priv_key.sign({(uint8_t*)digest.data(), (uint8_t*)digest.data() + digest.data_size()}); + } + return std::make_shared(bsp->id(), decision == vote_decision::strong_vote, pub_key, sig); + } FC_LOG_AND_DROP() // bls_signature can throw if invalid signature } return {}; }