Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the ticket database with an efficient, atomic implementation #349

Merged
merged 1 commit into from
Oct 4, 2016

Conversation

cjepson
Copy link
Contributor

@cjepson cjepson commented Sep 20, 2016

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.

Thanks to @davecgh for the efficient treap primitive, which is widely
used.

TODO before merge:

  • Extend unit test coverage.

Fixes issue #337.

@raedah
Copy link
Contributor

raedah commented Sep 20, 2016

Will this prevent running older versions of the decred software once the database has been upgraded?

@davecgh
Copy link
Member

davecgh commented Sep 20, 2016

@cjepson can confirm, but I would expect the answer no. The stake database would be recreated from scratch using the old format (assuming it's not still around up to a certain point in which case it would continue from the last known good block).

@chappjc
Copy link
Member

chappjc commented Sep 20, 2016

Upgrade of a mainnet database to version 2 completed successfully in about 17 minutes.
Graceful shutdown of dcrd is less than a second (can it be?).
Sync of entire mainnet chain in 53 minutes.

BTW, discovered this trick: git fetch origin pull/349/head:fast-ticketdb

@jolan
Copy link
Contributor

jolan commented Sep 20, 2016

I've mined a few dozen testnet blocks with this. No issues encountered (will update if so).

tACK

@cjepson
Copy link
Contributor Author

cjepson commented Sep 20, 2016

@raedah It's not recommended to run the old and new databases from the same directory. I would rename the old data directory and then reference it directly with --datadir if you still wanted to use an old version concurrently.

@jcvernaleo
Copy link
Member

I've been running this one both of my testnet nodes for several days (one IBD and one upgraded) without issue.

We did see some rejected blocks on an upgraded bitrig node early on but have had no luck reproducing that failure (and I think that was a few commits ago).

@cjepson cjepson force-pushed the cj_060616blockchain2_ticketdb2 branch 2 times, most recently from 8963f81 to c134ee3 Compare September 24, 2016 01:24
@jolan
Copy link
Contributor

jolan commented Sep 26, 2016

Ran OK for me over the weekend on testnet. Was buying tickets/voting constantly. No problems encountered.

tACK

@jcvernaleo
Copy link
Member

My two nodes were also good running over the weekend.

@cjepson cjepson force-pushed the cj_060616blockchain2_ticketdb2 branch 2 times, most recently from 200c92d to 473a17c Compare September 26, 2016 17:21
@marcopeereboom marcopeereboom added this to the 0.5.0 milestone Sep 29, 2016
@cjepson cjepson force-pushed the cj_060616blockchain2_ticketdb2 branch 2 times, most recently from 88f5e1f to e6917c1 Compare September 30, 2016 20:02
@jolan
Copy link
Contributor

jolan commented Oct 3, 2016

Ran the latest version over the weekend on various testnet nodes that are used for stake pool testing and ticket purchasing and they've been running smoothly. Also have a mainnet node that's mostly idle and that's been running ok too.

@jcvernaleo
Copy link
Member

My testnet nodes have also been running fine.

@jrick jrick self-assigned this Oct 3, 2016
Copy link
Member

@jrick jrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been reviewing this over the past couple days and have not noticed any critical errors. There may be some performance improvements that can still be made but these can be shaken out in tree.

@jolan
Copy link
Contributor

jolan commented Oct 4, 2016

Re-tested PoW mining on testnet with the latest version. 16 blocks so far without problems.

tACK

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.
@cjepson cjepson force-pushed the cj_060616blockchain2_ticketdb2 branch from e6917c1 to d98fc83 Compare October 4, 2016 17:45
@cjepson cjepson merged commit d98fc83 into decred:master Oct 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants