Skip to content

Commit

Permalink
DetailsDataStore directly returns AionContractDetailsImpl snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraRoatis committed Jan 28, 2020
1 parent 2880284 commit 0608efe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
18 changes: 5 additions & 13 deletions modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,18 +473,16 @@ private void updateAccountState(AionAddress address, AccountState accountState)

/**
* @inheritDoc
* @implNote Any other method calling this can rely on the fact that the contract details
* returned is a newly created object by {@link AionContractDetailsImpl#getSnapshotTo(byte[],
* InternalVmType)}. Since this querying method it locked, the methods calling it <b>may not
* need to be locked or synchronized</b>, depending on the specific use case.
* @implNote Methods calling this can rely on the fact that the contract details returned is a
* newly created snapshot object. Since this method it locked, the methods using the
* returned object <b>do not need to be locked or synchronized</b>, depending on the
* specific use case.
*/
@Override
public AionContractDetailsImpl getContractDetails(AionAddress address) {
rwLock.readLock().lock();

try {
AionContractDetailsImpl details;

// That part is important cause if we have
// to sync details storage according the trie root
// saved in the account
Expand All @@ -497,13 +495,7 @@ public AionContractDetailsImpl getContractDetails(AionAddress address) {
}

InternalVmType vm = getVMUsed(address, codeHash);
details = detailsDS.get(vm, address.toByteArray());

if (details != null) {
details = details.getSnapshotTo(storageRoot, vm);
}

return details;
return detailsDS.getSnapshot(vm, address.toByteArray(), storageRoot);
} finally {
rwLock.readLock().unlock();
}
Expand Down
27 changes: 12 additions & 15 deletions modAionImpl/src/org/aion/zero/impl/db/DetailsDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,25 @@ public DetailsDataStore(
}

/**
* Fetches the ContractDetails from the cache, and if it doesn't exist, add to the remove set.
* Fetches the ContractDetails with the given root.
*
* @param key the contract address as bytes
* @param vm the virtual machine used at contract deployment
* @return
* @param key the contract address as bytes
* @param storageRoot the requested storage root
* @return a snapshot of the contract details with the requested root
*/
public synchronized AionContractDetailsImpl get(InternalVmType vm, byte[] key) {

public synchronized AionContractDetailsImpl getSnapshot(InternalVmType vm, byte[] key, byte[] storageRoot) {
Optional<byte[]> rawDetails = detailsSrc.get(key);

// If it doesn't exist in cache or database.
if (!rawDetails.isPresent()) {
if (rawDetails.isPresent()) {
// decode raw details and return snapshot
AionContractDetailsImpl detailsImpl = new AionContractDetailsImpl(storageDSPrune, graphSrc);
detailsImpl.setVmType(vm);
detailsImpl.decode(rawDetails.get());
return detailsImpl.getSnapshotTo(storageRoot, vm);
} else {
return null;
}

// Found something from cache or database, return it by decoding it.
AionContractDetailsImpl detailsImpl = new AionContractDetailsImpl(storageDSPrune, graphSrc);
detailsImpl.setVmType(vm);
detailsImpl.decode(rawDetails.get()); // We can safely get as we checked
// if it is present.

return detailsImpl;
}

/** Determine if the contract exists in the database. */
Expand Down

0 comments on commit 0608efe

Please sign in to comment.