From 46e1ae047c86b6dae449165e32e90035af798291 Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Wed, 6 Jan 2021 13:01:05 -0600 Subject: [PATCH 1/2] Fix problem with libpqxx 7.3.0 upgrade --- .../postgres_backend.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/blockvault_client_plugin/postgres_backend.cpp b/plugins/blockvault_client_plugin/postgres_backend.cpp index b3d367796bd..a82fd980bf2 100644 --- a/plugins/blockvault_client_plugin/postgres_backend.cpp +++ b/plugins/blockvault_client_plugin/postgres_backend.cpp @@ -81,10 +81,12 @@ bool postgres_backend::propose_constructed_block(std::pair w pqxx::binarystring previous_block_id_blob(previous_block_id.data(), previous_block_id.size()); w.exec_prepared0("insert_constructed_block", watermark.first, watermark.second, lib, block_id_blob, previous_block_id_blob, obj.id(), block_content.size()); - auto r = w.exec_prepared1("get_block_insertion_result", obj.id()); - obj.write(block_content.data(), block_content.size()); - w.commit(); - return true; + auto r = w.exec_prepared("get_block_insertion_result", obj.id()); + if (!r.empty()) { + obj.write(block_content.data(), block_content.size()); + w.commit(); + return true; + } } catch (const pqxx::unexpected_rows&) { } catch (const pqxx::unique_violation&) { } catch (const pqxx::serialization_failure&) { @@ -105,11 +107,12 @@ bool postgres_backend::append_external_block(uint32_t block_num, uint32_t lib, c pqxx::binarystring previous_block_id_blob(previous_block_id.data(), previous_block_id.size()); w.exec_prepared0("insert_external_block", block_num, lib, block_id_blob, previous_block_id_blob, obj.id(), block_content.size()); - auto r = w.exec_prepared1("get_block_insertion_result", obj.id()); - obj.write(block_content.data(), block_content.size()); - w.commit(); - return true; - + auto r = w.exec_prepared("get_block_insertion_result", obj.id()); + if (!r.empty()) { + obj.write(block_content.data(), block_content.size()); + w.commit(); + return true; + } } catch (const pqxx::unexpected_rows&) { } catch (const pqxx::unique_violation&) { } catch (const pqxx::serialization_failure&) { From 73963d66ae0d3b9b1811a18c752fc2a18fe8f472 Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Wed, 6 Jan 2021 15:30:26 -0600 Subject: [PATCH 2/2] Consolidate exception catching --- .../blockvault_client_plugin/postgres_backend.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/plugins/blockvault_client_plugin/postgres_backend.cpp b/plugins/blockvault_client_plugin/postgres_backend.cpp index a82fd980bf2..01d211a9bb6 100644 --- a/plugins/blockvault_client_plugin/postgres_backend.cpp +++ b/plugins/blockvault_client_plugin/postgres_backend.cpp @@ -87,11 +87,8 @@ bool postgres_backend::propose_constructed_block(std::pair w w.commit(); return true; } - } catch (const pqxx::unexpected_rows&) { - } catch (const pqxx::unique_violation&) { - } catch (const pqxx::serialization_failure&) { - } catch (const pqxx::transaction_rollback&) { - } + } catch (const pqxx::sql_error&) { + } return false; } @@ -113,11 +110,8 @@ bool postgres_backend::append_external_block(uint32_t block_num, uint32_t lib, c w.commit(); return true; } - } catch (const pqxx::unexpected_rows&) { - } catch (const pqxx::unique_violation&) { - } catch (const pqxx::serialization_failure&) { - } catch (const pqxx::transaction_rollback&) { - } + } catch (const pqxx::sql_error&) { + } return false; }