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

Hashwork sync algo #160

hclivess opened this issue Dec 11, 2017 · 0 comments

Hashwork sync algo #160

hclivess opened this issue Dec 11, 2017 · 0 comments


Copy link

@hclivess hclivess commented Dec 11, 2017

import sqlite3, math
from decimal import *

ledger_path_conf = "../Bismuth/static/ledger.db"
conn = sqlite3.connect(ledger_path_conf, uri=True, timeout=1, isolation_level=None)
c = conn.cursor()
c.execute("SELECT * FROM transactions where reward!=0 ORDER BY block_height DESC LIMIT 1")
row = c.fetchone()
timestamp_last = row[1]
# Time window in seconds
L = 3600

c.execute("SELECT * FROM transactions where reward!=0 and timestamp > ? order by timestamp asc limit 1",(timestamp_last-L,))
row = c.fetchone()
block_start = row[0]

c.execute("SELECT difficulty FROM misc where block_height>? ORDER BY block_height ASC",(block_start,))

hashwork = Decimal(0)

for row in c:
  # Difficulty
  D = Decimal(row[0])
  # Calculcate network hashrate * blocktime
  HT = pow(2, D / Decimal(2.0)) / math.ceil(28 - D / Decimal(16.0))
  # Integrate HT to hashwork (unit terrahashes TH)
  hashwork += HT/Decimal(1e12)

print("Hashwork last {} hours={} TH".format(L/3600,round(hashwork,2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant