Commit Graph

11 Commits

Author SHA1 Message Date
David Hill
393a95c079 multi: fix some maligned linter warnings 2018-02-13 14:50:33 -06:00
Dave Collins
6fcd077696
stake: Override false positive vet error.
This adds a directive to instruct gometalinter to ignore a false
positive produced by vet.  The code in question intentionally makes use
of the property vet is warning about.
2018-01-06 19:23:23 -06:00
David Hill
6df741c633 blockchain: removed unused funcs and vars 2017-10-17 17:52:21 -05:00
David Hill
b7a37a3ca2 gofmt 2017-10-09 17:01:46 -04:00
Jason Zavaglia
65cd08cc75 blockchain.stake: ticket expiry perf improvement.
Change tickettreap to allow for efficient queries by min blockheight,
allowing for O(1) ticket expiry.

This allows for a very significant performance increase as previously
the same query required an iteration of 40,000 or so items while
processing each block.

Remove tickettreap.Mutable - it is not used, and it is difficult to
maintain with the other changes made to the treapNode class used by
Immutable.
2017-10-04 22:55:43 -05:00
Jason Zavaglia
4cbd3b738d blockchain.stake: treap index perf improvement.
Fix O(n) lookups-by-position into being O(ln n) in liveTickets.
This reduces the time to handle a new block by around a third.

Update memory-usage calculations to be more accurate, and have
extra testing.
2017-10-04 22:55:43 -05:00
David Hill
caa57df468 travis: enable gometalinter (#603)
* Hook up gometalinter

* travis: enable unconvert

* travis: enable gosimple
2017-03-08 15:44:15 -05:00
Dave Collins
67b9004bab
stake/dcrjson: Simplify code with gofmt -s. 2016-11-21 11:03:17 -06:00
Dave Collins
c162fbde71
multi: Upstream chainhash abstraction sync
Contains the following commits:

- 711f33450c
- b6b1e55d1e
  - Reverted because Travis is already at a more recent version
- bd4e64d1d4

Also, the merge commit contains the necessary decred-specific
alterations, converts all other references to sha to hash to keep with
the spirit of the merged commits, and various other cleanup intended to
bring the code bases more in line with one another.
2016-11-16 12:48:40 -06:00
C Jepson
d98fc8319f Replace the ticket database with an efficient, atomic implementation
The legacy ticket database, which was GOB serialized and stored on
shut down, has been removed.  Ticket state information is now held in
a stake node, which acts as a modularized "black box" to contain all
information about the state of the stake system.  Stake nodes are now
a component of the blockchain blockNode struct, and are updated with
them.

Stake nodes, like their internal treap primitives, are immutable
objects that are created with their connect and disconnect node
functions.  The blockchain database now stores all information about
the stake state of the best node in the block database.  The blockchain
makes the assumption that the stake state of the best node is known at
any given time.  If the states of former blocks or sidechains must be
evaluated, this can be achieved by iterating backwards along the
blockchain from the best node, and then connecting stake nodes
iteratively if necessary.

Performance improvements with this new module are dramatic.  The long
delays on start up and shut down are removed.  Blockchain
synchronization time is improved approximately 5-10x on the mainnet
chain.  The state of the database is atomic, so unexpected shut downs
should no longer have the ability to disrupt the chain state.

An upgrade path has been added for version 1 blockchain databases.
Users with this blockchain database will automatically update when
they start their clients.
2016-10-04 13:40:19 -04:00
Dave Collins
92635a475e stake: New package for fast access to live tickets. (#266)
Ticket voting selection and validation require fast access to a
lexicographically sorted list of all available tickets.  The current
implementation stores these tickets in bucketized maps which are
unordered.  This means the data has to be sorted every time it is needed
in order to select a ticket and validate a block.  On my hardware, the
process of removing tickets that have been voted and adding new tickets
takes ~27ms with the current implementation.

In order to speed this up, this introduces a new internal package named
tickettreap that provides a tailored treap data structure that is
intended to be used for the in-memory live ticket pool when the new
database and blockchain enhancements have been synced from upstream.
Since it maintains the data in sorted order, it provides a significant
speedup over the current map-based implementation.  On my hardware, this
implementation is able to remove the tickets that have voted and add the
new tickets in ~0.083ms and iterate the entire structure for selecting the
tickets in ~1.88ms for a total of ~1.96ms.  That equates to roughly 14x
faster access.

In addition, it would also be possible for the stake code to keep a map
for height-based lookups (while still relying on this new data structure
for keeping the lexicographic sort ordering requirements) for an even
greater speedup since it would eliminate the need to iterate the
structure to remove tickets at a given height.

Finally, when evaluating forks, the current code is quite inefficient
because it needs to make a copy of all of the live ticket maps.  This
new structure provides O(1) snapshot/copy capabilities so it is much
more efficient in that regard as well.

Benchmarks:

ImmutableCopy     30000000      40.7 ns/op   0 B/op   0 allocs/op
ImmutableIterate  1000       1881738 ns/op   0 B/op   0 allocs/op
2016-06-06 14:33:17 -05:00