From c5bbe0f0880c9fa506cf55c517fca1828ce45487 Mon Sep 17 00:00:00 2001 From: 4tochka Date: Sat, 11 May 2019 20:21:34 +0400 Subject: [PATCH] connector --- pybtc/__init__.py | 2 +- pybtc/{lru => _lru}/lru.c | 15 ++++++--------- pybtc/connector/block_loader.py | 4 +++- pybtc/connector/utxo.py | 9 +++++---- setup.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) rename pybtc/{lru => _lru}/lru.c (98%) diff --git a/pybtc/__init__.py b/pybtc/__init__.py index f6b92a8..d674359 100644 --- a/pybtc/__init__.py +++ b/pybtc/__init__.py @@ -7,6 +7,6 @@ from .block import * from .address import * from .wallet import * from .crypto import * -from lru import LRU +from _lru import LRU from pybtc.connector import Connector diff --git a/pybtc/lru/lru.c b/pybtc/_lru/lru.c similarity index 98% rename from pybtc/lru/lru.c rename to pybtc/_lru/lru.c index f2bc7e1..15cb2c9 100644 --- a/pybtc/lru/lru.c +++ b/pybtc/_lru/lru.c @@ -250,11 +250,6 @@ lru_subscript(LRU *self, register PyObject *key) return NULL; } - assert(PyObject_TypeCheck(node, &NodeType)); - - /* We don't need to move the node when it's already self->first. */ - - self->hits++; Py_INCREF(node->value); 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")}, {"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")}, + {"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, PyDoc_STR("L.update() -> update value for key in LRU")}, {"set_callback", (PyCFunction)LRU_set_callback, METH_VARARGS, @@ -633,7 +630,7 @@ PyDoc_STRVAR(lru_doc, static PyTypeObject LRUType = { PyVarObject_HEAD_INIT(NULL, 0) - "lru.LRU", /* tp_name */ + "_lru.LRU", /* tp_name */ sizeof(LRU), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)LRU_dealloc, /* tp_dealloc */ @@ -675,7 +672,7 @@ static PyTypeObject LRUType = { #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, - "lru", /* m_name */ + "_lru", /* m_name */ lru_doc, /* m_doc */ -1, /* m_size */ NULL, /* m_methods */ @@ -702,7 +699,7 @@ moduleinit(void) #if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&moduledef); #else - m = Py_InitModule3("lru", NULL, lru_doc); + m = Py_InitModule3("_lru", NULL, lru_doc); #endif if (m == NULL) @@ -723,7 +720,7 @@ moduleinit(void) } #else PyMODINIT_FUNC - PyInit_lru(void) + PyInit__lru(void) { return moduleinit(); } diff --git a/pybtc/connector/block_loader.py b/pybtc/connector/block_loader.py index aa86076..a526a66 100644 --- a/pybtc/connector/block_loader.py +++ b/pybtc/connector/block_loader.py @@ -178,7 +178,9 @@ class BlockLoader: for i in blocks: self.parent.block_preload.set(i, blocks[i]) 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): diff --git a/pybtc/connector/utxo.py b/pybtc/connector/utxo.py index 560e750..19032d5 100644 --- a/pybtc/connector/utxo.py +++ b/pybtc/connector/utxo.py @@ -57,10 +57,10 @@ class UTXO(): self.destroyed_utxo += 1 pass - # if len(self.cached) > self._cache_hard_limit: - # await self.save_utxo() - # elif len(self.cached) > self._cache_soft_limit and self.save_future.done(): - # self.loop.create_task(self.save_utxo()) + if len(self.cached) > self._cache_hard_limit: + await self.save_utxo() + elif len(self.cached) > self._cache_soft_limit and self.save_future.done(): + self.loop.create_task(self.save_utxo()) @@ -73,6 +73,7 @@ class UTXO(): while True: c = len(self.cached) - self._cache_soft_limit - self.block_txo_max if c <= 0: break + self.log.critical("str>>>>") try: lb = 0 for key in iter(self.cached): diff --git a/setup.py b/setup.py index dce07aa..3977a68 100644 --- a/setup.py +++ b/setup.py @@ -148,7 +148,7 @@ setup(name='pybtc', 'bdist_wheel': bdist_wheel }, 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"], include_dirs=["libsecp256k1/include/", "libsecp256k1/src/"]), Extension("_crypto",