get block from db bugfixes
This commit is contained in:
@@ -202,8 +202,8 @@ async def main():
|
|||||||
await tx.wait()
|
await tx.wait()
|
||||||
last_prices[pool] = price
|
last_prices[pool] = price
|
||||||
log.debug(f'Mirrored {pool} {price}')
|
log.debug(f'Mirrored {pool} {price}')
|
||||||
except Exception:
|
except Exception as x:
|
||||||
log.debug(f'Could not update {pool}')
|
log.debug(f'Could not update {pool}: {x}')
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
pool = next(pool_iter)
|
pool = next(pool_iter)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ async def _fetch(fetch: FetchLock, chain_id: int, block_id: Union[int,bytes]) ->
|
|||||||
blocks = [b for b in blocks if b.confirmed]
|
blocks = [b for b in blocks if b.confirmed]
|
||||||
found = blocks[0] if len(blocks) == 1 else None
|
found = blocks[0] if len(blocks) == 1 else None
|
||||||
else:
|
else:
|
||||||
found = db.session.get(DbBlock, (chain, block_id)) # by-hash is the primary key
|
found = db.session.get(DbBlock, dict(chain=chain, hash=block_id)) # by-hash is the primary key
|
||||||
if found:
|
if found:
|
||||||
return Block(chain_id, found.data)
|
return Block(chain_id, found.data)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from .. import db, DELETE
|
|||||||
from ..base.chain import current_chain
|
from ..base.chain import current_chain
|
||||||
from ..blocks import get_block
|
from ..blocks import get_block
|
||||||
from ..database.model import SeriesSet, SeriesDict
|
from ..database.model import SeriesSet, SeriesDict
|
||||||
from ..util import hexstr
|
from ..util import hexbytes
|
||||||
from ..util.shutdown import fatal
|
from ..util.shutdown import fatal
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -72,17 +72,18 @@ class DbState(SeriesCollection):
|
|||||||
async def load(self) -> Optional[BlockState]:
|
async def load(self) -> Optional[BlockState]:
|
||||||
chain_id = current_chain.get().id
|
chain_id = current_chain.get().id
|
||||||
try:
|
try:
|
||||||
height, hash = db.kv[f'root_block|{chain_id}']
|
height, hash_str = db.kv[f'root_block|{chain_id}']
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
return None
|
return None
|
||||||
# log.debug(f'getting state for hash {hash}')
|
# log.debug(f'getting state for hash {hash}')
|
||||||
root_block = await get_block(hash)
|
blockhash = hexbytes(hash_str)
|
||||||
|
root_block = await get_block(blockhash)
|
||||||
if root_block is None:
|
if root_block is None:
|
||||||
log.debug(f'couldn\'t find root block by hash. trying number {height}.')
|
log.debug(f'couldn\'t find root block by hash. trying number {height}.')
|
||||||
root_block = await get_block(height)
|
root_block = await get_block(height)
|
||||||
if root_block is None:
|
if root_block is None:
|
||||||
fatal(f'Could not get root block {height} {hash} from RPC')
|
fatal(f'Could not get root block {height} {hash_str} from RPC')
|
||||||
assert hexstr(root_block.hash) == hash
|
assert root_block.hash == blockhash
|
||||||
assert root_block.height == height
|
assert root_block.height == height
|
||||||
state = BlockState()
|
state = BlockState()
|
||||||
root_fork = state.init_root_block(root_block)
|
root_fork = state.init_root_block(root_block)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class Db:
|
|||||||
kwargs.setdefault('expire_on_commit', False)
|
kwargs.setdefault('expire_on_commit', False)
|
||||||
s = Session(engine, **kwargs)
|
s = Session(engine, **kwargs)
|
||||||
_session.set(s)
|
_session.set(s)
|
||||||
|
log.debug('created new DB session')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -190,6 +190,8 @@ class BlockStateRunner(BlockProgressor):
|
|||||||
# do not query into the reorgable area. only query finalized data.
|
# do not query into the reorgable area. only query finalized data.
|
||||||
height = min( start + chain.batch_size, block.height - chain.confirms)
|
height = min( start + chain.batch_size, block.height - chain.confirms)
|
||||||
end_block = await get_block(height)
|
end_block = await get_block(height)
|
||||||
|
if end_block is None:
|
||||||
|
raise ValueError(f'Could not get block with height {block.height}')
|
||||||
branch = Branch(height, start, path=[end_block.hash]) # no parent
|
branch = Branch(height, start, path=[end_block.hash]) # no parent
|
||||||
return self.state.add_branch(branch)
|
return self.state.add_branch(branch)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user