Ok, I get it done.
There were two kind of errors I have found (not to mention the byte-order during submitting result - thank you @Charlie for that tip):
1. the result (false) I got as the last response from the pool server was not response to 'mining.submit' method
In my example communication log (question) I paste (among others) those requests:
There is (at least) one mistake:
There is no merkle branches (merkle branches array is empty), so hash
above is our merkle root
The merkle array for that specific job is not empty. It contains the following branches:
Yes, both scenarios are possible. The validity of a block is determined solely by its contents, not by when it is broadcast or received, so the attacker's longer chain is equally valid whether they broadcast it as they go, or all at once.
(There is an exception to this principle on testnet because of the 20-minute rule, but that's not relevant here.)
When a pool gives a miner data to mine it is not data for one specific block, but a template for a block. The miner hashes many variations of this block data to try to find a block that has a hash value below the current target (which is determined by the current difficulty).
To calculate the hash of a block on the blockchain given only the data that the ...