use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.
the class ContractDetailsImpl method syncStorage.
@Override
public synchronized void syncStorage() {
String hashString = this.getStorageHashAsString();
String addressString = this.getAddressAsString();
logger.trace("syncing storage address {}", addressString);
if (this.trie.hasStore()) {
logger.trace("syncing to storage, hash {}, address {}, storage size {}", hashString, addressString, this.getStorageSize());
this.trie.save();
if (this.externalStorage && !this.originalExternalStorage) {
// switching to data source
logger.trace("switching to data source, hash {}, address {}", hashString, addressString);
KeyValueDataSource ds = levelDbByName(config, this.getDataSourceName());
TrieStoreImpl newStore = new TrieStoreImpl(ds);
TrieStoreImpl originalStore = (TrieStoreImpl) ((TrieImpl) this.trie).getStore();
newStore.copyFrom(originalStore);
Trie newTrie = newStore.retrieve(this.trie.getHash().getBytes());
this.trie = newTrie;
if (newTrie == null) {
logger.error("error switching to data source, hash {}, address {}", hashString, addressString);
String message = "error switching to data source, hash " + hashString + ", address " + addressString;
panicProcessor.panic("newcontractdetails", message);
throw new TrieSerializationException(message, null);
}
// to avoid re switching to data source
this.originalExternalStorage = true;
}
if (this.externalStorage) {
logger.trace("closing contract details data source, hash {}, address {}", hashString, addressString);
DataSourcePool.closeDataSource(getDataSourceName());
this.closed = true;
}
}
}
Aggregations