Skip to content

Commit

Permalink
Small refactor removing unused classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal committed Oct 20, 2024
1 parent 883f363 commit 3ce63a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 42 deletions.
33 changes: 10 additions & 23 deletions rskj-core/src/main/java/org/ethereum/db/MutableRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@
import co.rsk.crypto.Keccak256;
import co.rsk.db.MutableTrieCache;
import co.rsk.db.MutableTrieImpl;
import co.rsk.trie.*;
import co.rsk.trie.IterationElement;
import co.rsk.trie.MutableTrie;
import co.rsk.trie.Trie;
import co.rsk.trie.TrieKeySlice;
import co.rsk.trie.TrieStore;
import com.google.common.annotations.VisibleForTesting;
import org.ethereum.core.AccountState;
import org.ethereum.core.Repository;
import org.ethereum.crypto.HashUtil;
import org.ethereum.crypto.Keccak256Helper;
import org.ethereum.datasource.HashMapDB;
import org.ethereum.vm.DataWord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.util.*;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;

public class MutableRepository implements Repository, TransientStorageRepository {
public class MutableRepository implements Repository {
private static final Logger logger = LoggerFactory.getLogger("repository");
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
public static final Keccak256 KECCAK_256_OF_EMPTY_ARRAY = new Keccak256(Keccak256Helper.keccak256(EMPTY_BYTE_ARRAY));
Expand All @@ -49,7 +55,6 @@ public class MutableRepository implements Repository, TransientStorageRepository
private final TrieKeyMapper trieKeyMapper;
private final MutableTrie mutableTrie;
private final IReadWrittenKeysTracker tracker;
private Repository transientRepository;

public MutableRepository(TrieStore trieStore, Trie trie) {
this(new MutableTrieImpl(trieStore, trie));
Expand Down Expand Up @@ -408,22 +413,4 @@ private Optional<Keccak256> internalGetValueHash(byte[] key) {
tracker.addNewReadKey(new ByteArrayWrapper(key));
return mutableTrie.getValueHash(key);
}

@Override
public Repository getTransientRepository() {
if(transientRepository == null) {
transientRepository = getMutableRepository();
}

return transientRepository;
}

@Override
public synchronized void clearTransientRepository() {
transientRepository = getMutableRepository();
}

private static MutableRepository getMutableRepository() {
return new MutableRepository(new MutableTrieImpl(new TrieStoreImpl(new HashMapDB()), new Trie()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

package org.ethereum.db;

import co.rsk.db.MutableTrieImpl;
import co.rsk.trie.Trie;
import co.rsk.trie.TrieStoreImpl;
import org.ethereum.core.Repository;
import org.ethereum.datasource.HashMapDB;

public interface TransientStorageRepository {
/**
* Returns the transientRepository initializing a new one if the current one is null
*/
Repository getTransientRepository();
public class TransientStorageRepositoryCreator {

/**
* Delete all the data for this repository
*/
void clearTransientRepository();
private TransientStorageRepositoryCreator() {
}

public static Repository createNewTransientStorage() {
return new MutableRepository(new MutableTrieImpl(new TrieStoreImpl(new HashMapDB()), new Trie()));
}
}
17 changes: 7 additions & 10 deletions rskj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import co.rsk.rpc.modules.trace.CallType;
import co.rsk.rpc.modules.trace.CreationData;
import co.rsk.rpc.modules.trace.ProgramSubtrace;
import co.rsk.trie.Trie;
import co.rsk.trie.TrieStoreImpl;
import co.rsk.vm.BitSet;
import com.google.common.annotations.VisibleForTesting;
import org.ethereum.config.Constants;
Expand All @@ -42,8 +40,7 @@
import org.ethereum.core.SignatureCache;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.HashUtil;
import org.ethereum.datasource.HashMapDB;
import org.ethereum.db.MutableRepository;
import org.ethereum.db.TransientStorageRepositoryCreator;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.FastByteComparisons;
import org.ethereum.vm.DataWord;
Expand Down Expand Up @@ -120,7 +117,7 @@ public class Program {
private final Stack stack;
private final Memory memory;
private final Storage storage;
private final Map<RskAddress, MutableRepository> transientStorages;
private final Map<RskAddress, Repository> transientStorages;
private byte[] returnDataBuffer;

private final ProgramResult result = new ProgramResult();
Expand Down Expand Up @@ -460,10 +457,10 @@ public Repository getStorage() {
return this.storage;
}

public MutableRepository getTransientStorage(RskAddress addr) {
MutableRepository current = transientStorages.get(addr);
public Repository getTransientStorage(RskAddress addr) {
Repository current = transientStorages.get(addr);
if(current == null) {
current = new MutableRepository(new TrieStoreImpl(new HashMapDB()), new Trie());
current = TransientStorageRepositoryCreator.createNewTransientStorage();
transientStorages.put(addr, current);
}
return current;
Expand Down Expand Up @@ -1004,7 +1001,7 @@ private void storageSave(byte[] key, byte[] val) {

public void transientStorageSave(DataWord key, DataWord value) {
RskAddress addr = getOwnerRskAddress();
MutableRepository storage = getTransientStorage(addr);
Repository storage = getTransientStorage(addr);
storage.addStorageRow(addr, key, value);
}

Expand Down Expand Up @@ -1120,7 +1117,7 @@ public DataWord storageLoad(DataWord key) {

public DataWord transientStorageLoad(DataWord key) {
RskAddress addr = getOwnerRskAddress();
MutableRepository currentTransientStorage = getTransientStorage(addr);
Repository currentTransientStorage = getTransientStorage(addr);

return currentTransientStorage.getStorageValue(addr, key);
}
Expand Down

0 comments on commit 3ce63a0

Please sign in to comment.