xelis-project / xelis-blockchain

A private blockDAG using Homomorphic Encryption with Smart Contract support
365 stars 85 forks source link

Daemon API: Invalid difficulty value #72

Open solopool opened 1 month ago

solopool commented 1 month ago

Hello!

We found bug on v1.12.0

Method get_block_template return correct difficulty value.

But method get_info and get_difficulty return invalid difficulty value.

Method get_block_template

{
  id: 1717844184748,
  jsonrpc: '2.0',
  result: {
    difficulty: '1634985537180000',
    height: 260176,
    template: '00000000000003f8500000018ff77e0eae0000000000000000432c21608708fcb296e8be3ce95d52f9e75a7e4733080cfccb980958d9fc749901d49a700271f3ac2fb1dd43756c6ca35ddb41ea2f2a442c4bbfe91b58eac8cec900040156a547866a2aea8ada2373555632cc6bc05ae3b02cbfc1a414d48e9673ab53c40b928e3fa0edd4d6e29b8eb4b27f42e6faa9de187ed16dfde82aade4f11509ffc4300b00f7dfefff4751194b23b8764093691121762556af5def151044a1cab63543c7bad39263a919837b1a692cb53c6c47d20cf8261552ca3cab3451ab5be2481a52e2a7046b45b4dd6c5bc7b7cd6da7d6ebbda6d5a94eadcdbc1fdefa56',
    topoheight: 273762
  }
}

Method get_info

{
  id: 1717844184745,
  jsonrpc: '2.0',
  result: {
    average_block_time: 14787,
    block_reward: 143191996,
    block_time_target: 15000,
    circulating_supply: 38227704294179,
    difficulty: '1203035435415000',
    height: 260175,
    maximum_supply: 1840000000000000,
    mempool_size: 4,
    network: 'Mainnet',
    pruned_topoheight: 185079,
    stableheight: 260167,
    top_block_hash: 'd49a700271f3ac2fb1dd43756c6ca35ddb41ea2f2a442c4bbfe91b58eac8cec9',
    topoheight: 273762,
    version: '1.12.0-ded9bb5'
  }
}

Method get_difficulty

{
  id: 1717844184755,
  jsonrpc: '2.0',
  result: {
    difficulty: '1203035435415000',
    hashrate: '80202362361000',
    hashrate_formatted: '80.20 TH/s'
  }
}

Corret value is 1634985537180000, invalid value is 1203035435415000 and it is constant.

Slixe commented 3 weeks ago

Hey there!

Difference can be normal due to the DAG,

get_block_template returns you the exact target for this block to be accepted by the network, while the get_info and get_difficulty is returning the difficulty based on all TIPS (all available DAG branches) which represents the network hashrate.

When get_tips returns only one hash, they should be both the same difficulty value.