59 Commits

Author SHA1 Message Date
jholdstock
1e6b379864 v3tool: Remove hard-coded agenda ID.
Getting an agenda ID dynamically so that this doesnt need to be manually
updated for future vote versions.
2023-09-26 10:21:38 +01:00
jholdstock
e1885bb7cb multi: Rename shutdownWg to wg.
The more verbose name was helpful in the past when some code was
handling more than one waitgroup, however that is no longer the case due
to refactoring so reverting to the more concise name makes sense.
2023-09-26 10:21:38 +01:00
jholdstock
fb1f250a74 vspd: Create shutdown context earlier.
Create the shutdown context earlier so process begins handling shutdown
signals earlier. Specifically, the context should be created before
creating any resources which need a graceful shutdown such as the
database. This is important because without explicit signal handling the
process will terminate immediately upon receiving a signal without
running deferred tasks.
2023-09-26 10:21:38 +01:00
Jamie Holdstock
81784accb6
Update main module dependencies 2023-09-26 09:23:32 +01:00
jholdstock
d1eddafb52 v3tool: Use shutdown context.
Using the shutdown context provided by the internal signal package means
v3tool can exit cleanly if shutdown is requested by the user.
2023-09-19 08:33:42 +01:00
jholdstock
9660de7d9f vote-validator: Use shutdown context.
Using the shutdown context provided by the internal signal package means
vote-validator can exit cleanly if shutdown is requested by the user.
2023-09-19 08:33:42 +01:00
jholdstock
935dcaece2 multi: Move signal to internal package. 2023-09-19 08:33:42 +01:00
jholdstock
2faaa8b32b vspd: Support SIGTERM on Win and all unix variants
Go 1.14 added runtime support for handling the windows CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT events by adding a definition
for syscall.SIGTERM to windows and converting the events to that signal.
It also added definitions for other common signals, including SIGHUP,
and treats them as NOOPs on windows.

Consequently, this modifies the logic that deals with conditionally
handling SIGTERM and SIGHUP to handle them for windows as well as all
unix-like operating systems, including newer ones that are supported by
Go since the code was originally written.

Although the additional signals could probably just be added
unconditionally without too much issue now due to the runtime adding
stubs to all operating systems the project officially supports, it is
safer to be explicit when dealing with syscall definitions since there
is no guarantee that they will exist for newly-added operating systems.
2023-09-19 08:33:42 +01:00
jholdstock
546a87fd5b vspd: Remove shutdownRequestChannel.
The removal of the requestShutdown function in a previous commit means
that the shutdownRequestChannel is no longer needed, so this commit
removes it.
2023-09-19 08:33:42 +01:00
jholdstock
d10e7daf74 vspd: Ensure backup loop runs forever.
Fixing a bug where the backup loop was not a loop - it was only running
one time.
2023-09-18 17:55:29 +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
ee4a440534 multi: Move vspd to internal package. 2023-09-16 08:29:17 +01:00
jholdstock
5bce5e6cfc vspd: Trigger database backups in main run func. 2023-09-16 08:29:17 +01:00
jholdstock
6c245b8418 vspd: Separate vspd and webapi.
The vspd Run func is now blocking and returns when its provided context
is cancelled. This means it is invoked/canceled in the same way as the
webapi Run func.

webapi is now created in the main run func rather than within vspd,
further decoupling these components.
2023-09-16 08:29:17 +01:00
jholdstock
ba3c7bf6d9 vspd: Create essential resources in main run func.
Creating the essential DB/RPC resources which are required for both
webapi and vspd in the main func allows the two components to be
decoupled.
2023-09-16 08:29:17 +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
e26c8db199 vspd: Copy VSP fee validation func from wallet.
This is such a trivial func that there is no need to import it from
wallet, it can just be copied into this project.
2023-09-14 20:42:22 +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
jholdstock
17fe1d7db1 vspd: Americanize "cancelled".
Consistent with the go stdlib (e.g. context.Canceled).
2023-09-13 09:10:10 +01:00
jholdstock
8038a0ea46 vspd: Move start/stop logging to main func.
This ensures that the startup/shutdown messages are always the
first/last thing to be logged.
2023-09-13 09:10:10 +01:00
jholdstock
e38032ba2f vspd: Run deferred tasks on os.Exit.
Any tasks deferred in the main func will not execute if os.Exit is
called. Moving application logic down into a new func which is called by
main works around this limitation.
2023-09-13 09:10:10 +01:00
jholdstock
b5ffecd280 version: Don't export funcs/vars unnecessarily. 2023-09-13 09:03:05 +01:00
jholdstock
3d4fb6ab99 version: Move package to internal. 2023-09-13 09:03:05 +01:00
jholdstock
7ad309c9aa webapi: Move package to internal. 2023-09-13 09:03:05 +01:00
jholdstock
841c8ba115 vspd: Enable checkWalletConsistency interrupting.
Add a Context parameter to checkWalletConsistency so it can be canceled
when a shutdown is requested.
2023-09-08 09:59:00 +01:00
jholdstock
97e7b01afe vspd: Enable blockConnected interrupting.
Check the status of the Context in blockConnected so it can be canceled
when a shutdown is requested.
2023-09-08 09:59:00 +01:00
jholdstock
ad7c587699 vspd: Enable findSpentTickets interrupting.
Add a Context parameter to findSpentTickets so it can be canceled when a
shutdown is requested.
2023-09-08 09:59:00 +01:00
jholdstock
b0f79e56f5 vspd: Exit if shutdown requested during startup.
vspd runs some tasks on startup - database consistency checks, catching
up with missed blocks, etc. If a shutdown is requested while these tasks
are running, vspd should stop immediately rather than continuing to
start the web API server and other background tasks.
2023-09-08 09:59:00 +01:00
jholdstock
b5909817e4 multi: Rename shutdownCtx to ctx.
The more verbose name was helpful in the past when some code was
handling more than one context, however that is no longer the case due
to refactoring so reverting to the more concise name makes sense.
2023-09-08 09:59:00 +01:00
jholdstock
8df00752c0 vspd: Consolidate background task timers.
Using a single select loop for background tasks removes a lot of
duplicated boilerplate code and helps to simplify shutdown logic. This
does reduce the amount of things which can run in parallel, but that
isn't of concern for vspd. The web server still runs in its own
goroutine so its responsiveness won't be affected.
2023-09-08 09:59:00 +01:00
jholdstock
cfc34a3adc vspd: Extract const time period for dcrd check. 2023-09-08 09:59:00 +01:00
jholdstock
939f094104 vspd: Stop scanning when ticket spender found.
Once the spender of a given ticket is found, the rest of the blocks
don't need to be checked.
2023-09-05 15:55:32 +01:00
jholdstock
2af3d4eca7 vspd: Fix OOB panic in spent ticket scanner.
Range expressions are only evaluated once before beginning a for loop,
which makes them unsuitable for loops which manually alter the index.
2023-09-05 15:55:32 +01:00
JoeGruff
61911a3f3b config: Add back simnet. 2023-09-04 16:51:17 +01:00
Jamie Holdstock
50c343e177
vspd: Use filter.MatchAny instead of filter.Match.
This brings a notable performance improvement to spent ticket scanning
without changing functionality. Can cut scanning time in half.
2023-09-04 16:46:24 +01:00
jholdstock
a52034cda7 multi: Update revoked tickets to expired/missed.
Any tickets in the database which are currently revoked should be
updated to either expired or missed.

