use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionRepositoryImpl method loadAccountState.
/**
* @implNote The loaded objects are fresh copies of the original account
* state and contract details.
*/
@Override
public synchronized void loadAccountState(Address address, Map<Address, AccountState> cacheAccounts, Map<Address, IContractDetails<DataWord>> cacheDetails) {
AccountState account = getAccountState(address);
IContractDetails<DataWord> details = getContractDetails(address);
account = (account == null) ? new AccountState() : new AccountState(account);
details = new ContractDetailsCacheImpl(details);
// details.setAddress(addr);
cacheAccounts.put(address, account);
cacheDetails.put(address, details);
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionRepositoryImpl method getContractDetails.
@Override
public synchronized IContractDetails<DataWord> getContractDetails(Address address) {
rwLock.readLock().lock();
try {
// That part is important cause if we have
// to sync details storage according the trie root
// saved in the account
AccountState accountState = getAccountState(address);
byte[] storageRoot = EMPTY_TRIE_HASH;
if (accountState != null) {
storageRoot = getAccountState(address).getStateRoot();
}
IContractDetails<DataWord> details = detailsDS.get(address.toBytes());
if (details != null) {
details = details.getSnapshotTo(storageRoot);
}
return details;
} finally {
rwLock.readLock().unlock();
}
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionContractDetailsImpl method get.
@Override
public DataWord get(DataWord key) {
DataWord result = DataWord.ZERO;
byte[] data = storageTrie.get(key.getData());
if (data.length > 0) {
byte[] dataDecoded = RLP.decode2(data).get(0).getRLPData();
result = new DataWord(dataDecoded);
}
return result;
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionRepositoryCache method flush.
/**
* @implNote To maintain intended functionality this method does not call
* the parent's {@code flush()} method. The changes are propagated
* to the parent through calling the parent's
* {@code updateBatch()} method.
*/
@Override
public synchronized void flush() {
// determine which accounts should get stored
HashMap<Address, AccountState> cleanedCacheAccounts = new HashMap<>();
for (Map.Entry<Address, 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<Address, IContractDetails<DataWord>> entry : cachedDetails.entrySet()) {
IContractDetails<DataWord> ctd = entry.getValue();
// different ContractDetails implementation
if (ctd != null && ctd instanceof ContractDetailsCacheImpl) {
ContractDetailsCacheImpl contractDetailsCache = (ContractDetailsCacheImpl) ctd;
contractDetailsCache.commit();
if (contractDetailsCache.origContract == null && repository.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 = repository.getContractDetails(entry.getKey());
contractDetailsCache.commit();
}
}
}
repository.updateBatch(cleanedCacheAccounts, cachedDetails);
cachedAccounts.clear();
cachedDetails.clear();
}
Aggregations