510 Commits

Author SHA1 Message Date
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
e263da08bd database: Remove RWMutex protecting ticket bucket.
The mutex was added to the ticket bucket as a pre-emptive safety
measure, but the bbolt project documentation seems to indicate that it
isn't necessary.

https://github.com/etcd-io/bbolt/blob/v1.3.7/README.md#transactions
2023-09-19 17:59:19 +01:00
jholdstock
57864ae58f main: POSIX compliant shebang for locating bash.
Improve portability of run_tests.sh and harness.sh by using the POSIX
compliant shebang for locating bash.
2023-09-19 17:59:07 +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
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
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
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
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
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
3967d9e24e webapi: Don't export funcs/vars unnecessarily. 2023-09-13 09:03:05 +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
030a4c6874 webapi: Display testnet/simnet in homepage banner.
Don't hardcode the banner to testnet because it is also displayed for
simnet.
2023-09-06 17:14:53 +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
jholdstock
7d1b7deb01 multi: Remove GetBlockHeaderVerbose.
A slight performance improvement becase vspd can do everything it needs
without the verbose block header.
2023-09-04 16:51:27 +01:00
jholdstock
fb47e65ef3 webapi: Use GetBlockCount not GetBestBlockHeader.
GetBestBlockHeader is a more demanding RPC so using GetBlockCount offers
a slight performance improvement.
2023-09-04 16:51:27 +01:00