obelisk

Electrum server using libbitcoin as its backend
git clone https://git.parazyd.org/obelisk
Log | Files | Refs | README | LICENSE

commit cab66a2fea98b07bcf9f30094c00d04047d740f3
parent 5ef73f51482298637aa7365a481503c5afba38fa
Author: parazyd <parazyd@dyne.org>
Date:   Thu, 15 Apr 2021 21:09:07 +0200

protocol/blockchain.block.header: WIP cp_height.

The merkle proof calculation is broken and I need help with this.

Diffstat:
Mobelisk/protocol.py | 17++++++++---------
Mtests/test_electrum_protocol.py | 15++++++++-------
2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/obelisk/protocol.py b/obelisk/protocol.py @@ -241,23 +241,22 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 return JsonRPCError.internalerror() return {"result": safe_hexlify(header)} + # TODO: Help needed cp_headers = [] - # headers up to and including cp_height - for i in range(index, cp_height + 1): + for i in range(index - 1, cp_height): _ec, data = await self.bx.fetch_block_header(i) if _ec and _ec != 0: self.log.debug("Got error: %s", repr(_ec)) return JsonRPCError.internalerror() cp_headers.append(data) - # TODO: Review - # TODO: Is index is 0 or last elem? - branch, root = merkle_branch_and_root(cp_headers, 0) + hashed = [double_sha256(i) for i in cp_headers] + branch, root = merkle_branch_and_root(hashed, 1, length=len(cp_headers)) return { "result": { - "branch": [safe_hexlify(i) for i in branch], - "header": safe_hexlify(cp_headers[0]), - "root": safe_hexlify(root), + "branch": [hash_to_hex_str(i) for i in branch], + "header": safe_hexlify(cp_headers[1]), + "root": hash_to_hex_str(root), } } @@ -297,7 +296,7 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 } # The assumption is to fetch more headers if necessary. - # TODO: Review + # TODO: Review, help needed if cp_height > 0 and cp_height - start_height > count: for i in range(cp_height - start_height): _ec, data = await self.bx.fetch_block_header(start_height + diff --git a/tests/test_electrum_protocol.py b/tests/test_electrum_protocol.py @@ -79,10 +79,10 @@ async def test_blockchain_block_header(protocol, writer): # params = [123, 130] # expect = get_expect(method, params) # data = await protocol.blockchain_block_header(writer, {"params": params}) - - # assert data["result"]["header"] == expect["result"]["header"] - # assert data["result"]["branch"] == expect["result"]["branch"] - # assert data["result"]["root"] == expect["result"]["root"] + # pprint(expect) + # print() + # pprint(data) + # assert data["result"] == expect["result"] async def test_blockchain_block_headers(protocol, writer): @@ -95,9 +95,10 @@ async def test_blockchain_block_headers(protocol, writer): # params = [123, 3, 127] # expect = get_expect(method, params) # data = await protocol.blockchain_block_headers(writer, {"params": params}) - # assert data["result"]["branch"] == expect["result"]["branch"] - # assert data["result"]["root"] == expect["result"]["root"] - # assert data["result"]["hex"] == expect["result"]["hex"] + # pprint(expect) + # print() + # pprint(data) + # assert data["result"] == expect["result"] async def test_blockchain_scripthash_get_balance(protocol, writer):