- Add support for reversed hash bytes.
- Add support for Python 3. The linearization scripts can now run on Python 2 or 3.
Continuing #9304.
Found a small bug affecting Python 3. Will update in a bit.
Nevermind. It wasn't a bug after all. Once I clarified things (command line foolishness on my behalf), I ran Python 2 and 3 with and without the bytes reversed, then ran shasum -a 256 bootstrap.dat each time the bootstrap file was written. The results were the same.
While here, I did add a few comments and then did a fixup and rebase.
Added some more documentation updates but seem to have borked my fixup. Will fix it momentarily.
Back to normal. Did a quick sanity check. Everything looks good.
12 | +* RPC: `rpcuser`, `rpcpassword` 13 | 14 | Optional config file setting for linearize-hashes: 15 | -* RPC: host, port 16 | -* Block chain: min_height, max_height 17 | +* RPC: `host`, `port` (Default: `127.0.0.1:8332`)
Minor nit: the default suggests that the ip:port format should be used, while it really is two different options.
47 | -* "file_timestamp": Set each file's last-modified time to that of the 48 | -most recent block in that file. 49 | +* `file_timestamp`: Set each file's last-modified time to that of the most 50 | +recent block in that file. 51 | +* `genesis`: The hash of the genesis block in the blockchain. 52 | +* `input: bitcoind blocks/ directory containing blkNNNNN.dat
Missing closing quote on for input.
30 | 31 | +##### Switch endian-ness ##### 32 | +def hex_switchEndian(s): 33 | + """ Switches the endianness of a hex string (in pairs of hex chars) """ 34 | + pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)] 35 | + return b''.join(pairList[::-1]).decode()
The encode and decode call seem to be unnecessary. Also my highly unscientific test shows that
s.decode('hex')[::-1].encode('hex')
is about 5 times faster than the above loop, but may be a bit more confusing.
hexlify(unhexlify(s)[::-1]) is even quicker :wink:
Thanks! Will fix everything up.
Hello. After playing around with timeit(), it looks like the original code and hexlify(unhexlify(s)[::-1]).decode() are about the same speed. (s.decode('hex')[::-1].encode('hex') doesn't work, and I think it'd return incorrect results anyway.) Can you let me know how you benchmarked everything? As is, I think I'm going to leave this alone.
As for encode/decode, that has more to do with writing code that can run on Python 2 & 3; I'm also trying to maintain backwards compatibility. hexlify(unhexlify(s)[::-1]) works by itself but the result is b'0e0ac90a'. That won't work without decoding it.
Yeah, I noticed too late that the encode/decode hex variant will not work on Python3. We're probably micro-optimizing here anyway, given that the rest of the code is doing RPC calls :-)
Currently, the linearization scripts require input hashes to be in one endian form. Add support for byte reversal.
utACK 3c8f63b