Search in sources :

Example 26 with KeyValueDataSource

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;
        }
    }
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) ByteUtil.toHexString(org.ethereum.util.ByteUtil.toHexString)

Aggregations

KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)26 HashMapDB (org.ethereum.datasource.HashMapDB)13 Test (org.junit.Test)13 LevelDbDataSource (org.ethereum.datasource.LevelDbDataSource)10 BlockDifficulty (co.rsk.core.BlockDifficulty)6 Block (org.ethereum.core.Block)6 DB (org.mapdb.DB)6 BigInteger (java.math.BigInteger)5 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 Bean (org.springframework.context.annotation.Bean)4 RskAddress (co.rsk.core.RskAddress)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)3 EthereumListener (org.ethereum.listener.EthereumListener)3 AdminInfo (org.ethereum.manager.AdminInfo)3 RskSystemProperties (co.rsk.config.RskSystemProperties)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2