Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static List<Actuator> createActuator(TransactionCapsule transactionCapsul
actuatorList
.add(getActuatorByContract(contract, chainBaseManager, transactionCapsule));
} catch (IllegalAccessException | InstantiationException e) {
e.printStackTrace();
logger.error("Failed to create actuator for contract {}.", contract.getType(), e);
}
});
return actuatorList;
Expand Down
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,30 @@ subprojects {
testImplementation "org.mockito:mockito-inline:4.11.0"
}
if (project.name != 'protocol' && project.name != 'errorprone'
&& javaVersion.isJava11Compatible()) {
&& javaVersion.isCompatibleWith(JavaVersion.VERSION_17)) {
apply plugin: 'net.ltgt.errorprone'
dependencies {
errorprone "com.google.errorprone:error_prone_core:${errorproneVersion}"
errorprone rootProject.project(':errorprone')
}
// Keep test compilation free of Error Prone so existing test code does not block builds.
tasks.withType(JavaCompile).configureEach {
options.errorprone.enabled = false
}
tasks.named(sourceSets.main.compileJavaTaskName, JavaCompile).configure {
options.errorprone {
enabled = true
disableWarningsInGeneratedCode = true
disableAllChecks = true
excludedPaths = '.*/generated/.*'
errorproneArgs.addAll([
'-Xep:BigDecimalFloatingPointConstructor:ERROR',
'-Xep:SelfAssignment:ERROR',
'-Xep:StringCaseLocaleUsage:ERROR',
'-Xep:StringCaseLocaleUsageMethodRef:ERROR',
'-Xep:ForbidJavaLangMath:ERROR',
'-Xep:ComparatorNeverReturnsZero:ERROR',
'-Xep:CatchAndPrintStackTrace:ERROR',
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.utils.ByteArray;
import org.tron.common.zksnark.JLibrustzcash;
import org.tron.common.zksnark.LibrustzcashParam.MerkleHashParams;
import org.tron.core.exception.ZksnarkException;
Expand Down Expand Up @@ -55,26 +54,6 @@ public static PedersenHashCapsule uncommitted() throws ZksnarkException {
return compressCapsule;
}

public static void main(String[] args) {
try {
byte[] a =
ByteArray
.fromHexString("05655316a07e6ec8c9769af54ef98b30667bfb6302b32987d552227dae86a087");
byte[] b =
ByteArray
.fromHexString("06041357de59ba64959d1b60f93de24dfe5ea1e26ed9e8a73d35b225a1845ba7");

PedersenHash sa = PedersenHash.newBuilder().setContent(ByteString.copyFrom(a)).build();
PedersenHash sb = PedersenHash.newBuilder().setContent(ByteString.copyFrom(b)).build();

PedersenHash result = combine(sa, sb, 25).getInstance();
// 61a50a5540b4944da27cbd9b3d6ec39234ba229d2c461f4d719bc136573bf45b
System.out.println(ByteArray.toHexString(result.getContent().toByteArray()));
} catch (ZksnarkException e) {
e.printStackTrace();
}
}

public ByteString getContent() {
return this.pedersenHash.getContent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public String toString() {
toStringBuff.append("transfer amount=").append(transferContract.getAmount())
.append("\n");
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
logger.debug("Failed to unpack transfer contract.", e);
}
} else if (contract.getType().equals(ContractType.TransferAssetContract)) {
TransferAssetContract transferAssetContract;
Expand All @@ -808,7 +808,7 @@ public String toString() {
toStringBuff.append("transfer amount=").append(transferAssetContract.getAmount())
.append("\n");
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
logger.debug("Failed to unpack transfer asset contract.", e);
}
}
if (this.transaction.getSignatureList().size() >= i.get() + 1) {
Expand Down
12 changes: 6 additions & 6 deletions chainbase/src/main/java/org/tron/core/store/AssetIssueStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.tron.common.utils.Commons.ASSET_ISSUE_COUNT_LIMIT_MAX;

import com.google.common.collect.Streams;
import com.google.protobuf.ByteString;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -46,12 +48,10 @@ private List<AssetIssueCapsule> getAssetIssuesPaginated(List<AssetIssueCapsule>
if (assetIssueList.size() <= offset) {
return null;
}
assetIssueList.sort((o1, o2) -> {
if (o1.getName() != o2.getName()) {
return o1.getName().toStringUtf8().compareTo(o2.getName().toStringUtf8());
}
return Long.compare(o1.getOrder(), o2.getOrder());
});
assetIssueList.sort(
Comparator.comparing(AssetIssueCapsule::getName,
ByteString.unsignedLexicographicalComparator())
.thenComparingLong(AssetIssueCapsule::getOrder));
limit = limit > ASSET_ISSUE_COUNT_LIMIT_MAX ? ASSET_ISSUE_COUNT_LIMIT_MAX : limit;
long end = offset + limit;
end = end > assetIssueList.size() ? assetIssueList.size() : end;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.core.store;

import com.google.common.collect.Streams;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -31,9 +32,7 @@ public ExchangeCapsule get(byte[] key) throws ItemNotFoundException {
public List<ExchangeCapsule> getAllExchanges() {
return Streams.stream(iterator())
.map(Map.Entry::getValue)
.sorted(
(ExchangeCapsule a, ExchangeCapsule b) -> a.getCreateTime() <= b.getCreateTime() ? 1
: -1)
.sorted(Comparator.comparingLong(ExchangeCapsule::getCreateTime).reversed())
.collect(Collectors.toList());
}
}
}
18 changes: 10 additions & 8 deletions chainbase/src/main/java/org/tron/core/store/ProposalStore.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.core.store;

import com.google.common.collect.Streams;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -32,23 +33,24 @@ public ProposalCapsule get(byte[] key) throws ItemNotFoundException {
public List<ProposalCapsule> getAllProposals() {
return Streams.stream(iterator())
.map(Map.Entry::getValue)
.sorted(
(ProposalCapsule a, ProposalCapsule b) -> a.getCreateTime() <= b.getCreateTime() ? 1
: -1)
.sorted(Comparator.comparingLong(ProposalCapsule::getCreateTime).reversed())
.collect(Collectors.toList());
}

/**
* note: return in asc order by expired time
* Returns proposals in ascending expiration order, ties broken by descending proposal ID.
*
* <p>The descending-id tie-break preserves the execution order for equal-expiration proposals:
* live execution applies the highest id first and the lowest id last (final value), and the
* energy/bandwidth price-history loaders rebuild from the tail, so the lowest id must be last.
*/
public List<ProposalCapsule> getSpecifiedProposals(State state, long code) {
return Streams.stream(iterator())
.map(Map.Entry::getValue)
.filter(proposalCapsule -> proposalCapsule.getState().equals(state))
.filter(proposalCapsule -> proposalCapsule.getParameters().containsKey(code))
.sorted(
(ProposalCapsule a, ProposalCapsule b) -> a.getExpirationTime() > b.getExpirationTime()
? 1 : -1)
.sorted(Comparator.comparingLong(ProposalCapsule::getExpirationTime)
.thenComparing(Comparator.comparingLong(ProposalCapsule::getID).reversed()))
.collect(Collectors.toList());
}
}
}
2 changes: 1 addition & 1 deletion common/src/main/java/org/tron/common/utils/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static int readData(String filePath, char[] buf) {
try (BufferedReader bufRead = new BufferedReader(new FileReader(file))) {
len = bufRead.read(buf, 0, buf.length);
} catch (IOException ex) {
ex.printStackTrace();
logger.warn("Failed to read data from file.", ex);
return 0;
}
return len;
Expand Down
21 changes: 19 additions & 2 deletions errorprone/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
if (!JavaVersion.current().isJava11Compatible()) {
// ErrorProne core requires JDK 11+; skip this module on JDK 8
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
// ErrorProne core 2.42.0 ships Java 17 bytecode; skip below JDK 17
tasks.withType(JavaCompile).configureEach { enabled = false }
tasks.withType(Jar).configureEach { enabled = false }
// No jar is produced, so the root maven-publish setup must not try to publish one
tasks.withType(AbstractPublishToMaven).configureEach { enabled = false }
tasks.withType(Test).configureEach { enabled = false }
} else {
dependencies {
compileOnly "com.google.errorprone:error_prone_annotations:${errorproneVersion}"
compileOnly "com.google.errorprone:error_prone_check_api:${errorproneVersion}"
compileOnly "com.google.errorprone:error_prone_core:${errorproneVersion}"
compileOnly "com.google.auto.service:auto-service:1.1.1"
annotationProcessor "com.google.auto.service:auto-service:1.1.1"
testImplementation "com.google.errorprone:error_prone_test_helpers:${errorproneVersion}"
}

tasks.withType(Test).configureEach {
jvmArgs(
'--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED'
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package errorprone;

import com.google.auto.service.AutoService;
import com.google.errorprone.BugPattern;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.NewClassTree;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
import java.util.List;

/**
* Prevents constructing {@link java.math.BigDecimal} from binary floating-point values.
*
* <p>This checks the resolved constructor signature, so it also catches {@link Double} and
* {@link Float} arguments that javac unboxes to the {@code double} constructor, constructor
* references such as {@code BigDecimal::new} resolved against a floating-point functional
* interface, anonymous subclasses of {@code BigDecimal}, and named subclasses delegating via
* {@code super(double)} -- the only source-level route into the floating-point constructor.
*/
@AutoService(BugChecker.class)
@BugPattern(
name = "BigDecimalFloatingPointConstructor",
summary = "Do not construct BigDecimal from a floating-point value. Use a decimal String, "
+ "for example new BigDecimal(\"0.0001\").",
severity = BugPattern.SeverityLevel.ERROR
)
public class BigDecimalFloatingPointConstructor extends BugChecker
implements BugChecker.NewClassTreeMatcher, BugChecker.MemberReferenceTreeMatcher,
BugChecker.MethodInvocationTreeMatcher {

private static final String BIG_DECIMAL = "java.math.BigDecimal";

@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(tree);
if (!(symbol instanceof Symbol.MethodSymbol)) {
return Description.NO_MATCH;
}

// For an anonymous subclass (new BigDecimal(...) { }) the resolved symbol is the synthetic
// constructor of the anonymous class, so match on the type being instantiated instead of the
// constructor owner.
Type constructed = ASTHelpers.getType(tree.getIdentifier());
if (constructed == null
|| !constructed.tsym.getQualifiedName().contentEquals(BIG_DECIMAL)) {
return Description.NO_MATCH;
}

if (!firstParameterIsDouble((Symbol.MethodSymbol) symbol, state)) {
return Description.NO_MATCH;
}

return describeMatch(tree);
}

@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
if (tree.getMode() != MemberReferenceTree.ReferenceMode.NEW) {
return Description.NO_MATCH;
}

Symbol symbol = ASTHelpers.getSymbol(tree);
if (!(symbol instanceof Symbol.MethodSymbol)) {
return Description.NO_MATCH;
}

Symbol.MethodSymbol constructor = (Symbol.MethodSymbol) symbol;
if (!constructor.owner.getQualifiedName().contentEquals(BIG_DECIMAL)) {
return Description.NO_MATCH;
}

if (!firstParameterIsDouble(constructor, state)) {
return Description.NO_MATCH;
}

return describeMatch(tree);
}

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(tree);
if (!(symbol instanceof Symbol.MethodSymbol)) {
return Description.NO_MATCH;
}

// A MethodInvocationTree resolving to a constructor is an explicit super(...)/this(...)
// call, so this flags named subclasses delegating to BigDecimal(double). Every named
// subclass must pass through such a call to reach the floating-point constructor, which
// also covers new NamedSubclass(...) and NamedSubclass::new at their declaration site.
Symbol.MethodSymbol method = (Symbol.MethodSymbol) symbol;
if (!method.isConstructor()
|| !method.owner.getQualifiedName().contentEquals(BIG_DECIMAL)) {
return Description.NO_MATCH;
}

if (!firstParameterIsDouble(method, state)) {
return Description.NO_MATCH;
}

return describeMatch(tree);
}

private static boolean firstParameterIsDouble(
Symbol.MethodSymbol constructor, VisitorState state) {
List<Symbol.VarSymbol> parameters = constructor.getParameters();
return !parameters.isEmpty()
&& ASTHelpers.isSameType(parameters.get(0).type, state.getSymtab().doubleType, state);
}
}
Loading
Loading