89 Commits

Author SHA1 Message Date
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
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
jholdstock
fb8c58c512 build: Update deps. 2023-02-17 20:45:01 +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
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
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
01b0df2d7a Remove global loggers from components.
- Web API Cache
- Recovery Middleware
- Database upgrades
- Address Generator
2022-06-13 14:50:16 +01:00
jholdstock
1db99bfddf db.Close() if an error occurs in db.Open(). 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
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
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
c91ec5c697 Use time.After instead of tickers. 2022-03-28 16:37:25 +01:00
jholdstock
fba9fe5b0a Move database encoding helpers. 2022-03-28 16:37:25 +01: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
Jamie Holdstock
da1cb8f916
Enable treasury vote choices. (#319)
This allows both tspend and treasury policies to be set by clients on a per-ticket basis. Preferences can be set when initially registering a ticket with `/payfee`, and can be later updated using `/setvotechoices`.

Any requests which alter treasury/tspend policy will be stored in the database using the existing accountability system.

**Note:** This does not include consistency checking, it will need to be added later when dcrwallet has an RPC to retrieve policies in batches.
2022-02-04 14:14:49 -05:00
ukane-philemon
0b78c9c2da Show altsignaddress req/res in admin UI 2022-01-13 12:40:16 +00:00
jholdstock
ab5aa4dd6d Clarify "setaltsig" terminology.
Stardardize "alt sig"/"alt signature"/"alt signing address" terminology to "alternate signing address".
2021-11-16 14:49:13 +00:00
jholdstock
6acc5be10c Add dcrd to VSP status.
This renames "Voting wallet status" to "VSP status" and it now includes the status of the local dcrd instance. This change impacts both the /admin page of the UI, and the response of the /admin/status API endpoint.
2021-11-16 14:33:39 +00:00
JoeGruff
6e13d23214 db/ticket: Add AltSigAddress.
To allow signing with addresses other than the commitment address, add
an alternate signature address. In order to continue to prove that the
address was chosen by the user, add an alternate signature history. Only
allow one record per ticket to be saved to cap needed db space.
2021-10-23 11:14:11 +01:00
Jamie Holdstock
67b4c6c019
Use reflect.DeepEqual where possible. (#294)
Comparing each field manually is unnecessary and error-prone.
2021-09-15 14:24:51 -05:00
Jamie Holdstock
83253f3c19
Use go 1.16 features (#292)
* Use features from Go 1.16 tooling.

- GO111MODULE environment variable now defaults to "on"
- "go build" and "go test" now exit with an error rather than silently modifying go.mod or go.sum files
- Update README.md

* Don't use deprecated ioutil package.
2021-08-26 09:29:43 -05:00
Jamie Holdstock
c1ba46347e
Be more specific about consensus vote choices. (#278)
* Be more specific about consensus vote choices.

Rather than referring to just "Vote choices", refer specifically to "consensus vote choices".

This will be useful when treasury and tspend vote choices are added, and the distinction becomes more important.

* dnldd suggestion.
2021-07-05 09:16:08 -05:00
Jamie Holdstock
74d32c5f09 Ensure PurchaseHeight is set for all tickets.
This is necessary because of an old bug which, in some circumstances, would prevent purchase height from being stored.
2021-06-25 15:56:35 +08:00
Jamie Holdstock
2b7903f7d5 Add database and logout tabs to admin page.
Buttons to logout and download DB backup are now moved into new tabs. Also the database size is displayed in the database tab.
2021-06-15 10:18:25 +08:00
Jamie Holdstock
4db50a4439 Helpers for bool<>[]byte conversion. 2021-06-09 21:25:21 +08:00
Jamie Holdstock
49af391b0c Only deserialize full ticket when filter matches. 2021-06-09 21:25:21 +08:00
Jamie Holdstock
e05ced391a Various minor cleanups.
- Updating and adding some copyrights which were missed recently.
- Slight improvements to some commenting and naming.
2021-06-01 07:17:11 +08:00
Jamie Holdstock
20cb546e74
Store each ticket in its own DB bucket.
**NOTE: This contains a backwards incompatible database migration, so if you plan to test it, please make a copy of your database first.**

Moves tickets from a single database bucket containing JSON encoded strings, to a bucket for each ticket.

This change is to preemptively deal with scaling issues seen with databases containing tens of thousands of tickets.
2021-05-24 17:45:47 +08:00
Jamie Holdstock
136e389f95 Update to golangci-lint 1.40.1.
Linter `golint` has been deprecated and replaced with `revive`.
2021-05-23 11:37:54 +08:00
Jamie Holdstock
2d0db6f6b3 Remove confirmed fee tx hex.
This PR introduces a database migration which deletes any raw fee transactions which remain in the database after already having been confirmed on-chain. There is no need to keep these, and they take up a lot of space.

There is also a change in the background handler to ensure that in future, tx hex is always removed from the database when the tx is confirmed.
2021-05-20 13:33:41 +08:00
Jamie Holdstock
8b5cd2a014 Properly close db after running tests 2021-05-18 23:25:42 +01:00
Jamie Holdstock
5f8ad656f7
Add framework for database upgrades. (#242)
Plus a few other miscellaneous pieces which will be usedful soon:

- Remove `Get` from func names `GetCookieSecret` and `GetFeeXPub`.
- Add helpers to encode/decode integers/bytes.
2021-05-05 08:54:51 -05:00
Jamie Holdstock
b0521251e4 Make test Tickets more realistic.
Use randomly generated values of the correct length in test Tickets, rather than using hard-coded and unrealistic values. This code was produced to aid with benchmarking DB performance.

Also fixing some minor typos/errors noticed while working in this file.
2021-04-30 21:37:12 +01:00
Jamie Holdstock
b92c31861f Remove check for duplicate fee address index.
This check was added to InsertNewTicket pre-emptivly as a sanity check. It is not strictly required because the fee address itself is also checked, and there is no scenario where we would expect a fee address and its index not to match.

Removing this check eases the route forward to improving database performance.
2021-04-30 21:37:12 +01:00
Jamie Holdstock
057b89e2f2
Only marshal DB record when needed (#214)
* Only marshal DB record when needed

* Lock mutex before deferring Unlock.
2020-12-27 15:20:46 +00:00
Jamie Holdstock
6474f0ea4c
Additional test coverage for DB code. (#213)
* Test DB HTTP backup

* Test DB initialization

* Test CountTickets
2020-12-26 20:42:50 +00:00
David Hill
2a096d81f9
fix errorlint warnings (#193) 2020-11-25 15:14:18 +00:00
David Hill
a67de8a024
rpc: optimize TicketInfo (#189) 2020-10-05 10:30:42 +01:00
jholdstock
fedd2cd784 Serialize record before creating bucket 2020-09-17 16:05:07 +00:00
jholdstock
825a717ca7 Store records of vote choice changes 2020-09-17 16:05:07 +00:00
jholdstock
4a207b15f8 Add missing copyright notices 2020-08-19 20:22:12 +00:00
jholdstock
e2483b6cea Fix backup file mode 2020-08-17 19:14:57 +00:00
jholdstock
6c12ddeb31 Write a backup after closing the db, not before 2020-08-17 19:14:57 +00:00
jholdstock
ba77d39f35 Comment exported methods 2020-08-07 17:03:03 +00:00
jholdstock
9d503e67ae Wallet consistency checks & setting ticket outcome 2020-07-28 20:09:23 +00:00
David Hill
4f0c980aca
database: protect access with a mutex (#150) 2020-07-06 10:06:43 +01:00
jholdstock
5a1a1b487e Dont use byte slices outside of db tx. 2020-06-16 13:29:32 +00:00
jholdstock
29268467f9 Delete tickets with no information. 2020-06-15 13:31:35 +00:00