This is achieved with a heuristic based on the expiry height and
revoke height of the tickets. It is not guaranteed to be 100% correct
but should be pretty close.

The web api is not yet updated to reflect this change, missed/expired
tickets will continue to be counted as revoked.
2023-08-29 10:12:30 +01:00
jholdstock
9be203c923 multi: Find voted/revoked tickets with GCS filters
Use dcrd and GCS filters to find voted/revoked tickets rather than using
the dcrwallet TicketInfo RPC.

Using TicketInfo was a bit flakey because wallets do not always
correctly detect votes/revokes, and as a result VSP admins may notice
that with this change vspd detects some historic voted/revoked tickets
which TicketInfo never detected.
2023-08-26 09:33:30 +01:00
jholdstock
618cfc7cf1 vspd: Remove simnet params.
Simnet params were added in the very first commit of vspd purely because
of copy/pasting from another project.

vspd has never actually been tested on simnet, so its possible
(probable) that it won't even operate correctly without additional dev
work. If we want simnet to be a properly supported network it can be
re-added and tested in the future.
2023-08-26 09:33:30 +01:00
jholdstock
49b9db1a64 rpc: Fix block connected handler.
Fix a bug where it appeared as though a notification handler was being
attached to the dcrd RPC client, but actually no notifications were
received until the client was disconnected a new one was created.

Now, rather than delaying attaching the notification handler, it is
attached immediately upon client creation and vspd does not start
handling the received notifications until it is ready.
2023-08-24 07:27:04 +01:00
jholdstock
bac0dcef71 multi: Hoist database integrity checks up to vspd.
Moving the existing integrity checks up into vspd removes the
depdendancy on rpc clients from the database client, and also creates a
natural home for future integrity checks to be added.
2023-08-23 12:48:19 +01:00
jholdstock
b1fbced17c vspd: Move vspd code to its own file.
Moving all vspd code into its own vspd.go file (fka background.go). This
leaves main.go as a minimal entry point for the vspd executable.
2023-08-23 12:32:14 +01:00
jholdstock
4419ae3a6e vspd: Introduce vspd struct.
Storing all of the essential resources such as db, rpcs and logger in a
vspd struct enables vspd functions to be called without passing a bunch
of parameters unnecessarily. This will be increasingly useful later when
further changes are introduced.
2023-08-23 12:32:14 +01:00
jholdstock
c039dc86cb multi: Use const instead of var when possible. 2023-08-22 15:58:48 +01:00
jholdstock
bca2a32a30 database: Add TicketList struct.
This enables a func to find the earliest purchase height to be reused in
multiple packages.
2023-08-22 15:58:48 +01:00
jholdstock
8b50fe619a vspd: Simplify shutdown listener.
The existing signal.go was inherited directly from dcrwallet, and was
slightly more flexible/complicated than required for vspd. This brings
the code more inline with the dcrd implementation which can be
instantiated in one line and with only one parameter.
2023-08-22 15:10:03 +01:00
jholdstock
350a3f5bb2 vspd: Create context and waitgroup near usage.
Creating these closer to where they are needed tidies things up a bit,
and reduces the chance of them being used unnecessarily (as was being
done previously).
2023-08-21 08:33:54 +01:00
jholdstock
bd41dbee63 vspd: Listen for dcrd notifs after startup.
Only attach the dcrd notification listener after all other startup tasks
have been completed.

Attaching the listener before this can result in the notification
handler being invoked whilst startup tasks are still running, which
isn't necessarily a problem, but it is unnecessary and makes a mess of
logging.
2023-08-21 08:33:54 +01:00