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

Chainwork DB upgrade. Hashrate and Chainwork charts. #808

Merged
merged 3 commits into from
Nov 26, 2018

Conversation

buck54321
Copy link
Member

@buck54321 buck54321 commented Nov 12, 2018

Resolves #744 and #723.

This PR performs a PostgreSQL DB upgrade, adding a TEXT column, chainwork. Relevant block insertion routines are updated to grab the newly available chainwork value from dcrd. Having chainwork also enables quick calculation of network hashrate data. A network hashrate chart and "total work" chart have been added to /charts.

@chappjc
Copy link
Member

chappjc commented Nov 12, 2018

We're discussing in Slack if dcrd/rpcclient and dcrd/dcrjson are ready for a new version tag so we can bump the module without using a pseudo-version.

@buck54321
Copy link
Member Author

I kept all the changes in this PR, even though the title is a little outdated. This will add a new column to your PostgreSQL blocks table. I've just been dropping the column from the table on the command line as needed.

I took a couple of liberties with the units. Since chainwork is a 32-byte hex string representing a number > 2^64, for use in JSON/charts I converted work to exahash and hashrate to terahash/s.

@chappjc chappjc added this to the 3.2 milestone Nov 14, 2018
@buck54321 buck54321 force-pushed the chainwork-api branch 3 times, most recently from a12b0a3 to f8b56fa Compare November 17, 2018 13:25
Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

Unfortunately, the node may not have orphaned/side chain blocks that in dcrdata's database. If it does not have a non-mainchain block, the "Block not found" error from dcrd can be ignored and the loop continued at the next row.

For instance, I get:

2018-11-23 13:37:36.794 [INF] PSQL: Adding column chainwork to table blocks...
2018-11-23 13:37:36.795 [INF] PSQL: Syncing chainwork. This might take a while...
2018-11-23 13:38:25.521 [ERR] PSQL: GetChainWork failed (000000000000000044b4a0c4ff6fdf5d32396a31333ab0fe3013ee9262e21b99). Aborting chainwork sync.: -5: Block not found: 000000000000000044b4a0c4ff6fdf5d32396a31333ab0fe3013ee9262e21b99
2018-11-23 13:38:25.535 [INF] DATD: Closing connection to dcrd.
2018-11-23 13:38:25.535 [INF] DATD: Bye!
2018-11-23 13:38:25.786 [ERR] DATD: failed to upgrade blocks table to version 3.7.0. Error: new chainwork column upgrade of blocks table ended prematurely after 289471 rows.Error: -5: Block not found: 000000000000000044b4a0c4ff6fdf5d32396a31333ab0fe3013ee9262e21b99

db/dcrpg/upgrades.go Outdated Show resolved Hide resolved
db/dcrpg/upgrades.go Outdated Show resolved Hide resolved
db/dcrpg/upgrades.go Outdated Show resolved Hide resolved
db/dcrpg/upgrades.go Outdated Show resolved Hide resolved
db/dcrpg/upgrades.go Outdated Show resolved Hide resolved
db/dcrpg/upgrades.go Outdated Show resolved Hide resolved
db/dcrpg/upgrades.go Show resolved Hide resolved
@chappjc
Copy link
Member

chappjc commented Nov 23, 2018

BTW, I was testing a rebased version: https://github.com/chappjc/dcrdata/tree/chainwork-api

@buck54321 buck54321 changed the title Updated minimum dependencies to add chainwork to api calls Chainwork DB upgrade. Hashrate and Chainwork charts. Nov 26, 2018
@chappjc chappjc merged commit db8e600 into decred:master Nov 26, 2018
mkingori pushed a commit to mkingori/dcrdata that referenced this pull request Apr 9, 2020
This adds chainwork to the dcrpg blocks table to support hashrate and work charts.

This performs a PostgreSQL DB upgrade, adding a TEXT column, chainwork.

Relevant block insertion routines are updated to grab the newly available chainwork
value from dcrd. Having chainwork also enables quick calculation of network hashrate
data. A network hashrate chart and "total work" chart have been added to /charts.
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.

2 participants