55 Commits

Author SHA1 Message Date
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
Jamie Holdstock
bfeddd25d1 Download db backup from admin page. 2020-06-12 13:35:43 +00:00
jholdstock
2f7c46e5f8 Misc front end improvements.
- Use bootstrap to improve layout.
- Add warning banners for webserver debug mode and vspd closed.

Admin page:
- Replace listing of all tickets with form to search by ticket hash
2020-06-12 13:35:43 +00:00
jholdstock
a95b214b3f Clean up duplicate database code and add tests. 2020-06-12 13:24:50 +00:00
jholdstock
a304fc9890 Close the database after web server is stopped.
Previously all of the shutdown tasks were running concurrently, which meant the db could be closed before the webserver is finished using it.
2020-06-12 13:23:55 +00:00
jholdstock
4f2766352b Improve handling of fee status.
- Fee tx status is now tracked using a dedicated field, with values none/received/broadcast/confirmed/error.
- Fee tx hex and hash are now both set in /payfee. The absense of txhash is no longer used to determine if a fee tx has been broadcast or not.
- setvotechoices can no longer be called before a fee is received.
- Remove `binding:required` from response types. It has no effect on responses, it is only needed on request types which are validated by gin.
2020-06-09 14:17:43 +00:00
David Hill
83514385d6
change feeamount from float64 to int64/atoms (#121) 2020-06-09 08:08:14 +01:00
jholdstock
b50615bc6f Add very basic admin page. 2020-06-08 15:24:49 +00:00
jholdstock
3136038746 Shorten db keys 2020-06-05 17:21:26 +00:00
jholdstock
c7835e8811 Update log level and add some TODOs 2020-06-04 15:04:39 +00:00
Jamie Holdstock
d407af35c0
Accept feexpub once at startup. (#97) 2020-06-03 18:10:30 +01:00
jholdstock
81a6bf1ea8 Reject unvotable tickets.
/payfee and /getaddress will now only accept tickets which are immature or live.
2020-06-03 12:49:14 +00:00
Jamie Holdstock
1a507badc2
Multi wallet fix (#83)
* Fix min required check

* Remove duplicated host logging on conn errors.

* Show confirmed tickets on homepage.
2020-05-28 15:01:44 +01:00
Jamie Holdstock
6b6bc20522
Periodically write a database backup. (#76) 2020-05-28 06:58:34 +01:00
Jamie Holdstock
d0dedd3af0
Resolving some TODOs (#71)
* Dont allow duplicate fee addresses

* Load webapi keypair in webapi package.

* Split database test file

* Add extra DB testing.
2020-05-27 14:55:59 +01:00
Jamie Holdstock
ccafd8dec4
Calculate fee from percentage. (#69)
* Calculate fee from percentage.

- Reverted config to accept a fee percentage, not absolute value.
- The fee amount to be paid is now included in the `getfeeaddress` response. The current best block is used to calculate the fee percentage, and new blocks may be mined before the fee is paid, so the fee expiry period is shortened from 24 hours to 1 hour to mitigate this.
- Rename ticket db field to FeeAmount so it is more representative of the data it holds.
- API fields renamed to "FeePercentage" and "FeeAmount"
- Relay fee is still hard coded.

* Use getbestblockhash
2020-05-27 14:44:40 +01:00
Jamie Holdstock
87500c3fef
Delay fee broadcast and adding tickets to wallets. (#62)
* Delay fee broadcast and adding tickets to wallets.

- Adds a `background` package which implements a dcrd notification handler.  On each blockconnected notification, tickets with 6+ confirmations are marked confirmed, relevant fee transactions are broadcast, and any fees with 6+ confirmations have their tickets added to voting wallets.
- VSP fee is now an absolute value measured in DCR rather than a percentage. This simplifies the code and is more appropriate for an MVP. We can re-add percentage based fees later.
- Database code for tickets is now simplified to just "Insert/Update", rather than having functions for updating particular fields.
- Pay fee response no longer includes the fee tx hash, because we dont necessarily broadcast the fee tx straight away.

* Const for required confs
2020-05-27 06:39:38 +01:00
Jamie Holdstock
9151f4f221
Generate fee addresses in dcrvsp, not dcrwallet (#59)
* Remove unnecessary error handling.

* Generate fee addresses in dcrvsp, not dcrwallet

* Break loop if multiple invalid children are generated.

* Use Mutex instead of RWMutex
2020-05-26 14:51:05 +01:00
Jamie Holdstock
ac488464c0
Rework client/server authentication. (#58)
* Rework client/server authentication.

- Remove Signature from all requests, and instead expect a signature in HTTP header "VSP-Client-Signature".
- Remove CommitmentSignatures from the database.
- Use a bool flag to indicate when a ticket is missing from the database rather than an error.

This commit introduces a lot of duplication into each of the authenticated HTTP handlers. This should be removed in future work which moves the authentication to a dedicated middleware.

* Introduce auth and rpc middleware.

This removed the duplication added in the previous commit, and also removes the duplication of RPC client error handling.
2020-05-26 14:14:38 +01:00
Jamie Holdstock
1ff55f4b30
Add some stats to homepage (#51) 2020-05-22 18:43:41 +01:00
Jamie Holdstock
96608718a0
Cleaning up some TODOs (#50) 2020-05-22 18:42:51 +01:00
Jamie Holdstock
740b9c8e0f
Get relay fee from wallet (#47) 2020-05-22 15:09:51 +01:00
Jamie Holdstock
bb416e8bc9
Set vote choices on voting wallets (#43) 2020-05-21 07:59:51 +01:00
Jamie Holdstock
cf55092c21
Add ticket hash to payfee request. (#38) 2020-05-20 08:09:07 +01:00
Jamie Holdstock
d31c24b531
Add missing tests and log errors. (#36) 2020-05-19 17:21:40 +01:00
David Hill
80e7983d4e
add in expiration logic (#31) 2020-05-19 16:13:48 +01:00
David Hill
fff8132b13
Store signing key in db. (#34) 2020-05-19 14:24:02 +01:00
Jamie Holdstock
5c1c19844c
Error logging for API methods (#28) 2020-05-19 10:55:25 +01:00
David Hill
302abce2fc
database: rename GetFeesByFeeAddress to GetTicketByFeeAddress (#30) 2020-05-19 10:54:06 +01:00
Jamie Holdstock
e70bb206c3
Generalize database accessor. (#24) 2020-05-18 15:20:29 +01:00
Jamie Holdstock
6ca2f620b7
Use a waitgroup to wait for shutdown tasks (#21) 2020-05-18 09:05:10 +01:00
David Hill
1092df5224
use dcrutil.VerifyMessage versus RPC (#22) 2020-05-18 08:42:35 +01:00
Jamie Holdstock
8768014348
Add shutdown context. (#20) 2020-05-17 07:49:53 +01:00
David Hill
70ed281215
start hooking up database (#17) 2020-05-15 16:33:55 +01:00
Jamie Holdstock
7c5ab7ebae
Add basic HTML page and project license (#15) 2020-05-15 16:07:26 +01:00