390 Commits

Author SHA1 Message Date
Jamie Holdstock
7718476caf
webapi: Move VSP closed check to middleware.
Checking this in middleware not only removes duplicated code from each of the handlers, but also makes things more efficient. Previously, dcrd/dcrwallet/database clients were initialized (and could possibly cause errors) **before** checking if the VSP is closed. Now the check happens before those other things.

Also bundled with some improvements to setaltsignaddr_test.go which I implemented along the way.
2023-02-17 20:44:13 +00:00
Jamie Holdstock
824c41c2a5
Remove duplicate fee addr check. (#361)
This check was added preemptively, the error has never actually been observed in dev, testing, or production.

It does not scale well. Its takes almost 500ms to insert into a database containing 100k tickets.
2022-12-01 00:08:18 -05:00
Jamie Holdstock
4acd57efbc
Add client module (#359)
* Add vspd client from dcrwallet.

* client: Extract and export ValidateServerSignature

* client: Add helper funcs.

* client: Add trace logging.

* client: Use existing error types.

* Add comments to explain error handling logic.
2022-11-28 11:16:00 -05:00
Jamie Holdstock
5d7d347114
Use tagged types module. (#358) 2022-11-28 11:14:58 -05:00
Jamie Holdstock
68047dc6ce build: Ensure ci lints all modules.
Use run_tests.sh in CI because the official golangci-lint GitHub action does not handle submodules.
2022-11-26 09:46:36 +08:00
Jamie Holdstock
c9f3573d8b build: Only invoke tests once.
`go test $ROOTPATH/...` runs all tests in the root module, and all tests in
submodules, so there is no need to run `go test` in the loop which
descends into submodule directories. Doing this actually causes each
test file to be run twice because the first iteration of the loop *is* the root
module, and thus all tests.

Only the linter needs to be invoked from each module directory.
2022-11-26 09:46:36 +08:00
Jamie Holdstock
42d91752f5 build: Rename root pkg path vars.
This renames the variables in the script that runs tests against all
modules to better reflect reality as of the latest versions of Go.

In particular, instead of referring to `ROOTPATH`, it now uses `ROOTPKG`
to better indicate that it is the name of root package as opposed to a
file path to it.
2022-11-26 09:46:36 +08:00
Jamie Holdstock
6d872db60e
Rename APIError to ErrorResponse. (#360)
Last commit before tagging v1.0.0 of the types module. The name ErrorResponse is consistent with all other response types.
2022-11-22 17:09:06 +08:00
Jamie Holdstock
ed1fac1a2a
Add types module for API requests/responses/errors. (#356)
* Remove helper func getCommitmentAddress.

This function is only used in one place so removing it does not introduce any duplication. Removing the func also removes the need for errors.Is comparison, which will be very useful in upcoming changes.

* Rename apiError to ErrorCode.

* Don't use inline type for API errors.

* Export webapi errors.

* Export webapi request/responses.

* Add types module for API requests/responses/errors
2022-11-18 15:06:47 -05:00
Jamie Holdstock
a5998264b3
Include commit ID in build info. (#357)
* ci: Update GitHub actions and linter.

* Update go deps.

* Include commit ID in build info.

Introduced in go 1.18, debug.ReadBuildInfo allows a go process to discover the git commit it was built from.
2022-11-18 15:06:00 -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
Jamie Holdstock
c961423e9e
Update to go 1.19 (#351) 2022-08-12 10:30:23 -05:00
jholdstock
e23e3729e8 Helper func for stdout logger.
Also reuse the logger in database tests, dont create a new one each time.
2022-06-29 08:31:44 +01:00
jholdstock
65fab01225 Remove remaining global loggers.
This removes all of the global loggers from the project and replaces them with loggers which are instantiated in vspd.go and passed down as params.

To support this, the background package was removed. It only contained one file so it was a bit pointless anyway. It only existed so background tasks could have their own named logger.
2022-06-29 08:31:44 +01:00
jholdstock
ebcfe0e5e9 Remove global logger from webapi. 2022-06-23 09:11:28 +01:00
jholdstock
7f72caafe7 Remove global vars from background.go
While removing the globals from background.go it also made sense to clean up the use of dcrd RPC clients. Previously two seperate clients were maintained, one for making RPC calls and one for receiving notifications. These clients have been unified.
2022-06-13 14:50:27 +01:00
jholdstock
01b0df2d7a Remove global loggers from components.
- Web API Cache
- Recovery Middleware
- Database upgrades
- Address Generator
2022-06-13 14:50:16 +01:00
jholdstock
63ce069a88 Use gin 1.8.1.
Nothing interesting in the release notes, but there are a few bug fixes/minor enhancements we should pick up.
2022-06-13 14:49:34 +01:00
jholdstock
4beb036663 rpc: Use context.TODO instead of .Background 2022-05-19 07:59:44 +01:00
jholdstock
1db99bfddf db.Close() if an error occurs in db.Open(). 2022-05-19 07:59:44 +01:00
jholdstock
ebadf8eefc Make run() return int instead of error.
Theres no reason for run() to return an error, it can simply return an exit code for the process.
2022-05-19 07:59:44 +01:00
jholdstock
75026f5e91 Clean up use of shutdown context.
- Rename all instances to "shutdownCtx" to be really explicit. This context is special in that it can be closed at any time without warning, so it should be obvious to the reader.
- Don't use shutdownCtx in RPC clients. Clients should not stop working immediately when shutdown is signalled, they need to keep working while the process is shutting down.
2022-05-19 07:59:44 +01:00
jholdstock
e0b0630248 Move MinWallets to netParams.
We already have a file with hard-coded parameters for each Decred network, so having logic to figure out parameters later is unnecessary.
2022-05-19 07:59:44 +01:00
jholdstock
d4b3d2fafb Make writeHotBackupFile a method of VspDatabase.
No reason for this to be a standalone func with a param when it can be a method of VspDatabase. This will be useful later when VspDatabase contains its own logger.
2022-05-19 07:59:44 +01:00
Jamie Holdstock
d8dd02433c Move CanTicketVote out of dcrd RPC client.
`CanTicketVote` doesn't really fit into the RPC client code as it is more of a business logic function. Moving it into the webapi package is more appropriate.
2022-05-06 11:14:22 +01:00
jholdstock
49f68fd5ec Rename test.
I assume "hist at max" is leftover from when it was possible to set more than one alt sign address.
2022-05-06 11:14:22 +01:00
jholdstock
5aa8f9faaf Create testNode up-front.
Theres no need to declare separate  vars for the testNode and then create it later, it can just be created up-front.
2022-05-06 11:14:22 +01:00
jholdstock
6057c2b273 Run webapi tests as sub-tests.
Running as sub-tests has the benefit of automatically logging the test name, no need to include it in failure messages manually. It even works if the test panics.
2022-05-06 11:14:22 +01:00
jholdstock
b32bb56032 Remove hash param from CanTicketVote.
CanTicketVote already has the full rawTx, so it doesn't need the hash passed in separately.
2022-05-06 11:14:22 +01:00
jholdstock
9c334d8afc .gitignore test.db created by webapi tests. 2022-05-06 11:14:22 +01:00
Jamie Holdstock
78bb28056c
Remove global cache variable. (#341)
* Remove global cache variable.

Rather than maintaining cached data in a global variable, instantiate a cache struct and keep it in the `Server` struct.

* Store net params in RPC clients.

This means net params only need to be supplied once at startup, and also removes a global instance of net params in `background.go`.
2022-03-30 11:00:42 -05:00
jholdstock
78abc59e97 Update for go 1.18 2022-03-28 16:37:39 +01:00
jholdstock
a412e3e8b9 Tidy hard-coded strings. 2022-03-28 16:37:25 +01:00
jholdstock
c91ec5c697 Use time.After instead of tickers. 2022-03-28 16:37:25 +01:00
jholdstock
9fe6eb8e52 Critical log startup and shutdown.
These messages should always be logged, even if log level is set to WARN or ERROR.
2022-03-28 16:37:25 +01:00
jholdstock
fba9fe5b0a Move database encoding helpers. 2022-03-28 16:37:25 +01:00
jholdstock
3b1812e98f Minor cleanups for new helpers.
- Ensure errors are properly wrapped with `%w`
- Error strings should not starts with caps.
- Add missing params to "Bad signature" error log
2022-03-28 16:37:25 +01:00
Jamie Holdstock
f1cc73e218
Add mainnet pre-release warning.
Make the existing startup warning more obvious, and add a new one for when a pre-release version of vspd is used on mainnet.
2022-03-28 16:37:12 +01:00
jholdstock
37d51df546 Remove global vars from webapi package. 2022-03-28 08:54:09 +01:00
Ukane philemon
4d4f9c8ca0
add new helper functions 2022-03-28 08:26:08 +01:00
Jamie Holdstock
860e50130e
Add 1.1.1 release note 2022-03-23 12:27:26 +00:00
Jamie Holdstock
aac96f8c9d
Fix assignment to nil map.
Ensure that Tickets loaded from the database are returned with empty maps instead of nil maps.

To be back-ported to 1.1.0 release.
2022-03-22 13:46:43 +00:00
jholdstock
9fa1012f3d Add some new linters. 2022-03-21 14:49:40 +00:00
jholdstock
2d67a35ba5 Use golangci-lint GitHub action.
- Rather than manually downloading and invoking golangci-lint, use the GitHub
action provided by the developers.
- Configure golangci with a config file rather than passing command line args.
This enables the same config to be used locally and on CI without introducing
duplication. It also allows much more flexibililty in configuration than using
CLI args alone.
2022-03-21 14:49:40 +00:00
Ukane philemon
00b26f8b0a
gitignore .exe files 2022-03-21 14:48:00 +00:00
Ukane philemon
3bb2f65151
add votingwalletsonline and totalvotingwallets to /vspinfo 2022-03-17 10:40:47 +00:00
Jamie Holdstock
9a4646f002
Use GitHub mermaid.js rendering.
GitHub is now capable of rendering mermaid.js diagrams, so we don't need to maintain a separate source and rendered .png file. The mermaid source can be embedded directly into the documentation itself.
2022-03-17 09:52:44 +00:00
Ukane philemon
655e5756af
Using error.Is and error.As
* This allow using error.Is and error.As within vsp.
* Add test cases for apiError type.
2022-03-15 10:20:07 +00:00