Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
develop committed Aug 25, 2018
1 parent 7383e13 commit 988ce90
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ public Deposit newDepositChild() {
return deposit.newDepositChild();
}

@Override
public Deposit newDepositNext() {
return deposit.newDepositNext();
}

@Override
public void flush() {
deposit.flush();
Expand Down Expand Up @@ -199,16 +194,6 @@ public void setParent(Deposit deposit) {
this.deposit.setParent(deposit);
}

@Override
public void setPrevDeposit(Deposit deposit) {
this.deposit.setPrevDeposit(deposit);
}

@Override
public void setNextDeposit(Deposit deposit) {
this.deposit.setNextDeposit(deposit);
}

@Override
public TransactionCapsule getTransaction(byte[] trxHash) {
return this.deposit.getTransaction(trxHash);
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/org/tron/common/runtime/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,7 @@ public Program(byte[] codeHash, byte[] ops, ProgramInvoke programInvoke,

public ProgramPrecompile getProgramPrecompile() {
if (programPrecompile == null) {
/*
if (codeHash != null && commonConfig.precompileSource() != null) {
programPrecompile = commonConfig.precompileSource().get(codeHash);
}
*/
if (programPrecompile == null) {
programPrecompile = ProgramPrecompile.compile(ops);

/*
if (codeHash != null && commonConfig.precompileSource() != null) {
commonConfig.precompileSource().put(codeHash, programPrecompile);
}
*/
}

programPrecompile = ProgramPrecompile.compile(ops);
}
return programPrecompile;
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/tron/common/storage/Deposit.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ public interface Deposit {

Deposit newDepositChild();

Deposit newDepositNext();

void setParent(Deposit deposit);

void setPrevDeposit(Deposit deposit);

void setNextDeposit(Deposit deposit);

void flush();

void commit();
Expand Down
80 changes: 23 additions & 57 deletions src/main/java/org/tron/common/storage/DepositImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.tron.common.utils.StringUtil;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.BytesCapsule;
import org.tron.core.capsule.ContractCapsule;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.db.AccountStore;
Expand All @@ -31,10 +30,8 @@ public class DepositImpl implements Deposit {

private Manager dbManager;
private Deposit parent = null;
private Deposit prevDeposit = null;
private Deposit nextDeposit = null;

private HashMap<Key, Value> accounCache = new HashMap<>();
private HashMap<Key, Value> accountCache = new HashMap<>();
private HashMap<Key, Value> transactionCache = new HashMap<>();
private HashMap<Key, Value> blockCache = new HashMap<>();
private HashMap<Key, Value> witnessCache = new HashMap<>();
Expand All @@ -46,15 +43,13 @@ public class DepositImpl implements Deposit {
private HashMap<Key, Value> accountContractIndexCache = new HashMap<>();
private HashMap<Key, Storage> storageCache = new HashMap<>();

private DepositImpl(Manager dbManager, DepositImpl parent, DepositImpl prev) {
init(dbManager, parent, prev);
private DepositImpl(Manager dbManager, DepositImpl parent) {
init(dbManager, parent);
}

protected void init(Manager dbManager, DepositImpl parent, DepositImpl prev) {
protected void init(Manager dbManager, DepositImpl parent) {
this.dbManager = dbManager;
this.parent = parent;
prevDeposit = prev;
nextDeposit = null;
}

@Override
Expand Down Expand Up @@ -100,19 +95,14 @@ private AssetIssueStore getAssetIssueStore() {

@Override
public Deposit newDepositChild() {
return new DepositImpl(dbManager, this, null);
}

@Override
public Deposit newDepositNext() {
return nextDeposit = new DepositImpl(dbManager, null, this);
return new DepositImpl(dbManager, this);
}

@Override
public synchronized AccountCapsule createAccount(byte[] address, Protocol.AccountType type) {
Key key = new Key(address);
AccountCapsule account = new AccountCapsule(ByteString.copyFrom(address), type);
accounCache.put(key, new Value(account.getData(), Type.VALUE_TYPE_CREATE));
accountCache.put(key, new Value(account.getData(), Type.VALUE_TYPE_CREATE));
return account;
}

Expand All @@ -123,28 +113,26 @@ public AccountCapsule createAccount(byte[] address, String accountName, AccountT
ByteString.copyFromUtf8(accountName),
type);

accounCache.put(key, new Value(account.getData(), Type.VALUE_TYPE_CREATE));
accountCache.put(key, new Value(account.getData(), Type.VALUE_TYPE_CREATE));
return account;
}

@Override
public synchronized AccountCapsule getAccount(byte[] address) {
Key key = new Key(address);
if (accounCache.containsKey(key)) {
return accounCache.get(key).getAccount();
if (accountCache.containsKey(key)) {
return accountCache.get(key).getAccount();
}

AccountCapsule accountCapsule;
if (parent != null) {
accountCapsule = parent.getAccount(address);
} else if (prevDeposit != null) {
accountCapsule = prevDeposit.getAccount(address);
} else {
accountCapsule = getAccountStore().get(address);
}

if (accountCapsule != null) {
accounCache.put(key, Value.create(accountCapsule.getData()));
accountCache.put(key, Value.create(accountCapsule.getData()));
}
return accountCapsule;
}
Expand All @@ -166,8 +154,6 @@ public synchronized ContractCapsule getContract(byte[] address) {
ContractCapsule contractCapsule;
if (parent != null) {
contractCapsule = parent.getContract(address);
} else if (prevDeposit != null) {
contractCapsule = prevDeposit.getContract(address);
} else {
contractCapsule = getContractStore().get(address);
}
Expand All @@ -186,22 +172,20 @@ public synchronized void saveCode(byte[] codeHash, byte[] code) {
}

@Override
public synchronized byte[] getCode(byte[] codeHash) {
Key key = Key.create(codeHash);
public synchronized byte[] getCode(byte[] addr) {
Key key = Key.create(addr);
if (codeCache.containsKey(key)) {
return codeCache.get(key).getCode().getData();
}

byte[] code;
if (parent != null) {
code = parent.getCode(codeHash);
} else if (prevDeposit != null) {
code = prevDeposit.getCode(codeHash);
code = parent.getCode(addr);
} else {
if (null == getCodeStore().get(codeHash)) {
if (null == getCodeStore().get(addr)) {
code = null;
} else {
code = getCodeStore().get(codeHash).getData();
code = getCodeStore().get(addr).getData();
}
}
if (code != null) {
Expand All @@ -220,8 +204,6 @@ public synchronized Storage getStorage(byte[] address) {
Storage storage;
if (this.parent != null) {
storage = parent.getStorage(address);
} else if (prevDeposit != null) {
storage = prevDeposit.getStorage(address);
} else {
storage = new Storage(address, dbManager);
}
Expand Down Expand Up @@ -288,8 +270,8 @@ public synchronized long addBalance(byte[] address, long value) {
accountCapsule.setBalance(Math.addExact(balance, value));
Key key = Key.create(address);
Value V = Value.create(accountCapsule.getData(),
Type.VALUE_TYPE_DIRTY | accounCache.get(key).getType().getType());
accounCache.put(key, V);
Type.VALUE_TYPE_DIRTY | accountCache.get(key).getType().getType());
accountCache.put(key, V);
return accountCapsule.getBalance();
}

Expand All @@ -303,8 +285,6 @@ public TransactionCapsule getTransaction(byte[] trxHash) {
TransactionCapsule transactionCapsule;
if (parent != null) {
transactionCapsule = parent.getTransaction(trxHash);
} else if (prevDeposit != null) {
transactionCapsule = prevDeposit.getTransaction(trxHash);
} else {
try {
transactionCapsule = getTransactionStore().get(trxHash);
Expand All @@ -330,8 +310,6 @@ public BlockCapsule getBlock(byte[] blockHash) {
try {
if (parent != null) {
ret = parent.getBlock(blockHash);
} else if (prevDeposit != null) {
ret = prevDeposit.getBlock(blockHash);
} else {
ret = getBlockStore().get(blockHash);
}
Expand Down Expand Up @@ -366,7 +344,7 @@ public long getBeforeRunStorageSize() {

@Override
public void putAccount(Key key, Value value) {
accounCache.put(key, value);
accountCache.put(key, value);
}

@Override
Expand Down Expand Up @@ -410,7 +388,7 @@ public void putVotes(Key key, Value value) {
}

private void commitAccountCache(Deposit deposit) {
accounCache.forEach((key, value) -> {
accountCache.forEach((key, value) -> {
if (value.getType().isCreate() || value.getType().isDirty()) {
if (deposit != null) {
deposit.putAccount(key, value);
Expand Down Expand Up @@ -510,13 +488,13 @@ private void commitVoteCache(Deposit deposit) {
public void syncCacheFromAccountStore(byte[] address) {
Key key = Key.create(address);
int type;
if (null == accounCache.get(key)) {
if (null == accountCache.get(key)) {
type = Type.VALUE_TYPE_DIRTY;
} else {
type = Type.VALUE_TYPE_DIRTY | accounCache.get(key).getType().getType();
type = Type.VALUE_TYPE_DIRTY | accountCache.get(key).getType().getType();
}
Value V = Value.create(getAccountStore().get(address).getData(), type);
accounCache.put(key, V);
accountCache.put(key, V);
}

@Override
Expand All @@ -537,8 +515,6 @@ public synchronized void commit() {
Deposit deposit = null;
if (parent != null) {
deposit = parent;
} else if (prevDeposit != null) {
deposit = prevDeposit;
}

commitAccountCache(deposit);
Expand All @@ -562,17 +538,7 @@ public void setParent(Deposit deposit) {
parent = deposit;
}

@Override
public void setPrevDeposit(Deposit deposit) {
prevDeposit = deposit;
}

@Override
public void setNextDeposit(Deposit deposit) {
nextDeposit = deposit;
}

public static DepositImpl createRoot(Manager dbManager) {
return new DepositImpl(dbManager, null, null);
return new DepositImpl(dbManager, null);
}
}

0 comments on commit 988ce90

Please sign in to comment.