Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge master to develop #5771

Merged
merged 57 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d518512
feat(LiteFullNode): remove LiteFullNodeTool
forfreeday Jan 2, 2024
c109b22
feat(LiteFullNode): fix deleting titles
forfreeday Jan 4, 2024
9fedb87
Merge branch 'feature/remove_lite_fullnode' into feature/add_testcase
forfreeday Jan 5, 2024
62d780d
test(case): add test case
forfreeday Jan 5, 2024
ae1865e
test(case): fix import order
forfreeday Jan 5, 2024
f04616a
test(case): add case
forfreeday Jan 6, 2024
8107586
test(case): add ZKProofStoreTest case
forfreeday Jan 7, 2024
8721f80
test(case): add servlet case
forfreeday Jan 8, 2024
05e3f55
test(case): add some cases
forfreeday Jan 9, 2024
bc701de
test(case): add db test cases
forfreeday Jan 10, 2024
d910713
feat(api):fix a concurrency issue for toString in BlockCapsule (#5657)
o85372940 Jan 11, 2024
e14f3dd
feat(db):optimize cache settings (#5659)
o85372940 Jan 11, 2024
81fbe87
feat(lite):optimize DbLite tool (#5658)
o85372940 Jan 11, 2024
259fa85
feat(version): update version to 4.7.3.1 (#5661)
halibobo1205 Jan 11, 2024
f9bab7a
feat(log): catch ContractExeException in createShieldedContractParame…
317787106 Jan 11, 2024
32f210d
test(case): add transaction test cases
forfreeday Jan 11, 2024
788136e
Merge pull request #5665 from tronprotocol/release_4.7.3.1
halibobo1205 Jan 12, 2024
c253725
update a new version. version name:GreatVoyage-v4.7.3-5-g788136ebe,ve…
halibobo1205 Jan 12, 2024
7a6a6d8
Merge pull request #5666 from tronprotocol/version/GreatVoyage-v4.7.3…
halibobo1205 Jan 12, 2024
5e7a405
Merge master into release_v4.7.4 branch (#5669)
lurais Jan 12, 2024
32e1e15
feat(db): optimize calculation services for reward when the node star…
halibobo1205 Jan 15, 2024
46454a2
feat(log):verify columns of hellomessage to avoid too long log (#5667)
317787106 Jan 15, 2024
1225ace
test(case): optimize case
forfreeday Jan 15, 2024
4bb4922
Merge pull request #5650 from forfreeday/feature/add_testcase
forfreeday Jan 16, 2024
ce04da4
feat(proposal): prevent re-submission after `ALLOW_OLD_REWARD_OPT` is…
halibobo1205 Jan 18, 2024
f02d6bf
test(case): remove useless code (#5679)
forfreeday Jan 18, 2024
24da384
feat(version): update version
forfreeday Jan 22, 2024
b08f46f
Merge pull request #5686 from forfreeday/feature/update_474version
forfreeday Jan 22, 2024
b5c6cbd
feat(log):optimize fork block version log (#5687)
lurais Jan 22, 2024
245ddfb
fix(dependency): mock jar version upgrade (#5689)
tomatoishealthy Jan 22, 2024
f0a46ff
fix(api): fix the bug of determine if triggerConstantContract succeed…
317787106 Jan 23, 2024
8960a6b
feat(version):update libp2p version to 2.2.0 (#5692)
317787106 Jan 23, 2024
931de44
feat(dependency):update libp2p version to test-v2.2.2
xxo1shine Jan 24, 2024
7489552
Merge pull request #5693 from ss3344520/update_libp2p_version
xxo1shine Jan 24, 2024
9911b05
feat(dependency): update libp2p version to 2.2.1
xxo1shine Jan 25, 2024
85bf0c3
Merge pull request #5694 from ss3344520/libp2p_version_update
xxo1shine Jan 25, 2024
baddd4f
feat(log): remove unused log for getnodeinfo api (#5697)
halibobo1205 Jan 25, 2024
cbf2417
fix the bug of concurrent usage of toString in TransactionCapsule (#5…
317787106 Jan 26, 2024
976d6f7
fix(pbft): fix concurrent access issue of srPbftMessage (#5703)
jwrct Jan 26, 2024
5acf3ef
feat(dependency): update libp2p version to test-v2.2.3
jwrct Jan 27, 2024
fd852c7
Merge pull request #5708 from jwrct/op_active_connect
Vikingzzu Jan 28, 2024
a578e85
feat(api): adjust API services to start first at startup (#5711)
halibobo1205 Jan 29, 2024
dcf1103
Revert "feat(dependency): update libp2p version to test-v2.2.3" (#5712)
jwrct Jan 29, 2024
96afa15
fix(conf): fix the config location of the RPC reflection servive (#5739)
tomatoishealthy Mar 4, 2024
fa46c4f
feat(*): optimize old rewards withdrawal (#5742)
halibobo1205 Mar 6, 2024
074e0d6
hotfix(net):throw exception if scalingFactor <=0 (#5746)
317787106 Mar 6, 2024
eaf2c34
feat(toolkit): show db root error to console (#5748)
halibobo1205 Mar 7, 2024
74c42e3
feat(conf):delete all bind.ip (#5750)
317787106 Mar 11, 2024
45a2af0
feat(param): modify the default value of maxUnsolidifiedBlocks (#5751)
xxo1shine Mar 11, 2024
3b5ed16
feat(net): optimize block processing logic (#5754)
fyyhtx Mar 11, 2024
038950d
Merge remote-tracking branch 'upstream/master' into release_v4.7.4
halibobo1205 Mar 15, 2024
9532bc0
remove unused test
halibobo1205 Mar 15, 2024
ca48980
Merge pull request #5766 from halibobo1205/release_v4.7.4
halibobo1205 Mar 15, 2024
e84a9e7
Merge pull request #5765 from tronprotocol/release_v4.7.4
halibobo1205 Mar 15, 2024
071f420
update a new version. version name:GreatVoyage-v4.7.3.1-78-ge84a9e778…
halibobo1205 Mar 15, 2024
b1fc2f0
Merge pull request #5768 from tronprotocol/version/GreatVoyage-v4.7.3…
halibobo1205 Mar 15, 2024
faa9d8d
Merge remote-tracking branch 'upstream/master' into develop
halibobo1205 Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,19 +733,19 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_OLD_REWARD_OPT]");
}
if (dynamicPropertiesStore.allowOldRewardOpt()) {
throw new ContractValidateException(
"[ALLOW_OLD_REWARD_OPT] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_OLD_REWARD_OPT] is only allowed to be 1");
}
if (!dynamicPropertiesStore.useNewRewardAlgorithm()) {
throw new ContractValidateException(
"[ALLOW_NEW_REWARD] proposal must be approved "
"[ALLOW_NEW_REWARD] or [ALLOW_TVM_VOTE] proposal must be approved "
+ "before [ALLOW_OLD_REWARD_OPT] can be proposed");
}
if (dynamicPropertiesStore.useNewRewardAlgorithmFromStart()) {
throw new ContractValidateException(
"no need old reward opt, ALLOW_NEW_REWARD from start cycle 1");
}
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ subprojects {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation "org.mockito:mockito-core:2.1.0"
testImplementation "org.mockito:mockito-core:2.13.0"
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private boolean passOld(int version) {
private boolean passNew(int version) {
ForkBlockVersionEnum versionEnum = ForkBlockVersionEnum.getForkBlockVersionEnum(version);
if (versionEnum == null) {
logger.error("Not exist block version: {}.", version);
logger.warn("Not exist block version: {}.", version);
return false;
}
long latestBlockTime = manager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
@Setter
private TransactionTrace trxTrace;

private StringBuilder toStringBuff = new StringBuilder();
@Getter
@Setter
private long time;
Expand Down Expand Up @@ -738,8 +737,7 @@ public Transaction getInstance() {

@Override
public String toString() {

toStringBuff.setLength(0);
StringBuilder toStringBuff = new StringBuilder();
toStringBuff.append("TransactionCapsule \n[ ");

toStringBuff.append("hash=").append(getTransactionId()).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import lombok.Getter;
import net.jcip.annotations.NotThreadSafe;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.Sha256Hash;

@Getter
@NotThreadSafe
public class MerkleTree {

private static volatile MerkleTree instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public interface DBIterator extends Iterator<Entry<byte[], byte[]>>, AutoCloseab

void seekToLast();

default UnmodifiableIterator<Entry<byte[], byte[]>> prefixQueryAfterThat
(byte[] key, byte[] afterThat) {
this.seek(afterThat == null ? key : afterThat);
return Iterators.filter(this, entry -> Bytes.indexOf(entry.getKey(), key) == 0);
}

/**
* An iterator is either positioned at a key/value pair, or
* not valid. This method returns true iff the iterator is valid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ public boolean valid() {

@Override
public byte[] getKey() {
checkState();
checkValid();
return dbIterator.key();
}

@Override
public byte[] getValue() {
checkState();
checkValid();
return dbIterator.value();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ public boolean valid() {

@Override
public byte[] getKey() {
checkState();
checkValid();
return dbIterator.peekNext().getKey();
}

@Override
public byte[] getValue() {
checkState();
checkValid();
return dbIterator.peekNext().getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.tron.core.store.DelegationStore.DECIMAL_OF_VI_REWARD;
import static org.tron.core.store.DelegationStore.REMARK;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Streams;
import com.google.common.primitives.Bytes;
import com.google.protobuf.ByteString;
Expand All @@ -17,9 +16,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,9 +25,9 @@
import org.tron.common.es.ExecutorServiceManager;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.MerkleRoot;
import org.tron.common.utils.Pair;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.capsule.utils.MerkleTree;
import org.tron.core.db.common.iterator.DBIterator;
import org.tron.core.db2.common.DB;
import org.tron.core.store.DelegationStore;
Expand All @@ -56,10 +53,11 @@ public class RewardViCalService {

private volatile long lastBlockNumber = -1;

@VisibleForTesting
@Setter
private Sha256Hash rewardViRoot = Sha256Hash.wrap(
ByteString.fromHex("9debcb9924055500aaae98cdee10501c5c39d4daa75800a996f4bdda73dbccd8"));
private static final String MAIN_NET_ROOT_HEX =
"9debcb9924055500aaae98cdee10501c5c39d4daa75800a996f4bdda73dbccd8";

private final Sha256Hash rewardViRoot = CommonParameter.getInstance().getStorage().getDbRoot(
"reward-vi", Sha256Hash.wrap(ByteString.fromHex(MAIN_NET_ROOT_HEX)));

private final CountDownLatch lock = new CountDownLatch(1);

Expand All @@ -75,8 +73,14 @@ public RewardViCalService(@Autowired DynamicPropertiesStore propertiesStore,
this.witnessStore = witnessStore.getDb();
}

@PostConstruct
private void init() {
public void init() {
// after init, we can get the latest block header number from db
this.newRewardCalStartCycle = this.getNewRewardAlgorithmEffectiveCycle();
boolean ret = this.newRewardCalStartCycle != Long.MAX_VALUE;
if (ret) {
// checkpoint is flushed to db, we can start rewardViCalService immediately
lastBlockNumber = Long.MAX_VALUE;
}
es.scheduleWithFixedDelay(this::maybeRun, 0, 3, TimeUnit.SECONDS);
}

Expand All @@ -94,24 +98,30 @@ private boolean isDone() {
}

private void maybeRun() {
if (enableNewRewardAlgorithm()) {
if (this.newRewardCalStartCycle > 1) {
if (isDone()) {
this.clearUp(true);
logger.info("rewardViCalService is already done");
} else {
if (this.getLatestBlockHeaderNumber() > lastBlockNumber) {
// checkpoint is flushed to db, so we can start rewardViCalService
startRewardCal();
clearUp(true);
try {
if (enableNewRewardAlgorithm()) {
if (this.newRewardCalStartCycle > 1) {
if (isDone()) {
this.clearUp(true);
logger.info("rewardViCalService is already done");
} else {
logger.info("startRewardCal will run after checkpoint is flushed to db");
if (lastBlockNumber == Long.MAX_VALUE // start rewardViCalService immediately
|| this.getLatestBlockHeaderNumber() > lastBlockNumber) {
// checkpoint is flushed to db, so we can start rewardViCalService
startRewardCal();
clearUp(true);
} else {
logger.info("startRewardCal will run after checkpoint is flushed to db");
}
}
} else {
clearUp(false);
logger.info("rewardViCalService is no need to run");
}
} else {
clearUp(false);
logger.info("rewardViCalService is no need to run");
}
} catch (Exception e) {
logger.error(" Find fatal error, program will be exited soon.", e);
System.exit(1);
}
}

Expand All @@ -131,7 +141,7 @@ private void destroy() {

public long getNewRewardAlgorithmReward(long beginCycle, long endCycle,
List<Pair<byte[], Long>> votes) {
if (!rewardViStore.has(IS_DONE_KEY)) {
if (!isDone()) {
logger.warn("rewardViCalService is not done, wait for it");
try {
lock.await();
Expand Down Expand Up @@ -168,10 +178,13 @@ private void calcMerkleRoot() {
.map(this::getHash)
.collect(Collectors.toCollection(ArrayList::new));

Sha256Hash rewardViRootLocal = MerkleTree.getInstance().createTree(ids).getRoot().getHash();
Sha256Hash rewardViRootLocal = MerkleRoot.root(ids);
if (!Objects.equals(rewardViRoot, rewardViRootLocal)) {
logger.error("merkle root mismatch, expect: {}, actual: {}",
rewardViRoot, rewardViRootLocal);
logger.warn("Merkle root mismatch, expect: {}, actual: {}."
+ " If you are quite sure that there is no miscalculation (not on the main network)"
+ ", please configure 'storage.merkleRoot.reward-vi = {}'"
+ "(for a specific network such as Nile, etc.) in config.conf to fix the hints",
rewardViRoot, rewardViRootLocal, rewardViRootLocal);
}
logger.info("calcMerkleRoot: {}", rewardViRootLocal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2525,10 +2525,6 @@ public boolean useNewRewardAlgorithm() {
return getNewRewardAlgorithmEffectiveCycle() != Long.MAX_VALUE;
}

public boolean useNewRewardAlgorithmFromStart() {
return getNewRewardAlgorithmEffectiveCycle() == 1;
}

public void saveNewRewardAlgorithmEffectiveCycle() {
if (getNewRewardAlgorithmEffectiveCycle() == Long.MAX_VALUE) {
long currentCycle = getCurrentCycleNumber();
Expand Down Expand Up @@ -2839,19 +2835,8 @@ public boolean supportMaxDelegateLockPeriod() {
getUnfreezeDelayDays() > 0;
}

/**
* @require NEW_REWARD_ALGORITHM_EFFECTIVE_CYCLE != Long.MAX_VALUE
* @require NEW_REWARD_ALGORITHM_EFFECTIVE_CYCLE > 1
*/
public void saveAllowOldRewardOpt(long allowOldRewardOpt) {
if (useNewRewardAlgorithm()) {
if (useNewRewardAlgorithmFromStart()) {
throw new IllegalStateException("no need old reward opt, ALLOW_NEW_REWARD from start");
}
this.put(ALLOW_OLD_REWARD_OPT, new BytesCapsule(ByteArray.fromLong(allowOldRewardOpt)));
} else {
throw new IllegalStateException("not support old reward opt, ALLOW_NEW_REWARD not set");
}
this.put(ALLOW_OLD_REWARD_OPT, new BytesCapsule(ByteArray.fromLong(allowOldRewardOpt)));
}

public boolean allowOldRewardOpt() {
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
compile 'org.aspectj:aspectjrt:1.8.13'
compile 'org.aspectj:aspectjweaver:1.8.13'
compile 'org.aspectj:aspectjtools:1.8.13'
compile group: 'com.github.tronprotocol', name: 'libp2p', version: 'test-v2.2.1',{
compile group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.1',{
exclude group: 'io.grpc', module: 'grpc-context'
exclude group: 'io.grpc', module: 'grpc-core'
exclude group: 'io.grpc', module: 'grpc-netty'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public static class Histogram {
public static final String MESSAGE_PROCESS_LATENCY = "tron:message_process_latency_seconds";
public static final String BLOCK_FETCH_LATENCY = "tron:block_fetch_latency_seconds";
public static final String BLOCK_RECEIVE_DELAY = "tron:block_receive_delay_seconds";
public static final String DO_REWARD_CAL_DELAY = "tron:do_reward_cal_seconds";


private Histogram() {
throw new IllegalStateException("Histogram");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public class MetricsHistogram {
init(MetricKeys.Histogram.BLOCK_FETCH_LATENCY, "fetch block latency.");
init(MetricKeys.Histogram.BLOCK_RECEIVE_DELAY,
"receive block delay time, receiveTime - blockTime.");
init(MetricKeys.Histogram.DO_REWARD_CAL_DELAY,
"do reward cal delay time.", "depth");
}

private MetricsHistogram() {
Expand Down
68 changes: 68 additions & 0 deletions common/src/main/java/org/tron/common/utils/MerkleRoot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.tron.common.utils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import lombok.Getter;

public class MerkleRoot {

private MerkleRoot() {

}

public static Sha256Hash root(List<Sha256Hash> hashList) {
List<Leaf> leaves = createLeaves(hashList);
while (leaves.size() > 1) {
leaves = createParentLeaves(leaves);
}
return leaves.isEmpty() ? Sha256Hash.ZERO_HASH : leaves.get(0).hash;
}

private static List<Leaf> createParentLeaves(List<Leaf> leaves) {
int step = 2;
int len = leaves.size();
return IntStream.iterate(0, i -> i + step)
.limit(len)
.filter(i -> i < len)
.mapToObj(i -> {
Leaf right = i + 1 < len ? leaves.get(i + 1) : null;
return createLeaf(leaves.get(i), right);
}).collect(Collectors.toList());
}

private static List<Leaf> createLeaves(List<Sha256Hash> hashList) {
int step = 2;
int len = hashList.size();
return IntStream.iterate(0, i -> i + step)
.limit(len)
.filter(i -> i < len)
.mapToObj(i -> {
Leaf right = i + 1 < len ? createLeaf(hashList.get(i + 1)) : null;
return createLeaf(createLeaf(hashList.get(i)), right);
}).collect(Collectors.toList());
}

private static Leaf createLeaf(Leaf left, Leaf right) {
Leaf leaf = new Leaf();
leaf.hash = right == null ? left.hash : computeHash(left.hash, right.hash);
return leaf;
}

private static Leaf createLeaf(Sha256Hash hash) {
Leaf leaf = new Leaf();
leaf.hash = hash;
return leaf;
}

private static Sha256Hash computeHash(Sha256Hash leftHash, Sha256Hash rightHash) {
return Sha256Hash.of(true,
leftHash.getByteString().concat(rightHash.getByteString()).toByteArray());
}

@Getter
private static class Leaf {

private Sha256Hash hash;
}
}
Loading
Loading