42 Commits

Author SHA1 Message Date
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
Jamie Holdstock
f46ffcb60d
docs: Review and polish existing docs. (#390)
Also includes a couple of updates to comments in webapi code.
2023-06-13 13:22:57 -05:00
Jamie Holdstock
203bf7d2e6
build: Update linter to 1.53.2 (#384)
* build: Update linter to 1.53.2

* database: Rename helpers.go to encoding.go

* database: Ignore json.Marshal errors.
2023-06-05 09:39:01 -05:00
Jamie Holdstock
08ea48f7a3
Update decred dependencies. (#378)
* webapi: Use types 2.0.0

* v3tool: Use types 2.0.0

* Update decred dependencies.
2023-04-12 08:16:29 -05:00
Jamie Holdstock
6b99c5d2b5
webapi: Use types 2.0.0 (#376)
* webapi: Use types 2.0.0

* v3tool: Use types 2.0.0
2023-04-12 08:12:53 -05:00
Jamie Holdstock
b5ac64891e
Add v3tool. (#366)
This commit adds a new executable - v3tool - a developer testing tool which hits endpoints of the vspd API.
2023-03-24 13:10:44 -05:00
Jamie Holdstock
d00ba70f94
vspd: Fix invalid default config log level. (#371)
* vspd: Fix invalid default config log level.

slog.LevelDebug.String() returns "DBG" which is not valid per the config validation rules specified below. Hard-code "debug" instead.

* Update year.
2023-02-24 09:55:25 -05:00
Jamie Holdstock
8bb868a5a5
Add vote-validator tool. (#335)
vote-validator is a tool for VSP admins to verify that their vspd deployment
is voting correctly according to user preferences.
2022-11-18 15:05:38 -05:00
jholdstock
32790984fe Make database backups optional.
Periodic database backups are no longer started automatically in database.Open(), and the backup written by database.Close() can now be disabled.

Only vspd itself requires backups, they are not useful for test code or future upcoming tools such as vote-validator.
2022-09-29 14:54:40 +01:00
Jamie Holdstock
11401c5369
Move vspd into cmd directory. (#352)
* Update linter to 1.49.0

* Move vspd into cmd directory.

This is standard practise in Decred golang repos. Especially useful when multiple executables are built from a single repo.

* Ignore bins in new dir.
2022-09-27 08:54:23 -05:00