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

fix(LiteTool): fix data issue of snapshot generating when crash #5701

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
f9bab7a
feat(log): catch ContractExeException in createShieldedContractParame…
317787106 Jan 11, 2024
32f210d
test(case): add transaction test cases
forfreeday Jan 11, 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
a44d17b
fix(LiteTool): fix data inconsistency of snapshot generation in the c…
tomatoishealthy Jan 26, 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
4 changes: 4 additions & 0 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ 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");
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,7 +737,7 @@ public Transaction getInstance() {

@Override
public String toString() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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;
Expand Down Expand Up @@ -75,8 +74,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 @@ -100,7 +105,8 @@ private void maybeRun() {
this.clearUp(true);
logger.info("rewardViCalService is already done");
} else {
if (this.getLatestBlockHeaderNumber() > lastBlockNumber) {
if (lastBlockNumber == Long.MAX_VALUE // start rewardViCalService immediately
|| this.getLatestBlockHeaderNumber() > lastBlockNumber) {
// checkpoint is flushed to db, so we can start rewardViCalService
startRewardCal();
clearUp(true);
Expand Down Expand Up @@ -170,7 +176,7 @@ private void calcMerkleRoot() {

Sha256Hash rewardViRootLocal = MerkleTree.getInstance().createTree(ids).getRoot().getHash();
if (!Objects.equals(rewardViRoot, rewardViRootLocal)) {
logger.error("merkle root mismatch, expect: {}, actual: {}",
logger.warn("merkle root mismatch, expect: {}, actual: {}",
rewardViRoot, rewardViRootLocal);
}
logger.info("calcMerkleRoot: {}", rewardViRootLocal);
Expand Down
22 changes: 1 addition & 21 deletions chainbase/src/main/java/org/tron/core/store/WitnessStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tron.common.cache.CacheManager;
import org.tron.common.cache.CacheStrategies;
import org.tron.common.cache.CacheType;
import org.tron.common.cache.TronCache;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.core.config.Parameter;
import org.tron.core.db.TronStoreWithRevoking;

@Slf4j(topic = "DB")
@Component
public class WitnessStore extends TronStoreWithRevoking<WitnessCapsule> {
// cache for 127 SR
private final TronCache<Integer, List<WitnessCapsule>> witnessStandbyCache;

@Autowired
protected WitnessStore(@Value("witness") String dbName) {
super(dbName);
String strategy = String.format(CacheStrategies.PATTERNS, 1, 1, "30s", 1);
witnessStandbyCache = CacheManager.allocate(CacheType.witnessStandby, strategy);
}

/**
Expand All @@ -48,19 +40,8 @@ public WitnessCapsule get(byte[] key) {
}

public List<WitnessCapsule> getWitnessStandby() {
List<WitnessCapsule> list =
witnessStandbyCache.getIfPresent(Parameter.ChainConstant.WITNESS_STANDBY_LENGTH);
if (list != null) {
return list;
}
return updateWitnessStandby(null);
}

public List<WitnessCapsule> updateWitnessStandby(List<WitnessCapsule> all) {
List<WitnessCapsule> ret;
if (all == null) {
all = getAllWitnesses();
}
List<WitnessCapsule> all = getAllWitnesses();
all.sort(Comparator.comparingLong(WitnessCapsule::getVoteCount)
.reversed().thenComparing(Comparator.comparingInt(
(WitnessCapsule w) -> w.getAddress().hashCode()).reversed()));
Expand All @@ -71,7 +52,6 @@ public List<WitnessCapsule> updateWitnessStandby(List<WitnessCapsule> all) {
}
// trim voteCount = 0
ret.removeIf(w -> w.getVoteCount() < 1);
witnessStandbyCache.put(Parameter.ChainConstant.WITNESS_STANDBY_LENGTH, ret);
return ret;
}

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 @@ -108,10 +108,6 @@ public List<WitnessCapsule> getAllWitnesses() {
return witnessStore.getAllWitnesses();
}

public List<WitnessCapsule> updateWitnessStandby(List<WitnessCapsule> all) {
return witnessStore.updateWitnessStandby(all);
}

public void saveStateFlag(int flag) {
dynamicPropertiesStore.saveStateFlag(flag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,11 @@ public void doMaintenance() {
if (dynamicPropertiesStore.allowChangeDelegation()) {
long nextCycle = dynamicPropertiesStore.getCurrentCycleNumber() + 1;
dynamicPropertiesStore.saveCurrentCycleNumber(nextCycle);
List<WitnessCapsule> all = consensusDelegate.getAllWitnesses();
all.forEach(witness -> {
consensusDelegate.getAllWitnesses().forEach(witness -> {
delegationStore.setBrokerage(nextCycle, witness.createDbKey(),
delegationStore.getBrokerage(witness.createDbKey()));
delegationStore.setWitnessVote(nextCycle, witness.createDbKey(), witness.getVoteCount());
});
consensusDelegate.updateWitnessStandby(all);
}
}

Expand Down
6 changes: 0 additions & 6 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,11 @@ createScript(project, 'org.tron.program.SolidityNode', 'SolidityNode')
createScript(project, 'org.tron.program.FullNode', 'FullNode')
createScript(project, 'org.tron.program.KeystoreFactory', 'KeystoreFactory')
createScript(project, 'org.tron.program.DBConvert', 'DBConvert')
createScript(project, 'org.tron.tool.litefullnode.LiteFullNodeTool', 'LiteFullNodeTool')

def releaseBinary = hasProperty('binaryRelease') ? getProperty('binaryRelease') : 'true'
def skipSolidity = hasProperty('skipSolidity') ? true : false
def skipKeystore = hasProperty('skipKeystore') ? true : false
def skipConvert = hasProperty('skipConvert') ? true : false
def skipLite = hasProperty('skipLite') ? true : false
def skipAll = hasProperty('skipAll') ? true : false
if (releaseBinary == 'true') {
artifacts {
Expand All @@ -241,10 +239,6 @@ if (releaseBinary == 'true') {
artifacts {
archives(binaryRelease('buildDBConvertJar', 'DBConvert', 'org.tron.program.DBConvert'))}
}
if (!skipLite) {
artifacts {
archives(binaryRelease('buildLiteFullNodeToolJar', 'LiteFullNodeTool', 'org.tron.tool.litefullnode.LiteFullNodeTool'))}
}
}

}
Expand Down
14 changes: 8 additions & 6 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3862,11 +3862,12 @@ private boolean isShieldedTRC20NoteSpent(GrpcAPI.Note note, long pos, byte[] ak,
TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder();
Return.Builder retBuilder = Return.newBuilder();
TransactionExtention trxExt;
Transaction trx;

try {
TransactionCapsule trxCap = createTransactionCapsule(trigger,
ContractType.TriggerSmartContract);
Transaction trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);
trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);

retBuilder.setResult(true).setCode(response_code.SUCCESS);
trxExtBuilder.setTransaction(trx);
Expand All @@ -3889,10 +3890,10 @@ private boolean isShieldedTRC20NoteSpent(GrpcAPI.Note note, long pos, byte[] ak,
logger.warn("unknown exception caught: " + e.getMessage(), e);
} finally {
trxExt = trxExtBuilder.build();
trx = trxExt.getTransaction();
}

String code = trxExt.getResult().getCode().toString();
if ("SUCCESS".equals(code)) {
if (code.SUCESS == trx.getRet(0).getRet()) {
List<ByteString> list = trxExt.getConstantResultList();
byte[] listBytes = new byte[0];
for (ByteString bs : list) {
Expand Down Expand Up @@ -4126,11 +4127,12 @@ public byte[] getShieldedContractScalingFactor(byte[] contractAddress)
TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder();
Return.Builder retBuilder = Return.newBuilder();
TransactionExtention trxExt;
Transaction trx;

try {
TransactionCapsule trxCap = createTransactionCapsule(trigger,
ContractType.TriggerSmartContract);
Transaction trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);
trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);

retBuilder.setResult(true).setCode(response_code.SUCCESS);
trxExtBuilder.setTransaction(trx);
Expand All @@ -4153,10 +4155,10 @@ public byte[] getShieldedContractScalingFactor(byte[] contractAddress)
logger.warn("Unknown exception caught: " + e.getMessage(), e);
} finally {
trxExt = trxExtBuilder.build();
trx = trxExt.getTransaction();
}

String code = trxExt.getResult().getCode().toString();
if ("SUCCESS".equals(code)) {
if (code.SUCESS == trx.getRet(0).getRet()) {
List<ByteString> list = trxExt.getConstantResultList();
byte[] listBytes = new byte[0];
for (ByteString bs : list) {
Expand Down
10 changes: 10 additions & 0 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
import org.tron.core.metrics.MetricsKey;
import org.tron.core.metrics.MetricsUtil;
import org.tron.core.service.MortgageService;
import org.tron.core.service.RewardViCalService;
import org.tron.core.store.AccountAssetStore;
import org.tron.core.store.AccountIdIndexStore;
import org.tron.core.store.AccountIndexStore;
Expand Down Expand Up @@ -260,6 +261,9 @@ public class Manager {
private ExecutorService filterEs;
private static final String filterEsName = "filter";

@Autowired
private RewardViCalService rewardViCalService;

/**
* Cycle thread to rePush Transactions
*/
Expand Down Expand Up @@ -465,6 +469,7 @@ public void init() {
revokingStore.disable();
revokingStore.check();
transactionCache.initCache();
rewardViCalService.init();
this.setProposalController(ProposalController.createInstance(this));
this.setMerkleContainer(
merkleContainer.createInstance(chainBaseManager.getMerkleTreeStore(),
Expand Down Expand Up @@ -1843,6 +1848,7 @@ private void postSolidityLogContractTrigger(Long blockNum, Long lastSolidityNum)
triggerCapsule.setTriggerName(Trigger.SOLIDITYLOG_TRIGGER_NAME);
EventPluginLoader.getInstance().postSolidityLogTrigger(triggerCapsule);
} else {
// when switch fork, block will be post to triggerCapsuleQueue, transaction may be not found
logger.error("PostSolidityLogContractTrigger txId = {} not contains transaction.",
triggerCapsule.getTransactionId());
}
Expand Down Expand Up @@ -1908,6 +1914,10 @@ public long getSyncBeginNumber() {
chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber()
- revokingStore.size(),
chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum());
return this.fetchSyncBeginNumber();
}

public long fetchSyncBeginNumber() {
return chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber()
- revokingStore.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.DecodeUtil;
import org.tron.common.utils.StringUtil;
import org.tron.core.ChainBaseManager;
import org.tron.core.capsule.BlockCapsule;
Expand Down Expand Up @@ -169,6 +170,22 @@ public boolean valid() {
return false;
}

int maxByteSize = 200;
ByteString address = this.helloMessage.getAddress();
if (!address.isEmpty() && address.toByteArray().length > maxByteSize) {
return false;
}

ByteString sig = this.helloMessage.getSignature();
if (!sig.isEmpty() && sig.toByteArray().length > maxByteSize) {
return false;
}

ByteString codeVersion = this.helloMessage.getCodeVersion();
if (!codeVersion.isEmpty() && codeVersion.toByteArray().length > maxByteSize) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public void processHelloMessage(PeerConnection peer, HelloMessage msg) {
}

if (!msg.valid()) {
logger.warn("Peer {} invalid hello message parameters, "
+ "GenesisBlockId: {}, SolidBlockId: {}, HeadBlockId: {}",
peer.getInetSocketAddress(),
ByteArray.toHexString(msg.getInstance().getGenesisBlockId().getHash().toByteArray()),
ByteArray.toHexString(msg.getInstance().getSolidBlockId().getHash().toByteArray()),
ByteArray.toHexString(msg.getInstance().getHeadBlockId().getHash().toByteArray()));
logger.warn("Peer {} invalid hello message parameters, GenesisBlockId: {}, SolidBlockId: {}, "
+ "HeadBlockId: {}, address: {}, sig: {}, codeVersion: {}",
peer.getInetSocketAddress(),
ByteArray.toHexString(msg.getInstance().getGenesisBlockId().getHash().toByteArray()),
ByteArray.toHexString(msg.getInstance().getSolidBlockId().getHash().toByteArray()),
ByteArray.toHexString(msg.getInstance().getHeadBlockId().getHash().toByteArray()),
msg.getInstance().getAddress().toByteArray().length,
msg.getInstance().getSignature().toByteArray().length,
msg.getInstance().getCodeVersion().toByteArray().length);
peer.disconnect(ReasonCode.UNEXPECTED_IDENTITY);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void setConfigNodeInfo(NodeInfo nodeInfo) {
}

protected void setBlockInfo(NodeInfo nodeInfo) {
nodeInfo.setBeginSyncNum(dbManager.getSyncBeginNumber());
nodeInfo.setBeginSyncNum(dbManager.fetchSyncBeginNumber());
nodeInfo.setBlock(chainBaseManager.getHeadBlockId().getString());
nodeInfo.setSolidityBlock(chainBaseManager.getSolidBlockId().getString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.tron.core.config.args.Args;
import org.tron.core.db.Manager;
import org.tron.core.exception.BadItemException;
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.ItemNotFoundException;
import org.tron.core.exception.NonUniqueObjectException;
Expand Down Expand Up @@ -2475,7 +2476,7 @@ public void createShieldedContractParameters(
ShieldedTRC20Parameters shieldedTRC20Parameters = wallet
.createShieldedContractParameters(request);
responseObserver.onNext(shieldedTRC20Parameters);
} catch (ZksnarkException | ContractValidateException e) {
} catch (ZksnarkException | ContractValidateException | ContractExeException e) {
responseObserver.onError(getRunTimeException(e));
logger.info("createShieldedContractParameters: {}", e.getMessage());
return;
Expand Down
6 changes: 3 additions & 3 deletions framework/src/main/java/org/tron/program/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public class Version {

public static final String VERSION_NAME = "GreatVoyage-v4.7.2-140-g9d13f9cb69";
public static final String VERSION_CODE = "18173";
private static final String VERSION = "4.7.3";
public static final String VERSION_NAME = "GreatVoyage-v4.7.3-5-g788136ebe";
public static final String VERSION_CODE = "18180";
private static final String VERSION = "4.7.4";

public static String getVersion() {
return VERSION;
Expand Down
Loading