35 Commits

Author SHA1 Message Date
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
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