Compare commits

...

10 Commits

Author SHA1 Message Date
4tochka
ebb1e24e27 connector 2019-05-16 17:52:50 +03:00
4tochka
8cc5b24ee9 connector 2019-05-16 16:53:58 +03:00
4tochka
e74267a1b3 connector 2019-05-16 16:49:43 +03:00
4tochka
bb6464c5d5 connector 2019-05-16 16:38:20 +03:00
4tochka
7668bf3e83 connector 2019-05-16 16:29:23 +03:00
4tochka
dd93756767 connector 2019-05-16 16:22:31 +03:00
4tochka
0110a90ae8 connector 2019-05-16 16:21:18 +03:00
4tochka
8fdbdc8dda connector 2019-05-16 16:17:14 +03:00
4tochka
680cbf7914 connector 2019-05-16 16:09:44 +03:00
4tochka
eeb0196c1b connector 2019-05-16 16:05:48 +03:00
5 changed files with 19 additions and 19 deletions

View File

@ -7,7 +7,7 @@ from .block import *
from .address import *
from .wallet import *
from .crypto import *
# from cache_strategies import LRU
from cache_strategies import LRU
from cache_strategies import MRU
from pybtc.connector import Connector

View File

@ -242,12 +242,12 @@ static PyObject *CACHE_delete(CACHE *self, PyObject *args) {
return instead;
}
Py_INCREF(node->value);
cache_remove_node(self, node);
PyDict_DelItem(self->dict, node->key);
Py_XDECREF(node);
return node->value;
PyObject *return_value = Py_BuildValue("O", node->value);
return return_value;
}
static PyObject *CACHE_set_size(CACHE *self, PyObject *args, PyObject *kwds) {
@ -623,7 +623,7 @@ static PyMethodDef LRU_methods[] = {
static PyTypeObject MRUType = {
PyVarObject_HEAD_INIT(NULL, 0)
"cache_strategies.MRU", /* tp_name */
"_cache.MRU", /* tp_name */
sizeof(CACHE), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)cache_dealloc, /* tp_dealloc */
@ -664,7 +664,7 @@ static PyTypeObject MRUType = {
static PyTypeObject LRUType = {
PyVarObject_HEAD_INIT(NULL, 0)
"cache_strategies.LRU", /* tp_name */
"_cache.LRU", /* tp_name */
sizeof(CACHE), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)cache_dealloc, /* tp_dealloc */
@ -727,14 +727,14 @@ static PyObject *moduleinit(void) {
MRUType.tp_new = PyType_GenericNew;
if (PyType_Ready(&MRUType) < 0) return NULL;
LRUType.tp_new = PyType_GenericNew;
// if (PyType_Ready(&LRUType) < 0) return NULL;
if (PyType_Ready(&MRUType) < 0) return NULL;
m = PyModule_Create(&moduledef);
if (m == NULL) return NULL;
Py_INCREF(&NodeType);
Py_INCREF(&MRUType);
// Py_INCREF(&LRUType);
PyModule_AddObject(m, "MRU", (PyObject *) &MRUType);
// PyModule_AddObject(m, "LRU", (PyObject *) &LRUType);
Py_INCREF(&LRUType);
// PyModule_AddObject(m, "MRU", (PyObject *) &MRUType);
PyModule_AddObject(m, "LRU", (PyObject *) &LRUType);
return m;
}

View File

@ -12,7 +12,7 @@ import traceback
from pybtc.connector.utils import decode_block_tx
import _pickle as pickle
from pybtc import MRU
from pybtc import MRU
class BlockLoader:
@ -209,8 +209,8 @@ class Worker:
self.loop.set_default_executor(ThreadPoolExecutor(20))
self.out_writer = out_writer
self.in_reader = in_reader
# self.coins = MRU(100000)
# self.destroyed_coins = MRU(100000)
self.coins = MRU(100000)
self.destroyed_coins = MRU(100000)
signal.signal(signal.SIGTERM, self.terminate)
self.loop.create_task(self.message_loop())
self.loop.run_forever()
@ -245,10 +245,10 @@ class Worker:
inp = block["rawTx"][z]["vIn"][i]
outpoint = b"".join((inp["txId"], int_to_bytes(inp["vOut"])))
try:
# r = self.coins.delete(outpoint)
# block["rawTx"][z]["vIn"][i]["_c_"] = r
r = self.coins.delete(outpoint)
block["rawTx"][z]["vIn"][i]["_c_"] = r
t += 1
# self.destroyed_coins[r[0]] = True
self.destroyed_coins[r[0]] = True
except:
pass
for i in block["rawTx"][z]["vOut"]:
@ -259,7 +259,7 @@ class Worker:
except:
address = b"".join((bytes([block["rawTx"][z]["vOut"][i]["nType"]]),
block["rawTx"][z]["vOut"][i]["addressHash"]))
# self.coins[o] = (pointer, block["rawTx"][z]["vOut"][i]["value"], address)
self.coins[o] = (pointer, block["rawTx"][z]["vOut"][i]["value"], address)
blocks[x] = block
if blocks:
blocks[x]["checkpoint"] = x
@ -268,12 +268,12 @@ class Worker:
for i in blocks[x]["rawTx"][y]["vOut"]:
try:
pointer = (x << 42) + (y << 21) + i
# r = self.destroyed_coins.delete(pointer)
# blocks[x]["rawTx"][y]["vOut"][i]["_s_"] = r
r = self.destroyed_coins.delete(pointer)
blocks[x]["rawTx"][y]["vOut"][i]["_s_"] = r
except: pass
blocks[x] = pickle.dumps(blocks[x])
self.log.critical("worker [%s]" % self.name)
self.pipe_sent_msg(b'result', pickle.dumps(blocks))
except:
self.pipe_sent_msg(b'result', pickle.dumps([]))