105 Commits

Author SHA1 Message Date
jholdstock
4e4121335a database: Store xpub keys in a bucket.
**Warning: This commit contains a database upgrade.**

In order to add future support for retiring xpub keys, the database is
upgraded such that the keys are now stored in a dedicated bucket which
can hold multiple values rather than storing a single key as individual
values in the root bucket.

A new ID field is added to distinguish between keys. This ID is added to
every ticket record in the database in order to track which pubkey was
used for each ticket.

A new field named "Retired" has also been added to pubkeys. It is a unix
timestamp representing the moment the key was retired, or zero for the
currently active key.
2024-06-27 09:20:32 +01:00
Jamie Holdstock
0633260a3c
database: Combine xpub and index concepts.
Fee xpub key and last used address index are now wrapped into a struct,
with both fields being set and retrieved together rather than
individually.

The underlying format for storing these values in the database does not
change. The only change is the interface between the database code and
the caller.
2024-06-11 11:26:12 +01:00
jholdstock
be31d54dac database: Don't run unnecessary upgrades.
New databases are now created at the latest version by default, rather
than being version 1 and immediately requiring all upgrades to be
executed.
2024-06-07 13:10:17 +01:00
jholdstock
64ad28e19b database: Remove log param from CreateNew.
This logger did not write any useful information and all errors
generated by the func are already returned to the caller for logging.
2024-05-23 08:39:24 +01:00
Jamie Holdstock
cdd02dbd2e database: Use bytes.Clone instead of manual copy.
bytes.Clone was introduced in go 1.20 and removes the need to manually
copy byte slices.
2024-02-16 08:47:03 +08:00
Jamie Holdstock
cf8f791684 multi: Underscore unused func params. 2024-02-16 08:47:03 +08:00
Jamie Holdstock
a254e943f7
webapi: Add missed tickets to admin page.
A new tab on the admin page displays a list of all tickets which were
registered with the VSP but missed their votes. Clicking on the ticket
hash redirects to the Ticket Search tab with the details of the missed
ticket displayed.
2023-09-26 17:18:32 +01:00
jholdstock
f8bd606468 multi: Use const where possible. 2023-09-26 10:21:38 +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
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
54e243526e multi: Display expired/missed tickets on webpage.
Revoked ticket count is replaced by separate counts for expired/missed
tickets.

/vspinfo API response remains unchanged.
2023-09-04 16:47:00 +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
2fc60321e0 database: Return explicit nil instead of err.
No functional change because err is already checked and known to be nil,
but explicitly returning nil is easier/quicker to interpret when
reading.
2023-08-26 09:33:40 +01:00
jholdstock
5f81b0b40e database: Ensure comments end with period. 2023-08-24 07:52:40 +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
3ddad3eeb5 database: Try get purchase height for all tickets.
Only fatal errors should result in data integrity checks being stopped.
If a single ticket encounters an error, that error should be logged and
other tickets should still be attempted.
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
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