Comments (3)
I modelled the difficulty according to the bitcoin specs (see https://en.bitcoin.it/wiki/Difficulty and https://en.bitcoin.it/wiki/Target). The minimum difficulty is 1, which corresponds to the max target Policy.BLOCK_TARGET_MAX (compact 0x1f00ffff). The maximum difficulty is Policy.BLOCK_TARGET_MAX (target 1, compact 0x01010000).
Current differences to Bitcoin:
- We currently use a MAX_TARGET of compact 0x1f00ffff (bitcoin 0x1d00ffff), i.e. difficulty 1 is 16 leading zero bits (bitcoin 32). Otherwise, our wimpy browser miner needs like 3 days to mine a block at the lowest difficulty (which really sucks for testing).
- In some cases, the Bitcoin client uses a target of 0 (difficulty infinity). We enforce a minimum target of 1.
from core-js.
The behaviour difficulty !== BlockUtils.compactToDifficulty(BlockUtils.difficultyToCompact(difficulty))
for some difficulties is due to the fact the the compact representation is lossy. The compact representation (or nBits) encodes a 256 bit target value in 32 bits and is passed along in the block headers, so we want it to be small.
When computing BlockUtils.difficultyToCompact(difficulty)
, we first compute the target value that is difficulty
times harder than the Policy.BLOCK_TARGET_MAX
: target = Policy.BLOCK_TARGET_MAX / difficulty
. For difficulty = 250
this gives a target value of 10623d70a3d70a000000000000000000000000000000000000000000000
. The compact representation of this target is 1e010623
, which loses a lot of precision. Expanding this to a target again gives a truncated target value of 10623000000000000000000000000000000000000000000000000000000
, which corresponds to difficulty = 250.00312933077026
.
We only pass around compact target representations, i.e. all clients should work with truncated targets. The behaviour seems indeed unexpected, but in the end, I guess that's how it's supposed to work.
from core-js.
Makes sense. I adjusted the test to now only rely on nBits
instead of the difficulty.
from core-js.
Related Issues (20)
- RPC method getRawTransactionInfo always returns inMempool: false
- minning by php script. HOT 2
- VestingContract doesn't make funds above vestingTotalAmount immediately available. HOT 1
- Metrics server without HTTPS
- Provide the loader as modern es6 module HOT 2
- Client transaction history returns knownTxs above the limit HOT 3
- Mempool.getTransactions() might scan entire mempool
- core-js won't build with Node 14 HOT 1
- ipv6 ws address parse wrong HOT 1
- Different number of confirmations returned by getTransactionByHash and getTransactionReceipt HOT 5
- Deno support HOT 1
- Add recurring payments (subscription)
- refactor dockerfiles HOT 1
- DEB package includes dev dependencies HOT 1
- github repo missing tag `v1.5.8` HOT 1
- looking for example HOT 2
- Apple M1 support HOT 13
- Building on node js 18 / Ubuntu 22.04 gives an error HOT 2
- Replace node-deb with standard deb creation tools
- Unable to build core-js using Node v22.1.0 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core-js.