Search in sources :

Example 1 with ContractDetail

use of org.aion.base.db.ContractDetail in project aion by aionnetwork.

the class AionRepositoryCache method flushTo.

@Override
public void flushTo(Repository other, boolean clearStateAfterFlush) {
    lock.lock();
    try {
        // determine which accounts should get stored
        HashMap<AionAddress, AccountState> cleanedCacheAccounts = new HashMap<>();
        for (Map.Entry<AionAddress, AccountState> entry : cachedAccounts.entrySet()) {
            AccountState account = entry.getValue();
            if (account != null && account.isDirty() && account.isEmpty()) {
                // ignore contract state for empty accounts at storage
                cachedDetails.remove(entry.getKey());
            } else {
                cleanedCacheAccounts.put(entry.getKey(), entry.getValue());
            }
        }
        // determine which contracts should get stored
        for (Map.Entry<AionAddress, ContractDetail> entry : cachedDetails.entrySet()) {
            InnerContractDetails contractDetailsCache = (InnerContractDetails) entry.getValue();
            contractDetailsCache.commit();
            if (contractDetailsCache.origContract == null && other.hasContractDetails(entry.getKey())) {
                // in forked block the contract account might not exist thus it is created without origin,
                // but on the main chain details can contain data which should be merged into a single storage trie
                // so both branches with different stateRoots are valid
                contractDetailsCache.origContract = (ContractDetails) other.getContractDetails(entry.getKey());
                contractDetailsCache.commit();
            }
        }
        other.updateBatch(cleanedCacheAccounts, cachedDetails, cachedTransformedCode);
        if (clearStateAfterFlush) {
            cachedAccounts.clear();
            cachedDetails.clear();
            cachedTransformedCode.clear();
        }
    } finally {
        lock.unlock();
    }
}
Also used : AionAddress(org.aion.types.AionAddress) HashMap(java.util.HashMap) ContractDetail(org.aion.base.db.ContractDetail) AccountState(org.aion.base.AccountState) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 AccountState (org.aion.base.AccountState)1 ContractDetail (org.aion.base.db.ContractDetail)1 AionAddress (org.aion.types.AionAddress)1