connector
This commit is contained in:
parent
59a01e1132
commit
673688a291
@ -14,7 +14,7 @@ import zmq.asyncio
|
|||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
import io
|
import io
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict, deque
|
||||||
from lru import LRU
|
from lru import LRU
|
||||||
|
|
||||||
class Connector:
|
class Connector:
|
||||||
@ -61,6 +61,7 @@ class Connector:
|
|||||||
self.app_block_height_on_start = int(last_block_height) if int(last_block_height) else 0
|
self.app_block_height_on_start = int(last_block_height) if int(last_block_height) else 0
|
||||||
self.last_block_height = 0
|
self.last_block_height = 0
|
||||||
self.last_block_utxo_cached_height = 0
|
self.last_block_utxo_cached_height = 0
|
||||||
|
self.checkpoints = deque()
|
||||||
self.deep_synchronization = False
|
self.deep_synchronization = False
|
||||||
|
|
||||||
self.block_dependency_tx = 0 # counter of tx that have dependencies in block
|
self.block_dependency_tx = 0 # counter of tx that have dependencies in block
|
||||||
|
|||||||
@ -167,6 +167,8 @@ 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:
|
||||||
|
self.parent.checkpoints.append(i)
|
||||||
|
|
||||||
|
|
||||||
# def disconnect(self,ip):
|
# def disconnect(self,ip):
|
||||||
@ -197,8 +199,8 @@ class Worker:
|
|||||||
self.loop.set_default_executor(ThreadPoolExecutor(20))
|
self.loop.set_default_executor(ThreadPoolExecutor(20))
|
||||||
self.out_writer = out_writer
|
self.out_writer = out_writer
|
||||||
self.in_reader = in_reader
|
self.in_reader = in_reader
|
||||||
self.coins = LRU(rpc_batch_limit * 10000)
|
self.coins = LRU(1000000)
|
||||||
self.destroyed_coins = LRU(rpc_batch_limit * 10000)
|
self.destroyed_coins = LRU(1000000)
|
||||||
signal.signal(signal.SIGTERM, self.terminate)
|
signal.signal(signal.SIGTERM, self.terminate)
|
||||||
self.loop.create_task(self.message_loop())
|
self.loop.create_task(self.message_loop())
|
||||||
self.loop.run_forever()
|
self.loop.run_forever()
|
||||||
@ -208,10 +210,11 @@ class Worker:
|
|||||||
t = 0
|
t = 0
|
||||||
batch = list()
|
batch = list()
|
||||||
h_list = list()
|
h_list = list()
|
||||||
|
rpc_batch_limit = 50
|
||||||
while True:
|
while True:
|
||||||
batch.append(["getblockhash", height])
|
batch.append(["getblockhash", height])
|
||||||
h_list.append(height)
|
h_list.append(height)
|
||||||
if len(batch) >= self.rpc_batch_limit:
|
if len(batch) >= rpc_batch_limit:
|
||||||
height += 1
|
height += 1
|
||||||
break
|
break
|
||||||
height += 1
|
height += 1
|
||||||
@ -261,6 +264,7 @@ class Worker:
|
|||||||
|
|
||||||
self.pipe_sent_msg(b'result', pickle.dumps(blocks))
|
self.pipe_sent_msg(b'result', pickle.dumps(blocks))
|
||||||
except:
|
except:
|
||||||
|
self.pipe_sent_msg(b'result', pickle.dumps([]))
|
||||||
self.log.critical(str(traceback.format_exc()))
|
self.log.critical(str(traceback.format_exc()))
|
||||||
|
|
||||||
async def message_loop(self):
|
async def message_loop(self):
|
||||||
|
|||||||
@ -177,6 +177,7 @@ def decode_script(script, asm=False):
|
|||||||
while l - s > 0:
|
while l - s > 0:
|
||||||
if script[s] < 0x4c and script[s]:
|
if script[s] < 0x4c and script[s]:
|
||||||
if asm:
|
if asm:
|
||||||
|
append("OP_PUSHBYTES[%s]" % script[s] )
|
||||||
append(script[s + 1:s + 1 + script[s]].hex())
|
append(script[s + 1:s + 1 + script[s]].hex())
|
||||||
else:
|
else:
|
||||||
append('[%s]' % script[s])
|
append('[%s]' % script[s])
|
||||||
@ -186,7 +187,8 @@ def decode_script(script, asm=False):
|
|||||||
if script[s] == OPCODE["OP_PUSHDATA1"]:
|
if script[s] == OPCODE["OP_PUSHDATA1"]:
|
||||||
if asm:
|
if asm:
|
||||||
ld = script[s + 1]
|
ld = script[s + 1]
|
||||||
append(script[s + 1:s + 1 + ld].hex())
|
append("OP_PUSHDATA1[%s]" % ld)
|
||||||
|
append(script[s + 2:s + 2 + ld].hex())
|
||||||
else:
|
else:
|
||||||
append(RAW_OPCODE[script[s]])
|
append(RAW_OPCODE[script[s]])
|
||||||
ld = script[s + 1]
|
ld = script[s + 1]
|
||||||
@ -194,8 +196,10 @@ def decode_script(script, asm=False):
|
|||||||
s += 1 + script[s + 1] + 1
|
s += 1 + script[s + 1] + 1
|
||||||
elif script[s] == OPCODE["OP_PUSHDATA2"]:
|
elif script[s] == OPCODE["OP_PUSHDATA2"]:
|
||||||
if asm:
|
if asm:
|
||||||
|
|
||||||
ld = unpack('<H', script[s + 1: s + 3])[0]
|
ld = unpack('<H', script[s + 1: s + 3])[0]
|
||||||
append(script[s + 1:s + 1 + ld].hex())
|
append("OP_PUSHDATA2[%s]" % ld)
|
||||||
|
append(script[s + 3:s + 3 + ld].hex())
|
||||||
else:
|
else:
|
||||||
ld = unpack('<H', script[s + 1: s + 3])[0]
|
ld = unpack('<H', script[s + 1: s + 3])[0]
|
||||||
append(RAW_OPCODE[script[s]])
|
append(RAW_OPCODE[script[s]])
|
||||||
@ -204,7 +208,8 @@ def decode_script(script, asm=False):
|
|||||||
elif script[s] == OPCODE["OP_PUSHDATA4"]:
|
elif script[s] == OPCODE["OP_PUSHDATA4"]:
|
||||||
if asm:
|
if asm:
|
||||||
ld = unpack('<L', script[s + 1: s + 5])[0]
|
ld = unpack('<L', script[s + 1: s + 5])[0]
|
||||||
append(script[s + 1:s + 1 + ld].hex())
|
append("OP_PUSHDATA4[%s]" % ld)
|
||||||
|
append(script[s + 5:s + 5 + ld].hex())
|
||||||
else:
|
else:
|
||||||
ld = unpack('<L', script[s + 1: s + 5])[0]
|
ld = unpack('<L', script[s + 1: s + 5])[0]
|
||||||
append(RAW_OPCODE[script[s]])
|
append(RAW_OPCODE[script[s]])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user