connector

This commit is contained in:
4tochka 2019-05-11 20:21:34 +04:00
parent 584550e765
commit c5bbe0f088
5 changed files with 16 additions and 16 deletions

View File

@ -7,6 +7,6 @@ from .block import *
from .address import * from .address import *
from .wallet import * from .wallet import *
from .crypto import * from .crypto import *
from lru import LRU from _lru import LRU
from pybtc.connector import Connector from pybtc.connector import Connector

View File

@ -250,11 +250,6 @@ lru_subscript(LRU *self, register PyObject *key)
return NULL; return NULL;
} }
assert(PyObject_TypeCheck(node, &NodeType));
/* We don't need to move the node when it's already self->first. */
self->hits++; self->hits++;
Py_INCREF(node->value); Py_INCREF(node->value);
Py_DECREF(node); Py_DECREF(node);
@ -562,6 +557,8 @@ static PyMethodDef LRU_methods[] = {
PyDoc_STR("L.peek_first_item() -> returns the MRU item (key,value) without changing key order")}, PyDoc_STR("L.peek_first_item() -> returns the MRU item (key,value) without changing key order")},
{"peek_last_item", (PyCFunction)LRU_peek_last_item, METH_NOARGS, {"peek_last_item", (PyCFunction)LRU_peek_last_item, METH_NOARGS,
PyDoc_STR("L.peek_last_item() -> returns the LRU item (key,value) without changing key order")}, PyDoc_STR("L.peek_last_item() -> returns the LRU item (key,value) without changing key order")},
{"pop", (PyCFunction)LRU_pop, METH_NOARGS,
PyDoc_STR("L.pop() -> returns the LRU item (key,value) without changing key order")},
{"update", (PyCFunction)LRU_update, METH_VARARGS | METH_KEYWORDS, {"update", (PyCFunction)LRU_update, METH_VARARGS | METH_KEYWORDS,
PyDoc_STR("L.update() -> update value for key in LRU")}, PyDoc_STR("L.update() -> update value for key in LRU")},
{"set_callback", (PyCFunction)LRU_set_callback, METH_VARARGS, {"set_callback", (PyCFunction)LRU_set_callback, METH_VARARGS,
@ -633,7 +630,7 @@ PyDoc_STRVAR(lru_doc,
static PyTypeObject LRUType = { static PyTypeObject LRUType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"lru.LRU", /* tp_name */ "_lru.LRU", /* tp_name */
sizeof(LRU), /* tp_basicsize */ sizeof(LRU), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
(destructor)LRU_dealloc, /* tp_dealloc */ (destructor)LRU_dealloc, /* tp_dealloc */
@ -675,7 +672,7 @@ static PyTypeObject LRUType = {
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = { static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"lru", /* m_name */ "_lru", /* m_name */
lru_doc, /* m_doc */ lru_doc, /* m_doc */
-1, /* m_size */ -1, /* m_size */
NULL, /* m_methods */ NULL, /* m_methods */
@ -702,7 +699,7 @@ moduleinit(void)
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef); m = PyModule_Create(&moduledef);
#else #else
m = Py_InitModule3("lru", NULL, lru_doc); m = Py_InitModule3("_lru", NULL, lru_doc);
#endif #endif
if (m == NULL) if (m == NULL)
@ -723,7 +720,7 @@ moduleinit(void)
} }
#else #else
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit_lru(void) PyInit__lru(void)
{ {
return moduleinit(); return moduleinit();
} }

View File

@ -178,7 +178,9 @@ class BlockLoader:
for i in blocks: for i in blocks:
self.parent.block_preload.set(i, blocks[i]) self.parent.block_preload.set(i, blocks[i])
if blocks: if blocks:
self.parent.checkpoints.append(i) last_tx = blocks[i]["tx"][len(blocks[i]["tx"]) - 1]
pointer = (i << 42) + ((len(blocks[i]["tx"]) - 1) << 21) + (en(last_tx["vOut"]) - 1)
self.parent.checkpoints.append(pointer)
# def disconnect(self,ip): # def disconnect(self,ip):

View File

@ -57,10 +57,10 @@ class UTXO():
self.destroyed_utxo += 1 self.destroyed_utxo += 1
pass pass
# if len(self.cached) > self._cache_hard_limit: if len(self.cached) > self._cache_hard_limit:
# await self.save_utxo() await self.save_utxo()
# elif len(self.cached) > self._cache_soft_limit and self.save_future.done(): elif len(self.cached) > self._cache_soft_limit and self.save_future.done():
# self.loop.create_task(self.save_utxo()) self.loop.create_task(self.save_utxo())
@ -73,6 +73,7 @@ class UTXO():
while True: while True:
c = len(self.cached) - self._cache_soft_limit - self.block_txo_max c = len(self.cached) - self._cache_soft_limit - self.block_txo_max
if c <= 0: break if c <= 0: break
self.log.critical("str>>>>")
try: try:
lb = 0 lb = 0
for key in iter(self.cached): for key in iter(self.cached):

View File

@ -148,7 +148,7 @@ setup(name='pybtc',
'bdist_wheel': bdist_wheel 'bdist_wheel': bdist_wheel
}, },
distclass=Distribution, distclass=Distribution,
ext_modules=[Extension("lru", ["pybtc/lru/lru.c"]), ext_modules=[Extension("_lru", ["pybtc/_lru/lru.c"]),
Extension("_secp256k1", ["pybtc/_secp256k1/module_secp256k1.c"], Extension("_secp256k1", ["pybtc/_secp256k1/module_secp256k1.c"],
include_dirs=["libsecp256k1/include/", "libsecp256k1/src/"]), include_dirs=["libsecp256k1/include/", "libsecp256k1/src/"]),
Extension("_crypto", Extension("_crypto",