Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement protocol 2.0; change db schema #101

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dc7eb24
history db: change schema, and rm compaction
SomberNight Oct 22, 2020
1877119
history db: change schema: prefix entries with b'H'
SomberNight Oct 28, 2020
81d8dd1
history db: store a tx_hash->tx_num map
SomberNight Oct 28, 2020
92cb55c
history db: sort key insertion order
SomberNight Oct 29, 2020
9c22323
utxo db: change schema: no longer use compressed txid
SomberNight Oct 28, 2020
6d38d0f
db: rm upgrade logic
SomberNight Oct 28, 2020
1853023
session: blockchain.transaction.get_merkle: make "height" optional
SomberNight Oct 29, 2020
90561ef
env: add new cfg option "DAEMON_HAS_TXINDEX", and support "False"
SomberNight Oct 29, 2020
4ebda7a
history db: store a (prev_txnum, prev_idx)->spender_txnum map
SomberNight Oct 30, 2020
64189cc
(trivial) make TXNUM_PADDING a global
SomberNight Oct 30, 2020
95c6ce6
db: add parameter for TXOUTIDX_LEN
SomberNight Oct 30, 2020
4326ae7
db: change TXOUTIDX_LEN from 4 to 3, to save db storage size
SomberNight Oct 30, 2020
3a41279
session: implement "blockchain.outpoint.subscribe" RPC
SomberNight Nov 3, 2020
7c7612b
"blockchain.outpoint.subscribe" RPC: add optional "spk_hint" argument
SomberNight Jan 19, 2021
65a7dd3
"blockchain.outpoint.subscribe" RPC: implement notifications
SomberNight Nov 4, 2020
b87a8ea
"blockchain.outpoint.subscribe" RPC: distinguish heights "-1" and "0"
SomberNight Jan 27, 2021
79e2690
protocol change: server.version must be the first message on the wire
SomberNight Nov 5, 2020
8b7efde
session: wait for protocol ver negotiation to finish before other reqs
SomberNight Jan 19, 2021
f410565
(bugfix) db: change tx_num endianness (LE->BE) to match db comparator
SomberNight Nov 16, 2020
df12667
protocol change: define order of mempool txs in status of scripthash
SomberNight Dec 15, 2020
0494caf
DB storage: implement iterator.seek(key)
SomberNight Feb 3, 2021
312e61d
new scripthash status: impl protocol 1.5 status; inefficient for now
SomberNight Jan 19, 2021
660deec
new scripthash status: speed-up calc by storing intermed. state in db
SomberNight Feb 4, 2021
36202d3
"scripthash.get_history": impl updates for proto 1.5; no client_* yet
SomberNight Feb 4, 2021
3dcb9f1
"scripthash.get_history": handle client_statushash and client_height
SomberNight Feb 5, 2021
09a15fb
session: rework statushash calculation.
SomberNight Oct 20, 2021
cee2d3f
[AuxPow] Add Support for individual block headers instead of a combin…
ahmedbodi Jun 28, 2020
2bfbc5c
Array headers: fix type error
JeremyRand Mar 18, 2021
31f8427
Array headers: move variable initialization
JeremyRand Mar 18, 2021
264daec
Array headers: Refactor AuxPoW
JeremyRand Mar 18, 2021
ef830fd
Array headers: Refactor AuxPoW truncation
JeremyRand Mar 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[AuxPow] Add Support for individual block headers instead of a combin…
…ed hex string
ahmedbodi authored and SomberNight committed Oct 20, 2021
commit cee2d3fc4d58118aefcee4b8d8444f6d78075b4d
44 changes: 44 additions & 0 deletions electrumx/server/session.py
Original file line number Diff line number Diff line change
@@ -1562,6 +1562,8 @@ async def block_headers(self, start_height, count, cp_height=0):
start_height and count must be non-negative integers. At most
MAX_CHUNK_SIZE headers will be returned.
'''
if self.protocol_tuple >= (1, 5):
return await self.block_headers_array(start_height, count, cp_height)
start_height = non_negative_integer(start_height)
count = non_negative_integer(count)
cp_height = non_negative_integer(cp_height)
@@ -1578,6 +1580,38 @@ async def block_headers(self, start_height, count, cp_height=0):
self.bump_cost(cost)
return result

async def block_headers_array(self, start_height, count, cp_height=0):
'''Return block headers in an array for the main chain;
starting at start_height.
start_height and count must be non-negative integers. At most
MAX_CHUNK_SIZE headers will be returned.
'''
start_height = non_negative_integer(start_height)
count = non_negative_integer(count)
cp_height = non_negative_integer(cp_height)
cost = count / 50

max_size = self.MAX_CHUNK_SIZE
count = min(count, max_size)
headers, count = await self.db.read_headers(start_height, count)
cursor = 0
result = {'count': count, 'max': max_size, 'headers': []}
if count and cp_height:
cost += 1.0
last_height = start_height + count - 1
result.update(await self._merkle_proof(cp_height, last_height))

height = 0
while cursor < len(headers):
next_cursor = self.db.header_offset(height + 1)
header = headers[cursor:next_cursor]
result['headers'].append(header)
cursor = next_cursor
height += 1

self.bump_cost(cost)
return result

def is_tor(self):
'''Try to detect if the connection is to a tor hidden service we are
running.'''
@@ -2128,9 +2162,19 @@ async def block_headers(self, start_height, count, cp_height=0):
return result

# Covered by a checkpoint; truncate AuxPoW data
if self.protocol_tuple >= (1, 5):
result['headers'] = self.truncate_auxpow_headers(result['headers'])
return

result['hex'] = self.truncate_auxpow(result['hex'], start_height)
return result

def truncate_auxpow_headers(self, headers):
result = []
for header in headers:
result.append(header[:self.coin.TRUNCATED_HEADER_SIZE])
return result

def truncate_auxpow(self, headers_full_hex, start_height):
height = start_height
headers_full = util.hex_to_bytes(headers_full_hex)