Skip to content

Commit

Permalink
♻️ Split shared session
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed May 16, 2024
1 parent 7f52c61 commit 1ed2e29
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 224 deletions.
36 changes: 19 additions & 17 deletions contrib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@
# See the file "LICENCE" for information about the copyright
# and warranty status of this software.

'''Script to query the database for debugging purposes.
"""Script to query the database for debugging purposes.
Not currently documented; might become easier to use in future.
'''
"""

import argparse
import asyncio

from electrumx import Env
from electrumx.server.db import DB
from electrumx.lib.hash import hash_to_hex_str, Base58Error
from electrumx.server.db import DB
from electrumx.server.env import Env
from electrumx.server.history import History


async def print_stats(hist_db, utxo_db):
count = 0
for key in utxo_db.iterator(prefix=b'u', include_value=False):
count += 1
print(f'UTXO count: {utxos}')
async def print_stats(hist_db: History, utxo_db):
utxo_count = 0
for _ in utxo_db.iterator(prefix=b'u', include_value=False):
utxo_count += 1
print(f'UTXO count: {utxo_count}')

count = 0
for key in utxo_db.iterator(prefix=b'h', include_value=False):
count += 1
print(f'HashX count: {count}')
hash_count = 0
for _ in utxo_db.iterator(prefix=b'h', include_value=False):
hash_count += 1
print(f'HashX count: {hash_count}')

hist = 0
hist_len = 0
for key, value in hist_db.iterator(prefix=b'H'):
for key, value in hist_db.db.iterator(prefix=b'H'):
hist += 1
hist_len += len(value) // 4
print(f'History rows {hist:,d} entries {hist_len:,d}')
Expand Down Expand Up @@ -64,7 +65,7 @@ async def query(args):
await db.open_for_serving()

if not args.scripts:
await print_stats(db.hist_db, db.utxo_db)
await print_stats(db.history, db.utxo_db)
return
limit = args.limit
for arg in args.scripts:
Expand Down Expand Up @@ -97,15 +98,16 @@ def main():
parser = argparse.ArgumentParser(
'query.py',
description='Invoke with COIN and DB_DIRECTORY set in the '
'environment as they would be invoking electrumx_server'
'environment as they would be invoking electrumx_server'
)
parser.add_argument('-l', '--limit', metavar='limit', type=int,
default=10, help=f'maximum number of entries to '
f'return (default: {default_limit})')
f'return (default: {default_limit})')
parser.add_argument('scripts', nargs='*', default=[], type=str,
help='hex scripts to query')
args = parser.parse_args()
asyncio.run(query(args))


if __name__ == '__main__':
main()
6 changes: 0 additions & 6 deletions electrumx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
__version__ = "1.16.0"
version = f'ElectrumX {__version__}'
version_short = __version__

from electrumx.server.controller import Controller
from electrumx.server.env import Env
10 changes: 9 additions & 1 deletion electrumx/lib/atomicals_blueprint_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,15 @@ def validate_ft_transfer_has_no_inflation(self, atomical_id_to_expected_outs_map
input_value = ft_info['value']
if sum_out_value and sum_out_value > input_value:
atomical_id_compact = location_id_bytes_to_compact(atomical_id)
raise AtomicalsTransferBlueprintBuilderError(f'validate_ft_transfer_has_no_inflation: Fatal error the output sum of outputs is greater than input sum for Atomical: atomical_id={atomical_id_compact} input_value={input_value} sum_out_value={sum_out_value} {hash_to_hex_str(tx_hash)} ft_atomicals={ft_atomicals}')
raise AtomicalsTransferBlueprintBuilderError(
'validate_ft_transfer_has_no_inflation: '
'Fatal error the output sum of outputs is greater than input sum for Atomical: '
f'atomical_id={atomical_id_compact} '
f'input_value={input_value} '
f'sum_out_value={sum_out_value} '
f'{hash_to_hex_str(self.tx_hash)} '
f'ft_atomicals={ft_atomicals}'
)

def is_split_operation(self):
return is_split_operation(self.operations_found_at_inputs)
Expand Down
32 changes: 19 additions & 13 deletions electrumx/lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import electrumx.lib.tx_axe as lib_tx_axe
import electrumx.server.block_processor as block_proc
import electrumx.server.daemon as daemon
from electrumx.server.session import (ElectrumX, DashElectrumX,
SmartCashElectrumX, AuxPoWElectrumX,
NameIndexElectrumX, NameIndexAuxPoWElectrumX)
from electrumx.server.session.electrumx_session import (ElectrumX, DashElectrumX,
SmartCashElectrumX, AuxPoWElectrumX,
NameIndexElectrumX, NameIndexAuxPoWElectrumX)


@dataclass
Expand All @@ -65,8 +65,19 @@ class CoinError(Exception):
'''Exception raised for coin-related errors.'''


class Coin:
'''Base class of coin hierarchy.'''
class CoinHeaderHashMixin:
@classmethod
def header_hash(cls, header):
"""Given a header return hash"""
return double_sha256(header)


class CoinShortNameMixin:
SHORTNAME: str


class Coin(CoinHeaderHashMixin, CoinShortNameMixin):
"""Base class of coin hierarchy."""

REORG_LIMIT = 200
# Not sure if these are coin-specific
Expand Down Expand Up @@ -225,11 +236,6 @@ def privkey_WIF(cls, privkey_bytes, compressed):
payload.append(0x01)
return cls.ENCODE_CHECK(payload)

@classmethod
def header_hash(cls, header):
'''Given a header return hash'''
return double_sha256(header)

@classmethod
def header_prevhash(cls, header):
'''Given a header return previous hash'''
Expand Down Expand Up @@ -328,7 +334,7 @@ def block_header(cls, block, height):
return deserializer.read_header(cls.BASIC_HEADER_SIZE)


class ScryptMixin:
class ScryptMixin(CoinHeaderHashMixin):

DESERIALIZER = lib_tx.DeserializerTxTime
HEADER_HASH = None
Expand Down Expand Up @@ -357,7 +363,7 @@ class KomodoMixin:
DESERIALIZER = lib_tx.DeserializerZcash


class BitcoinMixin:
class BitcoinMixin(CoinShortNameMixin):
SHORTNAME = "BTC"
NET = "mainnet"
XPUB_VERBYTES = bytes.fromhex("0488b21e")
Expand Down Expand Up @@ -845,7 +851,7 @@ def hashX_from_script(cls, script):
return super().hashX_from_script(address_script)


class BitcoinTestnetMixin:
class BitcoinTestnetMixin(CoinShortNameMixin):
SHORTNAME = "XTN"
NET = "testnet"
XPUB_VERBYTES = bytes.fromhex("043587cf")
Expand Down
Loading

0 comments on commit 1ed2e29

Please sign in to comment.