Skip to content

Commit

Permalink
Merge branch 'tronprotocol:develop' into feature/improve_test_coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lxcmyf committed Sep 4, 2023
2 parents edb3620 + d6ff733 commit b80f53e
Show file tree
Hide file tree
Showing 11 changed files with 1,202 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class AbstractSnapshot<K, V> implements Snapshot {

protected WeakReference<Snapshot> next;

protected boolean isOptimized;

@Override
public Snapshot advance() {
return new SnapshotImpl(this);
Expand All @@ -34,4 +36,9 @@ public void setNext(Snapshot next) {
public String getDbName() {
return db.getDbName();
}

@Override
public boolean isOptimized(){
return isOptimized;
}
}
4 changes: 4 additions & 0 deletions chainbase/src/main/java/org/tron/core/db2/core/Snapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ static boolean isImpl(Snapshot snapshot) {
void updateSolidity();

String getDbName();

boolean isOptimized();

void reloadToMem();
}
23 changes: 23 additions & 0 deletions chainbase/src/main/java/org/tron/core/db2/core/SnapshotImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class SnapshotImpl extends AbstractSnapshot<Key, Value> {
}
previous = snapshot;
snapshot.setNext(this);
isOptimized = snapshot.isOptimized();
if (isOptimized && root == previous) {
Streams.stream(root.iterator()).forEach( e -> put(e.getKey(),e.getValue()));
}
}

@Override
Expand All @@ -40,6 +44,7 @@ public byte[] get(byte[] key) {
private byte[] get(Snapshot head, byte[] key) {
Snapshot snapshot = head;
Value value;

while (Snapshot.isImpl(snapshot)) {
if ((value = ((SnapshotImpl) snapshot).db.get(Key.of(key))) != null) {
return value.getBytes();
Expand Down Expand Up @@ -83,6 +88,19 @@ public void merge(Snapshot from) {
Streams.stream(fromImpl.db).forEach(e -> db.put(e.getKey(), e.getValue()));
}

public void mergeAhead(Snapshot from) {
if (from instanceof SnapshotRoot) {
return ;
}
SnapshotImpl fromImpl = (SnapshotImpl) from;
Streams.stream(fromImpl.db).forEach(e -> {
if (db.get(e.getKey()) == null) {
db.put(e.getKey(), e.getValue());
}
}
);
}

@Override
public Snapshot retreat() {
return previous;
Expand Down Expand Up @@ -177,4 +195,9 @@ public String getDbName() {
public Snapshot newInstance() {
return new SnapshotImpl(this);
}

@Override
public void reloadToMem() {
mergeAhead(previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ public synchronized void commit() {
}

--activeSession;

dbs.forEach(db -> {
if (db.getHead().isOptimized()) {
db.getHead().reloadToMem();
}
});
}

public synchronized void pop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public SnapshotRoot(DB<byte[], byte[]> db) {
if (CACHE_DBS.contains(this.db.getDbName())) {
this.cache = CacheManager.allocate(CacheType.findByType(this.db.getDbName()));
}
isOptimized = "properties".equalsIgnoreCase(db.getDbName());
}

private boolean needOptAsset() {
Expand Down Expand Up @@ -221,4 +222,7 @@ public String getDbName() {
public Snapshot newInstance() {
return new SnapshotRoot(db.newInstance());
}

@Override
public void reloadToMem() { }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.tron.common.logsfilter.trigger;

import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -91,6 +93,10 @@ public class TransactionLogTrigger extends Trigger {
@Setter
private long energyUnitPrice;

@Getter
@Setter
private Map<String, Long> extMap;

public TransactionLogTrigger() {
setTriggerName(Trigger.TRANSACTION_TRIGGER_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.common.logsfilter.capsule;

import static org.tron.protos.Protocol.Transaction.Contract.ContractType.CreateSmartContract;
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;

import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
Expand All @@ -26,7 +27,14 @@
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.TransactionInfo;
import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
import org.tron.protos.contract.BalanceContract.CancelAllUnfreezeV2Contract;
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;
import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract;
import org.tron.protos.contract.BalanceContract.TransferContract;
import org.tron.protos.contract.BalanceContract.UnDelegateResourceContract;
import org.tron.protos.contract.BalanceContract.UnfreezeBalanceContract;
import org.tron.protos.contract.BalanceContract.UnfreezeBalanceV2Contract;
import org.tron.protos.contract.BalanceContract.WithdrawExpireUnfreezeContract;
import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;

Expand Down Expand Up @@ -156,6 +164,82 @@ public TransactionLogTriggerCapsule(TransactionCapsule trxCapsule, BlockCapsule
StringUtil.encode58Check(createSmartContract.getOwnerAddress().toByteArray()));
}
break;
case UnfreezeBalanceContract:
UnfreezeBalanceContract unfreezeBalanceContract = contractParameter
.unpack(UnfreezeBalanceContract.class);

transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(unfreezeBalanceContract.getOwnerAddress().toByteArray()));
if (!ByteString.EMPTY.equals(unfreezeBalanceContract.getReceiverAddress())) {
transactionLogTrigger.setToAddress(StringUtil
.encode58Check(unfreezeBalanceContract.getReceiverAddress().toByteArray()));
}
transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setAssetAmount(
transactionInfo.getUnfreezeAmount());
break;
case FreezeBalanceV2Contract:
FreezeBalanceV2Contract freezeBalanceV2Contract = contractParameter
.unpack(FreezeBalanceV2Contract.class);

transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(freezeBalanceV2Contract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setAssetAmount(freezeBalanceV2Contract.getFrozenBalance());
break;
case UnfreezeBalanceV2Contract:
UnfreezeBalanceV2Contract unfreezeBalanceV2Contract = contractParameter
.unpack(UnfreezeBalanceV2Contract.class);

transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(unfreezeBalanceV2Contract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setAssetAmount(
unfreezeBalanceV2Contract.getUnfreezeBalance());
break;
case WithdrawExpireUnfreezeContract:
WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract = contractParameter
.unpack(WithdrawExpireUnfreezeContract.class);

transactionLogTrigger.setFromAddress(StringUtil.encode58Check(
withdrawExpireUnfreezeContract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setAssetAmount(transactionInfo.getWithdrawExpireAmount());
break;
case DelegateResourceContract:
DelegateResourceContract delegateResourceContract = contractParameter
.unpack(DelegateResourceContract.class);

transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(delegateResourceContract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setToAddress(StringUtil
.encode58Check(delegateResourceContract.getReceiverAddress().toByteArray()));
transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setAssetAmount(
delegateResourceContract.getBalance());
break;
case UnDelegateResourceContract:
UnDelegateResourceContract unDelegateResourceContract = contractParameter
.unpack(UnDelegateResourceContract.class);

transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(unDelegateResourceContract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setToAddress(StringUtil.encode58Check(
unDelegateResourceContract.getReceiverAddress().toByteArray()));

transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setAssetAmount(
unDelegateResourceContract.getBalance());
break;
case CancelAllUnfreezeV2Contract:
CancelAllUnfreezeV2Contract cancelAllUnfreezeV2Contract = contractParameter
.unpack(CancelAllUnfreezeV2Contract.class);

transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(cancelAllUnfreezeV2Contract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setAssetName("trx");
transactionLogTrigger.setExtMap(transactionInfo.getCancelUnfreezeV2AmountMap());
break;
default:
break;
}
Expand Down Expand Up @@ -269,4 +353,5 @@ private List<InternalTransactionPojo> getInternalTransactionList(
public void processTrigger() {
EventPluginLoader.getInstance().postTransactionTrigger(transactionLogTrigger);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,7 @@ private void callContract(TriggerSmartContract request,
}
}

@Override
public void getPaginatedAssetIssueList(PaginatedMessage request,
StreamObserver<AssetIssueList> responseObserver) {
responseObserver.onNext(wallet.getAssetIssueList(request.getOffset(), request.getLimit()));
Expand Down
Loading

0 comments on commit b80f53e

Please sign in to comment.