Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: pull libbitcoin_server (governance) code out of wallet code 4/N #5762

Merged
merged 6 commits into from
Dec 22, 2023

Conversation

knst
Copy link
Collaborator

@knst knst commented Dec 11, 2023

Issue being fixed or feature implemented

Wallet library should not depends on server code (libbitcoin_server).

Untie this library will help to finish backport bitcoin#15639 and will unblock multiprocess: bitcoin#18677

Prior work:

What was done?

The class CGovernanceObject is doing too many things and doesn't have any public interface that can be used outside of governance module. This PR move publicly used functionality of CGovernanceObject to a new simple Governance::Object that can be used outside of governance module as a public interface for serialization/deserialization and can be used inside wallet.

As side effect have been removed 2 circular dependency:

-    "governance/object -> governance/validators -> governance/object"
-    "governance/object -> validationinterface -> governance/object"

How Has This Been Tested?

Amount of linkage errors is decreased from 141 to 66 if libbitcoin_server is excluded during linkage:

diff --git a/src/Makefile.am b/src/Makefile.am
index fb4850429f..c9c9c331a7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -865,9 +865,7 @@ endif
 # https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking#circular-dependency)
 dash_wallet_LDADD = \
   $(LIBBITCOIN_WALLET_TOOL) \
-  $(LIBBITCOIN_SERVER) \
   $(LIBBITCOIN_WALLET) \
-  $(LIBBITCOIN_SERVER) \
   $(LIBBITCOIN_COMMON) \
   $(LIBBITCOIN_CONSENSUS) \
   $(LIBBITCOIN_UTIL) \

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone

@knst knst added this to the 20.1 milestone Dec 11, 2023
@knst knst changed the title refactor: Pull wallet code out of libbitcoin_server 4/N refactor: Pull wallet code out of libbitcoin_server 4/N [governance] Dec 11, 2023
@knst knst changed the title refactor: Pull wallet code out of libbitcoin_server 4/N [governance] refactor(governance): Pull wallet code out of libbitcoin_server 4/N Dec 11, 2023
@knst knst changed the title refactor(governance): Pull wallet code out of libbitcoin_server 4/N refactor: (governance) Pull wallet code out of libbitcoin_server 4/N Dec 11, 2023
@knst knst changed the title refactor: (governance) Pull wallet code out of libbitcoin_server 4/N refactor(governance): (governance) Pull wallet code out of libbitcoin_server 4/N Dec 11, 2023
@knst knst changed the title refactor(governance): (governance) Pull wallet code out of libbitcoin_server 4/N refactor: (governance) Pull wallet code out of libbitcoin_server 4/N Dec 11, 2023
@knst knst requested review from PastaPastaPasta and UdjinM6 and removed request for PastaPastaPasta December 12, 2023 10:49
@knst knst changed the title refactor: (governance) Pull wallet code out of libbitcoin_server 4/N refactor: pull libbitcoin_server (governance) code out of wallet code 4/N Dec 15, 2023
knst added a commit to knst/dash that referenced this pull request Dec 16, 2023
Copy link

This pull request has conflicts, please rebase.

knst added a commit to knst/dash that referenced this pull request Dec 17, 2023

namespace Governance
{
struct Object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a class; while basically the same; we should stick to structs simply store some values; while classes also have methods and are generally more complex

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, here's no complex logic but still 2 constructors and several helpers

@@ -0,0 +1,73 @@
// Copyright (c) 2014-2023 The Dash Core developers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this in the util/ folder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to governance/common.h

Comment on lines 35 to 40
type{GovernanceObject::UNKNOWN},
hashParent{},
revision{0},
time{0},
collateralHash{},
vchData{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this constructor should be replaced with a =default and then place all of these default values on the actual variables for example int64_t time{0};

Comment on lines +279 to +280
for (auto it = vecObjects.begin() + std::max<int>(0, vecObjects.size() - nCount); it != vecObjects.end(); ++it) {
jsonArray.push_back((*it)->ToJson());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed from reverse iterators to non-reverse?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's changed to reverse because std::sort is changed also order of sorting from A > B to A < B

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK for either squash or merge via merge commit

@knst
Copy link
Collaborator Author

knst commented Dec 19, 2023

I'd prefer this one get merged as merge-commit - changes all related to governance, but not are same

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@PastaPastaPasta PastaPastaPasta merged commit 9bdb746 into dashpay:develop Dec 22, 2023
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants