- A complete fix would involve setting the DIFFICULTY_WINDOW to
1 unified constant for both pre/post HF16 code. My attempts to get this
to work have not succeeded and so I'm putting this aside to allocate
more time on getting Pulse ready for testnet.
For completeness sake, I'll be copying verbatim the changes requested below.
Of the changes requested only adjusting the DIFFICULTY_WINDOW to 59 was
done (with the appropriate offset changes to the other constants that
interact with it).
The changes requested by jagerman
(from https://github.com/loki-project/loki-core/pull/1235)
Two points about this analysis:
1. Most of the comments here belong in the commit message rather than
code comments.
2. Well before I joined LOKI I worked with zawy for a good bit of time
on LWMA implementations, and so I found this description very confusing
because adding 1 is the correct thing to do for an LWMA. You need 61
observations to do a LWMA 60 because you need solve times where are
timestamp differences of adjacent blocks.
However what you describe above is also correct. So then I investigated
the disparity, and figured it out:
We don't do a proper LWMA(60) because of this: N = (DIFFICULTY_WINDOW - 1)
That is just wrong: it means we are doing a LWMA(59). But even that
isn't quite right because the resize(N+1) done in next_difficulty_v2
also throws away the top value. So what we end up calculating is
a LWMA(59) with a lag of one (that is, we throw away the most recent
usable observation).
The fix in this commit is making the math line up, but in not quite the
right away because there is still a bunch of stuff that is off by one.
Instead what we need is:
DIFFICULTY_WINDOW_V2 should be changed to 59, since that's what it is
(and has always) actually done.
DIFFICULTY_BLOCKS_COUNT_V2 should remain as DIFFICULTY_WINDOW_V2 + 1 because that's the proper number of
required blocks needed for a LWMA(DIFFICULTY_WINDOW_V2).
- the -1 should be removed from next_difficulty_v2 (so that it remains at 59, with the
above change).
- if we're on HF15 or earlier then we still need
DIFFICULTY_BLOCKS_COUNT_V2 blocks, but because of this bug they need
to be the values from blocks (H-61) through (H-2) rather than (H-60)
through (H-1).
- The // TODO: put asserts here, so that the difficulty algorithm is never
called with an oversized window (removed in this commit) should be
actually done as it should work fine with these fixes.
- Pulse blocks will forcibly get the difficulty set to
1'000'000 * TARGET_BLOCK_TIME throughout time
- When PoW is required again, the past window of blocks will use these
difficulties, i.e. setup the chain for mining at 1'000'000 difficulty
which is easily mineable to continue the network and continue to pull
difficulties from the new-er mined blocks until the network is ready
for Pulse again.
- Difficulty is still necessary for falling back to mining when Pulse
fails. Switching between the two systems seamlessly can be done by
continuing to set the difficulty for Pulse blocks.
We're going to be coming down off a ~300MH/s high, so add a difficulty
cap of 30MH/s for the first 60 blocks so that we don't end with
extremely long blocks.
* create get_service_node_list rpc call
currently does nothing, just a shell (that compiles)
* implement get_all_service_node_keys rpc call
* change get_all_service_node_keys rpc to use json rpc
also change the result to be vector of hex strings rather than binary keys
* Make nodes be plural, add hex to base32z for keys
Base32z for Lokinet internal usage
* Add option to return fully funded service nodes only
* Add nullptr check for conversion
* Add assert for incorrect usage of to base32z
- Difficulty fix to prevent 0 difficulty which is not considered valid.
- CURRENT_BLOCK_MAJOR/MINOR_VERSION is only used for tests it appears
- Core Tests generate a blockchain using the nettype FAKECHAIN, so some
codepaths need to accept FAKECHAIN as a nettype. FAKECHAIN is essentially the
mainnet.
- Core Tests uses their own hard-fork data that specifies the current hard-fork
version and time it forked etc instead of using the data in blockchain.cpp at
the top. We started from v7, so get_test_options() is updated accordingly.