-
Notifications
You must be signed in to change notification settings - Fork 154
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
Repo package layout refactoring: determine which packages should be exported as vgo modules #1147
Comments
There are two possible improvements I see here. Either the |
#1151 moves walletdb to become a wallet internal package and introduces an opaque type to allow the database to continue to be referenced by loader and main. |
#1172 moves snacl package inside wallet internal packages dir |
#1173 moves txsizes package from wallet/internal to wallet package Additionaly, I'd open discussion about
I'd like to propose to consolidate 3 mentioned packages as a single |
The repo has been split into various modules with #1238. |
dcrwallet is not just a program -- like dcrd, it also includes packages that can be directly imported by other tools for integrating various wallet functionality. For example,
lnd
imports thewallet
package in order to implement key storage and signing. However, not all packages are designed for external consumption, and there should be a clear distinction between which packages must follow strict semantic versioning and those which don't. This issue provides a discussion to determine which packages should be created into modules, which should not, and whether the package layout must adjust to accommodate.The following are all of the packages imported or used by the main package, and the repo's root main package itself (all of which make up the
dcrwallet
executable):Some of my own observations/thoughts/rambling follow. Feel free to follow up with comments whether you agree, disagree, or have suggestions. Once thoughts are fleshed out, a new repo/module layout can be proposed.
The repository currently makes use of
internal
packages. These are packages which can not be imported by any other packages without the same package prefix (up to the/internal
). If they are included in a module, they do not make up the module's external API and compatibility may be broken without creating a new major version of the module. It can be advantageous to increase the number of internal packages in order to reduce a module's exported API.Some packages must be available for consumption by other projects. I believe this must include (at minimum)
errors
,pgpwordlist
andwalletseed
,version
,wallet
,wallet/txauthor
,wallet/txrules
,wallet/internal/txsizes
, andchain
. Rationale for each follows:errors
implements error handling throughout the project, and errors returned by modules must be compared using this package.pgpwordlist
andwalletseed
are each small packages and together implement encoding and decoding wallet seeds in hex or PGP word list format. They do not depend on any other wallet packages (besideserrors
) and would be trivial to make modules with semver guarantees.version
implements the release version of thedcrwallet
main package. This is useful for build systems which must include the release version of dcrwallet, as storing this information in the main package would prevent it from being imported. While it may be useful for external consumption, as it describes thedcrwallet
version, perhaps it should remain under the root module.wallet
is easily the most interesting package for external projects. It provides nearly all of the essential wallet functionality (managing transactions, authoring transactions, addresses, keys, signing, etc.). I say nearly all functionality as this package does not provide, by itself, any way to interact with the Decred network. That functionality is currently provided by awallet.NetworkBackend
interface which is implemented bychain
, and soon to be implemented by thespv
package as well.wallet
also exposes one of the largest package APIs in the project, and I expect that providing strict semver backwards compatibility may result in many major version bumps as the API is cleared of years of unfortunate decisions.wallet/txauthor
andwallet/txrules
, while under thewallet
package path, are each standalone packages which may prove useful to other projects.txauthor
provides a method of creating unsigned transactions over any UTXO set, andtxrules
describes basic consensus and policy rules, such as the transaction relay fee and dust threshold.wallet/internal/txsizes
is not currently available to be imported by external projects, but this would be a good opportunity to make it so. The package implements estimation calculations of transaction sizes given various numbers of inputs and outputs. It is currently an internal package since it makes assumptions regarding the precise types of inputs being used by the wallet to construct the transaction, and therefore is not suitable for all transaction size estimates. However, it is still useful, and as long as the API is modified to reflect its shortcomings, it can be exported as or as part of a module.chain
(andspv
in the future) provide an implementation ofwallet.NetworkBackend
and implement the ability to keep a wallet in sync with the Decred network. This is desirable for external projects if they need to care about more than just offline signing, such as details about the current blockchain, wallet UTXO set, transactions, double spend detection, and more.Some external projects may want to depend on packages in submodules not in the above list. I currently see this group made up of packages such as
ticketbuyer
andloader
. I'm open for future support for making modules out of these packages, but do not deem it a priority until the other packages have been modularized. Both packages depend heavily on the wallet and network abstractions. I would especially like to makeloader
a public module off the bat, as it provides a simpler way to manage the lifetime of a wallet, but this package exportsticketbuyer
and should wait untilticketbuyer
becomes a module.There are packages which likely should be internal packages but are not, either due to accident or necessity. For example, the
github.com/decred/dcrwallet/wallet/udb
package provides the implementation for storing and retrieving all database data for thegithub.com/decred/dcrwallet/wallet
package. This is an internal implementation detail, andudb
should not be available to import by other projects. At the moment, there exists a layering violation whereudb
types are exported by thewallet
package and consumed by other packages such as the RPC servers, which is whyudb
is currently not an internal package.snacl
is another good candidate to make internal, and would be easier to do thanudb
as it is not exported by any other proposed module. In addition to these, there are other packages, such as the service implementations of the RPC servers, which should not be imported by external projects as they are only used by the root module, but it is unclear to me at this point whether these should be made internal packages of the root module or left alone.The text was updated successfully, but these errors were encountered: