54 Commits

Author SHA1 Message Date
jholdstock
4e4121335a database: Store xpub keys in a bucket.
**Warning: This commit contains a database upgrade.**

In order to add future support for retiring xpub keys, the database is
upgraded such that the keys are now stored in a dedicated bucket which
can hold multiple values rather than storing a single key as individual
values in the root bucket.

A new ID field is added to distinguish between keys. This ID is added to
every ticket record in the database in order to track which pubkey was
used for each ticket.

A new field named "Retired" has also been added to pubkeys. It is a unix
timestamp representing the moment the key was retired, or zero for the
currently active key.
2024-06-27 09:20:32 +01:00
jholdstock
4e5fec8f3b vspadmin: Write default config file.
A new command in vspadmin writes the default config file for a new vspd
deployment. The behaviour is removed from vspd and documentation has
been updated to reflect the change.
2024-06-19 09:35:41 +01:00
jholdstock
997205ed95 vspadmin: New binary to create empty databases.
vspadmin is a new binary which implements one-off admin tasks which are
necessarily interactive and thus do not fit neatly into the long-lived
vspd binary.

The first behaviour added to vspadmin is the ability to create a new
vspd database. This behaviour is removed from vspd with the associated
config option deprecated. Documentation and scripts updated to reflect
the change.
2024-06-19 09:35:41 +01:00
Jamie Holdstock
0633260a3c
database: Combine xpub and index concepts.
Fee xpub key and last used address index are now wrapped into a struct,
with both fields being set and retrieved together rather than
individually.

The underlying format for storing these values in the database does not
change. The only change is the interface between the database code and
the caller.
2024-06-11 11:26:12 +01:00
jholdstock
1a2b02466c vspd: Wrap RPC connection details in a struct.
Returning a single struct which contains multiple named fields reduces
the chance of a mistake in the calling code, as compared to returning
multiple unnamed values which are all of the same type.
2024-05-30 08:41:10 +01:00
jholdstock
086143fed2 vspd: Move config to internal package.
This enables the config to be reused in multiple binaries - eg. the
upcoming vsp admin binary which will be responsible for writing a
default config file for new vspd deployments.
2024-05-30 08:41:10 +01:00
jholdstock
ba5b1b2990 types: Remove Revoked from VSP info response.
This was marked as deprecated in the previous release and is now being
removed.
2024-05-29 11:02:50 +01:00
jholdstock
ecf2baa193 Begin module dev cycles.
Upcoming changes constitute breaking public API changes to both the
client and types modules, therefore this bumps the version numbers of
both modules and adds local replacements to go.mod files such that the
new versions can be used before they are publicly tagged.
2024-05-29 11:02:50 +01:00
jholdstock
64ad28e19b database: Remove log param from CreateNew.
This logger did not write any useful information and all errors
generated by the func are already returned to the caller for logging.
2024-05-23 08:39:24 +01:00
jholdstock
2bd340ba08 multi: Explicitly handle help requests.
Checking for --help as an explicit step before parsing any other configs
makes the code more intuitive by removing a convoluted bit of error
handling, which happened to be unnecessarily duplicated in three places.

Moving it to a function in the internal package makes it reusable by
multiple binaries.

This also enables the IgnoreUnknown option to be used whilst parsing for
help, which ensures the presence of --help will always result in the
help message being printed. This fixes a minor inconsistency where the
help message would be printed if the flag was placed before an invalid
config, but placing it after would cause an invalid config error to be
written instead. For example, `vspd --help --fakeflag` vs `vspd
--fakeflag --help`.
2024-05-18 08:42:06 +01:00
jholdstock
ea6f5e8d7e config: Introduce NetworkFromName.
This moves the mapping logic to a more obvious home and enables it to be
reused later.
2024-05-16 08:23:24 +01:00
jholdstock
92a0eb7d4a webapi: Remove unnecessary err check.
err has already been checked and is known to be nil at this point.
2024-05-16 08:22:36 +01:00
jholdstock
0245d0f7c8 webapi: Update year to 2024 2024-01-12 08:51:54 +00:00
jholdstock
1e66b6ff59 Downgrade dcrwallet dep to v3.
This downgrade changes StakePoolTicketFee back to the version which does
not consider DCP-0012 activation.

This resolves an issue where Decrediton sometimes fails to pay VSP fees,
caused by Decrediton and vspd independently calculating the fee amount
using different versions of the algorithm.

Releasing the new algorithm will need to be more carefully coordinated,
potentially requiring both client and server sides to be updated in
sync.
2023-11-08 09:01:36 +00:00
jholdstock
34cd9d2892 webapi: Wait for unknown outputs to propagate.
If broadcasting parent transaction of a ticket fails because it
references unknown outputs, there is a good chance that waiting a few
seconds will resolve the issue because the ancestor transactions will
propagate through the network and reach the mempool of the local dcrd
instance.
2023-11-08 08:52:52 +00:00
jholdstock
9ee95f98ab version: Bump to 1.4.0-pre 2023-09-29 09:20:53 +01:00
Jamie Holdstock
a254e943f7
webapi: Add missed tickets to admin page.
A new tab on the admin page displays a list of all tickets which were
registered with the VSP but missed their votes. Clicking on the ticket
hash redirects to the Ticket Search tab with the details of the missed
ticket displayed.
2023-09-26 17:18:32 +01:00
jholdstock
4012b098fe vspd: Improve comment for update func.
A good comment explains what a function does, not when it is called.
2023-09-26 10:21:38 +01:00
jholdstock
f8bd606468 multi: Use const where possible. 2023-09-26 10:21:38 +01:00
jholdstock
e9cd529de5 webapi: Don't add extra context to dcrd errors.
The error returned by dcrd.Client() is already very descriptive and does
not need extra context.
2023-09-26 10:21:38 +01:00
jholdstock
a0d9cbf6b3 webapi: Remove deprecated css.
The overlay setting for overflow has been deprecated for quite some
time, and these days doesn't work on most browsers.
2023-09-26 10:21:38 +01:00
jholdstock
ed82998fe2 webapi: Only log "ticket added to wallet" once. 2023-09-20 09:21:33 +01:00
jholdstock
fde844e2e1 vspd: Make log format consistent.
Every log line which includes a ticket hash includes it in the end at in
brackets, not inline with the message.
2023-09-20 09:21:33 +01:00
jholdstock
f5b57f4169 vspd: Increase some logs to info level. 2023-09-20 09:21:33 +01:00
jholdstock
1f62d46bdd vspd: Reduce some logs to debug level. 2023-09-20 09:21:33 +01:00
jholdstock
2994d128fe vspd: Remove funcName from info/debug logs.
Including the funcName in informational log messages is not useful for
devs or admins, its just spam which bloats the log file.
2023-09-20 09:21:33 +01:00
jholdstock
12e61bab65 vspd: Remove unnecessary dcrd error logging.
The error returned by dcrd.Client() is already very descriptive and does
not need extra context.
2023-09-20 09:21:33 +01:00
jholdstock
c4de3d5d95 vspd: Pass dcrd RPC to findSpentTickets as a param
This allows RPC clients to be reused more easily in the case that the
caller of findSpentTickets already has a connected dcrd RPC client.
2023-09-19 18:01:43 +01:00
jholdstock
61c9c7087f vspd: Split update function.
The update function performs four distinct steps which can readily be
broken down into four separate functions.
2023-09-19 18:01:43 +01:00
jholdstock
01e88f39c6 vspd: Split vspd.go into smaller files.
This splits the code from vspd.go into various other files which broadly
represent the functional areas of vspd - the main update function,
database intgrity checks and voting wallet consistency checks.

Code is just moved without any modifications.
2023-09-19 18:01:43 +01:00
jholdstock
69b27ff1e6 vspd: Rename blockConnected to update.
The name blockConnected is not very accurate as this function is also
called when vspd is initializing. It doesnt depend on a block having
been connected at all, it can be called at any time.
2023-09-19 18:01:43 +01:00
jholdstock
841ac77890 webapi: Make debug warning banner more distinct.
Give the debug banner a unique look by changing its class to "danger",
and centering and bolding the text. This helps it to be more noticable
when displayed near other banners.
2023-09-19 18:00:05 +01:00
jholdstock
c7ebe28501 webapi: Try cache update before returning error.
Rather than immediately returning an error if the cache is not
initialized, attempt to initialize it first. Without this change there
is only an attempt to initialize the cache once per minute.
2023-09-19 17:58:59 +01:00
jholdstock
99dc97d6a3 webapi: Abort requests if web cache not ready.
A new middleware aborts any requests which require the data cache if the
cache is not yet initialized. An explicit error is returned so the admin
will be immediately aware what has gone wrong.

Previously, webpages were rendered and JSON responses were sent with
zero values, and with no indication of anything being wrong. This was
sometimes difficult to notice, and even when noticed the cause was not
immediately apparent.
2023-09-19 17:58:59 +01:00
jholdstock
935dcaece2 multi: Move signal to internal package. 2023-09-19 08:33:42 +01:00
jholdstock
b8cc99e4b6 webapi: Update netParams name in template.
netParams was renamed to Network in a prior commit, but this instance
was not updated.
2023-09-18 09:10:45 +01:00
jholdstock
74729c6cc9 multi: Consider DCP0012 in VSP fee calculations.
Upgrade the dcrwallet dependency to pick up the new version of
txrules.StakePoolTicketFee which considers the status of DCP0012 in its
fee calculation.
2023-09-16 08:36:41 +01:00
jholdstock
73ccfccda8 config: Add DCP12Active func.
The activation heights for DCP0012 are known for mainnet and testnet so
they can be hard-coded.
2023-09-16 08:36:41 +01:00
jholdstock
72b0411ee0 webapi: Refine server start/stop logging.
Don't log errors returned by server.Shutdown. They are exceedingly
unlikely, and there is nothing which can be done about them.

Moving the "Listening on..." log closer to where the server is actually
started reduces the chance of confusion. Also, logging the parsed
listener.Addr() string instead of the provided config string provides
extra debugging detail.
2023-09-16 08:29:17 +01:00
jholdstock
ee4a440534 multi: Move vspd to internal package. 2023-09-16 08:29:17 +01:00
jholdstock
61b6460014 webapi: Use existing context for server shutdown.
The server will shutdown cleanly even if the passed context is already
canceled, so there is no need to pass a new context and blindly guess at
how long the server may need to stop.
2023-09-16 07:54:24 +01:00
jholdstock
f881179024 webapi: Make Run func blocking.
This updates the Run func to make it blocking. When the provided context
is canceled the server is cleanly shut down and the func returns.
2023-09-16 07:54:24 +01:00
jholdstock
0742e0ff1a webapi: Split Start func into New and Run funcs.
Separating the single func grants the calling code greater control over
the webapi lifecycle.
2023-09-16 07:54:24 +01:00
jholdstock
a7bb0cd9d7 webapi: Rename server to WebAPI.
Exporting this struct is a step towards breaking up the Start func into
a New func and Run func, enabling calling code to use:

    api := webapi.New()
    api.Run()

WebAPI is a more suitable name than server because it matches the
package name, and also it helps to distinguish WebAPI from the HTTP
server it uses internally (ie. webapi.server rather than server.server).
2023-09-16 07:54:24 +01:00
jholdstock
8a8cbe47b9 webapi: Create server when all components ready.
It's generally good practice to first create everything that can fail
and then create the final instance at once with the results versus doing
it piecemeal.

Piecemeal creation is typically more error prone and, while not a huge
concern here, it also ends up needlessly creating objects that are just
thrown away in the event of a later error.
2023-09-16 07:54:24 +01:00
jholdstock
a9f517f787 multi: Don't use RPC to determine DCP0010 status.
The activation heights are known for mainnet and testnet, so they can be
hard-coded and RPC does not need to be used.
2023-09-14 20:45:24 +01:00
jholdstock
280dc391be webapi: Keep DB and RPC clients inside cache.
Storing references to the database/dcrd/dcrwallet clients inside the
cache struct means they don't need to be passed in every time the cache
is updated.
2023-09-14 20:43:09 +01:00
jholdstock
d1766c362e webapi: Add Listen to webapi Config.
No need for this value to be passed in separately, it can be passed in
the same as every other config value.
2023-09-14 20:42:12 +01:00
jholdstock
a33bcbcbfd multi: Reuse CurrentVoteVersion helper.
Moving CurrentVoteVersion to the config package allows it to be reused
in vote-validator.
2023-09-14 20:39:49 +01:00
jholdstock
d5d1c3239c multi: Move netparams to internal.
A new internal package named config contains all of the hard-coded, network specific values used by vspd.
2023-09-14 20:39:49 +01:00