Matoking/nanolib

Support work threshold/difficulty multiplier

guilhermelawless opened this issue · 4 comments

Thanks for this library, we've been using it for our service DPoW.

A few suggestions:

  1. The nano node is using difficulty rather than threshold in every work related RPC, perhaps it would be good to change the semantics before the next major version update. See https://docs.nano.org/commands/rpc-protocol/#work_generate
  2. Work multipliers are useful to know how much "more difficult" a certain work is. I have a gist here (use as you wish) with the code to do this. Similar code has been pushed to the next Nano node version here.
  3. A function to check the difficulty of a proof would be great as well.

I can obviously use my own two small functions to accomplish this, but since this librar is so complete I thought I'd make the suggestion.

Thanks for the details, I'll look into renaming Block.threshold into Block.difficulty and adding new functions to deal with work multipliers.

I've added new nanolib.work.derive_work_difficulty and nanolib.work.derive_work_multiplier functions to calculate work difficulties and multipliers. The term 'threshold' has been renamed 'difficulty' and the functions with difficulty parameters only accept 64-bit, 16-character hex strings to keep things in line with the NANO client.

I'll probably release a new version on PyPI shortly unless other issues arise before that.

Appreciate it! Everything seems good, only one piece of feedback:

multiplier = nanolib.work.derive_work_multiplier(hex(nanolib.work.get_work_value(block_hash, work))[2:])

Due to derive_work_multiplier only accepting the string version, I have to convert it there.

Appreciate it! Everything seems good, only one piece of feedback:

multiplier = nanolib.work.derive_work_multiplier(hex(nanolib.work.get_work_value(block_hash, work))[2:])

Due to derive_work_multiplier only accepting the string version, I have to convert it there.

nanolib.work.get_work_value now has a as_hex keyword argument to return it as a hex string instead.