Hello Senj,
GetNextTargetRequired method is used to generate nBits (target in compact format) twice:
1. when creating new block
2. when checking if nBits of a block (could be any block in a tree) conforms to algorithm
When creating PoW block (1), pIndexPrev is a pointer to last PoW block in best chain
I thought it was the previous block, PoS or PoW. So
pIndexPrev is a special
pIndexPrev , actually a
pIndexPrevPoW. I come from a bitcoin mentality where there are only PoW blocks.
. If there is PoW block at the tip of the chain, then pIndexPrev = pIndexLast, otherwise we have to search for it backwards with GetLastBlockIndex method. pIndexPrevPrev is a pointer to PoW block preceeding pIndexPrev.
So
pIndexPrevPrev is really a
pIndexPrevPrevPoW! Things get confusing really fast when bitcoin code is taken, modified, and the names of important items (methods, pointers, functions, etc. etc.) aren't changed.
When checking if nBits of a PoW block conforms to block generation rule (2) then pIndexPrev is a pointer to PoW block preceeding it. And as before, pIndexPrevPrev is a pointer to PoW block preceeding pIndexPrev.
The same principle is used for PoS blocks. Just replace all occurences of PoW with PoS in text above.
Not quite sure I understand how to do that? If
pIndexPrevPrev i is really a
pIndexPrevPrevPoW , how does that help me find a PoS block(s)? I seem to be missing something. That is why I said that it would be nice to have two separate pieces of code, perhaps with lots of commonality, but it would be clearer. Also better names! Doesn't everyone's IDE have (prompted for safety)global search and replace? Or is it only my free MSVC++ Express
What "(60 seconds)*(1 + pindexLast->nHeight - pindexPrev->nHeight)" does in case of proof-of-work blocks, it multiplies number of PoS blocks between last PoW block and the one before with 1 minute. If there are no PoS blocks between, then
pindexLast = pindexPrev and height difference in equation equals 0. PoW target spacing is then set to 1 minute.
Yacoin has 1 minute PoS block target spacing.
But PoW block target spacing always was dynamic and it get's wider (PoW difficulty gets higher) in proportion to PoS blocks between last two PoW blocks. It stops growing when 12 sequential PoS blocks are let in.
But if it is PoW easier to have less PoS blocks (PoW harder to have more PoS blocks) doesn't that play into the hands of GM ("greedy miner")?
After PoS block is accepted, target of next PoW block gets adjusted towards 2 minute.
But isn't time counted (on the average) from the moment of the PoS block acceptance? Seems to me that is still 1 minute to the next block. Isn't the PoS Merkle etc. part of the "best chain" at this moment? Or am I missing something?
Change in difficulty is incremental (exponential retargeting). Nevertheless, selfish miner can mine on lower PoW difficulty if he ignores PoS blocks.
I would think that an "inducement" to keep PoS blocks by reversing the above change in PoW difficulty, would "entice"
GM to take the current best chain with PoS block(s) since it's PoW difficulty would be trending down. A question would be how to keep a flood of "cheap" PoS blocks from happening? If
GM can "propose" PoS blocks that are "better" (whatever the criteria are) then so be it. But if another PoS block of "better worth" is simultaneously "proposed" (broadcasted), I would think that the "consensus" s/w should pick the better one.
Overall, setting block spacing is only one part of operation. In essence it prescribes block targets for a valid branch.
Currently there are bigger problems with chaintrust calculation - giving correct score to multiple valid branchees thus making possible for peers to choose the best one.
I have no idea what that means (LOL). Correct score? Trust calculation? What and where are those items?
Ron