npy0 / nanopy

Python implementation of NANO related functions.
https://nanopy.rtfd.io
MIT License
29 stars 7 forks source link

Is the work difficulty up to date? #15

Closed ptvirgo closed 2 years ago

ptvirgo commented 2 years ago

Probably I'm doing something dumb, but it looks like the default work_difficulty in nanopy (used by block_create) might need to be updated.

When I try to do a send, the RPC response consistently includes "error": "Block work is less than threshold"

def main():
    connection = nanopy.rpc.RPC(url="https://proxy.powernode.cc/proxy")
    info = connection.account_info(ACCOUNT, representative=True)
    balance = int(info["balance"]) - int(nanopy.nano_to_raw("5"))

    if balance < 0:
        raise ValueError("You're out of nano.")

    balance = str(balance)

    nb = nanopy.block_create(PRIVATE, info["frontier"], info["representative"], balance, nanopy.account_key(PRIMARY))

    result = connection.process(nb)
    print(json.dumps(result, sort_keys=True, indent=4))
npy0 commented 2 years ago

The work threshold for blocks used to be ffffffc000000000. But now, it is fffffff800000000 for send or change, and fffffe0000000000 for receive, open or epoch.

https://docs.nano.org/integration-guides/work-generation/#difficulty-thresholds

I've now added 6e573415c5742ea7b3d33aed6b5c01b2c5d36ac5 2 optional parameters to block_create: work and difficulty.

You can call block_create with difficulty = 'fffffff800000000' or difficulty = 'fffffe0000000000' depending on the type of block you are generating. I'll try to publish a new version to pypi soon.