connector
This commit is contained in:
parent
dea3869bfc
commit
6e89d38f07
@ -10,7 +10,7 @@ import sys
|
|||||||
import aiojsonrpc
|
import aiojsonrpc
|
||||||
import traceback
|
import traceback
|
||||||
from pybtc.connector.utils import decode_block_tx
|
from pybtc.connector.utils import decode_block_tx
|
||||||
import pickle
|
import msgpack
|
||||||
from lru import LRU
|
from lru import LRU
|
||||||
|
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ class BlockLoader:
|
|||||||
|
|
||||||
if msg_type == b'result':
|
if msg_type == b'result':
|
||||||
self.worker_busy[index] = False
|
self.worker_busy[index] = False
|
||||||
blocks = pickle.loads(msg)
|
blocks = msgpack.loads(msg)
|
||||||
|
|
||||||
for i in blocks:
|
for i in blocks:
|
||||||
self.parent.block_preload.set(i, blocks[i])
|
self.parent.block_preload.set(i, blocks[i])
|
||||||
@ -256,9 +256,9 @@ class Worker:
|
|||||||
blocks[x]["rawTx"][y]["vOut"][i]["_s_"] = self.destroyed_coins[pointer]
|
blocks[x]["rawTx"][y]["vOut"][i]["_s_"] = self.destroyed_coins[pointer]
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
blocks[x] = pickle.dumps(blocks[x])
|
blocks[x] = msgpack.dumps(blocks[x])
|
||||||
|
|
||||||
self.pipe_sent_msg(b'result', pickle.dumps(blocks))
|
self.pipe_sent_msg(b'result', msgpack.dumps(blocks))
|
||||||
except:
|
except:
|
||||||
self.log.critical(str(traceback.format_exc()))
|
self.log.critical(str(traceback.format_exc()))
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import zmq
|
|||||||
import zmq.asyncio
|
import zmq.asyncio
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
import pickle
|
import msgpack
|
||||||
|
|
||||||
class Connector:
|
class Connector:
|
||||||
def __init__(self, node_rpc_url, node_zerromq_url, logger,
|
def __init__(self, node_rpc_url, node_zerromq_url, logger,
|
||||||
@ -304,7 +304,7 @@ class Connector:
|
|||||||
raw_block = self.block_preload.pop(self.last_block_height + 1)
|
raw_block = self.block_preload.pop(self.last_block_height + 1)
|
||||||
if raw_block:
|
if raw_block:
|
||||||
q = time.time()
|
q = time.time()
|
||||||
block = pickle.loads(raw_block)
|
block = msgpack.loads(raw_block)
|
||||||
self.blocks_decode_time += time.time() - q
|
self.blocks_decode_time += time.time() - q
|
||||||
|
|
||||||
if not block:
|
if not block:
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from pybtc import int_to_c_int, c_int_to_int, c_int_len
|
|||||||
import asyncio
|
import asyncio
|
||||||
from collections import OrderedDict, deque
|
from collections import OrderedDict, deque
|
||||||
from lru import LRU
|
from lru import LRU
|
||||||
import pickle
|
|
||||||
|
|
||||||
class UTXO():
|
class UTXO():
|
||||||
def __init__(self, db_pool, loop, log, cache_size):
|
def __init__(self, db_pool, loop, log, cache_size):
|
||||||
@ -34,7 +34,7 @@ class UTXO():
|
|||||||
self.outs_total = 0
|
self.outs_total = 0
|
||||||
|
|
||||||
def set(self, outpoint, pointer, amount, address):
|
def set(self, outpoint, pointer, amount, address):
|
||||||
self.cached[outpoint] = pickle.dumps((pointer, amount, address))
|
self.cached[outpoint] = (pointer, amount, address)
|
||||||
self.outs_total += 1
|
self.outs_total += 1
|
||||||
if pointer:
|
if pointer:
|
||||||
self.last_cached_block = pointer >> 42
|
self.last_cached_block = pointer >> 42
|
||||||
@ -144,10 +144,10 @@ class UTXO():
|
|||||||
finally:
|
finally:
|
||||||
self.save_process = False
|
self.save_process = False
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key, block_height):
|
||||||
self._requests += 1
|
self._requests += 1
|
||||||
try:
|
try:
|
||||||
i = pickle.loads(self.cached[key])
|
i = self.cached[key]
|
||||||
self.destroyed.append(key)
|
self.destroyed.append(key)
|
||||||
# try:
|
# try:
|
||||||
# self.destroyed[block_height].add(key)
|
# self.destroyed[block_height].add(key)
|
||||||
|
|||||||
@ -604,6 +604,13 @@ class BlockDeserializeTests(unittest.TestCase):
|
|||||||
Block(fc[:-1], format="raw", keep_raw_tx=False),
|
Block(fc[:-1], format="raw", keep_raw_tx=False),
|
||||||
)
|
)
|
||||||
print("decoded block", time.time() - qt )
|
print("decoded block", time.time() - qt )
|
||||||
|
import msgpack
|
||||||
|
qt = time.time()
|
||||||
|
k = msgpack.dumps(bt)
|
||||||
|
print("decoded block dump", time.time() - qt)
|
||||||
|
qt = time.time()
|
||||||
|
p = msgpack.loads(k)
|
||||||
|
print("decoded block load", time.time() - qt)
|
||||||
import pickle
|
import pickle
|
||||||
qt = time.time()
|
qt = time.time()
|
||||||
k = pickle.dumps(bt)
|
k = pickle.dumps(bt)
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -140,7 +140,7 @@ setup(name='pybtc',
|
|||||||
package_data={
|
package_data={
|
||||||
'pybtc': ['bip39_word_list/*.txt', 'test/*.txt'],
|
'pybtc': ['bip39_word_list/*.txt', 'test/*.txt'],
|
||||||
},
|
},
|
||||||
install_requires=['lru-dict'],
|
install_requires=['lru-dict', 'msgpack'],
|
||||||
cmdclass={
|
cmdclass={
|
||||||
'build_clib': build_clib,
|
'build_clib': build_clib,
|
||||||
'build_ext': build_ext,
|
'build_ext': build_ext,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user