Optimization: keep the database in RAM, except when indexing. Be sure to invalidate

when finished indexing.  The only thing clients will pull from the db is
the current consensus hash.
This commit is contained in:
Jude Nelson
2016-06-21 01:48:28 -04:00
parent 0b79d37e5a
commit 4e3a66e2eb
3 changed files with 25 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ from ConfigParser import SafeConfigParser
import pybitcoin
from lib import nameset as blockstack_state_engine
from lib import get_db_state
from lib import get_db_state, invalidate_db_state
from lib.config import REINDEX_FREQUENCY, DEFAULT_DUST_FEE
from lib import *
from lib.storage import *
@@ -319,7 +319,7 @@ class BlockstackdRPC(SimpleXMLRPCServer):
def rpc_get_name_blockchain_record(self, name):
"""
Lookup the blockchain-derived profile for a name.
Lookup the blockchain-derived whois info for a name.
"""
db = get_state_engine()
@@ -331,6 +331,9 @@ class BlockstackdRPC(SimpleXMLRPCServer):
name_record = db.get_name(str(name))
namespace_id = get_namespace_from_name(name)
namespace_record = db.get_namespace(namespace_id)
if name_record is None:
if is_indexing():
return {"error": "Indexing blockchain"}
@@ -338,8 +341,14 @@ class BlockstackdRPC(SimpleXMLRPCServer):
return {"error": "Not found."}
else:
# when does this name expire (if it expires)?
if namespace_record['lifetime'] != NAMESPACE_LIFE_INFINITE:
name_record['expire_block'] = namespace_record['lifetime'] + name_record['last_renewed']
return name_record
def rpc_get_name_blockchain_history( self, name, start_block, end_block ):
"""
Get the sequence of name operations processed for a given name.
@@ -961,11 +970,14 @@ def index_blockchain():
# bring us up to speed
log.debug("Begin indexing (up to %s)" % current_block)
set_indexing( True )
db = virtualchain_hooks.get_db_state()
db = get_state_engine()
virtualchain.sync_virtualchain( bt_opts, current_block, db )
set_indexing( False )
log.debug("End indexing (up to %s)" % current_block)
# invalidate in-RAM copy, so we re-load it on next get_state_engine()
invalidate_db_state()
def blockstack_exit():
"""