diff --git a/actuator/src/main/java/org/tron/core/vm/VM.java b/actuator/src/main/java/org/tron/core/vm/VM.java index 2150df04c64..b1d7b027601 100644 --- a/actuator/src/main/java/org/tron/core/vm/VM.java +++ b/actuator/src/main/java/org/tron/core/vm/VM.java @@ -108,7 +108,10 @@ public static void play(Program program, JumpTable jumpTable) { } catch (JVMStackOverFlowException | OutOfTimeException e) { throw e; } catch (RuntimeException e) { - if (StringUtils.isEmpty(e.getMessage())) { + // https://openjdk.org/jeps/358 + // https://bugs.openjdk.org/browse/JDK-8220715 + // since jdk 14, the NullPointerExceptions message is not empty + if (e instanceof NullPointerException || StringUtils.isEmpty(e.getMessage())) { logger.warn("Unknown Exception occurred, tx id: {}", Hex.toHexString(program.getRootTransactionId()), e); program.setRuntimeFailure(new RuntimeException("Unknown Exception")); diff --git a/build.gradle b/build.gradle index b1aba1c0aa9..3ec30cf4d47 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,40 @@ +import org.gradle.nativeplatform.platform.internal.Architectures allprojects { version = "1.0.0" apply plugin: "java-library" } +static def isX86() { + def arch = System.getProperty("os.arch").toLowerCase() + return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch) +} + +static def isArm64() { + def arch = System.getProperty("os.arch").toLowerCase() + return new Architectures.KnownArchitecture("arm64", "aarch64").isAlias(arch) +} + +if (isArm64() && !JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + throw new GradleException("Java 17 or later is required to build Java-Tron for arm64.\n" + + " Detected version ${JavaVersion.current()}") +} + +if (isX86() && !JavaVersion.current().isJava8()) { + throw new GradleException("Java 8 is required to build Java-Tron for x86.\n" + + " Detected version ${JavaVersion.current()}") +} + subprojects { apply plugin: "jacoco" apply plugin: "maven-publish" sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.current() [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' - + jacoco { + toolVersion = "0.8.12" // see https://www.jacoco.org/jacoco/trunk/doc/changes.html + } buildscript { repositories { mavenCentral() @@ -46,30 +69,42 @@ subprojects { implementation group: 'joda-time', name: 'joda-time', version: '2.3' implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69' - compileOnly 'org.projectlombok:lombok:1.18.12' - annotationProcessor 'org.projectlombok:lombok:1.18.12' - testCompileOnly 'org.projectlombok:lombok:1.18.12' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.12' + compileOnly 'org.projectlombok:lombok:1.18.34' + annotationProcessor 'org.projectlombok:lombok:1.18.34' + testCompileOnly 'org.projectlombok:lombok:1.18.34' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.34' + + // https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8190378 + implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2' + annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2' testImplementation group: 'junit', name: 'junit', version: '4.13.2' - testImplementation "org.mockito:mockito-core:2.13.0" + // see https://github.com/mockito/mockito/releases/tag/v5.0.0 + // Mockito 5 update the minimum supported Java version to 11 + // Mockito 4 supports Java 8 and above. + testImplementation "org.mockito:mockito-core:4.11.0" } - task sourcesJar(type: Jar, dependsOn: classes) { + tasks.register('sourcesJar', Jar) { + dependsOn classes classifier = "sources" from sourceSets.main.allSource duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates } - tasks.withType(AbstractArchiveTask) { + tasks.withType(AbstractArchiveTask).configureEach { preserveFileTimestamps = false reproducibleFileOrder = true duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates } + tasks.withType(Test).configureEach { + // https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:environment + /* environment 'CI', 'true'*/ + } } -task copyToParent(type: Copy) { +tasks.register('copyToParent', Copy) { into "$buildDir/libs" subprojects { from tasks.withType(Jar) diff --git a/chainbase/build.gradle b/chainbase/build.gradle index 79a246014d7..997e789a391 100644 --- a/chainbase/build.gradle +++ b/chainbase/build.gradle @@ -2,7 +2,6 @@ description = "chainbase – a decentralized database for blockchain." // Dependency versions // --------------------------------------- -def jacocoVersion = "0.8.0" def jansiVersion = "1.16" // -------------------------------------- @@ -41,9 +40,6 @@ test { } } -jacoco { - toolVersion = jacocoVersion // See http://www.eclemma.org/jacoco/. -} jacocoTestReport { reports { diff --git a/chainbase/src/main/java/org/tron/common/storage/OptionsPicker.java b/chainbase/src/main/java/org/tron/common/storage/OptionsPicker.java new file mode 100644 index 00000000000..acace12b39d --- /dev/null +++ b/chainbase/src/main/java/org/tron/common/storage/OptionsPicker.java @@ -0,0 +1,15 @@ +package org.tron.common.storage; + +import org.tron.common.setting.RocksDbSettings; +import org.tron.common.utils.StorageUtils; + +public class OptionsPicker { + + protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) { + return StorageUtils.getOptionsByDbName(dbName); + } + + protected org.rocksdb.Options getOptionsByDbNameForRocksDB(String dbName) { + return RocksDbSettings.getOptionsByDbName(dbName); + } +} diff --git a/chainbase/src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java b/chainbase/src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java index 43a24ff4416..c7ab8288fe7 100644 --- a/chainbase/src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java +++ b/chainbase/src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java @@ -18,6 +18,7 @@ import static org.fusesource.leveldbjni.JniDBFactory.factory; import com.google.common.collect.Sets; +import com.google.common.primitives.Bytes; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -30,18 +31,14 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.Set; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; - -import com.google.common.primitives.Bytes; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.iq80.leveldb.CompressionType; import org.iq80.leveldb.DB; import org.iq80.leveldb.DBIterator; import org.iq80.leveldb.Logger; @@ -54,6 +51,7 @@ import org.tron.common.storage.WriteOptionsWrapper; import org.tron.common.storage.metric.DbStat; import org.tron.common.utils.FileUtil; +import org.tron.common.utils.PropUtil; import org.tron.common.utils.StorageUtils; import org.tron.core.db.common.DbSourceInter; import org.tron.core.db.common.iterator.StoreIterator; @@ -74,6 +72,7 @@ public class LevelDbDataSourceImpl extends DbStat implements DbSourceInter prefixQuery(byte[] key) { } } + @Deprecated @Override public long getTotal() throws RuntimeException { resetDbLock.readLock().lock(); @@ -377,13 +403,6 @@ public long getTotal() throws RuntimeException { } } - private void updateByBatchInner(Map rows) throws Exception { - try (WriteBatch batch = database.createWriteBatch()) { - innerBatchUpdate(rows,batch); - database.write(batch, writeOptions); - } - } - private void updateByBatchInner(Map rows, WriteOptions options) throws Exception { try (WriteBatch batch = database.createWriteBatch()) { innerBatchUpdate(rows,batch); @@ -403,30 +422,23 @@ private void innerBatchUpdate(Map rows, WriteBatch batch) { @Override public void updateByBatch(Map rows, WriteOptionsWrapper options) { - resetDbLock.readLock().lock(); - try { - updateByBatchInner(rows, options.level); - } catch (Exception e) { - try { - updateByBatchInner(rows, options.level); - } catch (Exception e1) { - throw new RuntimeException(e); - } - } finally { - resetDbLock.readLock().unlock(); - } + this.updateByBatch(rows, options.level); } @Override public void updateByBatch(Map rows) { + this.updateByBatch(rows, writeOptions); + } + + private void updateByBatch(Map rows, WriteOptions options) { resetDbLock.readLock().lock(); try { - updateByBatchInner(rows); + updateByBatchInner(rows, options); } catch (Exception e) { try { - updateByBatchInner(rows); + updateByBatchInner(rows, options); } catch (Exception e1) { - throw new RuntimeException(e); + throw new RuntimeException(e1); } } finally { resetDbLock.readLock().unlock(); diff --git a/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java b/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java index 6c5d8018487..5267d72e1f6 100644 --- a/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java +++ b/chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java @@ -1,5 +1,6 @@ package org.tron.common.storage.rocksdb; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Sets; import com.google.common.primitives.Bytes; import java.io.File; @@ -20,10 +21,7 @@ import java.util.stream.Collectors; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.rocksdb.BlockBasedTableConfig; -import org.rocksdb.BloomFilter; import org.rocksdb.Checkpoint; -import org.rocksdb.DirectComparator; import org.rocksdb.InfoLogLevel; import org.rocksdb.Logger; import org.rocksdb.Options; @@ -31,7 +29,6 @@ import org.rocksdb.RocksDB; import org.rocksdb.RocksDBException; import org.rocksdb.RocksIterator; -import org.rocksdb.Statistics; import org.rocksdb.Status; import org.rocksdb.WriteBatch; import org.rocksdb.WriteOptions; @@ -52,36 +49,28 @@ public class RocksDbDataSourceImpl extends DbStat implements DbSourceInter, Iterable>, Instance { - ReadOptions readOpts; private String dataBaseName; private RocksDB database; + private Options options; private volatile boolean alive; private String parentPath; private ReadWriteLock resetDbLock = new ReentrantReadWriteLock(); private static final String KEY_ENGINE = "ENGINE"; private static final String ROCKSDB = "ROCKSDB"; - private DirectComparator comparator; private static final org.slf4j.Logger rocksDbLogger = LoggerFactory.getLogger(ROCKSDB); - public RocksDbDataSourceImpl(String parentPath, String name, RocksDbSettings settings, - DirectComparator comparator) { + public RocksDbDataSourceImpl(String parentPath, String name, Options options) { this.dataBaseName = name; this.parentPath = parentPath; - this.comparator = comparator; - RocksDbSettings.setRocksDbSettings(settings); - initDB(); - } - - public RocksDbDataSourceImpl(String parentPath, String name, RocksDbSettings settings) { - this.dataBaseName = name; - this.parentPath = parentPath; - RocksDbSettings.setRocksDbSettings(settings); + this.options = options; initDB(); } + @VisibleForTesting public RocksDbDataSourceImpl(String parentPath, String name) { this.parentPath = parentPath; this.dataBaseName = name; + this.options = RocksDbSettings.getOptionsByDbName(name); } public Path getDbPath() { @@ -124,40 +113,62 @@ public void resetDb() { } } - private boolean quitIfNotAlive() { + private void throwIfNotAlive() { if (!isAlive()) { - logger.warn("DB {} is not alive.", dataBaseName); + throw new org.iq80.leveldb.DBException("DB " + this.getDBName() + " is closed."); } - return !isAlive(); } + /** copy from {@link org.fusesource.leveldbjni.internal#checkArgNotNull} */ + private static void checkArgNotNull(Object value, String name) { + if (value == null) { + throw new IllegalArgumentException("The " + name + " argument cannot be null"); + } + } + + @Deprecated @Override public Set allKeys() throws RuntimeException { resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return null; - } + try (final RocksIterator iter = getRocksIterator()) { Set result = Sets.newHashSet(); - try (final RocksIterator iter = getRocksIterator()) { - for (iter.seekToFirst(); iter.isValid(); iter.next()) { - result.add(iter.key()); - } - return result; + for (iter.seekToFirst(); iter.isValid(); iter.next()) { + result.add(iter.key()); } + return result; } finally { resetDbLock.readLock().unlock(); } } + @Deprecated @Override public Set allValues() throws RuntimeException { - return null; + resetDbLock.readLock().lock(); + try (final RocksIterator iter = getRocksIterator()) { + Set result = Sets.newHashSet(); + for (iter.seekToFirst(); iter.isValid(); iter.next()) { + result.add(iter.value()); + } + return result; + } finally { + resetDbLock.readLock().unlock(); + } } + @Deprecated @Override public long getTotal() throws RuntimeException { - return 0; + resetDbLock.readLock().lock(); + try (final RocksIterator iter = getRocksIterator()) { + long total = 0; + for (iter.seekToFirst(); iter.isValid(); iter.next()) { + total++; + } + return total; + } finally { + resetDbLock.readLock().unlock(); + } } @Override @@ -167,12 +178,18 @@ public String getDBName() { @Override public void setDBName(String name) { + this.dataBaseName = name; } public boolean checkOrInitEngine() { String dir = getDbPath().toString(); String enginePath = dir + File.separator + "engine.properties"; - + File currentFile = new File(dir, "CURRENT"); + if (currentFile.exists() && !Paths.get(enginePath).toFile().exists()) { + // if the CURRENT file exists, but the engine.properties file does not exist, it is LevelDB + logger.error(" You are trying to open a LevelDB database with RocksDB engine."); + return false; + } if (FileUtil.createDirIfNotExists(dir)) { if (!FileUtil.createFileIfNotExists(enginePath)) { return false; @@ -196,10 +213,6 @@ public void initDB() { throw new RuntimeException( String.format("failed to check database: %s, engine do not match", dataBaseName)); } - initDB(RocksDbSettings.getSettings()); - } - - public void initDB(RocksDbSettings settings) { resetDbLock.writeLock().lock(); try { if (isAlive()) { @@ -208,81 +221,40 @@ public void initDB(RocksDbSettings settings) { if (dataBaseName == null) { throw new IllegalArgumentException("No name set to the dbStore"); } + options.setLogger(new Logger(options) { + @Override + protected void log(InfoLogLevel infoLogLevel, String logMsg) { + rocksDbLogger.info("{} {}", dataBaseName, logMsg); + } + }); - try (Options options = new Options()) { - - // most of these options are suggested by https://github.com/facebook/rocksdb/wiki/Set-Up-Options + try { + logger.debug("Opening database {}.", dataBaseName); + final Path dbPath = getDbPath(); - // general options - if (settings.isEnableStatistics()) { - options.setStatistics(new Statistics()); - options.setStatsDumpPeriodSec(60); - } - options.setCreateIfMissing(true); - options.setIncreaseParallelism(1); - options.setLevelCompactionDynamicLevelBytes(true); - options.setMaxOpenFiles(settings.getMaxOpenFiles()); - - // general options supported user config - options.setNumLevels(settings.getLevelNumber()); - options.setMaxBytesForLevelMultiplier(settings.getMaxBytesForLevelMultiplier()); - options.setMaxBytesForLevelBase(settings.getMaxBytesForLevelBase()); - options.setMaxBackgroundCompactions(settings.getCompactThreads()); - options.setLevel0FileNumCompactionTrigger(settings.getLevel0FileNumCompactionTrigger()); - options.setTargetFileSizeMultiplier(settings.getTargetFileSizeMultiplier()); - options.setTargetFileSizeBase(settings.getTargetFileSizeBase()); - if (comparator != null) { - options.setComparator(comparator); + if (!Files.isSymbolicLink(dbPath.getParent())) { + Files.createDirectories(dbPath.getParent()); } - options.setLogger(new Logger(options) { - @Override - protected void log(InfoLogLevel infoLogLevel, String logMsg) { - rocksDbLogger.info("{} {}", dataBaseName, logMsg); - } - }); - - // table options - final BlockBasedTableConfig tableCfg; - options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig()); - tableCfg.setBlockSize(settings.getBlockSize()); - tableCfg.setBlockCache(RocksDbSettings.getCache()); - tableCfg.setCacheIndexAndFilterBlocks(true); - tableCfg.setPinL0FilterAndIndexBlocksInCache(true); - tableCfg.setFilter(new BloomFilter(10, false)); - - // read options - readOpts = new ReadOptions(); - readOpts = readOpts.setPrefixSameAsStart(true) - .setVerifyChecksums(false); try { - logger.debug("Opening database {}.", dataBaseName); - final Path dbPath = getDbPath(); - - if (!Files.isSymbolicLink(dbPath.getParent())) { - Files.createDirectories(dbPath.getParent()); - } - - try { - database = RocksDB.open(options, dbPath.toString()); - } catch (RocksDBException e) { - if (Objects.equals(e.getStatus().getCode(), Status.Code.Corruption)) { - logger.error("Database {} corrupted, please delete database directory({}) " + - "and restart.", dataBaseName, parentPath, e); - } else { - logger.error("Open Database {} failed", dataBaseName, e); - } - System.exit(1); + database = RocksDB.open(options, dbPath.toString()); + } catch (RocksDBException e) { + if (Objects.equals(e.getStatus().getCode(), Status.Code.Corruption)) { + logger.error("Database {} corrupted, please delete database directory({}) " + + "and restart.", dataBaseName, parentPath, e); + } else { + logger.error("Open Database {} failed", dataBaseName, e); } - - alive = true; - } catch (IOException ioe) { - throw new RuntimeException( - String.format("failed to init database: %s", dataBaseName), ioe); + System.exit(1); } - logger.debug("Init DB {} done.", dataBaseName); + alive = true; + } catch (IOException ioe) { + throw new RuntimeException( + String.format("failed to init database: %s", dataBaseName), ioe); } + + logger.debug("Init DB {} done.", dataBaseName); } finally { resetDbLock.writeLock().unlock(); } @@ -292,9 +264,9 @@ protected void log(InfoLogLevel infoLogLevel, String logMsg) { public void putData(byte[] key, byte[] value) { resetDbLock.readLock().lock(); try { - if (quitIfNotAlive()) { - return; - } + throwIfNotAlive(); + checkArgNotNull(key, "key"); + checkArgNotNull(value, "value"); database.put(key, value); } catch (RocksDBException e) { throw new RuntimeException(dataBaseName, e); @@ -307,9 +279,8 @@ public void putData(byte[] key, byte[] value) { public byte[] getData(byte[] key) { resetDbLock.readLock().lock(); try { - if (quitIfNotAlive()) { - return null; - } + throwIfNotAlive(); + checkArgNotNull(key, "key"); return database.get(key); } catch (RocksDBException e) { throw new RuntimeException(dataBaseName, e); @@ -322,9 +293,8 @@ public byte[] getData(byte[] key) { public void deleteData(byte[] key) { resetDbLock.readLock().lock(); try { - if (quitIfNotAlive()) { - return; - } + throwIfNotAlive(); + checkArgNotNull(key, "key"); database.delete(key); } catch (RocksDBException e) { throw new RuntimeException(dataBaseName, e); @@ -343,69 +313,39 @@ public org.tron.core.db.common.iterator.DBIterator iterator() { return new RockStoreIterator(getRocksIterator()); } - private void updateByBatchInner(Map rows) throws Exception { - if (quitIfNotAlive()) { - return; - } - try (WriteBatch batch = new WriteBatch()) { - for (Map.Entry entry : rows.entrySet()) { - if (entry.getValue() == null) { - batch.delete(entry.getKey()); - } else { - batch.put(entry.getKey(), entry.getValue()); - } - } - database.write(new WriteOptions(), batch); - } - } - private void updateByBatchInner(Map rows, WriteOptions options) throws Exception { - if (quitIfNotAlive()) { - return; - } try (WriteBatch batch = new WriteBatch()) { for (Map.Entry entry : rows.entrySet()) { + checkArgNotNull(entry.getKey(), "key"); if (entry.getValue() == null) { batch.delete(entry.getKey()); } else { batch.put(entry.getKey(), entry.getValue()); } } + throwIfNotAlive(); database.write(options, batch); } } @Override public void updateByBatch(Map rows, WriteOptionsWrapper optionsWrapper) { - resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return; - } - updateByBatchInner(rows, optionsWrapper.rocks); - } catch (Exception e) { - try { - updateByBatchInner(rows); - } catch (Exception e1) { - throw new RuntimeException(dataBaseName, e1); - } - } finally { - resetDbLock.readLock().unlock(); - } + this.updateByBatch(rows, optionsWrapper.rocks); } @Override public void updateByBatch(Map rows) { + this.updateByBatch(rows, new WriteOptions()); + } + + private void updateByBatch(Map rows, WriteOptions options) { resetDbLock.readLock().lock(); try { - if (quitIfNotAlive()) { - return; - } - updateByBatchInner(rows); + updateByBatchInner(rows, options); } catch (Exception e) { try { - updateByBatchInner(rows); + updateByBatchInner(rows, options); } catch (Exception e1) { throw new RuntimeException(dataBaseName, e1); } @@ -415,45 +355,34 @@ public void updateByBatch(Map rows) { } public List getKeysNext(byte[] key, long limit) { + if (limit <= 0) { + return new ArrayList<>(); + } resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return new ArrayList<>(); - } - if (limit <= 0) { - return new ArrayList<>(); - } - - try (RocksIterator iter = getRocksIterator()) { - List result = new ArrayList<>(); - long i = 0; - for (iter.seek(key); iter.isValid() && i < limit; iter.next(), i++) { - result.add(iter.key()); - } - return result; + try (RocksIterator iter = getRocksIterator()) { + List result = new ArrayList<>(); + long i = 0; + for (iter.seek(key); iter.isValid() && i < limit; iter.next(), i++) { + result.add(iter.key()); } + return result; } finally { resetDbLock.readLock().unlock(); } } public Map getNext(byte[] key, long limit) { + if (limit <= 0) { + return Collections.emptyMap(); + } resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return null; - } - if (limit <= 0) { - return Collections.emptyMap(); - } - try (RocksIterator iter = getRocksIterator()) { - Map result = new HashMap<>(); - long i = 0; - for (iter.seek(key); iter.isValid() && i < limit; iter.next(), i++) { - result.put(iter.key(), iter.value()); - } - return result; + try (RocksIterator iter = getRocksIterator()) { + Map result = new HashMap<>(); + long i = 0; + for (iter.seek(key); iter.isValid() && i < limit; iter.next(), i++) { + result.put(iter.key(), iter.value()); } + return result; } finally { resetDbLock.readLock().unlock(); } @@ -462,78 +391,64 @@ public Map getNext(byte[] key, long limit) { @Override public Map prefixQuery(byte[] key) { resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return null; - } - try (RocksIterator iterator = getRocksIterator()) { - Map result = new HashMap<>(); - for (iterator.seek(key); iterator.isValid(); iterator.next()) { - if (Bytes.indexOf(iterator.key(), key) == 0) { - result.put(WrappedByteArray.of(iterator.key()), iterator.value()); - } else { - return result; - } + try (RocksIterator iterator = getRocksIterator()) { + Map result = new HashMap<>(); + for (iterator.seek(key); iterator.isValid(); iterator.next()) { + if (Bytes.indexOf(iterator.key(), key) == 0) { + result.put(WrappedByteArray.of(iterator.key()), iterator.value()); + } else { + return result; } - return result; } + return result; } finally { resetDbLock.readLock().unlock(); } } public Set getlatestValues(long limit) { + if (limit <= 0) { + return Sets.newHashSet(); + } resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return null; - } - if (limit <= 0) { - return Sets.newHashSet(); - } - try (RocksIterator iter = getRocksIterator()) { - Set result = Sets.newHashSet(); - long i = 0; - for (iter.seekToLast(); iter.isValid() && i < limit; iter.prev(), i++) { - result.add(iter.value()); - } - return result; + try (RocksIterator iter = getRocksIterator()) { + Set result = Sets.newHashSet(); + long i = 0; + for (iter.seekToLast(); iter.isValid() && i < limit; iter.prev(), i++) { + result.add(iter.value()); } + return result; } finally { resetDbLock.readLock().unlock(); } } - public Set getValuesNext(byte[] key, long limit) { + if (limit <= 0) { + return Sets.newHashSet(); + } resetDbLock.readLock().lock(); - try { - if (quitIfNotAlive()) { - return null; - } - if (limit <= 0) { - return Sets.newHashSet(); - } - try (RocksIterator iter = getRocksIterator()) { - Set result = Sets.newHashSet(); - long i = 0; - for (iter.seek(key); iter.isValid() && i < limit; iter.next(), i++) { - result.add(iter.value()); - } - return result; + try (RocksIterator iter = getRocksIterator()) { + Set result = Sets.newHashSet(); + long i = 0; + for (iter.seek(key); iter.isValid() && i < limit; iter.next(), i++) { + result.add(iter.value()); } + return result; } finally { resetDbLock.readLock().unlock(); } } public void backup(String dir) throws RocksDBException { + throwIfNotAlive(); Checkpoint cp = Checkpoint.create(database); cp.createCheckpoint(dir + this.getDBName()); } private RocksIterator getRocksIterator() { try ( ReadOptions readOptions = new ReadOptions().setFillCache(false)) { + throwIfNotAlive(); return database.newIterator(readOptions); } } @@ -544,7 +459,7 @@ public boolean deleteDbBakPath(String dir) { @Override public RocksDbDataSourceImpl newInstance() { - return new RocksDbDataSourceImpl(parentPath, dataBaseName, RocksDbSettings.getSettings()); + return new RocksDbDataSourceImpl(parentPath, dataBaseName, this.options); } diff --git a/chainbase/src/main/java/org/tron/common/utils/StorageUtils.java b/chainbase/src/main/java/org/tron/common/utils/StorageUtils.java index 16df43f1534..06a131a35cc 100644 --- a/chainbase/src/main/java/org/tron/common/utils/StorageUtils.java +++ b/chainbase/src/main/java/org/tron/common/utils/StorageUtils.java @@ -52,9 +52,15 @@ public static String getOutputDirectory() { } public static Options getOptionsByDbName(String dbName) { + Options options; if (hasProperty(dbName)) { - return getProperty(dbName).getDbOptions(); + options = getProperty(dbName).getDbOptions(); + } else { + options = CommonParameter.getInstance().getStorage().newDefaultDbOptions(dbName); } - return CommonParameter.getInstance().getStorage().newDefaultDbOptions(dbName); + if ("market_pair_price_to_order".equals(dbName)) { + options.comparator(new MarketOrderPriceComparatorForLevelDB()); + } + return options; } } diff --git a/chainbase/src/main/java/org/tron/core/db/TronDatabase.java b/chainbase/src/main/java/org/tron/core/db/TronDatabase.java index d791e189eb4..8630fbdcdff 100644 --- a/chainbase/src/main/java/org/tron/core/db/TronDatabase.java +++ b/chainbase/src/main/java/org/tron/core/db/TronDatabase.java @@ -9,9 +9,9 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.iq80.leveldb.WriteOptions; -import org.rocksdb.DirectComparator; import org.springframework.beans.factory.annotation.Autowired; import org.tron.common.parameter.CommonParameter; +import org.tron.common.storage.OptionsPicker; import org.tron.common.storage.WriteOptionsWrapper; import org.tron.common.storage.leveldb.LevelDbDataSourceImpl; import org.tron.common.storage.metric.DbStatService; @@ -24,7 +24,7 @@ import org.tron.core.exception.ItemNotFoundException; @Slf4j(topic = "DB") -public abstract class TronDatabase implements ITronChainBase { +public abstract class TronDatabase extends OptionsPicker implements ITronChainBase { protected DbSourceInter dbSource; @Getter @@ -51,8 +51,7 @@ protected TronDatabase(String dbName) { String parentName = Paths.get(StorageUtils.getOutputDirectoryByDbName(dbName), CommonParameter.getInstance().getStorage().getDbDirectory()).toString(); dbSource = - new RocksDbDataSourceImpl(parentName, dbName, CommonParameter.getInstance() - .getRocksDBCustomSettings(), getDirectComparator()); + new RocksDbDataSourceImpl(parentName, dbName, getOptionsByDbNameForRocksDB(dbName)); } dbSource.initDB(); @@ -66,14 +65,6 @@ protected void init() { protected TronDatabase() { } - protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) { - return StorageUtils.getOptionsByDbName(dbName); - } - - protected DirectComparator getDirectComparator() { - return null; - } - public DbSourceInter getDbSource() { return dbSource; } diff --git a/chainbase/src/main/java/org/tron/core/db/TronStoreWithRevoking.java b/chainbase/src/main/java/org/tron/core/db/TronStoreWithRevoking.java index 4b75ddee3a4..4952b70478d 100644 --- a/chainbase/src/main/java/org/tron/core/db/TronStoreWithRevoking.java +++ b/chainbase/src/main/java/org/tron/core/db/TronStoreWithRevoking.java @@ -16,9 +16,9 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.iq80.leveldb.WriteOptions; -import org.rocksdb.DirectComparator; import org.springframework.beans.factory.annotation.Autowired; import org.tron.common.parameter.CommonParameter; +import org.tron.common.storage.OptionsPicker; import org.tron.common.storage.leveldb.LevelDbDataSourceImpl; import org.tron.common.storage.metric.DbStatService; import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl; @@ -38,7 +38,7 @@ @Slf4j(topic = "DB") -public abstract class TronStoreWithRevoking implements ITronChainBase { +public abstract class TronStoreWithRevoking extends OptionsPicker implements ITronChainBase { @Getter // only for unit test protected IRevokingDB revokingDB; @@ -69,22 +69,13 @@ protected TronStoreWithRevoking(String dbName) { .getInstance().getStorage().getDbDirectory()).toString(); this.db = new RocksDB( new RocksDbDataSourceImpl(parentPath, - dbName, CommonParameter.getInstance() - .getRocksDBCustomSettings(), getDirectComparator())); + dbName, getOptionsByDbNameForRocksDB(dbName))); } else { throw new RuntimeException(String.format("db engine %s is error", dbEngine)); } this.revokingDB = new Chainbase(new SnapshotRoot(this.db)); } - protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) { - return StorageUtils.getOptionsByDbName(dbName); - } - - protected DirectComparator getDirectComparator() { - return null; - } - protected TronStoreWithRevoking(DB db) { this.db = db; this.revokingDB = new Chainbase(new SnapshotRoot(db)); diff --git a/chainbase/src/main/java/org/tron/core/db/common/iterator/RockStoreIterator.java b/chainbase/src/main/java/org/tron/core/db/common/iterator/RockStoreIterator.java index 541f71348af..b4fbd082083 100644 --- a/chainbase/src/main/java/org/tron/core/db/common/iterator/RockStoreIterator.java +++ b/chainbase/src/main/java/org/tron/core/db/common/iterator/RockStoreIterator.java @@ -79,6 +79,11 @@ public byte[] setValue(byte[] value) { }; } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + @Override public void seek(byte[] key) { checkState(); diff --git a/chainbase/src/main/java/org/tron/core/db/common/iterator/StoreIterator.java b/chainbase/src/main/java/org/tron/core/db/common/iterator/StoreIterator.java index d771716a7e8..bb4d2bb48e3 100755 --- a/chainbase/src/main/java/org/tron/core/db/common/iterator/StoreIterator.java +++ b/chainbase/src/main/java/org/tron/core/db/common/iterator/StoreIterator.java @@ -46,6 +46,11 @@ public boolean hasNext() { } } catch (Exception e) { logger.error(e.getMessage(), e); + try { + close(); + } catch (Exception e1) { + logger.error(e.getMessage(), e); + } } return hasNext; diff --git a/chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java b/chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java index 9d2409685c9..db9516d6203 100644 --- a/chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java +++ b/chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java @@ -35,6 +35,7 @@ import org.tron.common.parameter.CommonParameter; import org.tron.common.prometheus.MetricKeys; import org.tron.common.prometheus.Metrics; +import org.tron.common.storage.OptionsPicker; import org.tron.common.storage.leveldb.LevelDbDataSourceImpl; import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl; import org.tron.common.utils.ByteArray; @@ -48,7 +49,7 @@ import org.tron.core.store.DynamicPropertiesStore; @Slf4j(topic = "DB") -public class TxCacheDB implements DB, Flusher { +public class TxCacheDB extends OptionsPicker implements DB, Flusher { // > 65_536(= 2^16) blocks, that is the number of the reference block private static final long MAX_BLOCK_SIZE = 65536; @@ -106,7 +107,7 @@ public TxCacheDB(String name, RecentTransactionStore recentTransactionStore, if ("LEVELDB".equals(dbEngine.toUpperCase())) { this.persistentStore = new LevelDB( new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(name), - name, StorageUtils.getOptionsByDbName(name), + name, getOptionsByDbNameForLevelDB(name), new WriteOptions().sync(CommonParameter.getInstance() .getStorage().isDbSync()))); } else if ("ROCKSDB".equals(dbEngine.toUpperCase())) { @@ -115,9 +116,7 @@ public TxCacheDB(String name, RecentTransactionStore recentTransactionStore, .getInstance().getStorage().getDbDirectory()).toString(); this.persistentStore = new RocksDB( - new RocksDbDataSourceImpl(parentPath, - name, CommonParameter.getInstance() - .getRocksDBCustomSettings())); + new RocksDbDataSourceImpl(parentPath, name, getOptionsByDbNameForRocksDB(name))); } else { throw new RuntimeException(String.format("db type: %s is not supported", dbEngine)); } diff --git a/chainbase/src/main/java/org/tron/core/store/MarketPairPriceToOrderStore.java b/chainbase/src/main/java/org/tron/core/store/MarketPairPriceToOrderStore.java index 605952328ed..254f0d82673 100644 --- a/chainbase/src/main/java/org/tron/core/store/MarketPairPriceToOrderStore.java +++ b/chainbase/src/main/java/org/tron/core/store/MarketPairPriceToOrderStore.java @@ -3,16 +3,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.iq80.leveldb.Options; -import org.rocksdb.ComparatorOptions; -import org.rocksdb.DirectComparator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.tron.common.utils.ByteUtil; -import org.tron.common.utils.MarketOrderPriceComparatorForLevelDB; -import org.tron.common.utils.MarketOrderPriceComparatorForRockDB; -import org.tron.common.utils.StorageUtils; import org.tron.core.capsule.MarketOrderIdListCapsule; import org.tron.core.capsule.utils.MarketUtils; import org.tron.core.db.TronStoreWithRevoking; @@ -26,20 +20,6 @@ protected MarketPairPriceToOrderStore(@Value("market_pair_price_to_order") Strin super(dbName); } - @Override - protected Options getOptionsByDbNameForLevelDB(String dbName) { - Options options = StorageUtils.getOptionsByDbName(dbName); - options.comparator(new MarketOrderPriceComparatorForLevelDB()); - return options; - } - - //todo: to test later - @Override - protected DirectComparator getDirectComparator() { - ComparatorOptions comparatorOptions = new ComparatorOptions(); - return new MarketOrderPriceComparatorForRockDB(comparatorOptions); - } - @Override public MarketOrderIdListCapsule get(byte[] key) throws ItemNotFoundException { byte[] value = revokingDB.get(key); diff --git a/common/build.gradle b/common/build.gradle index efd966897a4..593c9d1396f 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -6,46 +6,24 @@ version '1.0.0' sourceCompatibility = 1.8 -// Dependency versions -// --------------------------------------- -def leveldbVersion = "1.8" -// -------------------------------------- - -static def isWindows() { - return org.gradle.internal.os.OperatingSystem.current().isWindows() -} - -if (isWindows()) { - ext { - leveldbGroup = "org.ethereum" - leveldbName = "leveldbjni-all" - leveldbVersion = "1.18.3" - } -} else { - ext { - leveldbGroup = "org.fusesource.leveldbjni" - leveldbName = "leveldbjni-all" - leveldbVersion = "1.8" - } -} dependencies { api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.4.2' // https://github.com/FasterXML/jackson-databind/issues/3627 api "com.cedarsoftware:java-util:1.8.0" api group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.1' api group: 'commons-codec', name: 'commons-codec', version: '1.11' - api group: 'com.beust', name: 'jcommander', version: '1.72' + api group: 'com.beust', name: 'jcommander', version: '1.78' api group: 'com.typesafe', name: 'config', version: '1.3.2' - api group: leveldbGroup, name: leveldbName, version: leveldbVersion - api group: 'org.rocksdb', name: 'rocksdbjni', version: '5.15.10' // https://mvnrepository.com/artifact/org.quartz-scheduler/quartz api group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2' api group: 'io.prometheus', name: 'simpleclient', version: '0.15.0' api group: 'io.prometheus', name: 'simpleclient_httpserver', version: '0.15.0' api group: 'io.prometheus', name: 'simpleclient_hotspot', version: '0.15.0' - api 'org.aspectj:aspectjrt:1.8.13' - api 'org.aspectj:aspectjweaver:1.8.13' - api 'org.aspectj:aspectjtools:1.8.13' + // https://openjdk.org/jeps/396, JEP 396: Strongly Encapsulate JDK Internals by Default + // https://eclipse.dev/aspectj/doc/latest/release/JavaVersionCompatibility.html + api 'org.aspectj:aspectjrt:1.9.8' + api 'org.aspectj:aspectjweaver:1.9.8' + api 'org.aspectj:aspectjtools:1.9.8' api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.4',{ exclude group: 'io.grpc', module: 'grpc-context' exclude group: 'io.grpc', module: 'grpc-core' @@ -62,6 +40,7 @@ dependencies { exclude group: 'xpp3', module: 'xpp3' } api project(":protocol") + api project(":platform") } jacocoTestReport { diff --git a/common/src/main/java/org/tron/common/arch/Arch.java b/common/src/main/java/org/tron/common/arch/Arch.java new file mode 100644 index 00000000000..1a598c3cb4f --- /dev/null +++ b/common/src/main/java/org/tron/common/arch/Arch.java @@ -0,0 +1,101 @@ +package org.tron.common.arch; + +public class Arch { + + private final StringBuilder info = new StringBuilder(); + + public static Arch builder() { + return new Arch(); + } + + public String build() { + return info.toString(); + } + + public Arch withOsName() { + info.append("os.name").append(": ").append(getOsName()).append("\n"); + return this; + } + + public Arch withOsArch() { + info.append("os.arch").append(": ").append(getOsArch()).append("\n"); + return this; + } + + public Arch withBitModel() { + info.append("bit.model").append(": ").append(getBitModel()).append("\n"); + return this; + } + + public Arch withJavaVersion() { + info.append("java.version").append(": ").append(javaVersion()).append("\n"); + return this; + } + + public Arch withJavaSpecificationVersion() { + info.append("java.specification.version").append(": ").append(javaSpecificationVersion()) + .append("\n"); + return this; + } + + public Arch withJavaVendor() { + info.append("java.vendor").append(": ").append(javaVendor()).append("\n"); + return this; + } + + public static Arch withAll() { + return Arch.builder() + .withOsName() + .withOsArch() + .withBitModel() + .withJavaVersion() + .withJavaSpecificationVersion() + .withJavaVendor(); + } + + public static String getOsName() { + return System.getProperty("os.name").toLowerCase().trim(); + + } + public static String getOsArch() { + return System.getProperty("os.arch").toLowerCase().trim(); + } + + public static int getBitModel() { + String prop = System.getProperty("sun.arch.data.model"); + if (prop == null) { + prop = System.getProperty("com.ibm.vm.bitmode"); + } + if (prop != null) { + return Integer.parseInt(prop); + } + // GraalVM support, see https://github.com/fusesource/jansi/issues/162 + String arch = System.getProperty("os.arch"); + if (arch.endsWith("64") && "Substrate VM".equals(System.getProperty("java.vm.name"))) { + return 64; + } + return -1; // we don't know... + } + + public static String javaVersion() { + return System.getProperty("java.version").toLowerCase().trim(); + } + + public static String javaSpecificationVersion() { + return System.getProperty("java.specification.version").toLowerCase().trim(); + } + + public static String javaVendor() { + return System.getProperty("java.vendor").toLowerCase().trim(); + } + + public static boolean isArm64() { + String osArch = getOsArch(); + return osArch.contains("arm64") || osArch.contains("aarch64"); + } + + @Override + public String toString() { + return info.toString(); + } +} diff --git a/common/src/main/java/org/tron/common/parameter/CommonParameter.java b/common/src/main/java/org/tron/common/parameter/CommonParameter.java index 1aa3befe8aa..72cdf209787 100644 --- a/common/src/main/java/org/tron/common/parameter/CommonParameter.java +++ b/common/src/main/java/org/tron/common/parameter/CommonParameter.java @@ -199,7 +199,20 @@ public class CommonParameter { //If you are running a solidity node for java tron, this flag is set to true @Getter @Setter + @Parameter(names = {"--solidity"}, description = "running a solidity node for java tron") public boolean solidityNode = false; + //If you are running KeystoreFactory, this flag is set to true + @Getter + @Setter + @Parameter(names = {"--keystore"}, description = "running KeystoreFactory") + public boolean keystore = false; + + //If you are running leveldb to rocksdb convert tool, this flag is set to true + @Getter + @Setter + @Parameter(names = {"--db-convert"}, description = "running leveldb to rocksdb convert") + public boolean dbConvert = false; + @Getter @Setter public int rpcPort; @@ -456,12 +469,30 @@ public class CommonParameter { @Getter @Setter public String cryptoEngine = Constant.ECKey_ENGINE; + + @Getter + @Setter + public boolean rpcEnable = true; + + @Getter + @Setter + public boolean rpcSolidityEnable = true; + + @Getter + @Setter + public boolean rpcPBFTEnable = true; + @Getter @Setter public boolean fullNodeHttpEnable = true; @Getter @Setter public boolean solidityNodeHttpEnable = true; + + @Getter + @Setter + public boolean pBFTHttpEnable = true; + @Getter @Setter public boolean jsonRpcHttpFullNodeEnable = false; diff --git a/common/src/main/java/org/tron/common/setting/RocksDbSettings.java b/common/src/main/java/org/tron/common/setting/RocksDbSettings.java index 7436150cae2..bceb65ef019 100644 --- a/common/src/main/java/org/tron/common/setting/RocksDbSettings.java +++ b/common/src/main/java/org/tron/common/setting/RocksDbSettings.java @@ -1,16 +1,21 @@ package org.tron.common.setting; +import com.google.common.base.Preconditions; +import java.util.Objects; import lombok.Getter; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; +import org.rocksdb.BlockBasedTableConfig; +import org.rocksdb.BloomFilter; +import org.rocksdb.ComparatorOptions; import org.rocksdb.LRUCache; +import org.rocksdb.Options; import org.rocksdb.RocksDB; +import org.rocksdb.Statistics; +import org.tron.common.utils.MarketOrderPriceComparatorForRocksDB; @Slf4j public class RocksDbSettings { - @Setter - @Getter private static RocksDbSettings rocksDbSettings; @Getter @@ -60,9 +65,9 @@ public static RocksDbSettings initCustomSettings(int levelNumber, int compactThr int blockSize, long maxBytesForLevelBase, double maxBytesForLevelMultiplier, int level0FileNumCompactionTrigger, long targetFileSizeBase, - int targetFileSizeMultiplier) { + int targetFileSizeMultiplier, int maxOpenFiles) { rocksDbSettings = new RocksDbSettings() - .withMaxOpenFiles(5000) + .withMaxOpenFiles(maxOpenFiles) .withEnableStatistics(false) .withLevelNumber(levelNumber) .withCompactThreads(compactThreads) @@ -76,16 +81,17 @@ public static RocksDbSettings initCustomSettings(int levelNumber, int compactThr } public static void loggingSettings() { - logger.info(String.format( - "level number: %d, CompactThreads: %d, Blocksize: %d, maxBytesForLevelBase: %d," - + " withMaxBytesForLevelMultiplier: %f, level0FileNumCompactionTrigger: %d, " - + "withTargetFileSizeBase: %d, withTargetFileSizeMultiplier: %d", + logger.info( + "level number: {}, CompactThreads: {}, Blocksize:{}, maxBytesForLevelBase: {}," + + " withMaxBytesForLevelMultiplier: {}, level0FileNumCompactionTrigger: {}, " + + "withTargetFileSizeBase: {}, withTargetFileSizeMultiplier: {}, maxOpenFiles: {}", rocksDbSettings.getLevelNumber(), rocksDbSettings.getCompactThreads(), rocksDbSettings.getBlockSize(), rocksDbSettings.getMaxBytesForLevelBase(), rocksDbSettings.getMaxBytesForLevelMultiplier(), rocksDbSettings.getLevel0FileNumCompactionTrigger(), - rocksDbSettings.getTargetFileSizeBase(), rocksDbSettings.getTargetFileSizeMultiplier())); + rocksDbSettings.getTargetFileSizeBase(), rocksDbSettings.getTargetFileSizeMultiplier(), + rocksDbSettings.getMaxOpenFiles()); } public RocksDbSettings withMaxOpenFiles(int maxOpenFiles) { @@ -140,4 +146,46 @@ public RocksDbSettings withTargetFileSizeMultiplier(int targetFileSizeMultiplier public static LRUCache getCache() { return cache; } + + public static Options getOptionsByDbName(String dbName) { + RocksDbSettings settings = getSettings(); + + Options options = new Options(); + + // most of these options are suggested by https://github.com/facebook/rocksdb/wiki/Set-Up-Options + + // general options + if (settings.isEnableStatistics()) { + options.setStatistics(new Statistics()); + options.setStatsDumpPeriodSec(60); + } + options.setCreateIfMissing(true); + options.setIncreaseParallelism(1); + options.setLevelCompactionDynamicLevelBytes(true); + options.setMaxOpenFiles(settings.getMaxOpenFiles()); + + // general options supported user config + options.setNumLevels(settings.getLevelNumber()); + options.setMaxBytesForLevelMultiplier(settings.getMaxBytesForLevelMultiplier()); + options.setMaxBytesForLevelBase(settings.getMaxBytesForLevelBase()); + options.setMaxBackgroundCompactions(settings.getCompactThreads()); + options.setLevel0FileNumCompactionTrigger(settings.getLevel0FileNumCompactionTrigger()); + options.setTargetFileSizeMultiplier(settings.getTargetFileSizeMultiplier()); + options.setTargetFileSizeBase(settings.getTargetFileSizeBase()); + + // table options + final BlockBasedTableConfig tableCfg; + options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig()); + tableCfg.setBlockSize(settings.getBlockSize()); + tableCfg.setBlockCache(RocksDbSettings.getCache()); + tableCfg.setCacheIndexAndFilterBlocks(true); + tableCfg.setPinL0FilterAndIndexBlocksInCache(true); + tableCfg.setFilter(new BloomFilter(10, false)); + if ("market_pair_price_to_order".equals(dbName)) { + ComparatorOptions comparatorOptions = new ComparatorOptions(); + options.setComparator(new MarketOrderPriceComparatorForRocksDB(comparatorOptions)); + } + + return options; + } } diff --git a/common/src/main/java/org/tron/core/Constant.java b/common/src/main/java/org/tron/core/Constant.java index 96ff41b91da..de40b332a17 100644 --- a/common/src/main/java/org/tron/core/Constant.java +++ b/common/src/main/java/org/tron/core/Constant.java @@ -124,15 +124,21 @@ public class Constant { public static final String NODE_DNS_AWS_REGION = "node.dns.awsRegion"; public static final String NODE_DNS_AWS_HOST_ZONE_ID = "node.dns.awsHostZoneId"; + // config for rpc public static final String NODE_RPC_PORT = "node.rpc.port"; public static final String NODE_RPC_SOLIDITY_PORT = "node.rpc.solidityPort"; public static final String NODE_RPC_PBFT_PORT = "node.rpc.PBFTPort"; + public static final String NODE_RPC_ENABLE = "node.rpc.enable"; + public static final String NODE_RPC_SOLIDITY_ENABLE = "node.rpc.solidityEnable"; + public static final String NODE_RPC_PBFT_ENABLE = "node.rpc.PBFTEnable"; + // config for http public static final String NODE_HTTP_FULLNODE_PORT = "node.http.fullNodePort"; public static final String NODE_HTTP_SOLIDITY_PORT = "node.http.solidityPort"; public static final String NODE_HTTP_FULLNODE_ENABLE = "node.http.fullNodeEnable"; public static final String NODE_HTTP_SOLIDITY_ENABLE = "node.http.solidityEnable"; + public static final String NODE_HTTP_PBFT_ENABLE = "node.http.PBFTEnable"; public static final String NODE_HTTP_PBFT_PORT = "node.http.PBFTPort"; - + // config for jsonrpc public static final String NODE_JSONRPC_HTTP_FULLNODE_ENABLE = "node.jsonrpc.httpFullNodeEnable"; public static final String NODE_JSONRPC_HTTP_FULLNODE_PORT = "node.jsonrpc.httpFullNodePort"; public static final String NODE_JSONRPC_HTTP_SOLIDITY_ENABLE = "node.jsonrpc.httpSolidityEnable"; diff --git a/common/src/main/java/org/tron/core/config/args/Storage.java b/common/src/main/java/org/tron/core/config/args/Storage.java index 9cf6eb6bab1..956c0fcc68b 100644 --- a/common/src/main/java/org/tron/core/config/args/Storage.java +++ b/common/src/main/java/org/tron/core/config/args/Storage.java @@ -25,9 +25,11 @@ import java.util.stream.Collectors; import lombok.Getter; import lombok.Setter; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.iq80.leveldb.CompressionType; import org.iq80.leveldb.Options; +import org.tron.common.arch.Arch; import org.tron.common.cache.CacheStrategies; import org.tron.common.cache.CacheType; import org.tron.common.utils.DbOptionalsUtils; @@ -42,6 +44,7 @@ * @version 1.0 * @since 2018/5/25 */ +@Slf4j(topic = "db") public class Storage { /** @@ -87,6 +90,7 @@ public class Storage { * Default values of directory */ private static final String DEFAULT_DB_ENGINE = "LEVELDB"; + private static final String ROCKS_DB_ENGINE = "ROCKSDB"; private static final boolean DEFAULT_DB_SYNC = false; private static final boolean DEFAULT_EVENT_SUBSCRIBE_CONTRACT_PARSE = true; private static final String DEFAULT_DB_DIRECTORY = "database"; @@ -171,6 +175,10 @@ public class Storage { private final Map dbRoots = Maps.newConcurrentMap(); public static String getDbEngineFromConfig(final Config config) { + if (Arch.isArm64() && !System.getenv().containsKey("CI")) { + logger.info("Arm64 architecture detected, using RocksDB as db engine, ignore config."); + return ROCKS_DB_ENGINE; + } return config.hasPath(DB_ENGINE_CONFIG_KEY) ? config.getString(DB_ENGINE_CONFIG_KEY) : DEFAULT_DB_ENGINE; } diff --git a/framework/build.gradle b/framework/build.gradle index ec113c93cb1..91956a9c702 100644 --- a/framework/build.gradle +++ b/framework/build.gradle @@ -8,6 +8,7 @@ gitProperties.failOnNoGitDirectory = false; apply plugin: 'application' apply plugin: 'checkstyle' +apply plugin: 'com.github.johnrengelman.shadow' mainClassName = 'org.tron.program.FullNode' @@ -15,9 +16,6 @@ def versions = [ checkstyle: '8.7', ] -jacoco { - toolVersion = "0.8.1" -} configurations { @@ -25,7 +23,7 @@ configurations { } -configurations.getByName('checkstyleConfig') { +configurations.named('checkstyleConfig') { transitive = false } @@ -33,7 +31,7 @@ static def isWindows() { return org.gradle.internal.os.OperatingSystem.current().isWindows() } -task version(type: Exec) { +tasks.register('version', Exec) { commandLine 'bash', '-c', '../ver.sh' } @@ -42,12 +40,15 @@ dependencies { implementation fileTree(dir: 'libs', include: '*.jar') // end local libraries testImplementation group: 'org.hamcrest', name: 'hamcrest-junit', version: '1.0.0.1' + // https://github.com/stefanbirkner/system-rules/issues/85 + // https://openjdk.org/jeps/411, JEP 411: Deprecate the Security Manager for Removal from JDK17 + // WARNING: A terminally deprecated method in java.lang.System has been called + // WARNING: System::setSecurityManager will be removed in a future release testImplementation group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.16.0' implementation group: 'com.google.inject', name: 'guice', version: '4.1.0' implementation group: 'io.dropwizard.metrics', name: 'metrics-core', version: '3.1.2' implementation group: 'com.github.davidb', name: 'metrics-influxdb', version: '0.8.2' - implementation group: 'com.carrotsearch', name: 'java-sizeof', version: '0.0.5' // http implementation 'org.eclipse.jetty:jetty-server:9.4.53.v20231009' implementation 'org.eclipse.jetty:jetty-servlet:9.4.53.v20231009' @@ -61,7 +62,9 @@ dependencies { compileOnly group: 'javax.portlet', name: 'portlet-api', version: '3.0.1' implementation "io.vavr:vavr:0.9.2" - implementation group: 'org.pf4j', name: 'pf4j', version: '2.5.0' + implementation group: 'org.pf4j', name: 'pf4j', version: '3.10.0',{ + exclude group: 'org.slf4j', module: 'slf4j-api' + } testImplementation group: 'org.springframework', name: 'spring-test', version: '5.2.0.RELEASE' testImplementation group: 'org.springframework', name: 'spring-web', version: '5.2.0.RELEASE' @@ -85,7 +88,7 @@ checkstyleMain { source = 'src/main/java' } -task lint(type: Checkstyle) { +tasks.register('lint', Checkstyle) { // Cleaning the old log because of the creation of the new ones (not sure if totaly needed) delete fileTree(dir: "${project.rootDir}/app/build/reports") source 'src' @@ -98,7 +101,7 @@ task lint(type: Checkstyle) { ignoreFailures = false } -tasks.matching { it instanceof Test }.all { +tasks.matching { it instanceof Test }.configureEach { testLogging.events = ["failed", "passed", "skipped"] } @@ -150,33 +153,6 @@ jacocoTestReport { getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec")) } -def binaryRelease(taskName, jarName, mainClass) { - return tasks.create("${taskName}", Jar) { - baseName = jarName - version = null - from(sourceSets.main.output) { - include "/**" - } - - from { - configurations.runtimeClasspath.collect { - it.isDirectory() ? it : zipTree(it) - } - } - - // exclude these files for bouncycastle - exclude "META-INF/*.SF" - exclude "META-INF/*.DSA" - exclude "META-INF/*.RSA" - - manifest { - attributes "Main-Class": "${mainClass}" - } - -// classifier(jarName) - } -} - def createScript(project, mainClass, name) { project.tasks.create(name: name, type: CreateStartScripts) { unixStartScriptGenerator.template = resources.text.fromFile('../gradle/unixStartScript.txt') @@ -202,9 +178,14 @@ def createScript(project, mainClass, name) { } } } - -applicationDistribution.from("../gradle/java-tron.vmoptions") { - into "bin" +if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + applicationDistribution.from("${project.rootDir}/gradle/jdk17/java-tron.vmoptions") { + into "bin" + } +} else { + applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") { + into "bin" + } } //distZip { // doLast { @@ -217,38 +198,27 @@ startScripts.enabled = false run.enabled = false tasks.distTar.enabled = false -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') - -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 skipAll = hasProperty('skipAll') ? true : false -if (releaseBinary == 'true') { - artifacts { - archives(binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode')) - } - if (!skipAll) { - if (!skipSolidity) { - artifacts { - archives(binaryRelease('buildSolidityNodeJar', 'SolidityNode', 'org.tron.program.SolidityNode'))} - } - if (!skipKeystore) { - artifacts { - archives(binaryRelease('buildKeystoreFactoryJar', 'KeystoreFactory', 'org.tron.program.KeystoreFactory'))} - } - if (!skipConvert) { - artifacts { - archives(binaryRelease('buildDBConvertJar', 'DBConvert', 'org.tron.program.DBConvert'))} - } - } +shadowJar { + baseName = 'FullNode' + classifier = null + version = null + // exclude these files for bouncycastle + exclude "META-INF/*.SF" + exclude "META-INF/*.DSA" + exclude "META-INF/*.RSA" + mergeServiceFiles() // https://github.com/grpc/grpc-java/issues/10853 +} +shadowDistZip { + enabled = false +} + +startShadowScripts { + enabled = false } -task copyToParent(type: Copy) { +tasks.register('copyToParent', Copy) { into "../build/distributions" from "$buildDir/distributions" include "*.zip" diff --git a/framework/src/main/java/org/tron/common/application/AbstractService.java b/framework/src/main/java/org/tron/common/application/AbstractService.java new file mode 100644 index 00000000000..79c25dc4944 --- /dev/null +++ b/framework/src/main/java/org/tron/common/application/AbstractService.java @@ -0,0 +1,73 @@ +package org.tron.common.application; + +import com.google.common.base.Objects; +import java.util.concurrent.CompletableFuture; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.tron.core.config.args.Args; + + +@Slf4j(topic = "service") +public abstract class AbstractService implements Service { + + protected int port; + @Getter + protected boolean enable; + @Getter + protected final String name = this.getClass().getSimpleName(); + + + @Override + public CompletableFuture start() { + logger.info("{} starting on {}", name, port); + final CompletableFuture resultFuture = new CompletableFuture<>(); + try { + innerStart(); + resultFuture.complete(true); + logger.info("{} started, listening on {}", name, port); + } catch (Exception e) { + resultFuture.completeExceptionally(e); + } + return resultFuture; + } + + @Override + public CompletableFuture stop() { + logger.info("{} shutdown...", name); + final CompletableFuture resultFuture = new CompletableFuture<>(); + try { + innerStop(); + resultFuture.complete(true); + logger.info("{} shutdown complete", name); + } catch (Exception e) { + resultFuture.completeExceptionally(e); + } + return resultFuture; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AbstractService that = (AbstractService) o; + return port == that.port; + } + + @Override + public int hashCode() { + return Objects.hashCode(name, port); + } + + public abstract void innerStart() throws Exception; + + public abstract void innerStop() throws Exception; + + protected boolean isFullNode() { + return !Args.getInstance().isSolidityNode(); + } + +} diff --git a/framework/src/main/java/org/tron/common/application/ApplicationImpl.java b/framework/src/main/java/org/tron/common/application/ApplicationImpl.java index 3cb75cb1e24..28108adfa88 100644 --- a/framework/src/main/java/org/tron/common/application/ApplicationImpl.java +++ b/framework/src/main/java/org/tron/common/application/ApplicationImpl.java @@ -1,5 +1,6 @@ package org.tron.common.application; +import java.util.concurrent.CountDownLatch; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -15,6 +16,7 @@ @Component public class ApplicationImpl implements Application { + @Autowired private ServiceContainer services; @Autowired @@ -29,6 +31,8 @@ public class ApplicationImpl implements Application { @Autowired private ConsensusService consensusService; + private final CountDownLatch shutdown = new CountDownLatch(1); + @Override public void setOptions(Args args) { // not used @@ -37,24 +41,23 @@ public void setOptions(Args args) { @Override @Autowired public void init(CommonParameter parameter) { - services = new ServiceContainer(); + // not used } @Override public void addService(Service service) { - services.add(service); + // used by test } @Override public void initServices(CommonParameter parameter) { - services.init(parameter); + // not used } /** * start up the app. */ public void startup() { - this.initServices(Args.getInstance()); this.startServices(); if ((!Args.getInstance().isSolidityNode()) && (!Args.getInstance().isP2pDisable())) { tronNetService.start(); @@ -71,16 +74,27 @@ public void shutdown() { tronNetService.close(); } dbManager.close(); + shutdown.countDown(); } @Override public void startServices() { - services.start(); + try { + services.start(); + } catch (Exception e) { + logger.error("Failed to start services", e); + System.exit(1); + } } @Override public void blockUntilShutdown() { - services.blockUntilShutdown(); + try { + shutdown.await(); + } catch (final InterruptedException e) { + logger.debug("Interrupted, exiting", e); + Thread.currentThread().interrupt(); + } } @Override diff --git a/framework/src/main/java/org/tron/common/application/HttpService.java b/framework/src/main/java/org/tron/common/application/HttpService.java index 76f8e74d65c..e9a902002ba 100644 --- a/framework/src/main/java/org/tron/common/application/HttpService.java +++ b/framework/src/main/java/org/tron/common/application/HttpService.java @@ -15,67 +15,61 @@ package org.tron.common.application; -import com.google.common.base.Objects; +import java.util.concurrent.CompletableFuture; import lombok.extern.slf4j.Slf4j; +import org.eclipse.jetty.server.ConnectionLimit; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.tron.core.config.args.Args; @Slf4j(topic = "rpc") -public abstract class HttpService implements Service { +public abstract class HttpService extends AbstractService { protected Server apiServer; - protected int port; + + protected String contextPath; @Override - public void blockUntilShutdown() { - if (apiServer != null) { - try { - apiServer.join(); - } catch (InterruptedException e) { - logger.warn("{}", e.getMessage()); - Thread.currentThread().interrupt(); - } + public void innerStart() throws Exception { + if (this.apiServer != null) { + this.apiServer.start(); } } @Override - public void start() { - if (apiServer != null) { - try { - apiServer.start(); - logger.info("{} started, listening on {}", this.getClass().getSimpleName(), port); - } catch (Exception e) { - logger.error("{}", this.getClass().getSimpleName(), e); - } + public void innerStop() throws Exception { + if (this.apiServer != null) { + this.apiServer.stop(); } } @Override - public void stop() { - if (apiServer != null) { - logger.info("{} shutdown...", this.getClass().getSimpleName()); - try { - apiServer.stop(); - } catch (Exception e) { - logger.warn("{}", this.getClass().getSimpleName(), e); - } - logger.info("{} shutdown complete", this.getClass().getSimpleName()); - } + public CompletableFuture start() { + initServer(); + ServletContextHandler context = initContextHandler(); + addServlet(context); + addFilter(context); + return super.start(); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + protected void initServer() { + this.apiServer = new Server(this.port); + int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); + if (maxHttpConnectNumber > 0) { + this.apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, this.apiServer)); } - if (o == null || getClass() != o.getClass()) { - return false; - } - HttpService that = (HttpService) o; - return port == that.port; } - @Override - public int hashCode() { - return Objects.hashCode(getClass().getSimpleName(), port); + protected ServletContextHandler initContextHandler() { + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); + context.setContextPath(this.contextPath); + this.apiServer.setHandler(context); + return context; + } + + protected abstract void addServlet(ServletContextHandler context); + + protected void addFilter(ServletContextHandler context) { + } } diff --git a/framework/src/main/java/org/tron/common/application/RpcService.java b/framework/src/main/java/org/tron/common/application/RpcService.java index cb89441174a..2d118806e2c 100644 --- a/framework/src/main/java/org/tron/common/application/RpcService.java +++ b/framework/src/main/java/org/tron/common/application/RpcService.java @@ -15,71 +15,106 @@ package org.tron.common.application; -import com.google.common.base.Objects; import io.grpc.Server; -import java.io.IOException; +import io.grpc.netty.NettyServerBuilder; +import io.grpc.protobuf.services.ProtoReflectionService; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.tron.common.es.ExecutorServiceManager; +import org.tron.common.parameter.CommonParameter; +import org.tron.core.config.args.Args; +import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; +import org.tron.core.services.ratelimiter.PrometheusInterceptor; +import org.tron.core.services.ratelimiter.RateLimiterInterceptor; +import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; @Slf4j(topic = "rpc") -public abstract class RpcService implements Service { +public abstract class RpcService extends AbstractService { - protected Server apiServer; - protected int port; + private Server apiServer; + protected String executorName; + + @Autowired + private RateLimiterInterceptor rateLimiterInterceptor; + + @Autowired + private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; + + @Autowired + private RpcApiAccessInterceptor apiAccessInterceptor; + + @Autowired + private PrometheusInterceptor prometheusInterceptor; @Override - public void blockUntilShutdown() { - if (apiServer != null) { - try { - apiServer.awaitTermination(); - } catch (InterruptedException e) { - logger.warn("{}", e.getMessage()); - Thread.currentThread().interrupt(); - } + public void innerStart() throws Exception { + if (this.apiServer != null) { + this.apiServer.start(); } } @Override - public void start() { - if (apiServer != null) { - try { - apiServer.start(); - logger.info("{} started, listening on {}", this.getClass().getSimpleName(), port); - } catch (IOException e) { - logger.error("{}", this.getClass().getSimpleName(), e); - } + public void innerStop() throws Exception { + if (this.apiServer != null) { + this.apiServer.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } @Override - public void stop() { - if (apiServer != null) { - logger.info("{} shutdown...", this.getClass().getSimpleName()); - try { - apiServer.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - logger.warn("{}", this.getClass().getSimpleName(), e); - } - logger.info("{} shutdown complete", this.getClass().getSimpleName()); - } + public CompletableFuture start() { + NettyServerBuilder serverBuilder = initServerBuilder(); + addService(serverBuilder); + addInterceptor(serverBuilder); + initServer(serverBuilder); + this.rateLimiterInterceptor.init(this.apiServer); + return super.start(); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + protected NettyServerBuilder initServerBuilder() { + NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(this.port); + CommonParameter parameter = Args.getInstance(); + if (parameter.getRpcThreadNum() > 0) { + serverBuilder = serverBuilder + .executor(ExecutorServiceManager.newFixedThreadPool( + this.executorName, parameter.getRpcThreadNum())); } - if (o == null || getClass() != o.getClass()) { - return false; + // Set configs from config.conf or default value + serverBuilder + .maxConcurrentCallsPerConnection(parameter.getMaxConcurrentCallsPerConnection()) + .flowControlWindow(parameter.getFlowControlWindow()) + .maxConnectionIdle(parameter.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) + .maxConnectionAge(parameter.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) + .maxInboundMessageSize(parameter.getMaxMessageSize()) + .maxHeaderListSize(parameter.getMaxHeaderListSize()); + + if (parameter.isRpcReflectionServiceEnable()) { + serverBuilder.addService(ProtoReflectionService.newInstance()); } - RpcService that = (RpcService) o; - return port == that.port; + return serverBuilder; } - @Override - public int hashCode() { - return Objects.hashCode(getClass().getSimpleName(), port); + protected abstract void addService(NettyServerBuilder serverBuilder); + + protected void addInterceptor(NettyServerBuilder serverBuilder) { + // add a ratelimiter interceptor + serverBuilder.intercept(this.rateLimiterInterceptor); + + // add api access interceptor + serverBuilder.intercept(this.apiAccessInterceptor); + + // add lite fullnode query interceptor + serverBuilder.intercept(this.liteFnQueryGrpcInterceptor); + + // add prometheus interceptor + if (Args.getInstance().isMetricsPrometheusEnable()) { + serverBuilder.intercept(prometheusInterceptor); + } + } + + protected void initServer(NettyServerBuilder serverBuilder) { + this.apiServer = serverBuilder.build(); } } diff --git a/framework/src/main/java/org/tron/common/application/Service.java b/framework/src/main/java/org/tron/common/application/Service.java index 67b4e3ce9ae..629e7e61a4c 100644 --- a/framework/src/main/java/org/tron/common/application/Service.java +++ b/framework/src/main/java/org/tron/common/application/Service.java @@ -15,22 +15,25 @@ package org.tron.common.application; -import org.tron.common.parameter.CommonParameter; +import java.util.concurrent.CompletableFuture; public interface Service { - void init(); - - void init(CommonParameter parameter); + /** + * Starts the service and all needed backend systems. + * + * @return completion state + */ + CompletableFuture start(); /** - * Start the service. - * {@link Service#init(CommonParameter parameter) init(CommonParameter parameter)} must be called - * before this method. + * Stops the service and performs needed cleanup. + * + * @return completion state */ - void start(); + CompletableFuture stop(); - void stop(); + boolean isEnable(); - void blockUntilShutdown(); + String getName(); } diff --git a/framework/src/main/java/org/tron/common/application/ServiceContainer.java b/framework/src/main/java/org/tron/common/application/ServiceContainer.java index 2951596add7..943f4617c1e 100644 --- a/framework/src/main/java/org/tron/common/application/ServiceContainer.java +++ b/framework/src/main/java/org/tron/common/application/ServiceContainer.java @@ -15,59 +15,77 @@ package org.tron.common.application; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; -import org.tron.common.parameter.CommonParameter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; @Slf4j(topic = "app") +@Component public class ServiceContainer { - private final Set services; + @Autowired + private List services; - public ServiceContainer() { - this.services = Collections.synchronizedSet(new LinkedHashSet<>()); - } - - public void add(Service service) { - this.services.add(service); - } + private List enabledServices; - - public void init() { - this.services.forEach(service -> { - logger.debug("Initing {}.", service.getClass().getSimpleName()); - service.init(); - }); + public ServiceContainer() { } - public void init(CommonParameter parameter) { - this.services.forEach(service -> { - logger.debug("Initing {}.", service.getClass().getSimpleName()); - service.init(parameter); - }); + @PostConstruct + private void initEnabledServices() { + this.enabledServices = this.services.stream() + .filter(Service::isEnable) + .collect(Collectors.toList()); } - public void start() { + void start() { logger.info("Starting api services."); - this.services.forEach(service -> { - logger.debug("Starting {}.", service.getClass().getSimpleName()); - service.start(); - }); + this.enabledServices.forEach(this::waitForServiceToStart); logger.info("All api services started."); } - public void stop() { + void stop() { logger.info("Stopping api services."); - this.services.forEach(service -> { - logger.debug("Stopping {}.", service.getClass().getSimpleName()); - service.stop(); - }); + this.enabledServices.forEach(this::waitForServiceToStop); logger.info("All api services stopped."); } - public void blockUntilShutdown() { - this.services.stream().findFirst().ifPresent(Service::blockUntilShutdown); + private void waitForServiceToStart(Service service) { + final String serviceName = service.getName(); + final CompletableFuture startFuture = service.start(); + do { + try { + startFuture.get(60, TimeUnit.SECONDS); + } catch (final InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException("Interrupted while waiting for service to start", e); + } catch (final ExecutionException e) { + throw new IllegalStateException("Service " + serviceName + " failed to start", e); + } catch (final TimeoutException e) { + logger.warn("Service {} is taking an unusually long time to start", serviceName); + } + } while (!startFuture.isDone()); + } + + private void waitForServiceToStop(Service service) { + final String serviceName = service.getName(); + final CompletableFuture stopFuture = service.stop(); + try { + stopFuture.get(30, TimeUnit.SECONDS); + } catch (final InterruptedException e) { + logger.debug("Interrupted while waiting for service {} to complete", serviceName, e); + Thread.currentThread().interrupt(); + } catch (final ExecutionException e) { + logger.error("Service {} failed to shutdown", serviceName, e); + } catch (final TimeoutException e) { + logger.error("Service {} did not shut down cleanly", serviceName); + } } } diff --git a/framework/src/main/java/org/tron/core/config/args/Args.java b/framework/src/main/java/org/tron/core/config/args/Args.java index 8853971a5f8..9ecd76d357d 100644 --- a/framework/src/main/java/org/tron/core/config/args/Args.java +++ b/framework/src/main/java/org/tron/core/config/args/Args.java @@ -44,6 +44,7 @@ import org.quartz.CronExpression; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.common.arch.Arch; import org.tron.common.args.Account; import org.tron.common.args.GenesisBlock; import org.tron.common.args.Witness; @@ -166,6 +167,8 @@ public static void clearParam() { PARAMETER.tcpNettyWorkThreadNum = 0; PARAMETER.udpNettyWorkThreadNum = 0; PARAMETER.solidityNode = false; + PARAMETER.keystore = false; + PARAMETER.dbConvert = false; PARAMETER.trustNodeAddr = ""; PARAMETER.walletExtensionApi = false; PARAMETER.estimateEnergy = false; @@ -190,8 +193,12 @@ public static void clearParam() { PARAMETER.validContractProtoThreadNum = 1; PARAMETER.shieldedTransInPendingMaxCounts = 10; PARAMETER.changedDelegation = 0; + PARAMETER.rpcEnable = true; + PARAMETER.rpcSolidityEnable = true; + PARAMETER.rpcPBFTEnable = true; PARAMETER.fullNodeHttpEnable = true; PARAMETER.solidityNodeHttpEnable = true; + PARAMETER.pBFTHttpEnable = true; PARAMETER.jsonRpcHttpFullNodeEnable = false; PARAMETER.jsonRpcHttpSolidityNodeEnable = false; PARAMETER.jsonRpcHttpPBFTNodeEnable = false; @@ -253,14 +260,15 @@ private static void printVersion() { } catch (IOException e) { logger.error(e.getMessage()); } - JCommander.getConsole().println("OS : " + System.getProperty("os.name")); - JCommander.getConsole().println("JVM : " + System.getProperty("java.vendor") + " " + JCommander jCommander = JCommander.newBuilder().build(); + jCommander.getConsole().println("OS : " + System.getProperty("os.name")); + jCommander.getConsole().println("JVM : " + System.getProperty("java.vendor") + " " + System.getProperty("java.version") + " " + System.getProperty("os.arch")); if (!noGitProperties) { - JCommander.getConsole().println("Git : " + properties.getProperty("git.commit.id")); + jCommander.getConsole().println("Git : " + properties.getProperty("git.commit.id")); } - JCommander.getConsole().println("Version : " + Version.getVersion()); - JCommander.getConsole().println("Code : " + Version.VERSION_CODE); + jCommander.getConsole().println("Version : " + Version.getVersion()); + jCommander.getConsole().println("Code : " + Version.VERSION_CODE); } public static void printHelp(JCommander jCommander) { @@ -304,7 +312,7 @@ public static void printHelp(JCommander jCommander) { helpStr.append(tmpOptionDesc); } } - JCommander.getConsole().println(helpStr.toString()); + jCommander.getConsole().println(helpStr.toString()); } public static String upperFirst(String name) { @@ -356,14 +364,21 @@ private static Map getOptionGroup() { * set parameters. */ public static void setParam(final String[] args, final String confFileName) { + Config config = Configuration.getByFileName(PARAMETER.shellConfFileName, confFileName); + setParam(args, config); + } + + /** + * set parameters. + */ + public static void setParam(final String[] args, final Config config) { + JCommander.newBuilder().addObject(PARAMETER).build().parse(args); if (PARAMETER.version) { printVersion(); exit(0); } - Config config = Configuration.getByFileName(PARAMETER.shellConfFileName, confFileName); - if (config.hasPath(Constant.NET_TYPE) && Constant.TESTNET.equalsIgnoreCase(config.getString(Constant.NET_TYPE))) { Wallet.setAddressPreFixByte(Constant.ADD_PRE_FIX_BYTE_TESTNET); @@ -450,6 +465,18 @@ public static void setParam(final String[] args, final String confFileName) { PARAMETER.lruCacheSize = config.getInt(Constant.VM_LRU_CACHE_SIZE); } + if (config.hasPath(Constant.NODE_RPC_ENABLE)) { + PARAMETER.rpcEnable = config.getBoolean(Constant.NODE_RPC_ENABLE); + } + + if (config.hasPath(Constant.NODE_RPC_SOLIDITY_ENABLE)) { + PARAMETER.rpcSolidityEnable = config.getBoolean(Constant.NODE_RPC_SOLIDITY_ENABLE); + } + + if (config.hasPath(Constant.NODE_RPC_PBFT_ENABLE)) { + PARAMETER.rpcPBFTEnable = config.getBoolean(Constant.NODE_RPC_PBFT_ENABLE); + } + if (config.hasPath(Constant.NODE_HTTP_FULLNODE_ENABLE)) { PARAMETER.fullNodeHttpEnable = config.getBoolean(Constant.NODE_HTTP_FULLNODE_ENABLE); } @@ -458,6 +485,10 @@ public static void setParam(final String[] args, final String confFileName) { PARAMETER.solidityNodeHttpEnable = config.getBoolean(Constant.NODE_HTTP_SOLIDITY_ENABLE); } + if (config.hasPath(Constant.NODE_HTTP_PBFT_ENABLE)) { + PARAMETER.pBFTHttpEnable = config.getBoolean(Constant.NODE_HTTP_PBFT_ENABLE); + } + if (config.hasPath(Constant.NODE_JSONRPC_HTTP_FULLNODE_ENABLE)) { PARAMETER.jsonRpcHttpFullNodeEnable = config.getBoolean(Constant.NODE_JSONRPC_HTTP_FULLNODE_ENABLE); @@ -1600,11 +1631,13 @@ private static void initRocksDbSettings(Config config) { .getLong(prefix + "targetFileSizeBase") : 64; int targetFileSizeMultiplier = config.hasPath(prefix + "targetFileSizeMultiplier") ? config .getInt(prefix + "targetFileSizeMultiplier") : 1; + int maxOpenFiles = config.hasPath(prefix + "maxOpenFiles") + ? config.getInt(prefix + "maxOpenFiles") : 5000; PARAMETER.rocksDBCustomSettings = RocksDbSettings .initCustomSettings(levelNumber, compactThreads, blocksize, maxBytesForLevelBase, maxBytesForLevelMultiplier, level0FileNumCompactionTrigger, - targetFileSizeBase, targetFileSizeMultiplier); + targetFileSizeBase, targetFileSizeMultiplier, maxOpenFiles); RocksDbSettings.loggingSettings(); } @@ -1641,6 +1674,8 @@ private static void initBackupProperty(Config config) { public static void logConfig() { CommonParameter parameter = CommonParameter.getInstance(); logger.info("\n"); + logger.info("************************ System info ************************"); + logger.info("{}", Arch.withAll()); logger.info("************************ Net config ************************"); logger.info("P2P version: {}", parameter.getNodeP2pVersion()); logger.info("LAN IP: {}", parameter.getNodeLanIp()); diff --git a/framework/src/main/java/org/tron/core/db/Manager.java b/framework/src/main/java/org/tron/core/db/Manager.java index 908e248bdee..24f4dba0392 100644 --- a/framework/src/main/java/org/tron/core/db/Manager.java +++ b/framework/src/main/java/org/tron/core/db/Manager.java @@ -1452,16 +1452,17 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block chainBaseManager.getBalanceTraceStore().initCurrentTransactionBalanceTrace(trxCap); trxCap.setInBlock(true); } + if (Objects.isNull(blockCap) || !blockCap.generatedByMyself) { + validateTapos(trxCap); + validateCommon(trxCap); - validateTapos(trxCap); - validateCommon(trxCap); + validateDup(trxCap); - validateDup(trxCap); - - if (!trxCap.validateSignature(chainBaseManager.getAccountStore(), - chainBaseManager.getDynamicPropertiesStore())) { - throw new ValidateSignatureException( - String.format(" %s transaction signature validate failed", txId)); + if (!trxCap.validateSignature(chainBaseManager.getAccountStore(), + chainBaseManager.getDynamicPropertiesStore())) { + throw new ValidateSignatureException( + String.format(" %s transaction signature validate failed", txId)); + } } TransactionTrace trace = new TransactionTrace(trxCap, StoreFactory.getInstance(), diff --git a/framework/src/main/java/org/tron/core/net/TronNetDelegate.java b/framework/src/main/java/org/tron/core/net/TronNetDelegate.java index a6f9812a2d7..050f6df7af9 100644 --- a/framework/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/framework/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -229,6 +229,14 @@ public Message getData(Sha256Hash hash, InventoryType type) throws P2pException } } + public void unparkHitThread() { + LockSupport.unpark(hitThread); + } + + public void markHitDown() { + hitDown = true; + } + public void processBlock(BlockCapsule block, boolean isSync) throws P2pException { if (!hitDown && dbManager.getLatestSolidityNumShutDown() > 0 && dbManager.getLatestSolidityNumShutDown() == dbManager.getDynamicPropertiesStore() @@ -238,8 +246,8 @@ public void processBlock(BlockCapsule block, boolean isSync) throws P2pException dbManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber(), dbManager.getDynamicPropertiesStore().getLatestBlockHeaderNumberFromDB(), dbManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum()); - hitDown = true; - LockSupport.unpark(hitThread); + markHitDown(); + unparkHitThread(); return; } if (hitDown) { diff --git a/framework/src/main/java/org/tron/core/services/RpcApiService.java b/framework/src/main/java/org/tron/core/services/RpcApiService.java index 3cc50c77890..8f9c6b15bb7 100755 --- a/framework/src/main/java/org/tron/core/services/RpcApiService.java +++ b/framework/src/main/java/org/tron/core/services/RpcApiService.java @@ -8,10 +8,8 @@ import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.netty.NettyServerBuilder; -import io.grpc.protobuf.services.ProtoReflectionService; import io.grpc.stub.StreamObserver; import java.util.Objects; -import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -75,7 +73,6 @@ import org.tron.api.WalletGrpc.WalletImplBase; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.RpcService; -import org.tron.common.es.ExecutorServiceManager; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.ByteArray; import org.tron.common.utils.Sha256Hash; @@ -97,10 +94,6 @@ import org.tron.core.exception.VMIllegalException; import org.tron.core.exception.ZksnarkException; import org.tron.core.metrics.MetricsApiService; -import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; -import org.tron.core.services.ratelimiter.PrometheusInterceptor; -import org.tron.core.services.ratelimiter.RateLimiterInterceptor; -import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; import org.tron.core.utils.TransactionUtil; import org.tron.core.zen.address.DiversifierT; import org.tron.core.zen.address.IncomingViewingKey; @@ -183,15 +176,7 @@ public class RpcApiService extends RpcService { @Autowired private NodeInfoService nodeInfoService; @Autowired - private RateLimiterInterceptor rateLimiterInterceptor; - @Autowired - private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; - @Autowired - private RpcApiAccessInterceptor apiAccessInterceptor; - @Autowired private MetricsApiService metricsApiService; - @Autowired - private PrometheusInterceptor prometheusInterceptor; @Getter private DatabaseApi databaseApi = new DatabaseApi(); private WalletApi walletApi = new WalletApi(); @@ -200,75 +185,27 @@ public class RpcApiService extends RpcService { @Getter private MonitorApi monitorApi = new MonitorApi(); - private final String executorName = "rpc-full-executor"; - - @Override - public void init() { - - } - - @Override - public void init(CommonParameter args) { + public RpcApiService() { port = Args.getInstance().getRpcPort(); + enable = Args.getInstance().isRpcEnable(); + executorName = "rpc-full-executor"; } @Override - public void start() { - try { - NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port).addService(databaseApi); - CommonParameter parameter = Args.getInstance(); - - if (parameter.getRpcThreadNum() > 0) { - serverBuilder = serverBuilder - .executor(ExecutorServiceManager.newFixedThreadPool( - executorName, parameter.getRpcThreadNum())); - } - - if (parameter.isSolidityNode()) { - serverBuilder = serverBuilder.addService(walletSolidityApi); - if (parameter.isWalletExtensionApi()) { - serverBuilder = serverBuilder.addService(new WalletExtensionApi()); - } - } else { - serverBuilder = serverBuilder.addService(walletApi); - } - - if (parameter.isNodeMetricsEnable()) { - serverBuilder = serverBuilder.addService(monitorApi); - } - - // Set configs from config.conf or default value - serverBuilder - .maxConcurrentCallsPerConnection(parameter.getMaxConcurrentCallsPerConnection()) - .flowControlWindow(parameter.getFlowControlWindow()) - .maxConnectionIdle(parameter.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) - .maxConnectionAge(parameter.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) - .maxInboundMessageSize(parameter.getMaxMessageSize()) - .maxHeaderListSize(parameter.getMaxHeaderListSize()); - - // add a rate limiter interceptor - serverBuilder.intercept(rateLimiterInterceptor); - - // add api access interceptor - serverBuilder.intercept(apiAccessInterceptor); - - // add lite fullnode query interceptor - serverBuilder.intercept(liteFnQueryGrpcInterceptor); - - // add prometheus interceptor - if (parameter.isMetricsPrometheusEnable()) { - serverBuilder.intercept(prometheusInterceptor); - } - - if (parameter.isRpcReflectionServiceEnable()) { - serverBuilder.addService(ProtoReflectionService.newInstance()); + protected void addService(NettyServerBuilder serverBuilder) { + serverBuilder.addService(databaseApi); + CommonParameter parameter = Args.getInstance(); + if (parameter.isSolidityNode()) { + serverBuilder.addService(walletSolidityApi); + if (parameter.isWalletExtensionApi()) { + serverBuilder.addService(new WalletExtensionApi()); } + } else { + serverBuilder.addService(walletApi); + } - apiServer = serverBuilder.build(); - rateLimiterInterceptor.init(apiServer); - super.start(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); + if (parameter.isNodeMetricsEnable()) { + serverBuilder.addService(monitorApi); } } diff --git a/framework/src/main/java/org/tron/program/SolidityNode.java b/framework/src/main/java/org/tron/core/services/SolidityService.java similarity index 64% rename from framework/src/main/java/org/tron/program/SolidityNode.java rename to framework/src/main/java/org/tron/core/services/SolidityService.java index 4cf71177803..641ffb3257c 100644 --- a/framework/src/main/java/org/tron/program/SolidityNode.java +++ b/framework/src/main/java/org/tron/core/services/SolidityService.java @@ -1,217 +1,196 @@ -package org.tron.program; - -import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL; - -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.atomic.AtomicLong; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.BooleanUtils; -import org.springframework.context.ApplicationContext; -import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; -import org.tron.common.application.Application; -import org.tron.common.application.ApplicationFactory; -import org.tron.common.application.TronApplicationContext; -import org.tron.common.client.DatabaseGrpcClient; -import org.tron.common.parameter.CommonParameter; -import org.tron.common.prometheus.Metrics; -import org.tron.core.ChainBaseManager; -import org.tron.core.Constant; -import org.tron.core.capsule.BlockCapsule; -import org.tron.core.config.DefaultConfig; -import org.tron.core.config.args.Args; -import org.tron.core.db.Manager; -import org.tron.core.services.RpcApiService; -import org.tron.core.services.http.solidity.SolidityNodeHttpApiService; -import org.tron.protos.Protocol.Block; - -@Slf4j(topic = "app") -public class SolidityNode { - - private Manager dbManager; - - private ChainBaseManager chainBaseManager; - - private DatabaseGrpcClient databaseGrpcClient; - - private AtomicLong ID = new AtomicLong(); - - private AtomicLong remoteBlockNum = new AtomicLong(); - - private LinkedBlockingDeque blockQueue = new LinkedBlockingDeque<>(100); - - private int exceptionSleepTime = 1000; - - private volatile boolean flag = true; - - public SolidityNode(Manager dbManager) { - this.dbManager = dbManager; - this.chainBaseManager = dbManager.getChainBaseManager(); - resolveCompatibilityIssueIfUsingFullNodeDatabase(); - ID.set(chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum()); - databaseGrpcClient = new DatabaseGrpcClient(CommonParameter.getInstance().getTrustNodeAddr()); - remoteBlockNum.set(getLastSolidityBlockNum()); - } - - /** - * Start the SolidityNode. - */ - public static void main(String[] args) { - logger.info("Solidity node is running."); - Args.setParam(args, Constant.TESTNET_CONF); - CommonParameter parameter = CommonParameter.getInstance(); - - logger.info("index switch is {}", - BooleanUtils.toStringOnOff(BooleanUtils - .toBoolean(parameter.getStorage().getIndexSwitch()))); - - if (ObjectUtils.isEmpty(parameter.getTrustNodeAddr())) { - logger.error("Trust node is not set."); - return; - } - parameter.setSolidityNode(true); - - TronApplicationContext context = new TronApplicationContext(DefaultConfig.class); - context.registerShutdownHook(); - - if (parameter.isHelp()) { - logger.info("Here is the help message."); - return; - } - // init metrics first - Metrics.init(); - - Application appT = ApplicationFactory.create(context); - RpcApiService rpcApiService = context.getBean(RpcApiService.class); - appT.addService(rpcApiService); - //http - SolidityNodeHttpApiService httpApiService = context.getBean(SolidityNodeHttpApiService.class); - if (CommonParameter.getInstance().solidityNodeHttpEnable) { - appT.addService(httpApiService); - } - - SolidityNode node = new SolidityNode(appT.getDbManager()); - node.start(); - appT.startup(); - appT.blockUntilShutdown(); - } - - private void start() { - try { - new Thread(this::getBlock).start(); - new Thread(this::processBlock).start(); - logger.info("Success to start solid node, ID: {}, remoteBlockNum: {}.", ID.get(), - remoteBlockNum); - } catch (Exception e) { - logger.error("Failed to start solid node, address: {}.", - CommonParameter.getInstance().getTrustNodeAddr()); - System.exit(0); - } - } - - private void getBlock() { - long blockNum = ID.incrementAndGet(); - while (flag) { - try { - if (blockNum > remoteBlockNum.get()) { - sleep(BLOCK_PRODUCED_INTERVAL); - remoteBlockNum.set(getLastSolidityBlockNum()); - continue; - } - Block block = getBlockByNum(blockNum); - blockQueue.put(block); - blockNum = ID.incrementAndGet(); - } catch (Exception e) { - logger.error("Failed to get block {}, reason: {}.", blockNum, e.getMessage()); - sleep(exceptionSleepTime); - } - } - } - - private void processBlock() { - while (flag) { - try { - Block block = blockQueue.take(); - loopProcessBlock(block); - } catch (Exception e) { - logger.error(e.getMessage()); - sleep(exceptionSleepTime); - } - } - } - - private void loopProcessBlock(Block block) { - while (flag) { - long blockNum = block.getBlockHeader().getRawData().getNumber(); - try { - dbManager.pushVerifiedBlock(new BlockCapsule(block)); - chainBaseManager.getDynamicPropertiesStore().saveLatestSolidifiedBlockNum(blockNum); - logger - .info("Success to process block: {}, blockQueueSize: {}.", blockNum, blockQueue.size()); - return; - } catch (Exception e) { - logger.error("Failed to process block {}.", new BlockCapsule(block), e); - sleep(exceptionSleepTime); - block = getBlockByNum(blockNum); - } - } - } - - private Block getBlockByNum(long blockNum) { - while (true) { - try { - long time = System.currentTimeMillis(); - Block block = databaseGrpcClient.getBlock(blockNum); - long num = block.getBlockHeader().getRawData().getNumber(); - if (num == blockNum) { - logger.info("Success to get block: {}, cost: {}ms.", - blockNum, System.currentTimeMillis() - time); - return block; - } else { - logger.warn("Get block id not the same , {}, {}.", num, blockNum); - sleep(exceptionSleepTime); - } - } catch (Exception e) { - logger.error("Failed to get block: {}, reason: {}.", blockNum, e.getMessage()); - sleep(exceptionSleepTime); - } - } - } - - private long getLastSolidityBlockNum() { - while (true) { - try { - long time = System.currentTimeMillis(); - long blockNum = databaseGrpcClient.getDynamicProperties().getLastSolidityBlockNum(); - logger.info("Get last remote solid blockNum: {}, remoteBlockNum: {}, cost: {}.", - blockNum, remoteBlockNum, System.currentTimeMillis() - time); - return blockNum; - } catch (Exception e) { - logger.error("Failed to get last solid blockNum: {}, reason: {}.", remoteBlockNum.get(), - e.getMessage()); - sleep(exceptionSleepTime); - } - } - } - - public void sleep(long time) { - try { - Thread.sleep(time); - } catch (Exception e1) { - logger.error(e1.getMessage()); - } - } - - private void resolveCompatibilityIssueIfUsingFullNodeDatabase() { - long lastSolidityBlockNum = - chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum(); - long headBlockNum = chainBaseManager.getHeadBlockNum(); - logger.info("headBlockNum:{}, solidityBlockNum:{}, diff:{}", - headBlockNum, lastSolidityBlockNum, headBlockNum - lastSolidityBlockNum); - if (lastSolidityBlockNum < headBlockNum) { - logger.info("use fullNode database, headBlockNum:{}, solidityBlockNum:{}, diff:{}", - headBlockNum, lastSolidityBlockNum, headBlockNum - lastSolidityBlockNum); - chainBaseManager.getDynamicPropertiesStore().saveLatestSolidifiedBlockNum(headBlockNum); - } - } +package org.tron.core.services; + +import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL; + +import java.util.Optional; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.atomic.AtomicLong; +import javax.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; +import org.tron.common.client.DatabaseGrpcClient; +import org.tron.common.parameter.CommonParameter; +import org.tron.core.ChainBaseManager; +import org.tron.core.capsule.BlockCapsule; +import org.tron.core.db.Manager; +import org.tron.core.net.TronNetDelegate; +import org.tron.protos.Protocol.Block; + +@Slf4j(topic = "app") +@Component +public class SolidityService { + + @Autowired + private Manager dbManager; + + @Autowired + private ChainBaseManager chainBaseManager; + + private DatabaseGrpcClient databaseGrpcClient; + + @Autowired + private TronNetDelegate tronNetDelegate; + + private AtomicLong ID; + + private AtomicLong remoteBlockNum; + + private LinkedBlockingDeque blockQueue; + + private int exceptionSleepTime; + + private volatile boolean flag = true; + + private static Optional INSTANCE = Optional.empty(); + + @PostConstruct + private void init() { + if (!CommonParameter.getInstance().isSolidityNode()) { + return; + } + if (ObjectUtils.isEmpty(CommonParameter.getInstance().getTrustNodeAddr())) { + throw new IllegalArgumentException("Trust node is not set."); + } + resolveCompatibilityIssueIfUsingFullNodeDatabase(); + ID = new AtomicLong(chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum()); + databaseGrpcClient = new DatabaseGrpcClient(CommonParameter.getInstance().getTrustNodeAddr()); + remoteBlockNum = new AtomicLong(0); + blockQueue = new LinkedBlockingDeque<>(100); + exceptionSleepTime = 1000; + INSTANCE = Optional.of(this); + } + + public static void runIfNeed() { + INSTANCE.ifPresent(SolidityService::start); + } + + private void start() { + try { + remoteBlockNum.set(getLastSolidityBlockNum()); + new Thread(this::getBlock).start(); + new Thread(this::processBlock).start(); + logger.info("Success to start solid node, ID: {}, remoteBlockNum: {}.", ID.get(), + remoteBlockNum); + } catch (Exception e) { + logger.error("Failed to start solid node, address: {}.", + CommonParameter.getInstance().getTrustNodeAddr()); + System.exit(0); + } + } + + private void getBlock() { + long blockNum = ID.incrementAndGet(); + while (flag) { + try { + if (blockNum > remoteBlockNum.get()) { + sleep(BLOCK_PRODUCED_INTERVAL); + remoteBlockNum.set(getLastSolidityBlockNum()); + continue; + } + Block block = getBlockByNum(blockNum); + blockQueue.put(block); + blockNum = ID.incrementAndGet(); + } catch (Exception e) { + logger.error("Failed to get block {}, reason: {}.", blockNum, e.getMessage()); + sleep(exceptionSleepTime); + } + } + } + + private void processBlock() { + while (flag) { + try { + Block block = blockQueue.take(); + loopProcessBlock(block); + flag = dbManager.getLatestSolidityNumShutDown() != dbManager.getDynamicPropertiesStore() + .getLatestBlockHeaderNumberFromDB(); + } catch (Exception e) { + logger.error(e.getMessage()); + sleep(exceptionSleepTime); + } + } + logger.info("Begin shutdown, currentBlockNum:{}, DbBlockNum:{}, solidifiedBlockNum:{}", + dbManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber(), + dbManager.getDynamicPropertiesStore().getLatestBlockHeaderNumberFromDB(), + dbManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum()); + tronNetDelegate.markHitDown(); + tronNetDelegate.unparkHitThread(); + } + + private void loopProcessBlock(Block block) { + while (flag) { + long blockNum = block.getBlockHeader().getRawData().getNumber(); + try { + dbManager.pushVerifiedBlock(new BlockCapsule(block)); + chainBaseManager.getDynamicPropertiesStore().saveLatestSolidifiedBlockNum(blockNum); + logger + .info("Success to process block: {}, blockQueueSize: {}.", blockNum, blockQueue.size()); + return; + } catch (Exception e) { + logger.error("Failed to process block {}.", new BlockCapsule(block), e); + sleep(exceptionSleepTime); + block = getBlockByNum(blockNum); + } + } + } + + private Block getBlockByNum(long blockNum) { + while (true) { + try { + long time = System.currentTimeMillis(); + Block block = databaseGrpcClient.getBlock(blockNum); + long num = block.getBlockHeader().getRawData().getNumber(); + if (num == blockNum) { + logger.info("Success to get block: {}, cost: {}ms.", + blockNum, System.currentTimeMillis() - time); + return block; + } else { + logger.warn("Get block id not the same , {}, {}.", num, blockNum); + sleep(exceptionSleepTime); + } + } catch (Exception e) { + logger.error("Failed to get block: {}, reason: {}.", blockNum, e.getMessage()); + sleep(exceptionSleepTime); + } + } + } + + private long getLastSolidityBlockNum() { + while (true) { + try { + long time = System.currentTimeMillis(); + long blockNum = databaseGrpcClient.getDynamicProperties().getLastSolidityBlockNum(); + logger.info("Get last remote solid blockNum: {}, remoteBlockNum: {}, cost: {}.", + blockNum, remoteBlockNum, System.currentTimeMillis() - time); + return blockNum; + } catch (Exception e) { + logger.error("Failed to get last solid blockNum: {}, reason: {}.", remoteBlockNum.get(), + e.getMessage()); + sleep(exceptionSleepTime); + } + } + } + + private void sleep(long time) { + try { + Thread.sleep(time); + } catch (Exception e1) { + logger.error(e1.getMessage()); + } + } + + private void resolveCompatibilityIssueIfUsingFullNodeDatabase() { + long lastSolidityBlockNum = + chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum(); + long headBlockNum = chainBaseManager.getHeadBlockNum(); + logger.info("headBlockNum:{}, solidityBlockNum:{}, diff:{}", + headBlockNum, lastSolidityBlockNum, headBlockNum - lastSolidityBlockNum); + if (lastSolidityBlockNum < headBlockNum) { + logger.info("use fullNode database, headBlockNum:{}, solidityBlockNum:{}, diff:{}", + headBlockNum, lastSolidityBlockNum, headBlockNum - lastSolidityBlockNum); + chainBaseManager.getDynamicPropertiesStore().saveLatestSolidifiedBlockNum(headBlockNum); + } + } } \ No newline at end of file diff --git a/framework/src/main/java/org/tron/core/services/annotation/FullServlet.java b/framework/src/main/java/org/tron/core/services/annotation/FullServlet.java new file mode 100644 index 00000000000..fa811b2d495 --- /dev/null +++ b/framework/src/main/java/org/tron/core/services/annotation/FullServlet.java @@ -0,0 +1,22 @@ +package org.tron.core.services.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.tron.core.services.http.FullNodeHttpApiService; + +/** + * Annotation for {@link FullNodeHttpApiService} servlet. + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface FullServlet { + + /** + * servlet pathSpec. + */ + String[] value(); +} diff --git a/framework/src/main/java/org/tron/core/services/annotation/PbftServlet.java b/framework/src/main/java/org/tron/core/services/annotation/PbftServlet.java new file mode 100644 index 00000000000..bccb5abc5cd --- /dev/null +++ b/framework/src/main/java/org/tron/core/services/annotation/PbftServlet.java @@ -0,0 +1,22 @@ +package org.tron.core.services.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.tron.core.services.interfaceOnPBFT.http.PBFT.HttpApiOnPBFTService; + +/** + * Annotation for {@link HttpApiOnPBFTService} servlet. + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface PbftServlet { + + /** + * servlet pathSpec. + */ + String[] value(); +} diff --git a/framework/src/main/java/org/tron/core/services/annotation/SolidityNodeServlet.java b/framework/src/main/java/org/tron/core/services/annotation/SolidityNodeServlet.java new file mode 100644 index 00000000000..591043b64ee --- /dev/null +++ b/framework/src/main/java/org/tron/core/services/annotation/SolidityNodeServlet.java @@ -0,0 +1,22 @@ +package org.tron.core.services.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.tron.core.services.http.solidity.SolidityNodeHttpApiService; + +/** + * Annotation for {@link SolidityNodeHttpApiService} servlet. + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface SolidityNodeServlet { + + /** + * servlet pathSpec. + */ + String[] value(); +} diff --git a/framework/src/main/java/org/tron/core/services/annotation/SolidityServlet.java b/framework/src/main/java/org/tron/core/services/annotation/SolidityServlet.java new file mode 100644 index 00000000000..3cddea81acb --- /dev/null +++ b/framework/src/main/java/org/tron/core/services/annotation/SolidityServlet.java @@ -0,0 +1,23 @@ +package org.tron.core.services.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.tron.core.services.interfaceOnSolidity.http.solidity.HttpApiOnSolidityService; + +/** + * Annotation for {@link HttpApiOnSolidityService} + * servlet. + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface SolidityServlet { + + /** + * servlet pathSpec. + */ + String[] value(); +} diff --git a/framework/src/main/java/org/tron/core/services/http/AccountPermissionUpdateServlet.java b/framework/src/main/java/org/tron/core/services/http/AccountPermissionUpdateServlet.java index c8ddd93f103..48cabc2f316 100644 --- a/framework/src/main/java/org/tron/core/services/http/AccountPermissionUpdateServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/AccountPermissionUpdateServlet.java @@ -7,11 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AccountContract.AccountPermissionUpdateContract; - +@FullServlet("/wallet/accountpermissionupdate") @Component @Slf4j(topic = "API") public class AccountPermissionUpdateServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/BroadcastHexServlet.java b/framework/src/main/java/org/tron/core/services/http/BroadcastHexServlet.java index ec115b20a15..f003f60fecc 100644 --- a/framework/src/main/java/org/tron/core/services/http/BroadcastHexServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/BroadcastHexServlet.java @@ -11,8 +11,10 @@ import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; import org.tron.core.capsule.TransactionCapsule; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; +@FullServlet("/wallet/broadcasthex") @Component @Slf4j(topic = "API") public class BroadcastHexServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/BroadcastServlet.java b/framework/src/main/java/org/tron/core/services/http/BroadcastServlet.java index 6b265c35e02..8abce1a528b 100644 --- a/framework/src/main/java/org/tron/core/services/http/BroadcastServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/BroadcastServlet.java @@ -10,9 +10,10 @@ import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; import org.tron.core.capsule.TransactionCapsule; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; - +@FullServlet("/wallet/broadcasttransaction") @Component @Slf4j(topic = "API") public class BroadcastServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CancelAllUnfreezeV2Servlet.java b/framework/src/main/java/org/tron/core/services/http/CancelAllUnfreezeV2Servlet.java index 894126e50da..57d65b5dc39 100644 --- a/framework/src/main/java/org/tron/core/services/http/CancelAllUnfreezeV2Servlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CancelAllUnfreezeV2Servlet.java @@ -8,10 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.CancelAllUnfreezeV2Contract; +@FullServlet("/wallet/cancelallunfreezev2") @Component @Slf4j(topic = "API") public class CancelAllUnfreezeV2Servlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ClearABIServlet.java b/framework/src/main/java/org/tron/core/services/http/ClearABIServlet.java index c897b895c58..e95d4bdfe65 100644 --- a/framework/src/main/java/org/tron/core/services/http/ClearABIServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ClearABIServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.SmartContractOuterClass.ClearABIContract; +@FullServlet("/wallet/clearabi") @Component @Slf4j(topic = "API") public class ClearABIServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateAccountServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateAccountServlet.java index 102d9ca80ce..9b1dd7b234e 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateAccountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateAccountServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AccountContract.AccountCreateContract; +@FullServlet("/wallet/createaccount") @Component @Slf4j(topic = "API") public class CreateAccountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateAssetIssueServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateAssetIssueServlet.java index 9d537ab641b..2cea9ff2f1a 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateAssetIssueServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateAssetIssueServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract; +@FullServlet("/wallet/createassetissue") @Component @Slf4j(topic = "API") public class CreateAssetIssueServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateCommonTransactionServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateCommonTransactionServlet.java index c3a515f84a5..2ec2ba46a8d 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateCommonTransactionServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateCommonTransactionServlet.java @@ -13,10 +13,12 @@ import org.tron.core.Wallet; import org.tron.core.actuator.TransactionFactory; import org.tron.core.exception.ContractValidateException; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; +@FullServlet("/wallet/createCommonTransaction") @Component @Slf4j(topic = "API") public class CreateCommonTransactionServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersServlet.java index 2b5afbbd8e2..e55f15a3107 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersServlet.java @@ -9,7 +9,9 @@ import org.tron.api.GrpcAPI.PrivateShieldedTRC20Parameters; import org.tron.api.GrpcAPI.ShieldedTRC20Parameters; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/createshieldedcontractparameters") @Component @Slf4j(topic = "API") public class CreateShieldedContractParametersServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersWithoutAskServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersWithoutAskServlet.java index 80a8ba53bbc..bcd7431aef8 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersWithoutAskServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateShieldedContractParametersWithoutAskServlet.java @@ -1,6 +1,5 @@ package org.tron.core.services.http; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -9,7 +8,9 @@ import org.tron.api.GrpcAPI.PrivateShieldedTRC20ParametersWithoutAsk; import org.tron.api.GrpcAPI.ShieldedTRC20Parameters; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/createshieldedcontractparameterswithoutask") @Component @Slf4j(topic = "API") public class CreateShieldedContractParametersWithoutAskServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateSpendAuthSigServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateSpendAuthSigServlet.java index b2b57c9cb9d..c182246be9e 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateSpendAuthSigServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateSpendAuthSigServlet.java @@ -8,8 +8,10 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.api.GrpcAPI.SpendAuthSigParameters; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/createspendauthsig") @Component @Slf4j(topic = "API") public class CreateSpendAuthSigServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/CreateWitnessServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateWitnessServlet.java index 55e1b25ce3d..eb6ff413c77 100644 --- a/framework/src/main/java/org/tron/core/services/http/CreateWitnessServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/CreateWitnessServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.WitnessContract.WitnessCreateContract; +@FullServlet("/wallet/createwitness") @Component @Slf4j(topic = "API") public class CreateWitnessServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/DelegateResourceServlet.java b/framework/src/main/java/org/tron/core/services/http/DelegateResourceServlet.java index 00994238988..014cbd2ed9e 100644 --- a/framework/src/main/java/org/tron/core/services/http/DelegateResourceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/DelegateResourceServlet.java @@ -8,10 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.DelegateResourceContract; +@FullServlet("/wallet/delegateresource") @Component @Slf4j(topic = "API") public class DelegateResourceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/DeployContractServlet.java b/framework/src/main/java/org/tron/core/services/http/DeployContractServlet.java index 1209c6fb385..0ce7739a112 100644 --- a/framework/src/main/java/org/tron/core/services/http/DeployContractServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/DeployContractServlet.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract; @@ -21,6 +22,7 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI; +@FullServlet("/wallet/deploycontract") @Component @Slf4j(topic = "API") public class DeployContractServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/EstimateEnergyServlet.java b/framework/src/main/java/org/tron/core/services/http/EstimateEnergyServlet.java index d88f7dd1af1..782b72c0237 100644 --- a/framework/src/main/java/org/tron/core/services/http/EstimateEnergyServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/EstimateEnergyServlet.java @@ -17,9 +17,13 @@ import org.tron.core.Wallet; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.exception.ContractValidateException; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract; +@FullServlet("/wallet/estimateenergy") +@SolidityNodeServlet("/walletsolidity/estimateenergy") @Component @Slf4j(topic = "API") public class EstimateEnergyServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ExchangeCreateServlet.java b/framework/src/main/java/org/tron/core/services/http/ExchangeCreateServlet.java index b7e2d7beb50..8cff0cfc3f2 100644 --- a/framework/src/main/java/org/tron/core/services/http/ExchangeCreateServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ExchangeCreateServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ExchangeContract.ExchangeCreateContract; +@FullServlet("/wallet/exchangecreate") @Component @Slf4j(topic = "API") public class ExchangeCreateServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ExchangeInjectServlet.java b/framework/src/main/java/org/tron/core/services/http/ExchangeInjectServlet.java index a6c8ebc2132..add78dd5130 100644 --- a/framework/src/main/java/org/tron/core/services/http/ExchangeInjectServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ExchangeInjectServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ExchangeContract.ExchangeInjectContract; +@FullServlet("/wallet/exchangeinject") @Component @Slf4j(topic = "API") public class ExchangeInjectServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ExchangeTransactionServlet.java b/framework/src/main/java/org/tron/core/services/http/ExchangeTransactionServlet.java index b788e6bba9f..42dde03d7ad 100644 --- a/framework/src/main/java/org/tron/core/services/http/ExchangeTransactionServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ExchangeTransactionServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ExchangeContract.ExchangeTransactionContract; +@FullServlet("/wallet/exchangetransaction") @Component @Slf4j(topic = "API") public class ExchangeTransactionServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ExchangeWithdrawServlet.java b/framework/src/main/java/org/tron/core/services/http/ExchangeWithdrawServlet.java index f454e08df9c..b701f9324d9 100644 --- a/framework/src/main/java/org/tron/core/services/http/ExchangeWithdrawServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ExchangeWithdrawServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ExchangeContract.ExchangeWithdrawContract; +@FullServlet("/wallet/exchangewithdraw") @Component @Slf4j(topic = "API") public class ExchangeWithdrawServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/FreezeBalanceServlet.java b/framework/src/main/java/org/tron/core/services/http/FreezeBalanceServlet.java index e73c294e023..813c16f3864 100644 --- a/framework/src/main/java/org/tron/core/services/http/FreezeBalanceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/FreezeBalanceServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.FreezeBalanceContract; +@FullServlet("/wallet/freezebalance") @Component @Slf4j(topic = "API") public class FreezeBalanceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/FreezeBalanceV2Servlet.java b/framework/src/main/java/org/tron/core/services/http/FreezeBalanceV2Servlet.java index f1687a5bbb1..8129f7fff04 100644 --- a/framework/src/main/java/org/tron/core/services/http/FreezeBalanceV2Servlet.java +++ b/framework/src/main/java/org/tron/core/services/http/FreezeBalanceV2Servlet.java @@ -7,10 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract; +@FullServlet("/wallet/freezebalancev2") @Component @Slf4j(topic = "API") public class FreezeBalanceV2Servlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java b/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java index 55e6e07b5ec..27b9a71fb86 100644 --- a/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java +++ b/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java @@ -1,20 +1,23 @@ package org.tron.core.services.http; +import java.util.Arrays; import java.util.EnumSet; import javax.servlet.DispatcherType; import javax.servlet.Filter; +import javax.servlet.Servlet; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.StringUtil; +import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; import org.tron.core.config.args.Args; +import org.tron.core.services.annotation.FullServlet; import org.tron.core.services.filter.HttpApiAccessFilter; import org.tron.core.services.filter.HttpInterceptor; import org.tron.core.services.filter.LiteFnQueryHttpFilter; @@ -25,530 +28,53 @@ public class FullNodeHttpApiService extends HttpService { @Autowired - private GetAccountServlet getAccountServlet; - @Autowired - private TransferServlet transferServlet; - @Autowired - private BroadcastServlet broadcastServlet; - @Autowired - private UpdateAccountServlet updateAccountServlet; - @Autowired - private VoteWitnessAccountServlet voteWitnessAccountServlet; - @Autowired - private CreateAssetIssueServlet createAssetIssueServlet; - @Autowired - private UpdateWitnessServlet updateWitnessServlet; - @Autowired - private CreateAccountServlet createAccountServlet; - @Autowired - private CreateWitnessServlet createWitnessServlet; - @Autowired - private TransferAssetServlet transferAssetServlet; - @Autowired - private ParticipateAssetIssueServlet participateAssetIssueServlet; - @Autowired - private FreezeBalanceServlet freezeBalanceServlet; - @Autowired - private UnFreezeBalanceServlet unFreezeBalanceServlet; - @Autowired - private UnFreezeAssetServlet unFreezeAssetServlet; - @Autowired - private WithdrawBalanceServlet withdrawBalanceServlet; - @Autowired - private UpdateAssetServlet updateAssetServlet; - @Autowired - private ListNodesServlet listNodesServlet; - @Autowired - private GetAssetIssueByAccountServlet getAssetIssueByAccountServlet; - @Autowired - private GetAccountNetServlet getAccountNetServlet; - @Autowired - private GetAssetIssueByNameServlet getAssetIssueByNameServlet; - @Autowired - private GetAssetIssueListByNameServlet getAssetIssueListByNameServlet; - @Autowired - private GetAssetIssueByIdServlet getAssetIssueByIdServlet; - @Autowired - private GetNowBlockServlet getNowBlockServlet; - @Autowired - private GetBlockByNumServlet getBlockByNumServlet; - @Autowired - private GetBlockByIdServlet getBlockByIdServlet; - @Autowired - private GetBlockByLimitNextServlet getBlockByLimitNextServlet; - @Autowired - private GetBlockByLatestNumServlet getBlockByLatestNumServlet; - @Autowired - private GetTransactionByIdServlet getTransactionByIdServlet; - @Autowired - private GetTransactionInfoByIdServlet getTransactionInfoByIdServlet; - @Autowired - private GetTransactionReceiptByIdServlet getTransactionReceiptByIdServlet; - @Autowired - private GetTransactionCountByBlockNumServlet getTransactionCountByBlockNumServlet; - @Autowired - private ListWitnessesServlet listWitnessesServlet; - @Autowired - private GetAssetIssueListServlet getAssetIssueListServlet; - @Autowired - private GetPaginatedAssetIssueListServlet getPaginatedAssetIssueListServlet; - @Autowired - private GetPaginatedProposalListServlet getPaginatedProposalListServlet; - @Autowired - private GetPaginatedExchangeListServlet getPaginatedExchangeListServlet; - @Autowired - private TotalTransactionServlet totalTransactionServlet; - @Autowired - private GetNextMaintenanceTimeServlet getNextMaintenanceTimeServlet; - @Autowired - private ValidateAddressServlet validateAddressServlet; - @Autowired - private DeployContractServlet deployContractServlet; - @Autowired - private TriggerSmartContractServlet triggerSmartContractServlet; - @Autowired - private TriggerConstantContractServlet triggerConstantContractServlet; - @Autowired - private EstimateEnergyServlet estimateEnergyServlet; - @Autowired - private GetContractServlet getContractServlet; - @Autowired - private GetContractInfoServlet getContractInfoServlet; - @Autowired - private ClearABIServlet clearABIServlet; - @Autowired - private ProposalCreateServlet proposalCreateServlet; - @Autowired - private ProposalApproveServlet proposalApproveServlet; - @Autowired - private ProposalDeleteServlet proposalDeleteServlet; - @Autowired - private ListProposalsServlet listProposalsServlet; - @Autowired - private GetProposalByIdServlet getProposalByIdServlet; - @Autowired - private ExchangeCreateServlet exchangeCreateServlet; - @Autowired - private ExchangeInjectServlet exchangeInjectServlet; - @Autowired - private ExchangeTransactionServlet exchangeTransactionServlet; - @Autowired - private ExchangeWithdrawServlet exchangeWithdrawServlet; - @Autowired - private GetExchangeByIdServlet getExchangeByIdServlet; - @Autowired - private ListExchangesServlet listExchangesServlet; - @Autowired - private GetChainParametersServlet getChainParametersServlet; - @Autowired - private GetAccountResourceServlet getAccountResourceServlet; - @Autowired - private GetNodeInfoServlet getNodeInfoServlet; - @Autowired - private GetTransactionSignWeightServlet getTransactionSignWeightServlet; - @Autowired - private GetTransactionApprovedListServlet getTransactionApprovedListServlet; - @Autowired - private AccountPermissionUpdateServlet accountPermissionUpdateServlet; - @Autowired - private UpdateSettingServlet updateSettingServlet; - @Autowired - private UpdateEnergyLimitServlet updateEnergyLimitServlet; - @Autowired - private GetDelegatedResourceAccountIndexServlet getDelegatedResourceAccountIndexServlet; - @Autowired - private GetDelegatedResourceAccountIndexV2Servlet getDelegatedResourceAccountIndexV2Servlet; - @Autowired - private GetDelegatedResourceServlet getDelegatedResourceServlet; - @Autowired - private GetDelegatedResourceV2Servlet getDelegatedResourceV2Servlet; - @Autowired - private GetCanDelegatedMaxSizeServlet getCanDelegatedMaxSizeServlet; - @Autowired - private GetAvailableUnfreezeCountServlet getAvailableUnfreezeCountServlet; - @Autowired - private GetCanWithdrawUnfreezeAmountServlet getCanWithdrawUnfreezeAmountServlet; - @Autowired - private SetAccountIdServlet setAccountServlet; - @Autowired - private GetAccountByIdServlet getAccountByIdServlet; - @Autowired - private GetExpandedSpendingKeyServlet getExpandedSpendingKeyServlet; - @Autowired - private GetAkFromAskServlet getAkFromAskServlet; - @Autowired - private GetNkFromNskServlet getNkFromNskServlet; - @Autowired - private GetSpendingKeyServlet getSpendingKeyServlet; - @Autowired - private GetNewShieldedAddressServlet getNewShieldedAddressServlet; - @Autowired - private GetDiversifierServlet getDiversifierServlet; - @Autowired - private GetIncomingViewingKeyServlet getIncomingViewingKeyServlet; - @Autowired - private GetZenPaymentAddressServlet getZenPaymentAddressServlet; - @Autowired - private CreateShieldedTransactionServlet createShieldedTransactionServlet; - @Autowired - private ScanNoteByIvkServlet scanNoteByIvkServlet; - @Autowired - private ScanAndMarkNoteByIvkServlet scanAndMarkNoteByIvkServlet; - @Autowired - private ScanNoteByOvkServlet scanNoteByOvkServlet; - @Autowired - private GetRcmServlet getRcmServlet; - @Autowired - private CreateSpendAuthSigServlet createSpendAuthSigServlet; - @Autowired - private CreateShieldNullifierServlet createShieldNullifierServlet; - @Autowired - private GetShieldTransactionHashServlet getShieldTransactionHashServlet; - @Autowired - private GetMerkleTreeVoucherInfoServlet getMerkleTreeVoucherInfoServlet; - @Autowired - private IsSpendServlet isSpendServlet; - @Autowired - private CreateShieldedTransactionWithoutSpendAuthSigServlet - createShieldedTransactionWithoutSpendAuthSigServlet; - @Autowired - private BroadcastHexServlet broadcastHexServlet; - @Autowired - private GetBurnTrxServlet getBurnTrxServlet; - @Autowired - private GetBrokerageServlet getBrokerageServlet; - @Autowired - private GetRewardServlet getRewardServlet; - @Autowired - private UpdateBrokerageServlet updateBrokerageServlet; - @Autowired - private CreateCommonTransactionServlet createCommonTransactionServlet; - @Autowired - private GetTransactionInfoByBlockNumServlet getTransactionInfoByBlockNumServlet; - @Autowired - private IsShieldedTRC20ContractNoteSpentServlet isShieldedTRC20ContractNoteSpentServlet; - @Autowired - private CreateShieldedContractParametersServlet createShieldedContractParametersServlet; - @Autowired - private CreateShieldedContractParametersWithoutAskServlet - createShieldedContractParametersWithoutAskServlet; - @Autowired - private ScanShieldedTRC20NotesByIvkServlet scanShieldedTRC20NotesByIvkServlet; - @Autowired - private ScanShieldedTRC20NotesByOvkServlet scanShieldedTRC20NotesByOvkServlet; - @Autowired - private GetTriggerInputForShieldedTRC20ContractServlet - getTriggerInputForShieldedTRC20ContractServlet; - @Autowired - private MetricsServlet metricsServlet; - @Autowired - private MarketSellAssetServlet marketSellAssetServlet; - @Autowired - private MarketCancelOrderServlet marketCancelOrderServlet; - @Autowired - private GetMarketOrderByAccountServlet getMarketOrderByAccountServlet; - @Autowired - private GetMarketOrderByIdServlet getMarketOrderByIdServlet; - @Autowired - private GetMarketPriceByPairServlet getMarketPriceByPairServlet; - @Autowired - private GetMarketOrderListByPairServlet getMarketOrderListByPairServlet; - @Autowired - private GetMarketPairListServlet getMarketPairListServlet; - - @Autowired - private GetAccountBalanceServlet getAccountBalanceServlet; - - @Autowired - private GetBlockBalanceServlet getBlockBalanceServlet; - + private ApplicationContext applicationContext; @Autowired private LiteFnQueryHttpFilter liteFnQueryHttpFilter; @Autowired private HttpApiAccessFilter httpApiAccessFilter; - @Autowired - private GetTransactionFromPendingServlet getTransactionFromPendingServlet; - @Autowired - private GetTransactionListFromPendingServlet getTransactionListFromPendingServlet; - @Autowired - private GetPendingSizeServlet getPendingSizeServlet; - @Autowired - private GetEnergyPricesServlet getEnergyPricesServlet; - @Autowired - private GetBandwidthPricesServlet getBandwidthPricesServlet; - @Autowired - private GetBlockServlet getBlockServlet; - @Autowired - private GetMemoFeePricesServlet getMemoFeePricesServlet; - - @Autowired - private FreezeBalanceV2Servlet freezeBalanceV2Servlet; - @Autowired - private UnFreezeBalanceV2Servlet unFreezeBalanceV2Servlet; - @Autowired - private WithdrawExpireUnfreezeServlet withdrawExpireUnfreezeServlet; - @Autowired - private DelegateResourceServlet delegateResourceServlet; - @Autowired - private UnDelegateResourceServlet unDelegateResourceServlet; - @Autowired - private CancelAllUnfreezeV2Servlet cancelAllUnfreezeV2Servlet; - @Override - public void init() { + public FullNodeHttpApiService() { + port = Args.getInstance().getFullNodeHttpPort(); + enable = isFullNode() && Args.getInstance().isFullNodeHttpEnable(); + contextPath = "/"; } @Override - public void init(CommonParameter args) { - port = Args.getInstance().getFullNodeHttpPort(); + protected void addServlet(ServletContextHandler context) { + applicationContext.getBeansWithAnnotation(FullServlet.class).values() + .stream().filter(o -> o instanceof Servlet) + .map(o -> (Servlet) o) + .filter(o -> AopUtils.getTargetClass(o).isAnnotationPresent(FullServlet.class)) + .forEach(o -> { + FullServlet path = AopUtils.getTargetClass(o).getAnnotation(FullServlet.class); + Arrays.stream(path.value()).filter(StringUtil::isNotBlank).forEach(p -> + context.addServlet(new ServletHolder(o), p)); + }); } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(getAccountServlet), "/wallet/getaccount"); - context.addServlet(new ServletHolder(transferServlet), "/wallet/createtransaction"); - context.addServlet(new ServletHolder(broadcastServlet), "/wallet/broadcasttransaction"); - context.addServlet(new ServletHolder(updateAccountServlet), "/wallet/updateaccount"); - context.addServlet(new ServletHolder(voteWitnessAccountServlet), - "/wallet/votewitnessaccount"); - context.addServlet(new ServletHolder(createAssetIssueServlet), "/wallet/createassetissue"); - context.addServlet(new ServletHolder(updateWitnessServlet), "/wallet/updatewitness"); - context.addServlet(new ServletHolder(createAccountServlet), "/wallet/createaccount"); - context.addServlet(new ServletHolder(createWitnessServlet), "/wallet/createwitness"); - context.addServlet(new ServletHolder(transferAssetServlet), "/wallet/transferasset"); - context.addServlet(new ServletHolder(participateAssetIssueServlet), - "/wallet/participateassetissue"); - context.addServlet(new ServletHolder(freezeBalanceServlet), "/wallet/freezebalance"); - context.addServlet(new ServletHolder(unFreezeBalanceServlet), "/wallet/unfreezebalance"); - context.addServlet(new ServletHolder(unFreezeAssetServlet), "/wallet/unfreezeasset"); - context.addServlet(new ServletHolder(withdrawBalanceServlet), "/wallet/withdrawbalance"); - context.addServlet(new ServletHolder(updateAssetServlet), "/wallet/updateasset"); - context.addServlet(new ServletHolder(listNodesServlet), "/wallet/listnodes"); - context.addServlet( - new ServletHolder(getAssetIssueByAccountServlet), "/wallet/getassetissuebyaccount"); - context.addServlet(new ServletHolder(getAccountNetServlet), "/wallet/getaccountnet"); - context.addServlet(new ServletHolder(getAssetIssueByNameServlet), - "/wallet/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueListByNameServlet), - "/wallet/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdServlet), "/wallet/getassetissuebyid"); - context.addServlet(new ServletHolder(getNowBlockServlet), "/wallet/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumServlet), "/wallet/getblockbynum"); - context.addServlet(new ServletHolder(getBlockByIdServlet), "/wallet/getblockbyid"); - context.addServlet(new ServletHolder(getBlockByLimitNextServlet), - "/wallet/getblockbylimitnext"); - context.addServlet(new ServletHolder(getBlockByLatestNumServlet), - "/wallet/getblockbylatestnum"); - context.addServlet(new ServletHolder(getTransactionByIdServlet), - "/wallet/gettransactionbyid"); - context.addServlet( - new ServletHolder(getTransactionInfoByIdServlet), "/wallet/gettransactioninfobyid"); - context.addServlet( - new ServletHolder(getTransactionReceiptByIdServlet), "/wallet/gettransactionreceiptbyid"); - context.addServlet( - new ServletHolder(getTransactionCountByBlockNumServlet), - "/wallet/gettransactioncountbyblocknum"); - context.addServlet(new ServletHolder(listWitnessesServlet), "/wallet/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListServlet), "/wallet/getassetissuelist"); - context.addServlet( - new ServletHolder(getPaginatedAssetIssueListServlet), - "/wallet/getpaginatedassetissuelist"); - context.addServlet( - new ServletHolder(getPaginatedProposalListServlet), "/wallet/getpaginatedproposallist"); - context.addServlet( - new ServletHolder(getPaginatedExchangeListServlet), "/wallet/getpaginatedexchangelist"); - context.addServlet(new ServletHolder(totalTransactionServlet), "/wallet/totaltransaction"); - context.addServlet( - new ServletHolder(getNextMaintenanceTimeServlet), "/wallet/getnextmaintenancetime"); - context.addServlet(new ServletHolder(validateAddressServlet), "/wallet/validateaddress"); - context.addServlet(new ServletHolder(deployContractServlet), "/wallet/deploycontract"); - context.addServlet(new ServletHolder(triggerSmartContractServlet), - "/wallet/triggersmartcontract"); - context.addServlet(new ServletHolder(triggerConstantContractServlet), - "/wallet/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyServlet), "/wallet/estimateenergy"); - context.addServlet(new ServletHolder(getContractServlet), "/wallet/getcontract"); - context.addServlet(new ServletHolder(getContractInfoServlet), "/wallet/getcontractinfo"); - context.addServlet(new ServletHolder(clearABIServlet), "/wallet/clearabi"); - context.addServlet(new ServletHolder(proposalCreateServlet), "/wallet/proposalcreate"); - context.addServlet(new ServletHolder(proposalApproveServlet), "/wallet/proposalapprove"); - context.addServlet(new ServletHolder(proposalDeleteServlet), "/wallet/proposaldelete"); - context.addServlet(new ServletHolder(listProposalsServlet), "/wallet/listproposals"); - context.addServlet(new ServletHolder(getProposalByIdServlet), "/wallet/getproposalbyid"); - context.addServlet(new ServletHolder(exchangeCreateServlet), "/wallet/exchangecreate"); - context.addServlet(new ServletHolder(exchangeInjectServlet), "/wallet/exchangeinject"); - context.addServlet(new ServletHolder(exchangeTransactionServlet), - "/wallet/exchangetransaction"); - context.addServlet(new ServletHolder(exchangeWithdrawServlet), "/wallet/exchangewithdraw"); - context.addServlet(new ServletHolder(getExchangeByIdServlet), "/wallet/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesServlet), "/wallet/listexchanges"); - context.addServlet(new ServletHolder(getChainParametersServlet), - "/wallet/getchainparameters"); - context.addServlet(new ServletHolder(getAccountResourceServlet), - "/wallet/getaccountresource"); - context.addServlet(new ServletHolder(getTransactionSignWeightServlet), - "/wallet/getsignweight"); - context.addServlet(new ServletHolder(getTransactionApprovedListServlet), - "/wallet/getapprovedlist"); - context.addServlet(new ServletHolder(accountPermissionUpdateServlet), - "/wallet/accountpermissionupdate"); - context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); - context.addServlet(new ServletHolder(updateSettingServlet), "/wallet/updatesetting"); - context.addServlet(new ServletHolder(updateEnergyLimitServlet), "/wallet/updateenergylimit"); - context.addServlet(new ServletHolder(getDelegatedResourceServlet), - "/wallet/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceV2Servlet), - "/wallet/getdelegatedresourcev2"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeServlet), - "/wallet/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getAvailableUnfreezeCountServlet), - "/wallet/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountServlet), - "/wallet/getcanwithdrawunfreezeamount"); - context.addServlet( - new ServletHolder(getDelegatedResourceAccountIndexServlet), - "/wallet/getdelegatedresourceaccountindex"); - context.addServlet( - new ServletHolder(getDelegatedResourceAccountIndexV2Servlet), - "/wallet/getdelegatedresourceaccountindexv2"); - context.addServlet(new ServletHolder(setAccountServlet), "/wallet/setaccountid"); - context.addServlet(new ServletHolder(getAccountByIdServlet), "/wallet/getaccountbyid"); - context - .addServlet(new ServletHolder(getExpandedSpendingKeyServlet), - "/wallet/getexpandedspendingkey"); - context.addServlet(new ServletHolder(getAkFromAskServlet), "/wallet/getakfromask"); - context.addServlet(new ServletHolder(getNkFromNskServlet), "/wallet/getnkfromnsk"); - context.addServlet(new ServletHolder(getSpendingKeyServlet), "/wallet/getspendingkey"); - context - .addServlet(new ServletHolder(getNewShieldedAddressServlet), - "/wallet/getnewshieldedaddress"); - context.addServlet(new ServletHolder(getDiversifierServlet), "/wallet/getdiversifier"); - context.addServlet(new ServletHolder(getIncomingViewingKeyServlet), - "/wallet/getincomingviewingkey"); - context.addServlet(new ServletHolder(getZenPaymentAddressServlet), - "/wallet/getzenpaymentaddress"); - // context.addServlet(new ServletHolder(createShieldedTransactionServlet), - // "/wallet/createshieldedtransaction"); - // context.addServlet(new ServletHolder(createShieldedTransactionWithoutSpendAuthSigServlet), - // "/wallet/createshieldedtransactionwithoutspendauthsig"); - // context.addServlet(new ServletHolder(scanNoteByIvkServlet), "/wallet/scannotebyivk"); - // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkServlet), - // "/wallet/scanandmarknotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByOvkServlet), "/wallet/scannotebyovk"); - context.addServlet(new ServletHolder(getRcmServlet), "/wallet/getrcm"); - // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoServlet), - // "/wallet/getmerkletreevoucherinfo"); - // context.addServlet(new ServletHolder(isSpendServlet), "/wallet/isspend"); - context.addServlet(new ServletHolder(createSpendAuthSigServlet), - "/wallet/createspendauthsig"); - // context.addServlet(new ServletHolder(createShieldNullifierServlet), - // "/wallet/createshieldnullifier"); - // context.addServlet(new ServletHolder(getShieldTransactionHashServlet), - // "/wallet/getshieldtransactionhash"); - - context - .addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentServlet), - "/wallet/isshieldedtrc20contractnotespent"); - context.addServlet(new ServletHolder(createShieldedContractParametersServlet), - "/wallet/createshieldedcontractparameters"); - context.addServlet(new ServletHolder(createShieldedContractParametersWithoutAskServlet), - "/wallet/createshieldedcontractparameterswithoutask"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkServlet), - "/wallet/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkServlet), - "/wallet/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(getTriggerInputForShieldedTRC20ContractServlet), - "/wallet/gettriggerinputforshieldedtrc20contract"); - - context.addServlet(new ServletHolder(broadcastHexServlet), "/wallet/broadcasthex"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/wallet/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/wallet/getReward"); - context.addServlet(new ServletHolder(updateBrokerageServlet), "/wallet/updateBrokerage"); - context.addServlet(new ServletHolder(createCommonTransactionServlet), - "/wallet/createCommonTransaction"); - context.addServlet(new ServletHolder(getTransactionInfoByBlockNumServlet), - "/wallet/gettransactioninfobyblocknum"); - context.addServlet(new ServletHolder(listNodesServlet), "/net/listnodes"); - - context.addServlet(new ServletHolder(metricsServlet), "/monitor/getstatsinfo"); - context.addServlet(new ServletHolder(getNodeInfoServlet), "/monitor/getnodeinfo"); - context.addServlet(new ServletHolder(marketSellAssetServlet), "/wallet/marketsellasset"); - context.addServlet(new ServletHolder(marketCancelOrderServlet), "/wallet/marketcancelorder"); - context.addServlet(new ServletHolder(getMarketOrderByAccountServlet), - "/wallet/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdServlet), - "/wallet/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairServlet), - "/wallet/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairServlet), - "/wallet/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListServlet), - "/wallet/getmarketpairlist"); - - context.addServlet(new ServletHolder(getAccountBalanceServlet), - "/wallet/getaccountbalance"); - context.addServlet(new ServletHolder(getBlockBalanceServlet), - "/wallet/getblockbalance"); - context.addServlet(new ServletHolder(getBurnTrxServlet), "/wallet/getburntrx"); - context.addServlet(new ServletHolder(getTransactionFromPendingServlet), - "/wallet/gettransactionfrompending"); - context.addServlet(new ServletHolder(getTransactionListFromPendingServlet), - "/wallet/gettransactionlistfrompending"); - context.addServlet(new ServletHolder(getPendingSizeServlet), "/wallet/getpendingsize"); - context.addServlet(new ServletHolder(getEnergyPricesServlet), "/wallet/getenergyprices"); - context.addServlet(new ServletHolder(getBandwidthPricesServlet), - "/wallet/getbandwidthprices"); - context.addServlet(new ServletHolder(getBlockServlet), "/wallet/getblock"); - context.addServlet(new ServletHolder(getMemoFeePricesServlet), "/wallet/getmemofee"); - - context.addServlet(new ServletHolder(freezeBalanceV2Servlet), - "/wallet/freezebalancev2"); - context.addServlet(new ServletHolder(unFreezeBalanceV2Servlet), - "/wallet/unfreezebalancev2"); - context.addServlet(new ServletHolder(withdrawExpireUnfreezeServlet), - "/wallet/withdrawexpireunfreeze"); - context.addServlet(new ServletHolder(delegateResourceServlet), - "/wallet/delegateresource"); - context.addServlet(new ServletHolder(unDelegateResourceServlet), - "/wallet/undelegateresource"); - context.addServlet(new ServletHolder(cancelAllUnfreezeV2Servlet), - "/wallet/cancelallunfreezev2"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - // filters the specified APIs - // when node is lite fullnode and openHistoryQueryWhenLiteFN is false - context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", - EnumSet.allOf(DispatcherType.class)); - - // http access filter, it should have higher priority than HttpInterceptor - context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", - EnumSet.allOf(DispatcherType.class)); - // note: if the pathSpec of servlet is not started with wallet, it should be included here - context.getServletHandler().getFilterMappings()[1] - .setPathSpecs(new String[] {"/wallet/*", - "/net/listnodes", - "/monitor/getstatsinfo", - "/monitor/getnodeinfo"}); - - // metrics filter - ServletHandler handler = new ServletHandler(); - FilterHolder fh = handler - .addFilterWithMapping((Class) HttpInterceptor.class, "/*", - EnumSet.of(DispatcherType.REQUEST)); - context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + protected void addFilter(ServletContextHandler context) { + // filters the specified APIs + // when node is lite fullnode and openHistoryQueryWhenLiteFN is false + context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", + EnumSet.allOf(DispatcherType.class)); + + // http access filter, it should have higher priority than HttpInterceptor + context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", + EnumSet.allOf(DispatcherType.class)); + // note: if the pathSpec of servlet is not started with wallet, it should be included here + context.getServletHandler().getFilterMappings()[1] + .setPathSpecs(new String[] {"/wallet/*", + "/net/listnodes", + "/monitor/getstatsinfo", + "/monitor/getnodeinfo"}); + + // metrics filter + ServletHandler handler = new ServletHandler(); + FilterHolder fh = handler + .addFilterWithMapping((Class) HttpInterceptor.class, "/*", + EnumSet.of(DispatcherType.REQUEST)); + context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); } } diff --git a/framework/src/main/java/org/tron/core/services/http/GetAccountBalanceServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAccountBalanceServlet.java index 159c3899666..9bef9b0906d 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAccountBalanceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAccountBalanceServlet.java @@ -1,16 +1,16 @@ package org.tron.core.services.http; -import com.alibaba.fastjson.JSONObject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; -import org.tron.protos.Protocol.Account; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.contract.BalanceContract; +@FullServlet("/wallet/getaccountbalance") @Component @Slf4j(topic = "API") public class GetAccountBalanceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAccountByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAccountByIdServlet.java index 7387b801168..e5417927dd7 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAccountByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAccountByIdServlet.java @@ -8,9 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Account; +@FullServlet("/wallet/getaccountbyid") +@SolidityNodeServlet("/walletsolidity/getaccountbyid") @Component @Slf4j(topic = "API") public class GetAccountByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAccountNetServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAccountNetServlet.java index 121a23c61ab..b4e6386fdcd 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAccountNetServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAccountNetServlet.java @@ -9,9 +9,11 @@ import org.tron.api.GrpcAPI.AccountNetMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Account; +@FullServlet("/wallet/getaccountnet") @Component @Slf4j(topic = "API") public class GetAccountNetServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAccountResourceServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAccountResourceServlet.java index 98224334e1a..64ed45cc2f9 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAccountResourceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAccountResourceServlet.java @@ -10,7 +10,9 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getaccountresource") @Component @Slf4j(topic = "API") public class GetAccountResourceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAccountServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAccountServlet.java index 7de95dab541..492c0283f95 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAccountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAccountServlet.java @@ -7,9 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Account; +@FullServlet("/wallet/getaccount") +@SolidityNodeServlet("/walletsolidity/getaccount") @Component @Slf4j(topic = "API") public class GetAccountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAkFromAskServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAkFromAskServlet.java index c31692413a9..92763ad0206 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAkFromAskServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAkFromAskServlet.java @@ -9,7 +9,9 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getakfromask") @Component @Slf4j(topic = "API") public class GetAkFromAskServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByAccountServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByAccountServlet.java index e9e85af2e81..f85177a1343 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByAccountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByAccountServlet.java @@ -9,9 +9,11 @@ import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Account; +@FullServlet("/wallet/getassetissuebyaccount") @Component @Slf4j(topic = "API") public class GetAssetIssueByAccountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByIdServlet.java index 08f8227deee..b907c4427d6 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByIdServlet.java @@ -7,9 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract; +@FullServlet("/wallet/getassetissuebyid") +@SolidityNodeServlet("/walletsolidity/getassetissuebyid") @Component @Slf4j(topic = "API") public class GetAssetIssueByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByNameServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByNameServlet.java index a1cc0525514..473c65806fe 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByNameServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueByNameServlet.java @@ -10,9 +10,13 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract; +@FullServlet("/wallet/getassetissuebyname") +@SolidityNodeServlet("/walletsolidity/getassetissuebyname") @Component @Slf4j(topic = "API") public class GetAssetIssueByNameServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListByNameServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListByNameServlet.java index d9b7426011d..8e38c25a630 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListByNameServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListByNameServlet.java @@ -12,8 +12,12 @@ import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getassetissuelistbyname") +@SolidityNodeServlet("/walletsolidity/getassetissuelistbyname") @Component @Slf4j(topic = "API") public class GetAssetIssueListByNameServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListServlet.java index 3968554a671..024a7fdb5c5 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAssetIssueListServlet.java @@ -7,7 +7,11 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getassetissuelist") +@SolidityNodeServlet("/walletsolidity/getassetissuelist") @Component @Slf4j(topic = "API") public class GetAssetIssueListServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetAvailableUnfreezeCountServlet.java b/framework/src/main/java/org/tron/core/services/http/GetAvailableUnfreezeCountServlet.java index 51f78fc4390..f6a85302c79 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetAvailableUnfreezeCountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetAvailableUnfreezeCountServlet.java @@ -10,7 +10,11 @@ import org.tron.api.GrpcAPI; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getavailableunfreezecount") +@SolidityNodeServlet("/walletsolidity/getavailableunfreezecount") @Component @Slf4j(topic = "API") public class GetAvailableUnfreezeCountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBandwidthPricesServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBandwidthPricesServlet.java index 09d51cc8635..480c8909ae1 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBandwidthPricesServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBandwidthPricesServlet.java @@ -7,7 +7,11 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.PricesResponseMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getbandwidthprices") +@SolidityNodeServlet("/walletsolidity/getbandwidthprices") @Component @Slf4j(topic = "API") public class GetBandwidthPricesServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBlockBalanceServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBlockBalanceServlet.java index 0fc3256899c..09462696177 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBlockBalanceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBlockBalanceServlet.java @@ -1,16 +1,16 @@ package org.tron.core.services.http; -import com.alibaba.fastjson.JSONObject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; -import org.tron.protos.Protocol.Account; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.contract.BalanceContract.BlockBalanceTrace; +@FullServlet("/wallet/getblockbalance") @Component @Slf4j(topic = "API") public class GetBlockBalanceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBlockByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBlockByIdServlet.java index f7e6ac0ff7d..71fd7f03486 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBlockByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBlockByIdServlet.java @@ -10,9 +10,13 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Block; +@FullServlet("/wallet/getblockbyid") +@SolidityNodeServlet("/walletsolidity/getblockbyid") @Component @Slf4j(topic = "API") public class GetBlockByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBlockByLatestNumServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBlockByLatestNumServlet.java index 1f2eabdd8dc..078080948c3 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBlockByLatestNumServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBlockByLatestNumServlet.java @@ -9,8 +9,12 @@ import org.tron.api.GrpcAPI.BlockList; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getblockbylatestnum") +@SolidityNodeServlet("/walletsolidity/getblockbylatestnum") @Component @Slf4j(topic = "API") public class GetBlockByLatestNumServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBlockByLimitNextServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBlockByLimitNextServlet.java index 3e6700a1fae..4b43f49f391 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBlockByLimitNextServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBlockByLimitNextServlet.java @@ -9,8 +9,12 @@ import org.tron.api.GrpcAPI.BlockLimit; import org.tron.api.GrpcAPI.BlockList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getblockbylimitnext") +@SolidityNodeServlet("/walletsolidity/getblockbylimitnext") @Component @Slf4j(topic = "API") public class GetBlockByLimitNextServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBlockByNumServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBlockByNumServlet.java index 800b421ace0..708a0af28d5 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBlockByNumServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBlockByNumServlet.java @@ -8,9 +8,13 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Block; +@FullServlet("/wallet/getblockbynum") +@SolidityNodeServlet("/walletsolidity/getblockbynum") @Component @Slf4j(topic = "API") public class GetBlockByNumServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBlockServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBlockServlet.java index 0e0104e8014..9319e76234e 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBlockServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBlockServlet.java @@ -12,9 +12,13 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.BlockReq; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Block; +@FullServlet("/wallet/getblock") +@SolidityNodeServlet("/walletsolidity/getblock") @Component @Slf4j(topic = "API") public class GetBlockServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBrokerageServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBrokerageServlet.java index 1fbd94fe690..801fdccd1cd 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBrokerageServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBrokerageServlet.java @@ -8,8 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.db.Manager; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getBrokerage") +@SolidityNodeServlet("/walletsolidity/getBrokerage") @Component @Slf4j(topic = "API") public class GetBrokerageServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetBurnTrxServlet.java b/framework/src/main/java/org/tron/core/services/http/GetBurnTrxServlet.java index e574affff6b..8a4097a2704 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetBurnTrxServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetBurnTrxServlet.java @@ -7,8 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.db.Manager; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getburntrx") +@SolidityNodeServlet("/walletsolidity/getburntrx") @Component @Slf4j(topic = "API") public class GetBurnTrxServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetCanDelegatedMaxSizeServlet.java b/framework/src/main/java/org/tron/core/services/http/GetCanDelegatedMaxSizeServlet.java index 924306a6a3f..999975f8f28 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetCanDelegatedMaxSizeServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetCanDelegatedMaxSizeServlet.java @@ -10,7 +10,11 @@ import org.tron.api.GrpcAPI; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getcandelegatedmaxsize") +@SolidityNodeServlet("/walletsolidity/getcandelegatedmaxsize") @Component @Slf4j(topic = "API") public class GetCanDelegatedMaxSizeServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetCanWithdrawUnfreezeAmountServlet.java b/framework/src/main/java/org/tron/core/services/http/GetCanWithdrawUnfreezeAmountServlet.java index 435cca9e5fb..1288ac6c380 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetCanWithdrawUnfreezeAmountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetCanWithdrawUnfreezeAmountServlet.java @@ -10,7 +10,11 @@ import org.tron.api.GrpcAPI; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getcanwithdrawunfreezeamount") +@SolidityNodeServlet("/walletsolidity/getcanwithdrawunfreezeamount") @Component @Slf4j(topic = "API") public class GetCanWithdrawUnfreezeAmountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetChainParametersServlet.java b/framework/src/main/java/org/tron/core/services/http/GetChainParametersServlet.java index 18c96f4d64e..fd9e3b849b6 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetChainParametersServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetChainParametersServlet.java @@ -6,8 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getchainparameters") @Component @Slf4j(topic = "API") public class GetChainParametersServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetContractInfoServlet.java b/framework/src/main/java/org/tron/core/services/http/GetContractInfoServlet.java index 86ed7f6d9b6..ee4875be6f2 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetContractInfoServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetContractInfoServlet.java @@ -1,7 +1,6 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -9,10 +8,11 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.BytesMessage; import org.tron.core.Wallet; -import org.tron.protos.contract.SmartContractOuterClass.SmartContract; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.contract.SmartContractOuterClass.SmartContractDataWrapper; +@FullServlet("/wallet/getcontractinfo") @Component @Slf4j(topic = "API") public class GetContractInfoServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetContractServlet.java b/framework/src/main/java/org/tron/core/services/http/GetContractServlet.java index b9efd6c1520..ff0c9aacfe4 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetContractServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetContractServlet.java @@ -10,9 +10,11 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.BytesMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; +@FullServlet("/wallet/getcontract") @Component @Slf4j(topic = "API") public class GetContractServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexServlet.java b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexServlet.java index 035e20cb873..e8f84839b94 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexServlet.java @@ -11,9 +11,13 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; +@FullServlet("/wallet/getdelegatedresourceaccountindex") +@SolidityNodeServlet("/walletsolidity/getdelegatedresourceaccountindex") @Component @Slf4j(topic = "API") public class GetDelegatedResourceAccountIndexServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexV2Servlet.java b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexV2Servlet.java index 3d5bff80941..592e26286e7 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexV2Servlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceAccountIndexV2Servlet.java @@ -11,9 +11,13 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; +@FullServlet("/wallet/getdelegatedresourceaccountindexv2") +@SolidityNodeServlet("/walletsolidity/getdelegatedresourceaccountindexv2") @Component @Slf4j(topic = "API") public class GetDelegatedResourceAccountIndexV2Servlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceServlet.java b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceServlet.java index 5787aba3c93..bc2e33f6006 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceServlet.java @@ -2,7 +2,6 @@ import com.google.protobuf.ByteString; import java.io.IOException; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -12,8 +11,12 @@ import org.tron.api.GrpcAPI.DelegatedResourceMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getdelegatedresource") +@SolidityNodeServlet("/walletsolidity/getdelegatedresource") @Component @Slf4j(topic = "API") public class GetDelegatedResourceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceV2Servlet.java b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceV2Servlet.java index 632bb4f8033..1b5cc5181d4 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceV2Servlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetDelegatedResourceV2Servlet.java @@ -2,7 +2,6 @@ import com.google.protobuf.ByteString; import java.io.IOException; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -12,9 +11,12 @@ import org.tron.api.GrpcAPI.DelegatedResourceMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; - +@FullServlet("/wallet/getdelegatedresourcev2") +@SolidityNodeServlet("/walletsolidity/getdelegatedresourcev2") @Component @Slf4j(topic = "API") public class GetDelegatedResourceV2Servlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetDiversifierServlet.java b/framework/src/main/java/org/tron/core/services/http/GetDiversifierServlet.java index e37a1d6a785..2b1ee1ceaba 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetDiversifierServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetDiversifierServlet.java @@ -1,6 +1,5 @@ package org.tron.core.services.http; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -8,8 +7,10 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getdiversifier") @Component @Slf4j(topic = "API") public class GetDiversifierServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetEnergyPricesServlet.java b/framework/src/main/java/org/tron/core/services/http/GetEnergyPricesServlet.java index b9b6ba0d893..caea1b75d1f 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetEnergyPricesServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetEnergyPricesServlet.java @@ -7,7 +7,11 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.PricesResponseMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getenergyprices") +@SolidityNodeServlet("/walletsolidity/getenergyprices") @Component @Slf4j(topic = "API") public class GetEnergyPricesServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetExchangeByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetExchangeByIdServlet.java index 7a84c0ea8a4..327a44945c9 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetExchangeByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetExchangeByIdServlet.java @@ -3,7 +3,6 @@ import com.alibaba.fastjson.JSONObject; import com.google.protobuf.ByteString; import java.io.IOException; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -11,8 +10,12 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getexchangebyid") +@SolidityNodeServlet("/walletsolidity/getexchangebyid") @Component @Slf4j(topic = "API") public class GetExchangeByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetExpandedSpendingKeyServlet.java b/framework/src/main/java/org/tron/core/services/http/GetExpandedSpendingKeyServlet.java index a71f5db56e1..80c3b2bf47d 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetExpandedSpendingKeyServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetExpandedSpendingKeyServlet.java @@ -1,7 +1,6 @@ package org.tron.core.services.http; import com.google.protobuf.ByteString; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -11,7 +10,9 @@ import org.tron.api.GrpcAPI.ExpandedSpendingKeyMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getexpandedspendingkey") @Component @Slf4j(topic = "API") public class GetExpandedSpendingKeyServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetIncomingViewingKeyServlet.java b/framework/src/main/java/org/tron/core/services/http/GetIncomingViewingKeyServlet.java index b572cf348e5..2b7435c2278 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetIncomingViewingKeyServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetIncomingViewingKeyServlet.java @@ -9,8 +9,10 @@ import org.tron.api.GrpcAPI; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getincomingviewingkey") @Component @Slf4j(topic = "API") public class GetIncomingViewingKeyServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByAccountServlet.java b/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByAccountServlet.java index 1c3190b62ea..47e0825a580 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByAccountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByAccountServlet.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; import com.google.protobuf.ByteString; import java.io.IOException; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -12,9 +11,13 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.MarketOrderList; +@FullServlet("/wallet/getmarketorderbyaccount") +@SolidityNodeServlet("/walletsolidity/getmarketorderbyaccount") @Component @Slf4j(topic = "API") public class GetMarketOrderByAccountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByIdServlet.java index bdb8a4b6d3c..a216d41b749 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetMarketOrderByIdServlet.java @@ -10,9 +10,13 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.MarketOrder; +@FullServlet("/wallet/getmarketorderbyid") +@SolidityNodeServlet("/walletsolidity/getmarketorderbyid") @Component @Slf4j(topic = "API") public class GetMarketOrderByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetMarketOrderListByPairServlet.java b/framework/src/main/java/org/tron/core/services/http/GetMarketOrderListByPairServlet.java index 963ea880033..2c4b05698f3 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetMarketOrderListByPairServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetMarketOrderListByPairServlet.java @@ -8,10 +8,14 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.MarketOrderList; import org.tron.protos.Protocol.MarketOrderPair; +@FullServlet("/wallet/getmarketorderlistbypair") +@SolidityNodeServlet("/walletsolidity/getmarketorderlistbypair") @Component @Slf4j(topic = "API") public class GetMarketOrderListByPairServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetMarketPairListServlet.java b/framework/src/main/java/org/tron/core/services/http/GetMarketPairListServlet.java index 6cb9c5d868f..d416ad88ca0 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetMarketPairListServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetMarketPairListServlet.java @@ -7,9 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.MarketOrderPairList; +@FullServlet("/wallet/getmarketpairlist") +@SolidityNodeServlet("/walletsolidity/getmarketpairlist") @Component @Slf4j(topic = "API") public class GetMarketPairListServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetMarketPriceByPairServlet.java b/framework/src/main/java/org/tron/core/services/http/GetMarketPriceByPairServlet.java index b6d31e10936..95f32c7cf06 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetMarketPriceByPairServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetMarketPriceByPairServlet.java @@ -8,10 +8,14 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.MarketOrderPair; import org.tron.protos.Protocol.MarketPriceList; +@FullServlet("/wallet/getmarketpricebypair") +@SolidityNodeServlet("/walletsolidity/getmarketpricebypair") @Component @Slf4j(topic = "API") public class GetMarketPriceByPairServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetMemoFeePricesServlet.java b/framework/src/main/java/org/tron/core/services/http/GetMemoFeePricesServlet.java index 0da52bf9d35..912df4e7f9e 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetMemoFeePricesServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetMemoFeePricesServlet.java @@ -7,7 +7,9 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.PricesResponseMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getmemofee") @Component @Slf4j(topic = "API") public class GetMemoFeePricesServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetNewShieldedAddressServlet.java b/framework/src/main/java/org/tron/core/services/http/GetNewShieldedAddressServlet.java index 853268b7c8c..e78bc677b3e 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetNewShieldedAddressServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetNewShieldedAddressServlet.java @@ -7,7 +7,9 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.ShieldedAddressInfo; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getnewshieldedaddress") @Component @Slf4j(topic = "API") public class GetNewShieldedAddressServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetNextMaintenanceTimeServlet.java b/framework/src/main/java/org/tron/core/services/http/GetNextMaintenanceTimeServlet.java index c93244f5782..d39cf9a4bf2 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetNextMaintenanceTimeServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetNextMaintenanceTimeServlet.java @@ -7,8 +7,10 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getnextmaintenancetime") @Component @Slf4j(topic = "API") public class GetNextMaintenanceTimeServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetNkFromNskServlet.java b/framework/src/main/java/org/tron/core/services/http/GetNkFromNskServlet.java index 6ec2f525e1b..36d70953069 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetNkFromNskServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetNkFromNskServlet.java @@ -9,7 +9,9 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getnkfromnsk") @Component @Slf4j(topic = "API") public class GetNkFromNskServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetNodeInfoServlet.java b/framework/src/main/java/org/tron/core/services/http/GetNodeInfoServlet.java index 8516d1c51bb..c4ec816ca62 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetNodeInfoServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetNodeInfoServlet.java @@ -9,8 +9,12 @@ import org.springframework.stereotype.Component; import org.tron.common.entity.NodeInfo; import org.tron.core.services.NodeInfoService; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet({"/wallet/getnodeinfo", "/monitor/getnodeinfo"}) +@SolidityNodeServlet({"/wallet/getnodeinfo", "/walletsolidity/getnodeinfo"}) @Component @Slf4j(topic = "API") public class GetNodeInfoServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetNowBlockServlet.java b/framework/src/main/java/org/tron/core/services/http/GetNowBlockServlet.java index 56e01d557f5..44b87926374 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetNowBlockServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetNowBlockServlet.java @@ -6,8 +6,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Block; +@FullServlet("/wallet/getnowblock") +@SolidityNodeServlet("/walletsolidity/getnowblock") @Component @Slf4j(topic = "API") public class GetNowBlockServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetPaginatedAssetIssueListServlet.java b/framework/src/main/java/org/tron/core/services/http/GetPaginatedAssetIssueListServlet.java index 0246979e279..eb2f196e8c7 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetPaginatedAssetIssueListServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetPaginatedAssetIssueListServlet.java @@ -9,7 +9,11 @@ import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.api.GrpcAPI.PaginatedMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getpaginatedassetissuelist") +@SolidityNodeServlet("/walletsolidity/getpaginatedassetissuelist") @Component @Slf4j(topic = "API") public class GetPaginatedAssetIssueListServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetPaginatedExchangeListServlet.java b/framework/src/main/java/org/tron/core/services/http/GetPaginatedExchangeListServlet.java index 28018497952..e513c9dfc28 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetPaginatedExchangeListServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetPaginatedExchangeListServlet.java @@ -9,7 +9,9 @@ import org.tron.api.GrpcAPI.ExchangeList; import org.tron.api.GrpcAPI.PaginatedMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getpaginatedexchangelist") @Component @Slf4j(topic = "API") public class GetPaginatedExchangeListServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetPaginatedProposalListServlet.java b/framework/src/main/java/org/tron/core/services/http/GetPaginatedProposalListServlet.java index 11b2c57ff48..21d56b125ed 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetPaginatedProposalListServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetPaginatedProposalListServlet.java @@ -10,7 +10,9 @@ import org.tron.api.GrpcAPI.PaginatedMessage; import org.tron.api.GrpcAPI.ProposalList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getpaginatedproposallist") @Component @Slf4j(topic = "API") public class GetPaginatedProposalListServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetPendingSizeServlet.java b/framework/src/main/java/org/tron/core/services/http/GetPendingSizeServlet.java index 7e1a5f71841..87970da83f6 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetPendingSizeServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetPendingSizeServlet.java @@ -7,8 +7,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.db.Manager; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getpendingsize") @Component @Slf4j(topic = "API") public class GetPendingSizeServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetProposalByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetProposalByIdServlet.java index a903a5b4920..3d5c2d2c785 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetProposalByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetProposalByIdServlet.java @@ -3,8 +3,6 @@ import com.alibaba.fastjson.JSONObject; import com.google.protobuf.ByteString; import java.io.IOException; -import java.util.HashMap; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -12,9 +10,11 @@ import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Proposal; +@FullServlet("/wallet/getproposalbyid") @Component @Slf4j(topic = "API") public class GetProposalByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetRcmServlet.java b/framework/src/main/java/org/tron/core/services/http/GetRcmServlet.java index 091867455f5..8ab3a97889c 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetRcmServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetRcmServlet.java @@ -7,8 +7,10 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.BytesMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getrcm") @Component @Slf4j(topic = "API") public class GetRcmServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetRewardServlet.java b/framework/src/main/java/org/tron/core/services/http/GetRewardServlet.java index c4d97f46c57..6ef5f8ccc44 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetRewardServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetRewardServlet.java @@ -8,8 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.db.Manager; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/getReward") +@SolidityNodeServlet("/walletsolidity/getReward") @Component @Slf4j(topic = "API") public class GetRewardServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetSpendingKeyServlet.java b/framework/src/main/java/org/tron/core/services/http/GetSpendingKeyServlet.java index 23c274566ca..13ca0b79494 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetSpendingKeyServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetSpendingKeyServlet.java @@ -1,6 +1,5 @@ package org.tron.core.services.http; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -8,7 +7,9 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.BytesMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/getspendingkey") @Component @Slf4j(topic = "API") public class GetSpendingKeyServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionApprovedListServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionApprovedListServlet.java index d4d123b7efe..dc081d3f6a5 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionApprovedListServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionApprovedListServlet.java @@ -7,9 +7,11 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.TransactionApprovedList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; +@FullServlet("/wallet/getapprovedlist") @Component @Slf4j(topic = "API") public class GetTransactionApprovedListServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionByIdServlet.java index 49343da9070..eaf512a37e9 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionByIdServlet.java @@ -2,7 +2,6 @@ import com.google.protobuf.ByteString; import java.io.IOException; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -11,9 +10,13 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Transaction; +@FullServlet("/wallet/gettransactionbyid") +@SolidityNodeServlet("/walletsolidity/gettransactionbyid") @Component @Slf4j(topic = "API") public class GetTransactionByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionCountByBlockNumServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionCountByBlockNumServlet.java index e096df507d7..14c83c6c7d7 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionCountByBlockNumServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionCountByBlockNumServlet.java @@ -1,7 +1,6 @@ package org.tron.core.services.http; import java.io.IOException; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -9,8 +8,12 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/gettransactioncountbyblocknum") +@SolidityNodeServlet("/walletsolidity/gettransactioncountbyblocknum") @Component @Slf4j(topic = "API") public class GetTransactionCountByBlockNumServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionFromPendingServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionFromPendingServlet.java index 276eff62af8..f7d866a6cb2 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionFromPendingServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionFromPendingServlet.java @@ -9,8 +9,10 @@ import org.tron.common.utils.ByteArray; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.db.Manager; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/gettransactionfrompending") @Component @Slf4j(topic = "API") public class GetTransactionFromPendingServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByBlockNumServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByBlockNumServlet.java index 587dd2d6613..ad0b196e6df 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByBlockNumServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByBlockNumServlet.java @@ -12,9 +12,13 @@ import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.GrpcAPI.TransactionInfoList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.Protocol.TransactionInfo.Log; +@FullServlet("/wallet/gettransactioninfobyblocknum") +@SolidityNodeServlet("/walletsolidity/gettransactioninfobyblocknum") @Component @Slf4j(topic = "API") public class GetTransactionInfoByBlockNumServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByIdServlet.java index 580cb4a5b66..82e40828a22 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionInfoByIdServlet.java @@ -2,7 +2,6 @@ import com.google.protobuf.ByteString; import java.util.List; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -11,10 +10,14 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.Protocol.TransactionInfo.Log; +@FullServlet("/wallet/gettransactioninfobyid") +@SolidityNodeServlet("/walletsolidity/gettransactioninfobyid") @Component @Slf4j(topic = "API") public class GetTransactionInfoByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionListFromPendingServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionListFromPendingServlet.java index 0a70b22eebf..f6b3bb70bf5 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionListFromPendingServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionListFromPendingServlet.java @@ -8,8 +8,10 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.TransactionIdList; import org.tron.core.db.Manager; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/gettransactionlistfrompending") @Component @Slf4j(topic = "API") public class GetTransactionListFromPendingServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionReceiptByIdServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionReceiptByIdServlet.java index bdd46d85a88..963f6d5cb8b 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionReceiptByIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionReceiptByIdServlet.java @@ -9,9 +9,11 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.TransactionInfo; +@FullServlet("/wallet/gettransactionreceiptbyid") @Component @Slf4j(topic = "API") public class GetTransactionReceiptByIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTransactionSignWeightServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTransactionSignWeightServlet.java index bbd819d4e6d..b9985c36cfd 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTransactionSignWeightServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTransactionSignWeightServlet.java @@ -6,10 +6,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.TransactionSignWeight; +import org.tron.core.services.annotation.FullServlet; import org.tron.core.utils.TransactionUtil; import org.tron.protos.Protocol.Transaction; +@FullServlet("/wallet/getsignweight") @Component @Slf4j(topic = "API") public class GetTransactionSignWeightServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetTriggerInputForShieldedTRC20ContractServlet.java b/framework/src/main/java/org/tron/core/services/http/GetTriggerInputForShieldedTRC20ContractServlet.java index 3a0bc4ed282..b873f1d05f7 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetTriggerInputForShieldedTRC20ContractServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetTriggerInputForShieldedTRC20ContractServlet.java @@ -1,6 +1,5 @@ package org.tron.core.services.http; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -9,7 +8,9 @@ import org.tron.api.GrpcAPI.BytesMessage; import org.tron.api.GrpcAPI.ShieldedTRC20TriggerContractParameters; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/gettriggerinputforshieldedtrc20contract") @Component @Slf4j(topic = "API") public class GetTriggerInputForShieldedTRC20ContractServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/GetZenPaymentAddressServlet.java b/framework/src/main/java/org/tron/core/services/http/GetZenPaymentAddressServlet.java index c78b663eec2..3f7ace66043 100644 --- a/framework/src/main/java/org/tron/core/services/http/GetZenPaymentAddressServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/GetZenPaymentAddressServlet.java @@ -10,10 +10,12 @@ import org.tron.api.GrpcAPI; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.core.zen.address.DiversifierT; import org.tron.core.zen.address.IncomingViewingKey; +@FullServlet("/wallet/getzenpaymentaddress") @Component @Slf4j(topic = "API") public class GetZenPaymentAddressServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/IsShieldedTRC20ContractNoteSpentServlet.java b/framework/src/main/java/org/tron/core/services/http/IsShieldedTRC20ContractNoteSpentServlet.java index 9e01ec8fda1..85fb7a08dc7 100644 --- a/framework/src/main/java/org/tron/core/services/http/IsShieldedTRC20ContractNoteSpentServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/IsShieldedTRC20ContractNoteSpentServlet.java @@ -1,6 +1,5 @@ package org.tron.core.services.http; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -9,7 +8,11 @@ import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.NfTRC20Parameters; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/isshieldedtrc20contractnotespent") +@SolidityNodeServlet("/walletsolidity/isshieldedtrc20contractnotespent") @Component @Slf4j(topic = "API") public class IsShieldedTRC20ContractNoteSpentServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ListExchangesServlet.java b/framework/src/main/java/org/tron/core/services/http/ListExchangesServlet.java index ff349ecefab..70e81a7948a 100644 --- a/framework/src/main/java/org/tron/core/services/http/ListExchangesServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ListExchangesServlet.java @@ -6,8 +6,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/listexchanges") +@SolidityNodeServlet("/walletsolidity/listexchanges") @Component @Slf4j(topic = "API") public class ListExchangesServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ListNodesServlet.java b/framework/src/main/java/org/tron/core/services/http/ListNodesServlet.java index 6b7b2b251a8..247120987d4 100644 --- a/framework/src/main/java/org/tron/core/services/http/ListNodesServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ListNodesServlet.java @@ -7,7 +7,9 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.NodeList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet({"/wallet/listnodes", "/net/listnodes"}) @Component @Slf4j(topic = "API") public class ListNodesServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ListProposalsServlet.java b/framework/src/main/java/org/tron/core/services/http/ListProposalsServlet.java index a3b26d4afc6..d251e82f12a 100644 --- a/framework/src/main/java/org/tron/core/services/http/ListProposalsServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ListProposalsServlet.java @@ -7,7 +7,9 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.ProposalList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/listproposals") @Component @Slf4j(topic = "API") public class ListProposalsServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ListWitnessesServlet.java b/framework/src/main/java/org/tron/core/services/http/ListWitnessesServlet.java index 5274d07992b..fa6e7659add 100644 --- a/framework/src/main/java/org/tron/core/services/http/ListWitnessesServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ListWitnessesServlet.java @@ -7,8 +7,12 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.WitnessList; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/listwitnesses") +@SolidityNodeServlet("/walletsolidity/listwitnesses") @Component @Slf4j(topic = "API") public class ListWitnessesServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/MarketCancelOrderServlet.java b/framework/src/main/java/org/tron/core/services/http/MarketCancelOrderServlet.java index 8d19d60ce5c..7e8604d4df8 100644 --- a/framework/src/main/java/org/tron/core/services/http/MarketCancelOrderServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/MarketCancelOrderServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.MarketContract.MarketCancelOrderContract; +@FullServlet("/wallet/marketcancelorder") @Component @Slf4j(topic = "API") public class MarketCancelOrderServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/MarketSellAssetServlet.java b/framework/src/main/java/org/tron/core/services/http/MarketSellAssetServlet.java index 258dd270811..2dd5f8b2b0f 100644 --- a/framework/src/main/java/org/tron/core/services/http/MarketSellAssetServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/MarketSellAssetServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.MarketContract.MarketSellAssetContract; +@FullServlet("/wallet/marketsellasset") @Component @Slf4j(topic = "API") public class MarketSellAssetServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/MetricsServlet.java b/framework/src/main/java/org/tron/core/services/http/MetricsServlet.java index bb4bf18e58e..a40b1d3bd4f 100644 --- a/framework/src/main/java/org/tron/core/services/http/MetricsServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/MetricsServlet.java @@ -8,7 +8,9 @@ import org.springframework.stereotype.Component; import org.tron.core.metrics.MetricsApiService; import org.tron.core.metrics.MetricsInfo; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/monitor/getstatsinfo") @Component @Slf4j(topic = "API") public class MetricsServlet extends RateLimiterServlet { @@ -29,4 +31,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) { Util.processError(e, response); } } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) { + doGet(request, response); + } } diff --git a/framework/src/main/java/org/tron/core/services/http/ParticipateAssetIssueServlet.java b/framework/src/main/java/org/tron/core/services/http/ParticipateAssetIssueServlet.java index 1e864250bff..4bf74fe3ca2 100644 --- a/framework/src/main/java/org/tron/core/services/http/ParticipateAssetIssueServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ParticipateAssetIssueServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AssetIssueContractOuterClass.ParticipateAssetIssueContract; +@FullServlet("/wallet/participateassetissue") @Component @Slf4j(topic = "API") public class ParticipateAssetIssueServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ProposalApproveServlet.java b/framework/src/main/java/org/tron/core/services/http/ProposalApproveServlet.java index 3fc60016780..36542407fb1 100644 --- a/framework/src/main/java/org/tron/core/services/http/ProposalApproveServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ProposalApproveServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ProposalContract.ProposalApproveContract; +@FullServlet("/wallet/proposalapprove") @Component @Slf4j(topic = "API") public class ProposalApproveServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ProposalCreateServlet.java b/framework/src/main/java/org/tron/core/services/http/ProposalCreateServlet.java index 9660ee7f863..aec7707c45c 100644 --- a/framework/src/main/java/org/tron/core/services/http/ProposalCreateServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ProposalCreateServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ProposalContract.ProposalCreateContract; +@FullServlet("/wallet/proposalcreate") @Component @Slf4j(topic = "API") public class ProposalCreateServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ProposalDeleteServlet.java b/framework/src/main/java/org/tron/core/services/http/ProposalDeleteServlet.java index 09c4c78a37a..c5360eb8c79 100644 --- a/framework/src/main/java/org/tron/core/services/http/ProposalDeleteServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ProposalDeleteServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.ProposalContract.ProposalDeleteContract; +@FullServlet("/wallet/proposaldelete") @Component @Slf4j(topic = "API") public class ProposalDeleteServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByIvkServlet.java b/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByIvkServlet.java index 2b52883f490..d688121ad8a 100644 --- a/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByIvkServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByIvkServlet.java @@ -2,7 +2,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -12,7 +11,11 @@ import org.tron.api.GrpcAPI.IvkDecryptTRC20Parameters; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/scanshieldedtrc20notesbyivk") +@SolidityNodeServlet("/walletsolidity/scanshieldedtrc20notesbyivk") @Component @Slf4j(topic = "API") public class ScanShieldedTRC20NotesByIvkServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByOvkServlet.java b/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByOvkServlet.java index b5fbbab1625..350e6d54619 100644 --- a/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByOvkServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByOvkServlet.java @@ -1,6 +1,5 @@ package org.tron.core.services.http; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -10,7 +9,11 @@ import org.tron.api.GrpcAPI.OvkDecryptTRC20Parameters; import org.tron.common.utils.ByteArray; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; +@FullServlet("/wallet/scanshieldedtrc20notesbyovk") +@SolidityNodeServlet("/walletsolidity/scanshieldedtrc20notesbyovk") @Component @Slf4j(topic = "API") public class ScanShieldedTRC20NotesByOvkServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/SetAccountIdServlet.java b/framework/src/main/java/org/tron/core/services/http/SetAccountIdServlet.java index 36203749e0b..2bd65868bad 100644 --- a/framework/src/main/java/org/tron/core/services/http/SetAccountIdServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/SetAccountIdServlet.java @@ -8,10 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol; import org.tron.protos.contract.AccountContract.SetAccountIdContract; +@FullServlet("/wallet/setaccountid") @Component @Slf4j(topic = "API") public class SetAccountIdServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/TotalTransactionServlet.java b/framework/src/main/java/org/tron/core/services/http/TotalTransactionServlet.java index 6af40232e8f..fd46385fe7b 100644 --- a/framework/src/main/java/org/tron/core/services/http/TotalTransactionServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/TotalTransactionServlet.java @@ -7,8 +7,10 @@ import org.springframework.stereotype.Component; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/totaltransaction") @Component @Slf4j(topic = "API") public class TotalTransactionServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/TransferAssetServlet.java b/framework/src/main/java/org/tron/core/services/http/TransferAssetServlet.java index af2699c4bf4..574e70167f7 100644 --- a/framework/src/main/java/org/tron/core/services/http/TransferAssetServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/TransferAssetServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract; +@FullServlet("/wallet/transferasset") @Component @Slf4j(topic = "API") public class TransferAssetServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/TransferServlet.java b/framework/src/main/java/org/tron/core/services/http/TransferServlet.java index 6f575e4fe3f..3bcf0b786c8 100644 --- a/framework/src/main/java/org/tron/core/services/http/TransferServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/TransferServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.TransferContract; +@FullServlet("/wallet/createtransaction") @Component @Slf4j(topic = "API") public class TransferServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/TriggerConstantContractServlet.java b/framework/src/main/java/org/tron/core/services/http/TriggerConstantContractServlet.java index 8a46ee1ed74..9667b00b156 100644 --- a/framework/src/main/java/org/tron/core/services/http/TriggerConstantContractServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/TriggerConstantContractServlet.java @@ -17,11 +17,15 @@ import org.tron.core.Wallet; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.exception.ContractValidateException; +import org.tron.core.services.annotation.FullServlet; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract; +@FullServlet("/wallet/triggerconstantcontract") +@SolidityNodeServlet("/walletsolidity/triggerconstantcontract") @Component @Slf4j(topic = "API") public class TriggerConstantContractServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/TriggerSmartContractServlet.java b/framework/src/main/java/org/tron/core/services/http/TriggerSmartContractServlet.java index 6577a9e5f24..99ecaffa3c0 100644 --- a/framework/src/main/java/org/tron/core/services/http/TriggerSmartContractServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/TriggerSmartContractServlet.java @@ -18,11 +18,13 @@ import org.tron.core.Wallet; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.exception.ContractValidateException; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract; +@FullServlet("/wallet/triggersmartcontract") @Component @Slf4j(topic = "API") public class TriggerSmartContractServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UnDelegateResourceServlet.java b/framework/src/main/java/org/tron/core/services/http/UnDelegateResourceServlet.java index cf9c2c95dcd..84a96a0e271 100644 --- a/framework/src/main/java/org/tron/core/services/http/UnDelegateResourceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UnDelegateResourceServlet.java @@ -7,10 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.UnDelegateResourceContract; +@FullServlet("/wallet/undelegateresource") @Component @Slf4j(topic = "API") public class UnDelegateResourceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UnFreezeAssetServlet.java b/framework/src/main/java/org/tron/core/services/http/UnFreezeAssetServlet.java index 6118b39f2cd..21895da12ff 100644 --- a/framework/src/main/java/org/tron/core/services/http/UnFreezeAssetServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UnFreezeAssetServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AssetIssueContractOuterClass.UnfreezeAssetContract; +@FullServlet("/wallet/unfreezeasset") @Component @Slf4j(topic = "API") public class UnFreezeAssetServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceServlet.java b/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceServlet.java index eb075b7139d..5691ea5248b 100644 --- a/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.UnfreezeBalanceContract; +@FullServlet("/wallet/unfreezebalance") @Component @Slf4j(topic = "API") public class UnFreezeBalanceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceV2Servlet.java b/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceV2Servlet.java index 614a7ca6b7a..5cbfa1f0c67 100644 --- a/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceV2Servlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UnFreezeBalanceV2Servlet.java @@ -7,10 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.UnfreezeBalanceV2Contract; +@FullServlet("/wallet/unfreezebalancev2") @Component @Slf4j(topic = "API") public class UnFreezeBalanceV2Servlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UpdateAccountServlet.java b/framework/src/main/java/org/tron/core/services/http/UpdateAccountServlet.java index 0251a46ec64..0acec95a0bf 100644 --- a/framework/src/main/java/org/tron/core/services/http/UpdateAccountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UpdateAccountServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AccountContract.AccountUpdateContract; +@FullServlet("/wallet/updateaccount") @Component @Slf4j(topic = "API") public class UpdateAccountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UpdateAssetServlet.java b/framework/src/main/java/org/tron/core/services/http/UpdateAssetServlet.java index d3f467ff7a8..08c8d173724 100644 --- a/framework/src/main/java/org/tron/core/services/http/UpdateAssetServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UpdateAssetServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.AssetIssueContractOuterClass.UpdateAssetContract; +@FullServlet("/wallet/updateasset") @Component @Slf4j(topic = "API") public class UpdateAssetServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UpdateBrokerageServlet.java b/framework/src/main/java/org/tron/core/services/http/UpdateBrokerageServlet.java index 23daaef6072..e7ed9069575 100644 --- a/framework/src/main/java/org/tron/core/services/http/UpdateBrokerageServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UpdateBrokerageServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.StorageContract.UpdateBrokerageContract; +@FullServlet("/wallet/updateBrokerage") @Component @Slf4j(topic = "API") public class UpdateBrokerageServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UpdateEnergyLimitServlet.java b/framework/src/main/java/org/tron/core/services/http/UpdateEnergyLimitServlet.java index aac6e8ff50e..56d1f83b0c6 100644 --- a/framework/src/main/java/org/tron/core/services/http/UpdateEnergyLimitServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UpdateEnergyLimitServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.SmartContractOuterClass.UpdateEnergyLimitContract; +@FullServlet("/wallet/updateenergylimit") @Component @Slf4j(topic = "API") public class UpdateEnergyLimitServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UpdateSettingServlet.java b/framework/src/main/java/org/tron/core/services/http/UpdateSettingServlet.java index 821054c7b4e..66cdbe53f6e 100644 --- a/framework/src/main/java/org/tron/core/services/http/UpdateSettingServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UpdateSettingServlet.java @@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.SmartContractOuterClass.UpdateSettingContract; +@FullServlet("/wallet/updatesetting") @Component @Slf4j(topic = "API") public class UpdateSettingServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/UpdateWitnessServlet.java b/framework/src/main/java/org/tron/core/services/http/UpdateWitnessServlet.java index 3584557d3b6..9c4fc1ca81a 100644 --- a/framework/src/main/java/org/tron/core/services/http/UpdateWitnessServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/UpdateWitnessServlet.java @@ -1,18 +1,19 @@ package org.tron.core.services.http; import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.WitnessContract.WitnessUpdateContract; +@FullServlet("/wallet/updatewitness") @Component @Slf4j(topic = "API") public class UpdateWitnessServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/Util.java b/framework/src/main/java/org/tron/core/services/http/Util.java index 2b6b929d8a0..4c2b839b68a 100644 --- a/framework/src/main/java/org/tron/core/services/http/Util.java +++ b/framework/src/main/java/org/tron/core/services/http/Util.java @@ -12,7 +12,6 @@ import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Message; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; diff --git a/framework/src/main/java/org/tron/core/services/http/ValidateAddressServlet.java b/framework/src/main/java/org/tron/core/services/http/ValidateAddressServlet.java index a65e2ce2ee0..932133c33db 100644 --- a/framework/src/main/java/org/tron/core/services/http/ValidateAddressServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/ValidateAddressServlet.java @@ -12,8 +12,10 @@ import org.tron.common.utils.ByteArray; import org.tron.common.utils.Commons; import org.tron.common.utils.DecodeUtil; +import org.tron.core.services.annotation.FullServlet; +@FullServlet("/wallet/validateaddress") @Component @Slf4j(topic = "API") public class ValidateAddressServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/VoteWitnessAccountServlet.java b/framework/src/main/java/org/tron/core/services/http/VoteWitnessAccountServlet.java index 0a77a0e6fc1..7720830e86f 100644 --- a/framework/src/main/java/org/tron/core/services/http/VoteWitnessAccountServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/VoteWitnessAccountServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.WitnessContract.VoteWitnessContract; +@FullServlet("/wallet/votewitnessaccount") @Component @Slf4j(topic = "API") public class VoteWitnessAccountServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/WithdrawBalanceServlet.java b/framework/src/main/java/org/tron/core/services/http/WithdrawBalanceServlet.java index 27ea54d8ee2..8560268a4a3 100644 --- a/framework/src/main/java/org/tron/core/services/http/WithdrawBalanceServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/WithdrawBalanceServlet.java @@ -8,11 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.WithdrawBalanceContract; +@FullServlet("/wallet/withdrawbalance") @Component @Slf4j(topic = "API") public class WithdrawBalanceServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/WithdrawExpireUnfreezeServlet.java b/framework/src/main/java/org/tron/core/services/http/WithdrawExpireUnfreezeServlet.java index 4888ee42de4..5d1a1e423f9 100644 --- a/framework/src/main/java/org/tron/core/services/http/WithdrawExpireUnfreezeServlet.java +++ b/framework/src/main/java/org/tron/core/services/http/WithdrawExpireUnfreezeServlet.java @@ -9,11 +9,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.FullServlet; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.WithdrawExpireUnfreezeContract; +@FullServlet("/wallet/withdrawexpireunfreeze") @Component @Slf4j(topic = "API") public class WithdrawExpireUnfreezeServlet extends RateLimiterServlet { diff --git a/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java b/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java index 0c66b220e09..f18f822fedc 100644 --- a/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java +++ b/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java @@ -1,65 +1,22 @@ package org.tron.core.services.http.solidity; +import java.util.Arrays; import java.util.EnumSet; import javax.servlet.DispatcherType; +import javax.servlet.Servlet; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.StringUtil; +import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; import org.tron.core.config.args.Args; +import org.tron.core.services.annotation.SolidityNodeServlet; import org.tron.core.services.filter.HttpApiAccessFilter; -import org.tron.core.services.http.EstimateEnergyServlet; -import org.tron.core.services.http.GetAccountByIdServlet; -import org.tron.core.services.http.GetAccountServlet; -import org.tron.core.services.http.GetAssetIssueByIdServlet; -import org.tron.core.services.http.GetAssetIssueByNameServlet; -import org.tron.core.services.http.GetAssetIssueListByNameServlet; -import org.tron.core.services.http.GetAssetIssueListServlet; -import org.tron.core.services.http.GetAvailableUnfreezeCountServlet; -import org.tron.core.services.http.GetBandwidthPricesServlet; -import org.tron.core.services.http.GetBlockByIdServlet; -import org.tron.core.services.http.GetBlockByLatestNumServlet; -import org.tron.core.services.http.GetBlockByLimitNextServlet; -import org.tron.core.services.http.GetBlockByNumServlet; -import org.tron.core.services.http.GetBlockServlet; -import org.tron.core.services.http.GetBrokerageServlet; -import org.tron.core.services.http.GetBurnTrxServlet; -import org.tron.core.services.http.GetCanDelegatedMaxSizeServlet; -import org.tron.core.services.http.GetCanWithdrawUnfreezeAmountServlet; -import org.tron.core.services.http.GetDelegatedResourceAccountIndexServlet; -import org.tron.core.services.http.GetDelegatedResourceAccountIndexV2Servlet; -import org.tron.core.services.http.GetDelegatedResourceServlet; -import org.tron.core.services.http.GetDelegatedResourceV2Servlet; -import org.tron.core.services.http.GetEnergyPricesServlet; -import org.tron.core.services.http.GetExchangeByIdServlet; -import org.tron.core.services.http.GetMarketOrderByAccountServlet; -import org.tron.core.services.http.GetMarketOrderByIdServlet; -import org.tron.core.services.http.GetMarketOrderListByPairServlet; -import org.tron.core.services.http.GetMarketPairListServlet; -import org.tron.core.services.http.GetMarketPriceByPairServlet; -import org.tron.core.services.http.GetMerkleTreeVoucherInfoServlet; -import org.tron.core.services.http.GetNodeInfoServlet; -import org.tron.core.services.http.GetNowBlockServlet; -import org.tron.core.services.http.GetPaginatedAssetIssueListServlet; -import org.tron.core.services.http.GetRewardServlet; -import org.tron.core.services.http.GetTransactionCountByBlockNumServlet; -import org.tron.core.services.http.GetTransactionInfoByBlockNumServlet; -import org.tron.core.services.http.IsShieldedTRC20ContractNoteSpentServlet; -import org.tron.core.services.http.IsSpendServlet; -import org.tron.core.services.http.ListExchangesServlet; -import org.tron.core.services.http.ListWitnessesServlet; -import org.tron.core.services.http.ScanAndMarkNoteByIvkServlet; -import org.tron.core.services.http.ScanNoteByIvkServlet; -import org.tron.core.services.http.ScanNoteByOvkServlet; -import org.tron.core.services.http.ScanShieldedTRC20NotesByIvkServlet; -import org.tron.core.services.http.ScanShieldedTRC20NotesByOvkServlet; -import org.tron.core.services.http.TriggerConstantContractServlet; @Component @@ -67,239 +24,38 @@ public class SolidityNodeHttpApiService extends HttpService { @Autowired - private GetAccountServlet getAccountServlet; - @Autowired - private GetTransactionByIdSolidityServlet getTransactionByIdServlet; - @Autowired - private GetTransactionInfoByIdSolidityServlet getTransactionInfoByIdServlet; - @Autowired - private GetTransactionCountByBlockNumServlet getTransactionCountByBlockNumServlet; - @Autowired - private GetDelegatedResourceServlet getDelegatedResourceServlet; - @Autowired - private GetDelegatedResourceV2Servlet getDelegatedResourceV2Servlet; - @Autowired - private GetCanDelegatedMaxSizeServlet getCanDelegatedMaxSizeServlet; - @Autowired - private GetAvailableUnfreezeCountServlet getAvailableUnfreezeCountServlet; - @Autowired - private GetCanWithdrawUnfreezeAmountServlet getCanWithdrawUnfreezeAmountServlet; - @Autowired - private GetDelegatedResourceAccountIndexServlet getDelegatedResourceAccountIndexServlet; - @Autowired - private GetDelegatedResourceAccountIndexV2Servlet getDelegatedResourceAccountIndexV2Servlet; - @Autowired - private GetExchangeByIdServlet getExchangeByIdServlet; - @Autowired - private ListExchangesServlet listExchangesServlet; - @Autowired - private ListWitnessesServlet listWitnessesServlet; - @Autowired - private GetAssetIssueListServlet getAssetIssueListServlet; - @Autowired - private GetPaginatedAssetIssueListServlet getPaginatedAssetIssueListServlet; - @Autowired - private GetAssetIssueByNameServlet getAssetIssueByNameServlet; - @Autowired - private GetAssetIssueByIdServlet getAssetIssueByIdServlet; - @Autowired - private GetAssetIssueListByNameServlet getAssetIssueListByNameServlet; - @Autowired - private GetNowBlockServlet getNowBlockServlet; - @Autowired - private GetBlockByNumServlet getBlockByNumServlet; - @Autowired - private GetNodeInfoServlet getNodeInfoServlet; - @Autowired - private GetAccountByIdServlet getAccountByIdServlet; - @Autowired - private GetBlockByIdServlet getBlockByIdServlet; - @Autowired - private GetBlockByLimitNextServlet getBlockByLimitNextServlet; - @Autowired - private GetBlockByLatestNumServlet getBlockByLatestNumServlet; - @Autowired - private ScanAndMarkNoteByIvkServlet scanAndMarkNoteByIvkServlet; - @Autowired - private ScanNoteByIvkServlet scanNoteByIvkServlet; - @Autowired - private ScanNoteByOvkServlet scanNoteByOvkServlet; - @Autowired - private GetMerkleTreeVoucherInfoServlet getMerkleTreeVoucherInfoServlet; - @Autowired - private IsSpendServlet isSpendServlet; - @Autowired - private ScanShieldedTRC20NotesByIvkServlet scanShieldedTRC20NotesByIvkServlet; - @Autowired - private ScanShieldedTRC20NotesByOvkServlet scanShieldedTRC20NotesByOvkServlet; - @Autowired - private IsShieldedTRC20ContractNoteSpentServlet isShieldedTRC20ContractNoteSpentServlet; - @Autowired - private GetMarketOrderByAccountServlet getMarketOrderByAccountServlet; - @Autowired - private GetMarketOrderByIdServlet getMarketOrderByIdServlet; - @Autowired - private GetMarketPriceByPairServlet getMarketPriceByPairServlet; - @Autowired - private GetMarketOrderListByPairServlet getMarketOrderListByPairServlet; - @Autowired - private GetMarketPairListServlet getMarketPairListServlet; - @Autowired - private GetBurnTrxServlet getBurnTrxServlet; - @Autowired - private GetBrokerageServlet getBrokerageServlet; - @Autowired - private GetRewardServlet getRewardServlet; - @Autowired - private TriggerConstantContractServlet triggerConstantContractServlet; - @Autowired - private EstimateEnergyServlet estimateEnergyServlet; - @Autowired - private GetTransactionInfoByBlockNumServlet getTransactionInfoByBlockNumServlet; + private ApplicationContext applicationContext; @Autowired private HttpApiAccessFilter httpApiAccessFilter; - @Autowired - private GetBlockServlet getBlockServlet; - @Autowired - private GetBandwidthPricesServlet getBandwidthPricesServlet; - @Autowired - private GetEnergyPricesServlet getEnergyPricesServlet; - @Override - public void init() { + public SolidityNodeHttpApiService() { + port = Args.getInstance().getSolidityHttpPort(); + enable = !isFullNode() && Args.getInstance().isSolidityNodeHttpEnable(); + contextPath = "/"; } @Override - public void init(CommonParameter args) { - port = Args.getInstance().getSolidityHttpPort(); + protected void addServlet(ServletContextHandler context) { + applicationContext.getBeansWithAnnotation(SolidityNodeServlet.class).values() + .stream().filter(o -> o instanceof Servlet) + .map(o -> (Servlet) o) + .filter(o -> AopUtils.getTargetClass(o).isAnnotationPresent(SolidityNodeServlet.class)) + .forEach(o -> { + SolidityNodeServlet path = AopUtils.getTargetClass(o) + .getAnnotation(SolidityNodeServlet.class); + Arrays.stream(path.value()).filter(StringUtil::isNotBlank).forEach(p -> + context.addServlet(new ServletHolder(o), p)); + }); } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - // same as FullNode - context.addServlet(new ServletHolder(getAccountServlet), "/walletsolidity/getaccount"); - context.addServlet(new ServletHolder(listWitnessesServlet), "/walletsolidity/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListServlet), - "/walletsolidity/getassetissuelist"); - context.addServlet(new ServletHolder(getPaginatedAssetIssueListServlet), - "/walletsolidity/getpaginatedassetissuelist"); - context.addServlet(new ServletHolder(getAssetIssueByNameServlet), - "/walletsolidity/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdServlet), - "/walletsolidity/getassetissuebyid"); - context.addServlet(new ServletHolder(getAssetIssueListByNameServlet), - "/walletsolidity/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getNowBlockServlet), "/walletsolidity/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumServlet), "/walletsolidity/getblockbynum"); - context.addServlet(new ServletHolder(getDelegatedResourceServlet), - "/walletsolidity/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceV2Servlet), - "/walletsolidity/getdelegatedresourcev2"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeServlet), - "/walletsolidity/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getAvailableUnfreezeCountServlet), - "/walletsolidity/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountServlet), - "/walletsolidity/getcanwithdrawunfreezeamount"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexServlet), - "/walletsolidity/getdelegatedresourceaccountindex"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2Servlet), - "/walletsolidity/getdelegatedresourceaccountindexv2"); - context - .addServlet(new ServletHolder(getExchangeByIdServlet), - "/walletsolidity/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesServlet), - "/walletsolidity/listexchanges"); - - context.addServlet(new ServletHolder(getAccountByIdServlet), - "/walletsolidity/getaccountbyid"); - context.addServlet(new ServletHolder(getBlockByIdServlet), - "/walletsolidity/getblockbyid"); - context.addServlet(new ServletHolder(getBlockByLimitNextServlet), - "/walletsolidity/getblockbylimitnext"); - context.addServlet(new ServletHolder(getBlockByLatestNumServlet), - "/walletsolidity/getblockbylatestnum"); - - // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoServlet), - // "/walletsolidity/getmerkletreevoucherinfo"); - // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkServlet), - // "/walletsolidity/scanandmarknotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByIvkServlet), - // "/walletsolidity/scannotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByOvkServlet), - // "/walletsolidity/scannotebyovk"); - // context.addServlet(new ServletHolder(isSpendServlet), - // "/walletsolidity/isspend"); - - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkServlet), - "/walletsolidity/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkServlet), - "/walletsolidity/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentServlet), - "/walletsolidity/isshieldedtrc20contractnotespent"); - - context.addServlet(new ServletHolder(getTransactionInfoByBlockNumServlet), - "/walletsolidity/gettransactioninfobyblocknum"); - - context.addServlet(new ServletHolder(getMarketOrderByAccountServlet), - "/walletsolidity/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdServlet), - "/walletsolidity/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairServlet), - "/walletsolidity/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairServlet), - "/walletsolidity/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListServlet), - "/walletsolidity/getmarketpairlist"); - - // only for SolidityNode - context.addServlet(new ServletHolder(getTransactionByIdServlet), - "/walletsolidity/gettransactionbyid"); - - context - .addServlet(new ServletHolder(getTransactionInfoByIdServlet), - "/walletsolidity/gettransactioninfobyid"); - context - .addServlet(new ServletHolder(getTransactionCountByBlockNumServlet), - "/walletsolidity/gettransactioncountbyblocknum"); - context.addServlet(new ServletHolder(triggerConstantContractServlet), - "/walletsolidity/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyServlet), - "/walletsolidity/estimateenergy"); - - context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); - context.addServlet(new ServletHolder(getNodeInfoServlet), "/walletsolidity/getnodeinfo"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward"); - context.addServlet(new ServletHolder(getBurnTrxServlet), "/walletsolidity/getburntrx"); - context.addServlet(new ServletHolder(getBlockServlet), "/walletsolidity/getblock"); - context.addServlet(new ServletHolder(getBandwidthPricesServlet), - "/walletsolidity/getbandwidthprices"); - context.addServlet(new ServletHolder(getEnergyPricesServlet), - "/walletsolidity/getenergyprices"); - - // http access filter - context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", - EnumSet.allOf(DispatcherType.class)); - context.getServletHandler().getFilterMappings()[0] - .setPathSpecs(new String[] {"/walletsolidity/*", - "/wallet/getnodeinfo"}); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + protected void addFilter(ServletContextHandler context) { + // http access filter + context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", + EnumSet.allOf(DispatcherType.class)); + context.getServletHandler().getFilterMappings()[0] + .setPathSpecs(new String[] {"/walletsolidity/*", + "/wallet/getnodeinfo"}); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java index 1893a46045a..fffaf8d4e7b 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java +++ b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java @@ -1,14 +1,12 @@ package org.tron.core.services.interfaceJsonRpcOnPBFT; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; +import org.tron.core.config.args.Args; @Component @Slf4j(topic = "API") @@ -17,34 +15,14 @@ public class JsonRpcServiceOnPBFT extends HttpService { @Autowired private JsonRpcOnPBFTServlet jsonRpcOnPBFTServlet; - @Override - public void init() { - } - - @Override - public void init(CommonParameter args) { - port = CommonParameter.getInstance().getJsonRpcHttpPBFTPort(); + public JsonRpcServiceOnPBFT() { + port = Args.getInstance().getJsonRpcHttpPBFTPort(); + enable = isFullNode() && Args.getInstance().isJsonRpcHttpPBFTNodeEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(jsonRpcOnPBFTServlet), "/jsonrpc"); - - int maxHttpConnectNumber = CommonParameter.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - super.start(); - - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + public void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(jsonRpcOnPBFTServlet), "/jsonrpc"); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java index 52f5b761ae2..a6f7d5dd5e7 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java +++ b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java @@ -1,14 +1,12 @@ package org.tron.core.services.interfaceJsonRpcOnSolidity; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; +import org.tron.core.config.args.Args; @Component @Slf4j(topic = "API") @@ -17,33 +15,14 @@ public class JsonRpcServiceOnSolidity extends HttpService { @Autowired private JsonRpcOnSolidityServlet jsonRpcOnSolidityServlet; - @Override - public void init() { - } - - @Override - public void init(CommonParameter args) { - port = CommonParameter.getInstance().getJsonRpcHttpSolidityPort(); + public JsonRpcServiceOnSolidity() { + port = Args.getInstance().getJsonRpcHttpSolidityPort(); + enable = isFullNode() && Args.getInstance().isJsonRpcHttpSolidityNodeEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(jsonRpcOnSolidityServlet), "/jsonrpc"); - - int maxHttpConnectNumber = CommonParameter.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - super.start(); - - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + public void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(jsonRpcOnSolidityServlet), "/jsonrpc"); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java index cf945f664d1..54e7b69f7fc 100755 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java @@ -1,9 +1,7 @@ package org.tron.core.services.interfaceOnPBFT; import io.grpc.netty.NettyServerBuilder; -import io.grpc.protobuf.services.ProtoReflectionService; import io.grpc.stub.StreamObserver; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.tron.api.DatabaseGrpc.DatabaseImplBase; @@ -36,14 +34,8 @@ import org.tron.api.GrpcAPI.WitnessList; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.RpcService; -import org.tron.common.es.ExecutorServiceManager; -import org.tron.common.parameter.CommonParameter; import org.tron.core.config.args.Args; import org.tron.core.services.RpcApiService; -import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; -import org.tron.core.services.ratelimiter.PrometheusInterceptor; -import org.tron.core.services.ratelimiter.RateLimiterInterceptor; -import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; @@ -71,78 +63,16 @@ public class RpcApiServiceOnPBFT extends RpcService { @Autowired private RpcApiService rpcApiService; - @Autowired - private RateLimiterInterceptor rateLimiterInterceptor; - - @Autowired - private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; - - @Autowired - private RpcApiAccessInterceptor apiAccessInterceptor; - - @Autowired - private PrometheusInterceptor prometheusInterceptor; - - private final String executorName = "rpc-pbft-executor"; - - @Override - public void init() { - } - - @Override - public void init(CommonParameter parameter) { + public RpcApiServiceOnPBFT() { port = Args.getInstance().getRpcOnPBFTPort(); + enable = isFullNode() && Args.getInstance().isRpcPBFTEnable(); + executorName = "rpc-pbft-executor"; } @Override - public void start() { - try { - NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port) - .addService(new DatabaseApi()); - - CommonParameter args = CommonParameter.getInstance(); - - if (args.getRpcThreadNum() > 0) { - serverBuilder = serverBuilder - .executor(ExecutorServiceManager.newFixedThreadPool( - executorName, args.getRpcThreadNum())); - } - - serverBuilder = serverBuilder.addService(new WalletPBFTApi()); - - // Set configs from config.conf or default value - serverBuilder - .maxConcurrentCallsPerConnection(args.getMaxConcurrentCallsPerConnection()) - .flowControlWindow(args.getFlowControlWindow()) - .maxConnectionIdle(args.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) - .maxConnectionAge(args.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) - .maxInboundMessageSize(args.getMaxMessageSize()) - .maxHeaderListSize(args.getMaxHeaderListSize()); - - // add a ratelimiter interceptor - serverBuilder.intercept(rateLimiterInterceptor); - - // add api access interceptor - serverBuilder.intercept(apiAccessInterceptor); - - // add lite fullnode query interceptor - serverBuilder.intercept(liteFnQueryGrpcInterceptor); - - // add prometheus interceptor - if (args.isMetricsPrometheusEnable()) { - serverBuilder.intercept(prometheusInterceptor); - } - - if (args.isRpcReflectionServiceEnable()) { - serverBuilder.addService(ProtoReflectionService.newInstance()); - } - - apiServer = serverBuilder.build(); - rateLimiterInterceptor.init(apiServer); - super.start(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); - } + protected void addService(NettyServerBuilder serverBuilder) { + serverBuilder.addService(new DatabaseApi()); + serverBuilder.addService(new WalletPBFTApi()); } /** diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/EstimateEnergyOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/EstimateEnergyOnPBFTServlet.java index 825e2bf79e8..711899c39b1 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/EstimateEnergyOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/EstimateEnergyOnPBFTServlet.java @@ -3,13 +3,14 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.EstimateEnergyServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/estimateenergy") @Component @Slf4j(topic = "API") public class EstimateEnergyOnPBFTServlet extends EstimateEnergyServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountByIdOnPBFTServlet.java index 1506b98ee96..a9079a20d10 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountByIdOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAccountByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getaccountbyid") @Component @Slf4j(topic = "API") public class GetAccountByIdOnPBFTServlet extends GetAccountByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountOnPBFTServlet.java index 1db7d2fbd02..4dbb358e537 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAccountOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAccountServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getaccount") @Component @Slf4j(topic = "API") public class GetAccountOnPBFTServlet extends GetAccountServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByIdOnPBFTServlet.java index 497ac775731..30eb9490afc 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByIdOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAssetIssueByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getassetissuebyid") @Component @Slf4j(topic = "API") public class GetAssetIssueByIdOnPBFTServlet extends GetAssetIssueByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByNameOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByNameOnPBFTServlet.java index 9da748921ab..100bb2c28ed 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByNameOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueByNameOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAssetIssueByNameServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getassetissuebyname") @Component @Slf4j(topic = "API") public class GetAssetIssueByNameOnPBFTServlet extends GetAssetIssueByNameServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListByNameOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListByNameOnPBFTServlet.java index 4f781051cc1..a8e9ce2b234 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListByNameOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListByNameOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAssetIssueListByNameServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getassetissuelistbyname") @Component @Slf4j(topic = "API") public class GetAssetIssueListByNameOnPBFTServlet extends GetAssetIssueListByNameServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListOnPBFTServlet.java index 18f414c04b1..22b9010af1c 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAssetIssueListOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAssetIssueListServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getassetissuelist") @Component @Slf4j(topic = "API") public class GetAssetIssueListOnPBFTServlet extends GetAssetIssueListServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAvailableUnfreezeCountOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAvailableUnfreezeCountOnPBFTServlet.java index bb393f92efc..5e83fa930c5 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAvailableUnfreezeCountOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetAvailableUnfreezeCountOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetAvailableUnfreezeCountServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getavailableunfreezecount") @Component @Slf4j(topic = "API") public class GetAvailableUnfreezeCountOnPBFTServlet extends GetAvailableUnfreezeCountServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServlet.java index c89bc5f9646..ede1c8f72e5 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBandwidthPricesServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getbandwidthprices") @Component @Slf4j(topic = "API") public class GetBandwidthPricesOnPBFTServlet extends GetBandwidthPricesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByIdOnPBFTServlet.java index 59e186ab4e0..713902c80cb 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByIdOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBlockByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getblockbyid") @Component @Slf4j(topic = "API") public class GetBlockByIdOnPBFTServlet extends GetBlockByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLatestNumOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLatestNumOnPBFTServlet.java index 536d6c7bcce..026fac47e54 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLatestNumOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLatestNumOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBlockByLatestNumServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getblockbylatestnum") @Component @Slf4j(topic = "API") public class GetBlockByLatestNumOnPBFTServlet extends GetBlockByLatestNumServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLimitNextOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLimitNextOnPBFTServlet.java index f04d8820cbf..c57edb994d4 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLimitNextOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByLimitNextOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBlockByLimitNextServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getblockbylimitnext") @Component @Slf4j(topic = "API") public class GetBlockByLimitNextOnPBFTServlet extends GetBlockByLimitNextServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByNumOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByNumOnPBFTServlet.java index bc19befc9c0..556f190aa5b 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByNumOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBlockByNumOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBlockByNumServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getblockbynum") @Component @Slf4j(topic = "API") public class GetBlockByNumOnPBFTServlet extends GetBlockByNumServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBrokerageOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBrokerageOnPBFTServlet.java index c0bcc8de6b5..5486e3b4fa3 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBrokerageOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBrokerageOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBrokerageServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getBrokerage") @Component @Slf4j(topic = "API") public class GetBrokerageOnPBFTServlet extends GetBrokerageServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBurnTrxOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBurnTrxOnPBFTServlet.java index fb1654062c8..1066463b2d7 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBurnTrxOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetBurnTrxOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBurnTrxServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getburntrx") @Component @Slf4j(topic = "API") public class GetBurnTrxOnPBFTServlet extends GetBurnTrxServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanDelegatedMaxSizeOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanDelegatedMaxSizeOnPBFTServlet.java index 8b3b47462e8..2a0a81b6590 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanDelegatedMaxSizeOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanDelegatedMaxSizeOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetCanDelegatedMaxSizeServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getcandelegatedmaxsize") @Component @Slf4j(topic = "API") public class GetCanDelegatedMaxSizeOnPBFTServlet extends GetCanDelegatedMaxSizeServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanWithdrawUnfreezeAmountOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanWithdrawUnfreezeAmountOnPBFTServlet.java index c8b20c4eef7..82692ad3824 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanWithdrawUnfreezeAmountOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetCanWithdrawUnfreezeAmountOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetCanWithdrawUnfreezeAmountServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getcanwithdrawunfreezeamount") @Component @Slf4j(topic = "API") public class GetCanWithdrawUnfreezeAmountOnPBFTServlet diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexOnPBFTServlet.java index febee663796..14a94f68876 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetDelegatedResourceAccountIndexServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getdelegatedresourceaccountindex") @Component @Slf4j(topic = "API") public class GetDelegatedResourceAccountIndexOnPBFTServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexV2OnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexV2OnPBFTServlet.java index 07541905300..c0dac4e2db1 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexV2OnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceAccountIndexV2OnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetDelegatedResourceAccountIndexV2Servlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getdelegatedresourceaccountindexv2") @Component @Slf4j(topic = "API") public class GetDelegatedResourceAccountIndexV2OnPBFTServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceOnPBFTServlet.java index 04b4a0436aa..818c4a3b7ec 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetDelegatedResourceServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getdelegatedresource") @Component @Slf4j(topic = "API") public class GetDelegatedResourceOnPBFTServlet extends GetDelegatedResourceServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceV2OnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceV2OnPBFTServlet.java index 6429c90eec5..86a2c509386 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceV2OnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetDelegatedResourceV2OnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetDelegatedResourceV2Servlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getdelegatedresourcev2") @Component @Slf4j(topic = "API") public class GetDelegatedResourceV2OnPBFTServlet extends GetDelegatedResourceV2Servlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServlet.java index 11c1dcaa0e8..f653d190c7f 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetEnergyPricesServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getenergyprices") @Component @Slf4j(topic = "API") public class GetEnergyPricesOnPBFTServlet extends GetEnergyPricesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetExchangeByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetExchangeByIdOnPBFTServlet.java index ecdbd5228d2..f0ba2f33461 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetExchangeByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetExchangeByIdOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetExchangeByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getexchangebyid") @Component @Slf4j(topic = "API") public class GetExchangeByIdOnPBFTServlet extends GetExchangeByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByAccountOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByAccountOnPBFTServlet.java index 7fa308c3abc..9ccba4943d3 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByAccountOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByAccountOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetMarketOrderByAccountServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getmarketorderbyaccount") @Component @Slf4j(topic = "API") public class GetMarketOrderByAccountOnPBFTServlet extends GetMarketOrderByAccountServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByIdOnPBFTServlet.java index 63809fd032c..aa35d8c48ae 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderByIdOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetMarketOrderByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getmarketorderbyid") @Component @Slf4j(topic = "API") public class GetMarketOrderByIdOnPBFTServlet extends GetMarketOrderByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderListByPairOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderListByPairOnPBFTServlet.java index b18dde73651..2143c86ac68 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderListByPairOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketOrderListByPairOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetMarketOrderListByPairServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getmarketorderlistbypair") @Component @Slf4j(topic = "API") public class GetMarketOrderListByPairOnPBFTServlet extends GetMarketOrderListByPairServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPairListOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPairListOnPBFTServlet.java index 4d3f69c9132..59fc7db9ab8 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPairListOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPairListOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetMarketPairListServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getmarketpairlist") @Component @Slf4j(topic = "API") public class GetMarketPairListOnPBFTServlet extends GetMarketPairListServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPriceByPairOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPriceByPairOnPBFTServlet.java index 330cf2c2552..41926b9f530 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPriceByPairOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMarketPriceByPairOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetMarketPriceByPairServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getmarketpricebypair") @Component @Slf4j(topic = "API") public class GetMarketPriceByPairOnPBFTServlet extends GetMarketPriceByPairServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMerkleTreeVoucherInfoOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMerkleTreeVoucherInfoOnPBFTServlet.java index 0e92ccf2d92..0bb7ad4854d 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMerkleTreeVoucherInfoOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetMerkleTreeVoucherInfoOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetMerkleTreeVoucherInfoServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getmerkletreevoucherinfo") @Component @Slf4j(topic = "API") public class GetMerkleTreeVoucherInfoOnPBFTServlet extends GetMerkleTreeVoucherInfoServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNodeInfoOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNodeInfoOnPBFTServlet.java index 0149d29326d..891964b9df5 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNodeInfoOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNodeInfoOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetNodeInfoServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getnodeinfo") @Component @Slf4j(topic = "API") public class GetNodeInfoOnPBFTServlet extends GetNodeInfoServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNowBlockOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNowBlockOnPBFTServlet.java index e37ff729433..8a0d825414b 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNowBlockOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetNowBlockOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetNowBlockServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getnowblock") @Component @Slf4j(topic = "API") public class GetNowBlockOnPBFTServlet extends GetNowBlockServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetPaginatedAssetIssueListOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetPaginatedAssetIssueListOnPBFTServlet.java index 900c75d34af..3f6b06294d1 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetPaginatedAssetIssueListOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetPaginatedAssetIssueListOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetPaginatedAssetIssueListServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getpaginatedassetissuelist") @Component @Slf4j(topic = "API") public class GetPaginatedAssetIssueListOnPBFTServlet extends GetPaginatedAssetIssueListServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetRewardOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetRewardOnPBFTServlet.java index 98c20c7d5eb..df9db180b63 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetRewardOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetRewardOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetRewardServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getReward") @Component @Slf4j(topic = "API") public class GetRewardOnPBFTServlet extends GetRewardServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetTransactionCountByBlockNumOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetTransactionCountByBlockNumOnPBFTServlet.java index b79f6001d27..2b5525d78f0 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetTransactionCountByBlockNumOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/GetTransactionCountByBlockNumOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetTransactionCountByBlockNumServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/gettransactioncountbyblocknum") @Component @Slf4j(topic = "API") public class GetTransactionCountByBlockNumOnPBFTServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsShieldedTRC20ContractNoteSpentOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsShieldedTRC20ContractNoteSpentOnPBFTServlet.java index afdb6dfc71e..ae604894889 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsShieldedTRC20ContractNoteSpentOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsShieldedTRC20ContractNoteSpentOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.IsShieldedTRC20ContractNoteSpentServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/isshieldedtrc20contractnotespent") @Component @Slf4j(topic = "API") public class IsShieldedTRC20ContractNoteSpentOnPBFTServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsSpendOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsSpendOnPBFTServlet.java index 82fb6fb72a7..da5e2c4be8c 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsSpendOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/IsSpendOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.IsSpendServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/isspend") @Component @Slf4j(topic = "API") public class IsSpendOnPBFTServlet extends IsSpendServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListExchangesOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListExchangesOnPBFTServlet.java index 234db10b7ac..9dfe0995255 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListExchangesOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListExchangesOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ListExchangesServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/listexchanges") @Component @Slf4j(topic = "API") public class ListExchangesOnPBFTServlet extends ListExchangesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListWitnessesOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListWitnessesOnPBFTServlet.java index 940f072a709..765774e7242 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListWitnessesOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ListWitnessesOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ListWitnessesServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/listwitnesses") @Component @Slf4j(topic = "API") public class ListWitnessesOnPBFTServlet extends ListWitnessesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetBlockOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetBlockOnPBFTServlet.java index 3207ebcf161..1f02d458c41 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetBlockOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetBlockOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetBlockServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/getblock") @Component @Slf4j(topic = "API") public class GetBlockOnPBFTServlet extends GetBlockServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionByIdOnPBFTServlet.java index fc7a8a47257..38db2c7a144 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionByIdOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetTransactionByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/gettransactionbyid") @Component @Slf4j(topic = "API") public class GetTransactionByIdOnPBFTServlet extends GetTransactionByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionInfoByIdOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionInfoByIdOnPBFTServlet.java index f96720123fd..206920cf3f7 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionInfoByIdOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/GetTransactionInfoByIdOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.GetTransactionInfoByIdServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/gettransactioninfobyid") @Component @Slf4j(topic = "API") public class GetTransactionInfoByIdOnPBFTServlet extends GetTransactionInfoByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java index 7a5fd0cbcde..643c6723ce2 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java @@ -1,297 +1,64 @@ package org.tron.core.services.interfaceOnPBFT.http.PBFT; +import java.util.Arrays; import java.util.EnumSet; import javax.servlet.DispatcherType; +import javax.servlet.Servlet; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.StringUtil; +import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; import org.tron.core.config.args.Args; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.filter.HttpApiAccessFilter; import org.tron.core.services.filter.LiteFnQueryHttpFilter; -import org.tron.core.services.interfaceOnPBFT.http.EstimateEnergyOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAccountByIdOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAccountOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAssetIssueByIdOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAssetIssueByNameOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAssetIssueListByNameOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAssetIssueListOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetAvailableUnfreezeCountOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBandwidthPricesOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBlockByIdOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBlockByLatestNumOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBlockByLimitNextOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBlockByNumOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBrokerageOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetBurnTrxOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetCanDelegatedMaxSizeOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetCanWithdrawUnfreezeAmountOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetDelegatedResourceAccountIndexOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetDelegatedResourceAccountIndexV2OnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetDelegatedResourceOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetDelegatedResourceV2OnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetEnergyPricesOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetExchangeByIdOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetMarketOrderByAccountOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetMarketOrderByIdOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetMarketOrderListByPairOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetMarketPairListOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetMarketPriceByPairOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetMerkleTreeVoucherInfoOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetNodeInfoOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetNowBlockOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetPaginatedAssetIssueListOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetRewardOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.GetTransactionCountByBlockNumOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.IsShieldedTRC20ContractNoteSpentOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.IsSpendOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ListExchangesOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ListWitnessesOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ScanAndMarkNoteByIvkOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ScanNoteByIvkOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ScanNoteByOvkOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ScanShieldedTRC20NotesByIvkOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.ScanShieldedTRC20NotesByOvkOnPBFTServlet; -import org.tron.core.services.interfaceOnPBFT.http.TriggerConstantContractOnPBFTServlet; @Slf4j(topic = "API") public class HttpApiOnPBFTService extends HttpService { @Autowired - private GetAccountOnPBFTServlet accountOnPBFTServlet; + private ApplicationContext applicationContext; - @Autowired - private GetTransactionByIdOnPBFTServlet getTransactionByIdOnPBFTServlet; - @Autowired - private GetTransactionInfoByIdOnPBFTServlet getTransactionInfoByIdOnPBFTServlet; - @Autowired - private ListWitnessesOnPBFTServlet listWitnessesOnPBFTServlet; - @Autowired - private GetAssetIssueListOnPBFTServlet getAssetIssueListOnPBFTServlet; - @Autowired - private GetPaginatedAssetIssueListOnPBFTServlet getPaginatedAssetIssueListOnPBFTServlet; - @Autowired - private GetNowBlockOnPBFTServlet getNowBlockOnPBFTServlet; - @Autowired - private GetBlockByNumOnPBFTServlet getBlockByNumOnPBFTServlet; - - @Autowired - private GetNodeInfoOnPBFTServlet getNodeInfoOnPBFTServlet; - - @Autowired - private GetDelegatedResourceOnPBFTServlet getDelegatedResourceOnPBFTServlet; - @Autowired - private GetDelegatedResourceAccountIndexOnPBFTServlet - getDelegatedResourceAccountIndexOnPBFTServlet; - @Autowired - private GetExchangeByIdOnPBFTServlet getExchangeByIdOnPBFTServlet; - @Autowired - private ListExchangesOnPBFTServlet listExchangesOnPBFTServlet; - @Autowired - private GetTransactionCountByBlockNumOnPBFTServlet - getTransactionCountByBlockNumOnPBFTServlet; - @Autowired - private GetAssetIssueByNameOnPBFTServlet getAssetIssueByNameOnPBFTServlet; - @Autowired - private GetAssetIssueByIdOnPBFTServlet getAssetIssueByIdOnPBFTServlet; - @Autowired - private GetAssetIssueListByNameOnPBFTServlet getAssetIssueListByNameOnPBFTServlet; - @Autowired - private GetAccountByIdOnPBFTServlet getAccountByIdOnPBFTServlet; - @Autowired - private GetBlockByIdOnPBFTServlet getBlockByIdOnPBFTServlet; - @Autowired - private GetBlockByLimitNextOnPBFTServlet getBlockByLimitNextOnPBFTServlet; - @Autowired - private GetBlockByLatestNumOnPBFTServlet getBlockByLatestNumOnPBFTServlet; - @Autowired - private GetMerkleTreeVoucherInfoOnPBFTServlet getMerkleTreeVoucherInfoOnPBFTServlet; - @Autowired - private ScanNoteByIvkOnPBFTServlet scanNoteByIvkOnPBFTServlet; - @Autowired - private ScanAndMarkNoteByIvkOnPBFTServlet scanAndMarkNoteByIvkOnPBFTServlet; - @Autowired - private ScanNoteByOvkOnPBFTServlet scanNoteByOvkOnPBFTServlet; - @Autowired - private IsSpendOnPBFTServlet isSpendOnPBFTServlet; - @Autowired - private GetBrokerageOnPBFTServlet getBrokerageServlet; - @Autowired - private GetRewardOnPBFTServlet getRewardServlet; - @Autowired - private TriggerConstantContractOnPBFTServlet triggerConstantContractOnPBFTServlet; - @Autowired - private EstimateEnergyOnPBFTServlet estimateEnergyOnPBFTServlet; @Autowired private LiteFnQueryHttpFilter liteFnQueryHttpFilter; @Autowired private HttpApiAccessFilter httpApiAccessFilter; - @Autowired - private GetMarketOrderByAccountOnPBFTServlet getMarketOrderByAccountOnPBFTServlet; - @Autowired - private GetMarketOrderByIdOnPBFTServlet getMarketOrderByIdOnPBFTServlet; - @Autowired - private GetMarketPriceByPairOnPBFTServlet getMarketPriceByPairOnPBFTServlet; - @Autowired - private GetMarketOrderListByPairOnPBFTServlet getMarketOrderListByPairOnPBFTServlet; - @Autowired - private GetMarketPairListOnPBFTServlet getMarketPairListOnPBFTServlet; - - @Autowired - private ScanShieldedTRC20NotesByIvkOnPBFTServlet scanShieldedTRC20NotesByIvkOnPBFTServlet; - @Autowired - private ScanShieldedTRC20NotesByOvkOnPBFTServlet scanShieldedTRC20NotesByOvkOnPBFTServlet; - @Autowired - private IsShieldedTRC20ContractNoteSpentOnPBFTServlet - isShieldedTRC20ContractNoteSpentOnPBFTServlet; - @Autowired - private GetBurnTrxOnPBFTServlet getBurnTrxOnPBFTServlet; - @Autowired - private GetBandwidthPricesOnPBFTServlet getBandwidthPricesOnPBFTServlet; - @Autowired - private GetEnergyPricesOnPBFTServlet getEnergyPricesOnPBFTServlet; - - @Autowired - private GetBlockOnPBFTServlet getBlockOnPBFTServlet; - - @Autowired - private GetAvailableUnfreezeCountOnPBFTServlet getAvailableUnfreezeCountOnPBFTServlet; - @Autowired - private GetCanDelegatedMaxSizeOnPBFTServlet getCanDelegatedMaxSizeOnPBFTServlet; - @Autowired - private GetCanWithdrawUnfreezeAmountOnPBFTServlet getCanWithdrawUnfreezeAmountOnPBFTServlet; - @Autowired - private GetDelegatedResourceAccountIndexV2OnPBFTServlet - getDelegatedResourceAccountIndexV2OnPBFTServlet; - @Autowired - private GetDelegatedResourceV2OnPBFTServlet getDelegatedResourceV2OnPBFTServlet; - @Override - public void init() { + public HttpApiOnPBFTService() { + port = Args.getInstance().getPBFTHttpPort(); + enable = isFullNode() && Args.getInstance().isPBFTHttpEnable(); + contextPath = "/walletpbft/"; } @Override - public void init(CommonParameter parameter) { - port = Args.getInstance().getPBFTHttpPort(); + protected void addServlet(ServletContextHandler context) { + applicationContext.getBeansWithAnnotation(PbftServlet.class).values() + .stream().filter(o -> o instanceof Servlet) + .map(o -> (Servlet) o) + .filter(o -> AopUtils.getTargetClass(o).isAnnotationPresent(PbftServlet.class)) + .forEach(o -> { + PbftServlet path = AopUtils.getTargetClass(o).getAnnotation(PbftServlet.class); + Arrays.stream(path.value()).filter(StringUtil::isNotBlank).forEach(p -> + context.addServlet(new ServletHolder(o), p)); + }); } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/walletpbft/"); - apiServer.setHandler(context); - - // same as FullNode - context.addServlet(new ServletHolder(accountOnPBFTServlet), "/getaccount"); - context.addServlet(new ServletHolder(listWitnessesOnPBFTServlet), "/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListOnPBFTServlet), "/getassetissuelist"); - context.addServlet(new ServletHolder(getPaginatedAssetIssueListOnPBFTServlet), - "/getpaginatedassetissuelist"); - context - .addServlet(new ServletHolder(getAssetIssueByNameOnPBFTServlet), "/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdOnPBFTServlet), "/getassetissuebyid"); - context.addServlet(new ServletHolder(getAssetIssueListByNameOnPBFTServlet), - "/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getNowBlockOnPBFTServlet), "/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumOnPBFTServlet), "/getblockbynum"); - context.addServlet(new ServletHolder(getDelegatedResourceOnPBFTServlet), - "/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexOnPBFTServlet), - "/getdelegatedresourceaccountindex"); - context.addServlet(new ServletHolder(getExchangeByIdOnPBFTServlet), "/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesOnPBFTServlet), "/listexchanges"); - context.addServlet(new ServletHolder(getAccountByIdOnPBFTServlet), "/getaccountbyid"); - context.addServlet(new ServletHolder(getBlockByIdOnPBFTServlet), "/getblockbyid"); - context - .addServlet(new ServletHolder(getBlockByLimitNextOnPBFTServlet), "/getblockbylimitnext"); - context - .addServlet(new ServletHolder(getBlockByLatestNumOnPBFTServlet), "/getblockbylatestnum"); - context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoOnPBFTServlet), - "/getmerkletreevoucherinfo"); - context.addServlet(new ServletHolder(scanAndMarkNoteByIvkOnPBFTServlet), - "/scanandmarknotebyivk"); - context.addServlet(new ServletHolder(scanNoteByIvkOnPBFTServlet), "/scannotebyivk"); - context.addServlet(new ServletHolder(scanNoteByOvkOnPBFTServlet), "/scannotebyovk"); - context.addServlet(new ServletHolder(isSpendOnPBFTServlet), "/isspend"); - context.addServlet(new ServletHolder(triggerConstantContractOnPBFTServlet), - "/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyOnPBFTServlet), "/estimateenergy"); - - // only for PBFTNode - context.addServlet(new ServletHolder(getTransactionByIdOnPBFTServlet), "/gettransactionbyid"); - context.addServlet(new ServletHolder(getTransactionInfoByIdOnPBFTServlet), - "/gettransactioninfobyid"); - - context.addServlet(new ServletHolder(getTransactionCountByBlockNumOnPBFTServlet), - "/gettransactioncountbyblocknum"); - - context.addServlet(new ServletHolder(getNodeInfoOnPBFTServlet), "/getnodeinfo"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/getReward"); - - context.addServlet(new ServletHolder(getMarketOrderByAccountOnPBFTServlet), - "/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdOnPBFTServlet), - "/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairOnPBFTServlet), - "/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairOnPBFTServlet), - "/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListOnPBFTServlet), - "/getmarketpairlist"); - - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkOnPBFTServlet), - "/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkOnPBFTServlet), - "/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentOnPBFTServlet), - "/isshieldedtrc20contractnotespent"); - context.addServlet(new ServletHolder(getBurnTrxOnPBFTServlet), - "/getburntrx"); - context.addServlet(new ServletHolder(getBandwidthPricesOnPBFTServlet), - "/getbandwidthprices"); - context.addServlet(new ServletHolder(getEnergyPricesOnPBFTServlet), - "/getenergyprices"); - context.addServlet(new ServletHolder(getBlockOnPBFTServlet), - "/getblock"); - - context.addServlet(new ServletHolder(getAvailableUnfreezeCountOnPBFTServlet), - "/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeOnPBFTServlet), - "/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountOnPBFTServlet), - "/getcanwithdrawunfreezeamount"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2OnPBFTServlet), - "/getdelegatedresourceaccountindexv2"); - context.addServlet(new ServletHolder(getDelegatedResourceV2OnPBFTServlet), - "/getdelegatedresourcev2"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - // filters the specified APIs - // when node is lite fullnode and openHistoryQueryWhenLiteFN is false - context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", - EnumSet.allOf(DispatcherType.class)); - - // api access filter - context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", - EnumSet.allOf(DispatcherType.class)); - - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + protected void addFilter(ServletContextHandler context) { + // filters the specified APIs + // when node is lite fullnode and openHistoryQueryWhenLiteFN is false + context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", + EnumSet.allOf(DispatcherType.class)); + + // api access filter + context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", + EnumSet.allOf(DispatcherType.class)); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanAndMarkNoteByIvkOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanAndMarkNoteByIvkOnPBFTServlet.java index aa0d94796a0..393c9bfcb71 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanAndMarkNoteByIvkOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanAndMarkNoteByIvkOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ScanAndMarkNoteByIvkServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/scanandmarknotebyivk") @Component @Slf4j(topic = "API") public class ScanAndMarkNoteByIvkOnPBFTServlet extends ScanAndMarkNoteByIvkServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByIvkOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByIvkOnPBFTServlet.java index 6382c0f4cf6..cd765036b58 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByIvkOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByIvkOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ScanNoteByIvkServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/scannotebyivk") @Component @Slf4j(topic = "API") public class ScanNoteByIvkOnPBFTServlet extends ScanNoteByIvkServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByOvkOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByOvkOnPBFTServlet.java index e05445c0c66..5c80c8aa98d 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByOvkOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanNoteByOvkOnPBFTServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ScanNoteByOvkServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/scannotebyovk") @Component @Slf4j(topic = "API") public class ScanNoteByOvkOnPBFTServlet extends ScanNoteByOvkServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByIvkOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByIvkOnPBFTServlet.java index bf0b70a3a9b..6202be2a0f1 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByIvkOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByIvkOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ScanShieldedTRC20NotesByIvkServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/scanshieldedtrc20notesbyivk") @Component @Slf4j(topic = "API") public class ScanShieldedTRC20NotesByIvkOnPBFTServlet extends ScanShieldedTRC20NotesByIvkServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByOvkOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByOvkOnPBFTServlet.java index 2bc65ef27c4..2e5c7cc7b10 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByOvkOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/ScanShieldedTRC20NotesByOvkOnPBFTServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.ScanShieldedTRC20NotesByOvkServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/scanshieldedtrc20notesbyovk") @Component @Slf4j(topic = "API") public class ScanShieldedTRC20NotesByOvkOnPBFTServlet extends ScanShieldedTRC20NotesByOvkServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/TriggerConstantContractOnPBFTServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/TriggerConstantContractOnPBFTServlet.java index 2859326464d..53c690b75a4 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/TriggerConstantContractOnPBFTServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/TriggerConstantContractOnPBFTServlet.java @@ -6,10 +6,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.PbftServlet; import org.tron.core.services.http.TriggerConstantContractServlet; import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; +@PbftServlet("/triggerconstantcontract") @Component @Slf4j(topic = "API") public class TriggerConstantContractOnPBFTServlet extends TriggerConstantContractServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java index 4bd3fbe4fef..aa566f56042 100755 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java @@ -2,9 +2,7 @@ import com.google.protobuf.ByteString; import io.grpc.netty.NettyServerBuilder; -import io.grpc.protobuf.services.ProtoReflectionService; import io.grpc.stub.StreamObserver; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.tron.api.DatabaseGrpc.DatabaseImplBase; @@ -35,16 +33,11 @@ import org.tron.api.GrpcAPI.WitnessList; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.RpcService; -import org.tron.common.es.ExecutorServiceManager; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.Sha256Hash; import org.tron.core.capsule.BlockCapsule; import org.tron.core.config.args.Args; import org.tron.core.services.RpcApiService; -import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; -import org.tron.core.services.ratelimiter.PrometheusInterceptor; -import org.tron.core.services.ratelimiter.RateLimiterInterceptor; -import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; @@ -73,77 +66,16 @@ public class RpcApiServiceOnSolidity extends RpcService { @Autowired private RpcApiService rpcApiService; - @Autowired - private RateLimiterInterceptor rateLimiterInterceptor; - - @Autowired - private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; - - @Autowired - private RpcApiAccessInterceptor apiAccessInterceptor; - - @Autowired - private PrometheusInterceptor prometheusInterceptor; - - private final String executorName = "rpc-solidity-executor"; - - @Override - public void init() { - } - - @Override - public void init(CommonParameter args) { + public RpcApiServiceOnSolidity() { port = Args.getInstance().getRpcOnSolidityPort(); + enable = isFullNode() && Args.getInstance().isRpcSolidityEnable(); + executorName = "rpc-solidity-executor"; } @Override - public void start() { - try { - NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port) - .addService(new DatabaseApi()); - - CommonParameter parameter = Args.getInstance(); - - if (parameter.getRpcThreadNum() > 0) { - serverBuilder = serverBuilder - .executor(ExecutorServiceManager.newFixedThreadPool( - executorName, parameter.getRpcThreadNum())); - } - - serverBuilder = serverBuilder.addService(new WalletSolidityApi()); - - // Set configs from config.conf or default value - serverBuilder.maxConcurrentCallsPerConnection(parameter.getMaxConcurrentCallsPerConnection()) - .flowControlWindow(parameter.getFlowControlWindow()) - .maxConnectionIdle(parameter.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) - .maxConnectionAge(parameter.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) - .maxInboundMessageSize(parameter.getMaxMessageSize()) - .maxHeaderListSize(parameter.getMaxHeaderListSize()); - - // add a ratelimiter interceptor - serverBuilder.intercept(rateLimiterInterceptor); - - // add api access interceptor - serverBuilder.intercept(apiAccessInterceptor); - - // add lite fullnode query interceptor - serverBuilder.intercept(liteFnQueryGrpcInterceptor); - - // add prometheus interceptor - if (parameter.isMetricsPrometheusEnable()) { - serverBuilder.intercept(prometheusInterceptor); - } - - if (parameter.isRpcReflectionServiceEnable()) { - serverBuilder.addService(ProtoReflectionService.newInstance()); - } - - apiServer = serverBuilder.build(); - rateLimiterInterceptor.init(apiServer); - super.start(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); - } + protected void addService(NettyServerBuilder serverBuilder) { + serverBuilder.addService(new DatabaseApi()); + serverBuilder.addService(new WalletSolidityApi()); } private TransactionExtention transaction2Extention(Transaction transaction) { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/EstimateEnergyOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/EstimateEnergyOnSolidityServlet.java index e9e403c776b..db7601868a5 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/EstimateEnergyOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/EstimateEnergyOnSolidityServlet.java @@ -6,10 +6,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.EstimateEnergyServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/estimateenergy") @Component @Slf4j(topic = "API") public class EstimateEnergyOnSolidityServlet extends EstimateEnergyServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountByIdOnSolidityServlet.java index ce47e679d0a..b33c46544c0 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountByIdOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAccountByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getaccountbyid") @Component @Slf4j(topic = "API") public class GetAccountByIdOnSolidityServlet extends GetAccountByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountOnSolidityServlet.java index 1cb02b77336..64e5a4351b5 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAccountOnSolidityServlet.java @@ -5,10 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAccountServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; - +@SolidityServlet("/walletsolidity/getaccount") @Component @Slf4j(topic = "API") public class GetAccountOnSolidityServlet extends GetAccountServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByIdOnSolidityServlet.java index f3173972407..251f67f48ce 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByIdOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAssetIssueByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getassetissuebyid") @Component @Slf4j(topic = "API") public class GetAssetIssueByIdOnSolidityServlet extends GetAssetIssueByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByNameOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByNameOnSolidityServlet.java index 101e0f1e4ae..fd3bb34d3d0 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByNameOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueByNameOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAssetIssueByNameServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getassetissuebyname") @Component @Slf4j(topic = "API") public class GetAssetIssueByNameOnSolidityServlet extends GetAssetIssueByNameServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListByNameOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListByNameOnSolidityServlet.java index d21cc9c940d..6bf815cb084 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListByNameOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListByNameOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAssetIssueListByNameServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getassetissuelistbyname") @Component @Slf4j(topic = "API") public class GetAssetIssueListByNameOnSolidityServlet extends GetAssetIssueListByNameServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListOnSolidityServlet.java index 76a2e70d70c..e9071103758 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAssetIssueListOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAssetIssueListServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getassetissuelist") @Component @Slf4j(topic = "API") public class GetAssetIssueListOnSolidityServlet extends GetAssetIssueListServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAvailableUnfreezeCountOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAvailableUnfreezeCountOnSolidityServlet.java index 218164fffb0..66a7a5cab71 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAvailableUnfreezeCountOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetAvailableUnfreezeCountOnSolidityServlet.java @@ -6,9 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetAvailableUnfreezeCountServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getavailableunfreezecount") @Component @Slf4j(topic = "API") public class GetAvailableUnfreezeCountOnSolidityServlet extends GetAvailableUnfreezeCountServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServlet.java index bb2fca37a97..c6c469f7782 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBandwidthPricesServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getbandwidthprices") @Component @Slf4j(topic = "API") public class GetBandwidthPricesOnSolidityServlet extends GetBandwidthPricesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByIdOnSolidityServlet.java index 16192e2f484..94ea8898e51 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByIdOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBlockByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getblockbyid") @Component @Slf4j(topic = "API") public class GetBlockByIdOnSolidityServlet extends GetBlockByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLatestNumOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLatestNumOnSolidityServlet.java index 34b5f37dcf5..b5bbec3ff65 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLatestNumOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLatestNumOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBlockByLatestNumServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getblockbylatestnum") @Component @Slf4j(topic = "API") public class GetBlockByLatestNumOnSolidityServlet extends GetBlockByLatestNumServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLimitNextOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLimitNextOnSolidityServlet.java index 36de59a9e7e..153ae6a212f 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLimitNextOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByLimitNextOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBlockByLimitNextServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getblockbylimitnext") @Component @Slf4j(topic = "API") public class GetBlockByLimitNextOnSolidityServlet extends GetBlockByLimitNextServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByNumOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByNumOnSolidityServlet.java index e79da51ee7b..50abc9c38d5 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByNumOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockByNumOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBlockByNumServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getblockbynum") @Component @Slf4j(topic = "API") public class GetBlockByNumOnSolidityServlet extends GetBlockByNumServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockOnSolidityServlet.java index e00f8e91e62..a06dcfd2a65 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBlockOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBlockServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getblock") @Component @Slf4j(topic = "API") public class GetBlockOnSolidityServlet extends GetBlockServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBrokerageOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBrokerageOnSolidityServlet.java index b6b6a9ca993..abb00938143 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBrokerageOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBrokerageOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBrokerageServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getBrokerage") @Component @Slf4j(topic = "API") public class GetBrokerageOnSolidityServlet extends GetBrokerageServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBurnTrxOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBurnTrxOnSolidityServlet.java index 46435a92668..2fe31b954e0 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBurnTrxOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetBurnTrxOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetBurnTrxServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getburntrx") @Component @Slf4j(topic = "API") public class GetBurnTrxOnSolidityServlet extends GetBurnTrxServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanDelegatedMaxSizeOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanDelegatedMaxSizeOnSolidityServlet.java index f2a2fb394e4..372cb1111d8 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanDelegatedMaxSizeOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanDelegatedMaxSizeOnSolidityServlet.java @@ -6,9 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetCanDelegatedMaxSizeServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getcandelegatedmaxsize") @Component @Slf4j(topic = "API") public class GetCanDelegatedMaxSizeOnSolidityServlet extends GetCanDelegatedMaxSizeServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanWithdrawUnfreezeAmountOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanWithdrawUnfreezeAmountOnSolidityServlet.java index 3f0b487fbe6..a9fffbbcc09 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanWithdrawUnfreezeAmountOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetCanWithdrawUnfreezeAmountOnSolidityServlet.java @@ -6,9 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetCanWithdrawUnfreezeAmountServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getcanwithdrawunfreezeamount") @Component @Slf4j(topic = "API") public class GetCanWithdrawUnfreezeAmountOnSolidityServlet diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexOnSolidityServlet.java index 1ad23e35a2a..a79bd04d4e2 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetDelegatedResourceAccountIndexServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getdelegatedresourceaccountindex") @Component @Slf4j(topic = "API") public class GetDelegatedResourceAccountIndexOnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexV2OnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexV2OnSolidityServlet.java index edfaaf56c8b..cc4bbf505cd 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexV2OnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceAccountIndexV2OnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetDelegatedResourceAccountIndexV2Servlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getdelegatedresourceaccountindexv2") @Component @Slf4j(topic = "API") public class GetDelegatedResourceAccountIndexV2OnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceOnSolidityServlet.java index c5a5cc9cb64..9c8aaf667a3 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceOnSolidityServlet.java @@ -6,9 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetDelegatedResourceServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getdelegatedresource") @Component @Slf4j(topic = "API") public class GetDelegatedResourceOnSolidityServlet extends GetDelegatedResourceServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceV2OnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceV2OnSolidityServlet.java index f481def86ea..283b7a120e4 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceV2OnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetDelegatedResourceV2OnSolidityServlet.java @@ -6,9 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.Wallet; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetDelegatedResourceV2Servlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getdelegatedresourcev2") @Component @Slf4j(topic = "API") public class GetDelegatedResourceV2OnSolidityServlet extends GetDelegatedResourceV2Servlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServlet.java index a867fc3596a..98701a6e891 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetEnergyPricesServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getenergyprices") @Component @Slf4j(topic = "API") public class GetEnergyPricesOnSolidityServlet extends GetEnergyPricesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetExchangeByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetExchangeByIdOnSolidityServlet.java index 1da31a0674b..8b0f84a38d8 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetExchangeByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetExchangeByIdOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetExchangeByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getexchangebyid") @Component @Slf4j(topic = "API") public class GetExchangeByIdOnSolidityServlet extends GetExchangeByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByAccountOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByAccountOnSolidityServlet.java index 0f77006c867..b4be1fe0b5d 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByAccountOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByAccountOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetMarketOrderByAccountServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getmarketorderbyaccount") @Component @Slf4j(topic = "API") public class GetMarketOrderByAccountOnSolidityServlet extends GetMarketOrderByAccountServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByIdOnSolidityServlet.java index 5956a638573..9ac9215de50 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderByIdOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetMarketOrderByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getmarketorderbyid") @Component @Slf4j(topic = "API") public class GetMarketOrderByIdOnSolidityServlet extends GetMarketOrderByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderListByPairOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderListByPairOnSolidityServlet.java index 8452accc3d3..f45387305db 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderListByPairOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketOrderListByPairOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetMarketOrderListByPairServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getmarketorderlistbypair") @Component @Slf4j(topic = "API") public class GetMarketOrderListByPairOnSolidityServlet extends GetMarketOrderListByPairServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPairListOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPairListOnSolidityServlet.java index b0ee51fec1e..871ab5e80ec 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPairListOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPairListOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetMarketPairListServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getmarketpairlist") @Component @Slf4j(topic = "API") public class GetMarketPairListOnSolidityServlet extends GetMarketPairListServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPriceByPairOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPriceByPairOnSolidityServlet.java index ceccf215b19..bcb404d3cee 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPriceByPairOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetMarketPriceByPairOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetMarketPriceByPairServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getmarketpricebypair") @Component @Slf4j(topic = "API") public class GetMarketPriceByPairOnSolidityServlet extends GetMarketPriceByPairServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNodeInfoOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNodeInfoOnSolidityServlet.java index ec16a010632..e8a4ad4f1ab 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNodeInfoOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNodeInfoOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetNodeInfoServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet({"/walletsolidity/getnodeinfo", "/wallet/getnodeinfo"}) @Component @Slf4j(topic = "API") public class GetNodeInfoOnSolidityServlet extends GetNodeInfoServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNowBlockOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNowBlockOnSolidityServlet.java index e888e8a5101..3bbc727f662 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNowBlockOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetNowBlockOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetNowBlockServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getnowblock") @Component @Slf4j(topic = "API") public class GetNowBlockOnSolidityServlet extends GetNowBlockServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetPaginatedAssetIssueListOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetPaginatedAssetIssueListOnSolidityServlet.java index fcb5ff90842..98a5fbbcf1f 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetPaginatedAssetIssueListOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetPaginatedAssetIssueListOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetPaginatedAssetIssueListServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getpaginatedassetissuelist") @Component @Slf4j(topic = "API") public class GetPaginatedAssetIssueListOnSolidityServlet extends GetPaginatedAssetIssueListServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetRewardOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetRewardOnSolidityServlet.java index f125557d1bf..351d77d271c 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetRewardOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetRewardOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetRewardServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/getReward") @Component @Slf4j(topic = "API") public class GetRewardOnSolidityServlet extends GetRewardServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionCountByBlockNumOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionCountByBlockNumOnSolidityServlet.java index 10e5d5a9b29..5c58197c62d 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionCountByBlockNumOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionCountByBlockNumOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetTransactionCountByBlockNumServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/gettransactioncountbyblocknum") @Component @Slf4j(topic = "API") public class GetTransactionCountByBlockNumOnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionInfoByBlockNumOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionInfoByBlockNumOnSolidityServlet.java index 40e88afa1e0..a5470e45a8c 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionInfoByBlockNumOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/GetTransactionInfoByBlockNumOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetTransactionInfoByBlockNumServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/gettransactioninfobyblocknum") @Component @Slf4j(topic = "API") public class GetTransactionInfoByBlockNumOnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/IsShieldedTRC20ContractNoteSpentOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/IsShieldedTRC20ContractNoteSpentOnSolidityServlet.java index 12055c2db8b..c0302ee087b 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/IsShieldedTRC20ContractNoteSpentOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/IsShieldedTRC20ContractNoteSpentOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.IsShieldedTRC20ContractNoteSpentServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/isshieldedtrc20contractnotespent") @Component @Slf4j(topic = "API") public class IsShieldedTRC20ContractNoteSpentOnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListExchangesOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListExchangesOnSolidityServlet.java index 87fc546913d..6eb4a1f7b2d 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListExchangesOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListExchangesOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.ListExchangesServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/listexchanges") @Component @Slf4j(topic = "API") public class ListExchangesOnSolidityServlet extends ListExchangesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListWitnessesOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListWitnessesOnSolidityServlet.java index 9025b360d0d..817313e27fa 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListWitnessesOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ListWitnessesOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.ListWitnessesServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/listwitnesses") @Component @Slf4j(topic = "API") public class ListWitnessesOnSolidityServlet extends ListWitnessesServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByIvkOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByIvkOnSolidityServlet.java index 19a8d545502..4b40e8b5c42 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByIvkOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByIvkOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.ScanShieldedTRC20NotesByIvkServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/scanshieldedtrc20notesbyivk") @Component @Slf4j(topic = "API") public class ScanShieldedTRC20NotesByIvkOnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByOvkOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByOvkOnSolidityServlet.java index 30055b41a90..bf36ce0ede4 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByOvkOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/ScanShieldedTRC20NotesByOvkOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.ScanShieldedTRC20NotesByOvkServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/scanshieldedtrc20notesbyovk") @Component @Slf4j(topic = "API") public class ScanShieldedTRC20NotesByOvkOnSolidityServlet extends diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/TriggerConstantContractOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/TriggerConstantContractOnSolidityServlet.java index 75f602272b4..7a0ac33729e 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/TriggerConstantContractOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/TriggerConstantContractOnSolidityServlet.java @@ -6,10 +6,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.TriggerConstantContractServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/triggerconstantcontract") @Component @Slf4j(topic = "API") public class TriggerConstantContractOnSolidityServlet extends TriggerConstantContractServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionByIdOnSolidityServlet.java index db56a4cc1f1..7f4eafc3902 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionByIdOnSolidityServlet.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetTransactionByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/gettransactionbyid") @Component @Slf4j(topic = "API") public class GetTransactionByIdOnSolidityServlet extends GetTransactionByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionInfoByIdOnSolidityServlet.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionInfoByIdOnSolidityServlet.java index 96422e1b60f..bbb79648144 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionInfoByIdOnSolidityServlet.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/GetTransactionInfoByIdOnSolidityServlet.java @@ -5,10 +5,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.http.GetTransactionInfoByIdServlet; import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; +@SolidityServlet("/walletsolidity/gettransactioninfobyid") @Component @Slf4j(topic = "API") public class GetTransactionInfoByIdOnSolidityServlet extends GetTransactionInfoByIdServlet { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java index f89be80c71b..4e3e5cd1013 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java @@ -1,173 +1,28 @@ package org.tron.core.services.interfaceOnSolidity.http.solidity; +import java.util.Arrays; import java.util.EnumSet; import javax.servlet.DispatcherType; +import javax.servlet.Servlet; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.StringUtil; +import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; import org.tron.core.config.args.Args; +import org.tron.core.services.annotation.SolidityServlet; import org.tron.core.services.filter.HttpApiAccessFilter; import org.tron.core.services.filter.LiteFnQueryHttpFilter; -import org.tron.core.services.interfaceOnSolidity.http.EstimateEnergyOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAccountByIdOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAccountOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAssetIssueByIdOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAssetIssueByNameOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAssetIssueListByNameOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAssetIssueListOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetAvailableUnfreezeCountOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBandwidthPricesOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBlockByIdOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBlockByLatestNumOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBlockByLimitNextOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBlockByNumOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBlockOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBrokerageOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetBurnTrxOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetCanDelegatedMaxSizeOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetCanWithdrawUnfreezeAmountOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetDelegatedResourceAccountIndexOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetDelegatedResourceAccountIndexV2OnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetDelegatedResourceOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetDelegatedResourceV2OnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetEnergyPricesOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetExchangeByIdOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetMarketOrderByAccountOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetMarketOrderByIdOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetMarketOrderListByPairOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetMarketPairListOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetMarketPriceByPairOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetMerkleTreeVoucherInfoOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetNodeInfoOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetNowBlockOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetPaginatedAssetIssueListOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetRewardOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetTransactionCountByBlockNumOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.GetTransactionInfoByBlockNumOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.IsShieldedTRC20ContractNoteSpentOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.IsSpendOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ListExchangesOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ListWitnessesOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ScanAndMarkNoteByIvkOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ScanNoteByIvkOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ScanNoteByOvkOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ScanShieldedTRC20NotesByIvkOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.ScanShieldedTRC20NotesByOvkOnSolidityServlet; -import org.tron.core.services.interfaceOnSolidity.http.TriggerConstantContractOnSolidityServlet; - @Slf4j(topic = "API") public class HttpApiOnSolidityService extends HttpService { @Autowired - private GetAccountOnSolidityServlet accountOnSolidityServlet; - - @Autowired - private GetTransactionByIdOnSolidityServlet getTransactionByIdOnSolidityServlet; - @Autowired - private GetTransactionInfoByIdOnSolidityServlet getTransactionInfoByIdOnSolidityServlet; - @Autowired - private ListWitnessesOnSolidityServlet listWitnessesOnSolidityServlet; - @Autowired - private GetAssetIssueListOnSolidityServlet getAssetIssueListOnSolidityServlet; - @Autowired - private GetPaginatedAssetIssueListOnSolidityServlet getPaginatedAssetIssueListOnSolidityServlet; - @Autowired - private GetNowBlockOnSolidityServlet getNowBlockOnSolidityServlet; - @Autowired - private GetBlockByNumOnSolidityServlet getBlockByNumOnSolidityServlet; - - @Autowired - private GetNodeInfoOnSolidityServlet getNodeInfoOnSolidityServlet; - - @Autowired - private GetDelegatedResourceOnSolidityServlet getDelegatedResourceOnSolidityServlet; - @Autowired - private GetDelegatedResourceV2OnSolidityServlet getDelegatedResourceV2OnSolidityServlet; - @Autowired - private GetCanDelegatedMaxSizeOnSolidityServlet getCanDelegatedMaxSizeOnSolidityServlet; - @Autowired - private GetAvailableUnfreezeCountOnSolidityServlet getAvailableUnfreezeCountOnSolidityServlet; - @Autowired - private GetCanWithdrawUnfreezeAmountOnSolidityServlet - getCanWithdrawUnfreezeAmountOnSolidityServlet; - @Autowired - private GetDelegatedResourceAccountIndexOnSolidityServlet - getDelegatedResourceAccountIndexOnSolidityServlet; - @Autowired - private GetDelegatedResourceAccountIndexV2OnSolidityServlet - getDelegatedResourceAccountIndexV2OnSolidityServlet; - @Autowired - private GetExchangeByIdOnSolidityServlet getExchangeByIdOnSolidityServlet; - @Autowired - private ListExchangesOnSolidityServlet listExchangesOnSolidityServlet; - @Autowired - private GetTransactionCountByBlockNumOnSolidityServlet - getTransactionCountByBlockNumOnSolidityServlet; - @Autowired - private GetAssetIssueByNameOnSolidityServlet getAssetIssueByNameOnSolidityServlet; - @Autowired - private GetAssetIssueByIdOnSolidityServlet getAssetIssueByIdOnSolidityServlet; - @Autowired - private GetAssetIssueListByNameOnSolidityServlet getAssetIssueListByNameOnSolidityServlet; - @Autowired - private GetAccountByIdOnSolidityServlet getAccountByIdOnSolidityServlet; - @Autowired - private GetBlockByIdOnSolidityServlet getBlockByIdOnSolidityServlet; - @Autowired - private GetBlockByLimitNextOnSolidityServlet getBlockByLimitNextOnSolidityServlet; - @Autowired - private GetBlockByLatestNumOnSolidityServlet getBlockByLatestNumOnSolidityServlet; - @Autowired - private GetMerkleTreeVoucherInfoOnSolidityServlet getMerkleTreeVoucherInfoOnSolidityServlet; - @Autowired - private ScanNoteByIvkOnSolidityServlet scanNoteByIvkOnSolidityServlet; - @Autowired - private ScanAndMarkNoteByIvkOnSolidityServlet scanAndMarkNoteByIvkOnSolidityServlet; - @Autowired - private ScanNoteByOvkOnSolidityServlet scanNoteByOvkOnSolidityServlet; - @Autowired - private IsSpendOnSolidityServlet isSpendOnSolidityServlet; - @Autowired - private ScanShieldedTRC20NotesByIvkOnSolidityServlet scanShieldedTRC20NotesByIvkOnSolidityServlet; - @Autowired - private ScanShieldedTRC20NotesByOvkOnSolidityServlet scanShieldedTRC20NotesByOvkOnSolidityServlet; - @Autowired - private IsShieldedTRC20ContractNoteSpentOnSolidityServlet - isShieldedTRC20ContractNoteSpentOnSolidityServlet; - @Autowired - private GetBrokerageOnSolidityServlet getBrokerageServlet; - @Autowired - private GetRewardOnSolidityServlet getRewardServlet; - @Autowired - private GetBurnTrxOnSolidityServlet getBurnTrxOnSolidityServlet; - @Autowired - private TriggerConstantContractOnSolidityServlet triggerConstantContractOnSolidityServlet; - @Autowired - private EstimateEnergyOnSolidityServlet estimateEnergyOnSolidityServlet; - @Autowired - private GetTransactionInfoByBlockNumOnSolidityServlet - getTransactionInfoByBlockNumOnSolidityServlet; - @Autowired - private GetMarketOrderByAccountOnSolidityServlet getMarketOrderByAccountOnSolidityServlet; - @Autowired - private GetMarketOrderByIdOnSolidityServlet getMarketOrderByIdOnSolidityServlet; - @Autowired - private GetMarketPriceByPairOnSolidityServlet getMarketPriceByPairOnSolidityServlet; - @Autowired - private GetMarketOrderListByPairOnSolidityServlet getMarketOrderListByPairOnSolidityServlet; - @Autowired - private GetMarketPairListOnSolidityServlet getMarketPairListOnSolidityServlet; - @Autowired - private GetBandwidthPricesOnSolidityServlet getBandwidthPricesOnSolidityServlet; - @Autowired - private GetEnergyPricesOnSolidityServlet getEnergyPricesOnSolidityServlet; + private ApplicationContext applicationContext; @Autowired private LiteFnQueryHttpFilter liteFnQueryHttpFilter; @@ -175,147 +30,39 @@ public class HttpApiOnSolidityService extends HttpService { @Autowired private HttpApiAccessFilter httpApiAccessFilter; - @Autowired - private GetBlockOnSolidityServlet getBlockOnSolidityServlet; - - @Override - public void init() { - - } - - @Override - public void init(CommonParameter args) { + public HttpApiOnSolidityService() { port = Args.getInstance().getSolidityHttpPort(); + enable = isFullNode() && Args.getInstance().isSolidityNodeHttpEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); + protected void addServlet(ServletContextHandler context) { + applicationContext.getBeansWithAnnotation(SolidityServlet.class).values() + .stream().filter(o -> o instanceof Servlet) + .map(o -> (Servlet) o) + .filter(o -> AopUtils.getTargetClass(o).isAnnotationPresent(SolidityServlet.class)) + .forEach(o -> { + SolidityServlet path = AopUtils.getTargetClass(o) + .getAnnotation(SolidityServlet.class); + Arrays.stream(path.value()).filter(StringUtil::isNotBlank).forEach(p -> + context.addServlet(new ServletHolder(o), p)); + }); - // same as FullNode - context.addServlet(new ServletHolder(accountOnSolidityServlet), "/walletsolidity/getaccount"); - context.addServlet(new ServletHolder(listWitnessesOnSolidityServlet), - "/walletsolidity/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListOnSolidityServlet), - "/walletsolidity/getassetissuelist"); - context.addServlet(new ServletHolder(getPaginatedAssetIssueListOnSolidityServlet), - "/walletsolidity/getpaginatedassetissuelist"); - context.addServlet(new ServletHolder(getAssetIssueByNameOnSolidityServlet), - "/walletsolidity/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdOnSolidityServlet), - "/walletsolidity/getassetissuebyid"); - context.addServlet(new ServletHolder(getAssetIssueListByNameOnSolidityServlet), - "/walletsolidity/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getNowBlockOnSolidityServlet), - "/walletsolidity/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumOnSolidityServlet), - "/walletsolidity/getblockbynum"); - context.addServlet(new ServletHolder(getDelegatedResourceOnSolidityServlet), - "/walletsolidity/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceV2OnSolidityServlet), - "/walletsolidity/getdelegatedresourcev2"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeOnSolidityServlet), - "/walletsolidity/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getAvailableUnfreezeCountOnSolidityServlet), - "/walletsolidity/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountOnSolidityServlet), - "/walletsolidity/getcanwithdrawunfreezeamount"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexOnSolidityServlet), - "/walletsolidity/getdelegatedresourceaccountindex"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2OnSolidityServlet), - "/walletsolidity/getdelegatedresourceaccountindexv2"); - context.addServlet(new ServletHolder(getExchangeByIdOnSolidityServlet), - "/walletsolidity/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesOnSolidityServlet), - "/walletsolidity/listexchanges"); - context.addServlet(new ServletHolder(getAccountByIdOnSolidityServlet), - "/walletsolidity/getaccountbyid"); - context.addServlet(new ServletHolder(getBlockByIdOnSolidityServlet), - "/walletsolidity/getblockbyid"); - context.addServlet(new ServletHolder(getBlockByLimitNextOnSolidityServlet), - "/walletsolidity/getblockbylimitnext"); - context.addServlet(new ServletHolder(getBlockByLatestNumOnSolidityServlet), - "/walletsolidity/getblockbylatestnum"); - // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoOnSolidityServlet), - // "/walletsolidity/getmerkletreevoucherinfo"); - // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkOnSolidityServlet), - // "/walletsolidity/scanandmarknotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByIvkOnSolidityServlet), - // "/walletsolidity/scannotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByOvkOnSolidityServlet), - // "/walletsolidity/scannotebyovk"); - // context.addServlet(new ServletHolder(isSpendOnSolidityServlet), - // "/walletsolidity/isspend"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkOnSolidityServlet), - "/walletsolidity/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkOnSolidityServlet), - "/walletsolidity/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentOnSolidityServlet), - "/walletsolidity/isshieldedtrc20contractnotespent"); - context.addServlet(new ServletHolder(triggerConstantContractOnSolidityServlet), - "/walletsolidity/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyOnSolidityServlet), - "/walletsolidity/estimateenergy"); - context.addServlet(new ServletHolder(getTransactionInfoByBlockNumOnSolidityServlet), - "/walletsolidity/gettransactioninfobyblocknum"); - context.addServlet(new ServletHolder(getMarketOrderByAccountOnSolidityServlet), - "/walletsolidity/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdOnSolidityServlet), - "/walletsolidity/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairOnSolidityServlet), - "/walletsolidity/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairOnSolidityServlet), - "/walletsolidity/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListOnSolidityServlet), - "/walletsolidity/getmarketpairlist"); - - // only for SolidityNode - context.addServlet(new ServletHolder(getTransactionByIdOnSolidityServlet), - "/walletsolidity/gettransactionbyid"); - context.addServlet(new ServletHolder(getTransactionInfoByIdOnSolidityServlet), - "/walletsolidity/gettransactioninfobyid"); - - context.addServlet(new ServletHolder(getTransactionCountByBlockNumOnSolidityServlet), - "/walletsolidity/gettransactioncountbyblocknum"); - - context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), "/wallet/getnodeinfo"); - context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), - "/walletsolidity/getnodeinfo"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward"); - context - .addServlet(new ServletHolder(getBurnTrxOnSolidityServlet), "/walletsolidity/getburntrx"); - context.addServlet(new ServletHolder(getBandwidthPricesOnSolidityServlet), - "/walletsolidity/getbandwidthprices"); - context.addServlet(new ServletHolder(getEnergyPricesOnSolidityServlet), - "/walletsolidity/getenergyprices"); - - context.addServlet(new ServletHolder(getBlockOnSolidityServlet), - "/walletsolidity/getblock"); - - // filters the specified APIs - // when node is lite fullnode and openHistoryQueryWhenLiteFN is false - context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", - EnumSet.allOf(DispatcherType.class)); - - // api access filter - context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", - EnumSet.allOf(DispatcherType.class)); - context.getServletHandler().getFilterMappings()[1] - .setPathSpecs(new String[] {"/walletsolidity/*", - "/wallet/getnodeinfo"}); + } - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + @Override + protected void addFilter(ServletContextHandler context) { + // filters the specified APIs + // when node is lite fullnode and openHistoryQueryWhenLiteFN is false + context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", + EnumSet.allOf(DispatcherType.class)); + + // api access filter + context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", + EnumSet.allOf(DispatcherType.class)); + context.getServletHandler().getFilterMappings()[1] + .setPathSpecs(new String[] {"/walletsolidity/*", + "/wallet/getnodeinfo"}); } } diff --git a/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java b/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java index ff017f9562e..566ad33a722 100644 --- a/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java +++ b/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java @@ -3,8 +3,6 @@ import java.util.EnumSet; import javax.servlet.DispatcherType; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHandler; @@ -12,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.common.application.HttpService; -import org.tron.common.parameter.CommonParameter; +import org.tron.core.config.args.Args; import org.tron.core.services.filter.HttpInterceptor; @Component @@ -22,41 +20,24 @@ public class FullNodeJsonRpcHttpService extends HttpService { @Autowired private JsonRpcServlet jsonRpcServlet; - @Override - public void init() { + public FullNodeJsonRpcHttpService() { + port = Args.getInstance().getJsonRpcHttpFullNodePort(); + enable = isFullNode() && Args.getInstance().isJsonRpcHttpFullNodeEnable(); + contextPath = "/"; } @Override - public void init(CommonParameter args) { - port = CommonParameter.getInstance().getJsonRpcHttpFullNodePort(); + protected void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(jsonRpcServlet), "/jsonrpc"); } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(jsonRpcServlet), "/jsonrpc"); - - int maxHttpConnectNumber = CommonParameter.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - // filter - ServletHandler handler = new ServletHandler(); - FilterHolder fh = handler - .addFilterWithMapping(HttpInterceptor.class, "/*", - EnumSet.of(DispatcherType.REQUEST)); - context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); - - super.start(); - - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + protected void addFilter(ServletContextHandler context) { + // filter + ServletHandler handler = new ServletHandler(); + FilterHolder fh = handler + .addFilterWithMapping(HttpInterceptor.class, "/*", + EnumSet.of(DispatcherType.REQUEST)); + context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); } } diff --git a/framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java b/framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java index 0ca57a3b98c..7104ecc4346 100644 --- a/framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java +++ b/framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java @@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; -import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -226,15 +225,11 @@ public static void handleLogsFilter(LogsFilterCapsule logsFilterCapsule) { @Override public String web3ClientVersion() { - Pattern shortVersion = Pattern.compile("(\\d\\.\\d).*"); - Matcher matcher = shortVersion.matcher(System.getProperty("java.version")); - matcher.matches(); - return String.join("/", Arrays.asList( "TRON", "v" + Version.getVersion(), System.getProperty("os.name"), - "Java" + matcher.group(1))); + "Java" + System.getProperty("java.specification.version"))); } @Override diff --git a/framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java b/framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java index 8b9aafe4715..04405dfc758 100644 --- a/framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java +++ b/framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java @@ -6,7 +6,6 @@ import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; -import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import org.tron.common.zksnark.JLibrustzcash; import org.tron.common.zksnark.LibrustzcashParam; @@ -14,7 +13,6 @@ @Slf4j(topic = "API") @Component -@DependsOn("fullNodeHttpApiService") public class ZksnarkInitService { @PostConstruct diff --git a/framework/src/main/java/org/tron/program/DBConvert.java b/framework/src/main/java/org/tron/program/DBConvert.java index a13a2ffefb5..45ad9062256 100644 --- a/framework/src/main/java/org/tron/program/DBConvert.java +++ b/framework/src/main/java/org/tron/program/DBConvert.java @@ -33,7 +33,7 @@ import org.rocksdb.Status; import org.tron.common.utils.FileUtil; import org.tron.common.utils.MarketOrderPriceComparatorForLevelDB; -import org.tron.common.utils.MarketOrderPriceComparatorForRockDB; +import org.tron.common.utils.MarketOrderPriceComparatorForRocksDB; import org.tron.common.utils.PropUtil; @Slf4j @@ -88,13 +88,6 @@ public static org.iq80.leveldb.Options newDefaultLevelDbOptions() { return dbOptions; } - public static void main(String[] args) { - int code = run(args); - logger.info("exit code {}.", code); - System.out.printf("exit code %d.\n", code); - System.exit(code); - } - public static int run(String[] args) { String dbSrc; String dbDst; @@ -194,7 +187,7 @@ private Options newDefaultRocksDbOptions() { options.setLevel0FileNumCompactionTrigger(4); options.setLevelCompactionDynamicLevelBytes(true); if ("market_pair_price_to_order".equalsIgnoreCase(this.dbName)) { - options.setComparator(new MarketOrderPriceComparatorForRockDB(new ComparatorOptions())); + options.setComparator(new MarketOrderPriceComparatorForRocksDB(new ComparatorOptions())); } final BlockBasedTableConfig tableCfg; options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig()); diff --git a/framework/src/main/java/org/tron/program/FullNode.java b/framework/src/main/java/org/tron/program/FullNode.java index 0fd87eb5de0..ef45062cfe4 100644 --- a/framework/src/main/java/org/tron/program/FullNode.java +++ b/framework/src/main/java/org/tron/program/FullNode.java @@ -15,16 +15,7 @@ import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; -import org.tron.core.net.P2pEventHandlerImpl; -import org.tron.core.services.RpcApiService; -import org.tron.core.services.http.FullNodeHttpApiService; -import org.tron.core.services.interfaceJsonRpcOnPBFT.JsonRpcServiceOnPBFT; -import org.tron.core.services.interfaceJsonRpcOnSolidity.JsonRpcServiceOnSolidity; -import org.tron.core.services.interfaceOnPBFT.RpcApiServiceOnPBFT; -import org.tron.core.services.interfaceOnPBFT.http.PBFT.HttpApiOnPBFTService; -import org.tron.core.services.interfaceOnSolidity.RpcApiServiceOnSolidity; -import org.tron.core.services.interfaceOnSolidity.http.solidity.HttpApiOnSolidityService; -import org.tron.core.services.jsonrpc.FullNodeJsonRpcHttpService; +import org.tron.core.services.SolidityService; @Slf4j(topic = "app") public class FullNode { @@ -50,7 +41,6 @@ public static void load(String path) { * Start the FullNode. */ public static void main(String[] args) { - logger.info("Full node running."); Args.setParam(args, Constant.TESTNET_CONF); CommonParameter parameter = Args.getInstance(); @@ -63,6 +53,20 @@ public static void main(String[] args) { return; } + if (parameter.isKeystore()) { + KeystoreFactory.exec(); + return; + } + if (parameter.isDbConvert()) { + DBConvert.run(args); + return; + } + if (parameter.isSolidityNode()) { + logger.info("Solidity node is running."); + } else { + logger.info("Full node running."); + } + if (Args.getInstance().isDebug()) { logger.info("in debug mode, it won't check energy time"); } else { @@ -80,56 +84,8 @@ public static void main(String[] args) { context.refresh(); Application appT = ApplicationFactory.create(context); context.registerShutdownHook(); - - // grpc api server - RpcApiService rpcApiService = context.getBean(RpcApiService.class); - appT.addService(rpcApiService); - - // http api server - FullNodeHttpApiService httpApiService = context.getBean(FullNodeHttpApiService.class); - if (CommonParameter.getInstance().fullNodeHttpEnable) { - appT.addService(httpApiService); - } - - // JSON-RPC http server - if (CommonParameter.getInstance().jsonRpcHttpFullNodeEnable) { - FullNodeJsonRpcHttpService jsonRpcHttpService = - context.getBean(FullNodeJsonRpcHttpService.class); - appT.addService(jsonRpcHttpService); - } - - // full node and solidity node fuse together - // provide solidity rpc and http server on the full node. - RpcApiServiceOnSolidity rpcApiServiceOnSolidity = context - .getBean(RpcApiServiceOnSolidity.class); - appT.addService(rpcApiServiceOnSolidity); - HttpApiOnSolidityService httpApiOnSolidityService = context - .getBean(HttpApiOnSolidityService.class); - if (CommonParameter.getInstance().solidityNodeHttpEnable) { - appT.addService(httpApiOnSolidityService); - } - - // JSON-RPC on solidity - if (CommonParameter.getInstance().jsonRpcHttpSolidityNodeEnable) { - JsonRpcServiceOnSolidity jsonRpcServiceOnSolidity = context - .getBean(JsonRpcServiceOnSolidity.class); - appT.addService(jsonRpcServiceOnSolidity); - } - - // PBFT API (HTTP and GRPC) - RpcApiServiceOnPBFT rpcApiServiceOnPBFT = context - .getBean(RpcApiServiceOnPBFT.class); - appT.addService(rpcApiServiceOnPBFT); - HttpApiOnPBFTService httpApiOnPBFTService = context - .getBean(HttpApiOnPBFTService.class); - appT.addService(httpApiOnPBFTService); - - // JSON-RPC on PBFT - if (CommonParameter.getInstance().jsonRpcHttpPBFTNodeEnable) { - JsonRpcServiceOnPBFT jsonRpcServiceOnPBFT = context.getBean(JsonRpcServiceOnPBFT.class); - appT.addService(jsonRpcServiceOnPBFT); - } appT.startup(); + SolidityService.runIfNeed(); appT.blockUntilShutdown(); } } diff --git a/framework/src/main/java/org/tron/program/KeystoreFactory.java b/framework/src/main/java/org/tron/program/KeystoreFactory.java index bfd2df22856..2df7c420fa7 100755 --- a/framework/src/main/java/org/tron/program/KeystoreFactory.java +++ b/framework/src/main/java/org/tron/program/KeystoreFactory.java @@ -1,6 +1,5 @@ package org.tron.program; -import com.beust.jcommander.JCommander; import java.io.File; import java.io.IOException; import java.util.Scanner; @@ -11,8 +10,6 @@ import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.ByteArray; import org.tron.common.utils.Utils; -import org.tron.core.Constant; -import org.tron.core.config.args.Args; import org.tron.core.exception.CipherException; import org.tron.keystore.Credentials; import org.tron.keystore.WalletUtils; @@ -22,15 +19,8 @@ public class KeystoreFactory { private static final String FilePath = "Wallet"; - public static void main(String[] args) { - Args.setParam(args, Constant.TESTNET_CONF); + public static void exec() { KeystoreFactory cli = new KeystoreFactory(); - - JCommander.newBuilder() - .addObject(cli) - .build() - .parse(args); - cli.run(); } diff --git a/framework/src/main/resources/config.conf b/framework/src/main/resources/config.conf index f9fc2dd673d..49b11d41e42 100644 --- a/framework/src/main/resources/config.conf +++ b/framework/src/main/resources/config.conf @@ -210,6 +210,8 @@ node { fullNodePort = 8090 solidityEnable = true solidityPort = 8091 + PBFTEnable = true + PBFTPort = 8092 } # use your ipv6 address for node discovery and tcp connection, default false @@ -226,8 +228,12 @@ node { } rpc { + enable = true port = 50051 - #solidityPort = 50061 + solidityEnable = true + solidityPort = 50061 + PBFTEnable = true + PBFTPort = 50071 # Number of gRPC thread, default availableProcessors / 2 # thread = 16 diff --git a/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java b/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java index 50a55d24a0f..54bc02baf98 100644 --- a/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java +++ b/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java @@ -27,6 +27,7 @@ import com.google.common.collect.Sets; import java.io.File; import java.io.IOException; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -37,6 +38,8 @@ import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.iq80.leveldb.DBException; +import org.iq80.leveldb.WriteOptions; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -44,10 +47,17 @@ import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.rocksdb.RocksDB; +import org.tron.common.parameter.CommonParameter; +import org.tron.common.storage.WriteOptionsWrapper; +import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl; import org.tron.common.utils.ByteArray; import org.tron.common.utils.FileUtil; +import org.tron.common.utils.PropUtil; import org.tron.common.utils.PublicMethod; +import org.tron.common.utils.StorageUtils; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.db2.common.WrappedByteArray; @@ -76,6 +86,13 @@ public class LevelDbDataSourceImplTest { @Rule public final ExpectedSystemExit exit = ExpectedSystemExit.none(); + @Rule + public final ExpectedException exception = ExpectedException.none(); + + static { + RocksDB.loadLibrary(); + } + /** * Release resources. */ @@ -105,8 +122,19 @@ public void testPutGet() { assertNotNull(dataSourceTest.getData(key)); assertEquals(1, dataSourceTest.allKeys().size()); + assertEquals(1, dataSourceTest.getTotal()); + assertEquals(1, dataSourceTest.allValues().size()); assertEquals("50000", ByteArray.toStr(dataSourceTest.getData(key1.getBytes()))); + dataSourceTest.deleteData(key); + assertNull(dataSourceTest.getData(key)); + assertEquals(0, dataSourceTest.getTotal()); + dataSourceTest.iterator().forEachRemaining(entry -> Assert.fail("iterator should be empty")); + dataSourceTest.stream().forEach(entry -> Assert.fail("stream should be empty")); + dataSourceTest.stat(); dataSourceTest.closeDB(); + dataSourceTest.stat(); // stat again + exception.expect(DBException.class); + dataSourceTest.deleteData(key); } @Test @@ -145,6 +173,23 @@ public void testupdateByBatchInner() { assertEquals("50000", ByteArray.toStr(dataSource.getData(key1.getBytes()))); assertEquals("10000", ByteArray.toStr(dataSource.getData(key2.getBytes()))); assertEquals(2, dataSource.allKeys().size()); + + rows.clear(); + rows.put(key1.getBytes(), null); + rows.put(key2.getBytes(), null); + dataSource.updateByBatch(rows, WriteOptionsWrapper.getInstance()); + assertEquals(0, dataSource.allKeys().size()); + + rows.clear(); + rows.put(key1.getBytes(), value1.getBytes()); + rows.put(key2.getBytes(), null); + dataSource.updateByBatch(rows); + assertEquals("50000", ByteArray.toStr(dataSource.getData(key1.getBytes()))); + assertEquals(1, dataSource.allKeys().size()); + rows.clear(); + rows.put(null, null); + exception.expect(RuntimeException.class); + dataSource.updateByBatch(rows); dataSource.closeDB(); } @@ -358,6 +403,119 @@ public void initDbTest() { dataSource.closeDB(); } + @Test + public void testCheckOrInitEngine() { + String dir = + Args.getInstance().getOutputDirectory() + Args.getInstance().getStorage().getDbDirectory(); + String enginePath = dir + File.separator + "test_engine" + File.separator + "engine.properties"; + FileUtil.createDirIfNotExists(dir + File.separator + "test_engine"); + FileUtil.createFileIfNotExists(enginePath); + PropUtil.writeProperty(enginePath, "ENGINE", "LEVELDB"); + Assert.assertEquals("LEVELDB", PropUtil.readProperty(enginePath, "ENGINE")); + + LevelDbDataSourceImpl dataSource; + dataSource = new LevelDbDataSourceImpl(dir, "test_engine"); + dataSource.initDB(); + dataSource.closeDB(); + + System.gc(); + PropUtil.writeProperty(enginePath, "ENGINE", "ROCKSDB"); + Assert.assertEquals("ROCKSDB", PropUtil.readProperty(enginePath, "ENGINE")); + try { + dataSource = new LevelDbDataSourceImpl(dir, "test_engine"); + dataSource.initDB(); + } catch (Exception e) { + Assert.assertEquals(String.format("failed to check database: %s, engine do not match", + "test_engine"), + e.getMessage()); + } + } + + @Test + public void testLevelDbOpenRocksDb() { + String name = "test_openRocksDb"; + String output = Paths + .get(StorageUtils.getOutputDirectoryByDbName(name), CommonParameter + .getInstance().getStorage().getDbDirectory()).toString(); + RocksDbDataSourceImpl rocksDb = new RocksDbDataSourceImpl(output, name); + rocksDb.initDB(); + rocksDb.putData(key1, value1); + rocksDb.closeDB(); + LevelDbDataSourceImpl levelDB = + new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(name), name); + exception.expectMessage(String.format("failed to check database: %s, engine do not match", + name)); + levelDB.initDB(); + } + + @Test + public void testNewInstance() { + dataSourceTest.closeDB(); + LevelDbDataSourceImpl newInst = dataSourceTest.newInstance(); + newInst.initDB(); + assertFalse(newInst.flush()); + newInst.closeDB(); + LevelDbDataSourceImpl empty = new LevelDbDataSourceImpl(); + empty.setDBName("empty"); + assertEquals("empty", empty.getDBName()); + String name = "newInst2"; + LevelDbDataSourceImpl newInst2 = new LevelDbDataSourceImpl( + StorageUtils.getOutputDirectoryByDbName(name), + name, + StorageUtils.getOptionsByDbName(name), + new WriteOptions().sync(CommonParameter.getInstance() + .getStorage().isDbSync())); + newInst2.initDB(); + newInst2.closeDB(); + } + + @Test + public void testGetNext() { + LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl( + Args.getInstance().getOutputDirectory(), "test_getNext_key"); + dataSource.initDB(); + dataSource.resetDb(); + putSomeKeyValue(dataSource); + // case: normal + Map seekKvLimitNext = dataSource.getNext("0000000300".getBytes(), 2); + Map hashMap = Maps.newHashMap(); + hashMap.put(ByteArray.toStr(key3), ByteArray.toStr(value3)); + hashMap.put(ByteArray.toStr(key4), ByteArray.toStr(value4)); + seekKvLimitNext.forEach((key, value) -> { + String keyStr = ByteArray.toStr(key); + Assert.assertTrue("getNext", hashMap.containsKey(keyStr)); + Assert.assertEquals(ByteArray.toStr(value), hashMap.get(keyStr)); + }); + // case: targetKey greater than all existed keys + seekKvLimitNext = dataSource.getNext("0000000700".getBytes(), 2); + Assert.assertEquals(0, seekKvLimitNext.size()); + // case: limit<=0 + seekKvLimitNext = dataSource.getNext("0000000300".getBytes(), 0); + Assert.assertEquals(0, seekKvLimitNext.size()); + dataSource.resetDb(); + dataSource.closeDB(); + } + + @Test + public void testGetlatestValues() { + LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl( + Args.getInstance().getOutputDirectory(), "test_getlatestValues_key"); + dataSource.initDB(); + dataSource.resetDb(); + putSomeKeyValue(dataSource); + // case: normal + Set seekKeyLimitNext = dataSource.getlatestValues(2); + Set hashSet = Sets.newHashSet(ByteArray.toStr(value5), ByteArray.toStr(value6)); + seekKeyLimitNext.forEach(value -> { + Assert.assertTrue(hashSet.contains(ByteArray.toStr(value))); + }); + // case: limit<=0 + seekKeyLimitNext = dataSource.getlatestValues(0); + assertEquals(0, seekKeyLimitNext.size()); + dataSource.resetDb(); + dataSource.closeDB(); + } + private void makeExceptionDb(String dbName) { LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl( Args.getInstance().getOutputDirectory(), "test_initDb"); diff --git a/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java b/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java index ed37c1e4bcd..da769262d09 100644 --- a/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java +++ b/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java @@ -9,6 +9,8 @@ import com.google.common.collect.Sets; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -19,6 +21,7 @@ import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.iq80.leveldb.DBException; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -26,12 +29,18 @@ import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.rocksdb.RocksDBException; +import org.tron.common.parameter.CommonParameter; +import org.tron.common.setting.RocksDbSettings; +import org.tron.common.storage.WriteOptionsWrapper; import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl; import org.tron.common.utils.ByteArray; import org.tron.common.utils.FileUtil; import org.tron.common.utils.PropUtil; import org.tron.common.utils.PublicMethod; +import org.tron.common.utils.StorageUtils; import org.tron.core.config.args.Args; import org.tron.core.db2.common.WrappedByteArray; @@ -58,6 +67,9 @@ public class RocksDbDataSourceImplTest { @Rule public final ExpectedSystemExit exit = ExpectedSystemExit.none(); + @Rule + public final ExpectedException expectedException = ExpectedException.none(); + /** * Release resources. */ @@ -87,8 +99,18 @@ public void testPutGet() { assertNotNull(dataSourceTest.getData(key)); assertEquals(1, dataSourceTest.allKeys().size()); + assertEquals(1, dataSourceTest.getTotal()); + assertEquals(1, dataSourceTest.allValues().size()); assertEquals("50000", ByteArray.toStr(dataSourceTest.getData(key1.getBytes()))); + dataSourceTest.deleteData(key); + assertNull(dataSourceTest.getData(key)); + assertEquals(0, dataSourceTest.getTotal()); + dataSourceTest.iterator().forEachRemaining(entry -> Assert.fail("iterator should be empty")); + dataSourceTest.stat(); dataSourceTest.closeDB(); + dataSourceTest.stat(); // stat again + expectedException.expect(DBException.class); + dataSourceTest.deleteData(key); } @Test @@ -127,6 +149,23 @@ public void testupdateByBatchInner() { assertEquals("50000", ByteArray.toStr(dataSource.getData(key1.getBytes()))); assertEquals("10000", ByteArray.toStr(dataSource.getData(key2.getBytes()))); assertEquals(2, dataSource.allKeys().size()); + + rows.clear(); + rows.put(key1.getBytes(), null); + rows.put(key2.getBytes(), null); + dataSource.updateByBatch(rows, WriteOptionsWrapper.getInstance()); + assertEquals(0, dataSource.allKeys().size()); + + rows.clear(); + rows.put(key1.getBytes(), value1.getBytes()); + rows.put(key2.getBytes(), null); + dataSource.updateByBatch(rows); + assertEquals("50000", ByteArray.toStr(dataSource.getData(key1.getBytes()))); + assertEquals(1, dataSource.allKeys().size()); + rows.clear(); + rows.put(null, null); + expectedException.expect(RuntimeException.class); + dataSource.updateByBatch(rows); dataSource.closeDB(); } @@ -400,6 +439,75 @@ public void initDbTest() { dataSource.closeDB(); } + @Test + public void testRocksDbOpenLevelDb() { + String name = "test_openLevelDb"; + String output = Paths + .get(StorageUtils.getOutputDirectoryByDbName(name), CommonParameter + .getInstance().getStorage().getDbDirectory()).toString(); + LevelDbDataSourceImpl levelDb = new LevelDbDataSourceImpl( + StorageUtils.getOutputDirectoryByDbName(name), name); + levelDb.initDB(); + levelDb.putData(key1, value1); + levelDb.closeDB(); + RocksDbDataSourceImpl rocksDb = new RocksDbDataSourceImpl(output, name); + expectedException.expectMessage( + String.format("failed to check database: %s, engine do not match", name)); + rocksDb.initDB(); + } + + @Test + public void testNewInstance() { + dataSourceTest.closeDB(); + RocksDbDataSourceImpl newInst = dataSourceTest.newInstance(); + newInst.initDB(); + assertFalse(newInst.flush()); + newInst.closeDB(); + RocksDbDataSourceImpl empty = new RocksDbDataSourceImpl(); + empty.setDBName("empty"); + assertEquals("empty", empty.getDBName()); + String output = Paths + .get(StorageUtils.getOutputDirectoryByDbName("newInst2"), CommonParameter + .getInstance().getStorage().getDbDirectory()).toString(); + RocksDbDataSourceImpl newInst2 = new RocksDbDataSourceImpl(output, "newInst2"); + newInst2.initDB(); + newInst2.closeDB(); + } + + @Test + public void backupAndDelete() throws RocksDBException { + RocksDbDataSourceImpl dataSource = new RocksDbDataSourceImpl( + Args.getInstance().getOutputDirectory(), "backupAndDelete"); + dataSource.initDB(); + putSomeKeyValue(dataSource); + Path dir = Paths.get(Args.getInstance().getOutputDirectory(), "backup"); + String path = dir + File.separator; + FileUtil.createDirIfNotExists(path); + dataSource.backup(path); + File backDB = Paths.get(dir.toString(),dataSource.getDBName()).toFile(); + Assert.assertTrue(backDB.exists()); + dataSource.deleteDbBakPath(path); + Assert.assertFalse(backDB.exists()); + dataSource.closeDB(); + } + + @Test + public void testGetTotal() { + RocksDbDataSourceImpl dataSource = new RocksDbDataSourceImpl( + Args.getInstance().getOutputDirectory(), "test_getTotal_key"); + dataSource.initDB(); + dataSource.resetDb(); + + Map dataMapset = Maps.newHashMap(); + dataMapset.put(key1, value1); + dataMapset.put(key2, value2); + dataMapset.put(key3, value3); + dataMapset.forEach(dataSource::putData); + Assert.assertEquals(dataMapset.size(), dataSource.getTotal()); + dataSource.resetDb(); + dataSource.closeDB(); + } + private void makeExceptionDb(String dbName) { RocksDbDataSourceImpl dataSource = new RocksDbDataSourceImpl( Args.getInstance().getOutputDirectory(), "test_initDb"); diff --git a/framework/src/test/java/org/tron/common/utils/ObjectSizeUtilTest.java b/framework/src/test/java/org/tron/common/utils/ObjectSizeUtilTest.java deleted file mode 100644 index c4c72991979..00000000000 --- a/framework/src/test/java/org/tron/common/utils/ObjectSizeUtilTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * java-tron is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * java-tron is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.tron.common.utils; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class ObjectSizeUtilTest { - - @Test - public void testGetObjectSize() { - - Person person = new Person(); - assertEquals(48, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person)); - Person person1 = new Person(1, "tom", new int[]{}); - assertEquals(112, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person1)); - - Person person2 = new Person(1, "tom", new int[]{100}); - assertEquals(120, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person2)); - - Person person3 = new Person(1, "tom", new int[]{100, 100}); - assertEquals(120, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person3)); - Person person4 = new Person(1, "tom", new int[]{100, 100, 100}); - assertEquals(128, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person4)); - Person person5 = new Person(1, "tom", new int[]{100, 100, 100, 100}); - assertEquals(128, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person5)); - Person person6 = new Person(1, "tom", new int[]{100, 100, 100, 100, 100}); - assertEquals(136, com.carrotsearch.sizeof.RamUsageEstimator.sizeOf(person6)); - - } - - class Person { - - int age; - String name; - int[] scores; - - public Person() { - } - - public Person(int age, String name, int[] scores) { - this.age = age; - this.name = name; - this.scores = scores; - } - } - -} diff --git a/framework/src/test/java/org/tron/core/config/args/ArgsTest.java b/framework/src/test/java/org/tron/core/config/args/ArgsTest.java index 5bbf08fd96e..87933a62e5a 100644 --- a/framework/src/test/java/org/tron/core/config/args/ArgsTest.java +++ b/framework/src/test/java/org/tron/core/config/args/ArgsTest.java @@ -17,11 +17,15 @@ import com.google.common.collect.Lists; import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; import io.grpc.internal.GrpcUtil; import io.grpc.netty.NettyServerBuilder; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Assert; @@ -150,5 +154,94 @@ public void testOldRewardOpt() { thrown.expect(IllegalArgumentException.class); Args.setParam(new String[] {"-w"}, "args-test.conf"); } + + @Test + public void testInitService() { + Map storage = new HashMap<>(); + // avoid the exception for the missing storage + storage.put("storage.db.directory", "database"); + Config config = ConfigFactory.defaultOverrides().withFallback(ConfigFactory.parseMap(storage)); + // test default value + Args.setParam(new String[] {}, config); + Assert.assertTrue(Args.getInstance().isRpcEnable()); + Assert.assertTrue(Args.getInstance().isRpcSolidityEnable()); + Assert.assertTrue(Args.getInstance().isRpcPBFTEnable()); + Assert.assertTrue(Args.getInstance().isFullNodeHttpEnable()); + Assert.assertTrue(Args.getInstance().isSolidityNodeHttpEnable()); + Assert.assertTrue(Args.getInstance().isPBFTHttpEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpFullNodeEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpSolidityNodeEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpPBFTNodeEnable()); + Args.clearParam(); + // test set all true value + storage.put("node.rpc.enable", "true"); + storage.put("node.rpc.solidityEnable", "true"); + storage.put("node.rpc.PBFTEnable", "true"); + storage.put("node.http.fullNodeEnable", "true"); + storage.put("node.http.solidityEnable", "true"); + storage.put("node.http.PBFTEnable", "true"); + storage.put("node.jsonrpc.httpFullNodeEnable", "true"); + storage.put("node.jsonrpc.httpSolidityEnable", "true"); + storage.put("node.jsonrpc.httpPBFTEnable", "true"); + config = ConfigFactory.defaultOverrides().withFallback(ConfigFactory.parseMap(storage)); + // test value + Args.setParam(new String[] {}, config); + Assert.assertTrue(Args.getInstance().isRpcEnable()); + Assert.assertTrue(Args.getInstance().isRpcSolidityEnable()); + Assert.assertTrue(Args.getInstance().isRpcPBFTEnable()); + Assert.assertTrue(Args.getInstance().isFullNodeHttpEnable()); + Assert.assertTrue(Args.getInstance().isSolidityNodeHttpEnable()); + Assert.assertTrue(Args.getInstance().isPBFTHttpEnable()); + Assert.assertTrue(Args.getInstance().isJsonRpcHttpFullNodeEnable()); + Assert.assertTrue(Args.getInstance().isJsonRpcHttpSolidityNodeEnable()); + Assert.assertTrue(Args.getInstance().isJsonRpcHttpPBFTNodeEnable()); + Args.clearParam(); + // test set all false value + storage.put("node.rpc.enable", "false"); + storage.put("node.rpc.solidityEnable", "false"); + storage.put("node.rpc.PBFTEnable", "false"); + storage.put("node.http.fullNodeEnable", "false"); + storage.put("node.http.solidityEnable", "false"); + storage.put("node.http.PBFTEnable", "false"); + storage.put("node.jsonrpc.httpFullNodeEnable", "false"); + storage.put("node.jsonrpc.httpSolidityEnable", "false"); + storage.put("node.jsonrpc.httpPBFTEnable", "false"); + config = ConfigFactory.defaultOverrides().withFallback(ConfigFactory.parseMap(storage)); + // test value + Args.setParam(new String[] {}, config); + Assert.assertFalse(Args.getInstance().isRpcEnable()); + Assert.assertFalse(Args.getInstance().isRpcSolidityEnable()); + Assert.assertFalse(Args.getInstance().isRpcPBFTEnable()); + Assert.assertFalse(Args.getInstance().isFullNodeHttpEnable()); + Assert.assertFalse(Args.getInstance().isSolidityNodeHttpEnable()); + Assert.assertFalse(Args.getInstance().isPBFTHttpEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpFullNodeEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpSolidityNodeEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpPBFTNodeEnable()); + Args.clearParam(); + // test set random value + storage.put("node.rpc.enable", "false"); + storage.put("node.rpc.solidityEnable", "false"); + storage.put("node.rpc.PBFTEnable", "true"); + storage.put("node.http.fullNodeEnable", "false"); + storage.put("node.http.solidityEnable", "true"); + storage.put("node.http.PBFTEnable", "false"); + storage.put("node.jsonrpc.httpFullNodeEnable", "true"); + storage.put("node.jsonrpc.httpSolidityEnable", "false"); + storage.put("node.jsonrpc.httpPBFTEnable", "true"); + config = ConfigFactory.defaultOverrides().withFallback(ConfigFactory.parseMap(storage)); + // test value + Args.setParam(new String[] {}, config); + Assert.assertFalse(Args.getInstance().isRpcEnable()); + Assert.assertFalse(Args.getInstance().isRpcSolidityEnable()); + Assert.assertTrue(Args.getInstance().isRpcPBFTEnable()); + Assert.assertFalse(Args.getInstance().isFullNodeHttpEnable()); + Assert.assertTrue(Args.getInstance().isSolidityNodeHttpEnable()); + Assert.assertFalse(Args.getInstance().isPBFTHttpEnable()); + Assert.assertTrue(Args.getInstance().isJsonRpcHttpFullNodeEnable()); + Assert.assertFalse(Args.getInstance().isJsonRpcHttpSolidityNodeEnable()); + Assert.assertTrue(Args.getInstance().isJsonRpcHttpPBFTNodeEnable()); + Args.clearParam(); + } } diff --git a/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java b/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java index ed18b1be97d..96b6ac2c816 100644 --- a/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java +++ b/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java @@ -28,7 +28,6 @@ public class AssetUpdateHelperTest extends BaseTest { static { Args.setParam(new String[]{"-d", dbPath(), "-w"}, "config-test-index.conf"); - Args.getInstance().setSolidityNode(true); } @Before diff --git a/framework/src/test/java/org/tron/core/db/rocksdb/RocksDbTest.java b/framework/src/test/java/org/tron/core/db/rocksdb/RocksDbTest.java new file mode 100644 index 00000000000..56db0caf26e --- /dev/null +++ b/framework/src/test/java/org/tron/core/db/rocksdb/RocksDbTest.java @@ -0,0 +1,61 @@ +package org.tron.core.db.rocksdb; + +import java.io.File; +import java.io.IOException; +import java.util.function.IntSupplier; +import java.util.stream.IntStream; +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.rocksdb.Options; +import org.rocksdb.RocksDB; +import org.rocksdb.RocksDBException; +import org.tron.common.arch.Arch; + +@Slf4j(topic = "DB") +public class RocksDbTest { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + private File tmp; + + @Before + public void warmUP() throws RocksDBException, IOException { + tmp = temporaryFolder.newFolder(); + if (!tmp.exists() && !tmp.mkdirs()) { + throw new IOException("Unable to create temp folder"); + } + for (int i = 0; i < 10; i++) { + try (RocksDB db = RocksDB.open(tmp + "-" + i)) { + db.compactRange(); + } finally { + RocksDB.destroyDB(tmp + "-" + i, new Options()); + } + } + } + + @Test + public void testNewDB() { + logger.info("{}", Arch.withAll()); + IntStream.range(10, 60).mapToObj(i -> (IntSupplier) () -> { + try { + return Math.toIntExact(openDB(i)); + } catch (RocksDBException e) { + throw new org.iq80.leveldb.DBException(e); + } + }).mapToDouble(IntSupplier::getAsInt).average() + .ifPresent(avg -> logger.info("Agv cost: {} ms", avg)); + } + + private int openDB(int i) throws RocksDBException { + long start = System.currentTimeMillis(); + try (RocksDB db = RocksDB.open(tmp + "-" + i)) { + return StrictMath.toIntExact(System.currentTimeMillis() - start); + } finally { + RocksDB.destroyDB(tmp + "-" + i, new Options()); + } + } +} diff --git a/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java b/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java index b3ed26b591f..98631210374 100644 --- a/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java +++ b/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java @@ -265,7 +265,6 @@ public void testGetTransactionByHash() { @Test public void testGetBlockByNumber2() { - fullNodeJsonRpcHttpService.init(Args.getInstance()); fullNodeJsonRpcHttpService.start(); JsonArray params = new JsonArray(); params.add(ByteArray.toJsonHex(blockCapsule.getNum())); @@ -303,9 +302,7 @@ public void testGetBlockByNumber2() { @Test public void testServicesInit() { try { - jsonRpcServiceOnPBFT.init(Args.getInstance()); jsonRpcServiceOnPBFT.start(); - jsonRpcServiceOnSolidity.init(Args.getInstance()); jsonRpcServiceOnSolidity.start(); } finally { jsonRpcServiceOnPBFT.stop(); diff --git a/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java b/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java index 51a46b09388..e36029c6141 100644 --- a/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java +++ b/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java @@ -44,7 +44,7 @@ public void init() throws IOException { "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory }, - "config.conf" + Constant.TEST_CONF ); CommonParameter parameter = Args.getInstance(); parameter.setNodeListenPort(port); @@ -52,9 +52,7 @@ public void init() throws IOException { parameter.setNodeExternalIp("127.0.0.1"); context = new TronApplicationContext(DefaultConfig.class); appT = ApplicationFactory.create(context); - rpcApiService = context.getBean(RpcApiService.class); metricsApiService = context.getBean(MetricsApiService.class); - appT.addService(rpcApiService); appT.startup(); } diff --git a/framework/src/test/java/org/tron/core/net/BaseNet.java b/framework/src/test/java/org/tron/core/net/BaseNet.java index 7ae8b355168..65771bae952 100644 --- a/framework/src/test/java/org/tron/core/net/BaseNet.java +++ b/framework/src/test/java/org/tron/core/net/BaseNet.java @@ -30,12 +30,12 @@ import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.FileUtil; +import org.tron.common.utils.PublicMethod; import org.tron.common.utils.ReflectUtils; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; import org.tron.core.net.peer.PeerConnection; -import org.tron.core.services.RpcApiService; @Slf4j public class BaseNet { @@ -48,7 +48,6 @@ public class BaseNet { protected static TronApplicationContext context; - private static RpcApiService rpcApiService; private static Application appT; private static TronNetDelegate tronNetDelegate; @@ -98,10 +97,15 @@ public static void init() throws Exception { parameter.setNodeListenPort(port); parameter.getSeedNode().getAddressList().clear(); parameter.setNodeExternalIp(Constant.LOCAL_HOST); + parameter.setRpcEnable(true); + parameter.setRpcPort(PublicMethod.chooseRandomPort()); + parameter.setRpcSolidityEnable(false); + parameter.setRpcPBFTEnable(false); + parameter.setFullNodeHttpEnable(false); + parameter.setSolidityNodeHttpEnable(false); + parameter.setPBFTHttpEnable(false); context = new TronApplicationContext(DefaultConfig.class); appT = ApplicationFactory.create(context); - rpcApiService = context.getBean(RpcApiService.class); - appT.addService(rpcApiService); appT.startup(); try { Thread.sleep(2000); diff --git a/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java b/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java index 9bc942d6684..84fb632b93d 100755 --- a/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java +++ b/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java @@ -58,7 +58,6 @@ public void pbftapi() throws IOException { Assert.assertTrue(dynamicPropertiesStore.getLatestBlockHeaderNumber() >= 10); commonDataBase.saveLatestPbftBlockNum(6); - httpApiOnPBFTService.init(Args.getInstance()); httpApiOnPBFTService.start(); CloseableHttpResponse response; try (CloseableHttpClient httpClient = HttpClients.createDefault()) { diff --git a/framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java b/framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java index 83930403312..8fc2da5d61c 100644 --- a/framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java +++ b/framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java @@ -135,8 +135,11 @@ public static void init() throws IOException { Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); String OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; + getInstance().setRpcEnable(true); getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + getInstance().setRpcSolidityEnable(true); getInstance().setRpcOnSolidityPort(PublicMethod.chooseRandomPort()); + getInstance().setRpcPBFTEnable(true); getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort()); getInstance().setMetricsPrometheusPort(PublicMethod.chooseRandomPort()); getInstance().setMetricsPrometheusEnable(true); diff --git a/framework/src/test/java/org/tron/core/services/WalletApiTest.java b/framework/src/test/java/org/tron/core/services/WalletApiTest.java index 0a87c348fdb..8890d4bfd9e 100644 --- a/framework/src/test/java/org/tron/core/services/WalletApiTest.java +++ b/framework/src/test/java/org/tron/core/services/WalletApiTest.java @@ -5,8 +5,8 @@ import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; +import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.tron.api.GrpcAPI.EmptyMessage; @@ -14,7 +14,7 @@ import org.tron.common.application.Application; import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.client.Configuration; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; @@ -23,34 +23,34 @@ @Slf4j public class WalletApiTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); private static TronApplicationContext context; - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private RpcApiService rpcApiService; - private Application appT; + private static Application appT; - @Before - public void init() throws IOException { + + @BeforeClass + public static void init() throws IOException { Args.setParam(new String[]{ "-d", temporaryFolder.newFolder().toString(), "--p2p-disable", "true"}, Constant.TEST_CONF); + Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcEnable(true); context = new TronApplicationContext(DefaultConfig.class); appT = ApplicationFactory.create(context); - rpcApiService = context.getBean(RpcApiService.class); - appT.addService(rpcApiService); appT.startup(); } @Test public void listNodesTest() { + String fullNode = String.format("%s:%d", "127.0.0.1", + Args.getInstance().getRpcPort()); WalletGrpc.WalletBlockingStub walletStub = WalletGrpc - .newBlockingStub(ManagedChannelBuilder.forTarget(fullnode) + .newBlockingStub(ManagedChannelBuilder.forTarget(fullNode) .usePlaintext() .build()); Assert.assertTrue(walletStub.listNodes(EmptyMessage.getDefaultInstance()) - .getNodesList().size() == 0); + .getNodesList().isEmpty()); } @After diff --git a/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java b/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java index 5f883fc8c07..9484155a0b7 100644 --- a/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java @@ -14,10 +14,10 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.tron.common.BaseTest; import org.tron.common.parameter.CommonParameter; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.services.http.FullNodeHttpApiService; @@ -39,21 +39,17 @@ public class HttpApiAccessFilterTest extends BaseTest { static { Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false); - } - - /** - * init dependencies. - */ - @Before - public void init() { - appT.addService(httpApiService); - appT.addService(httpApiOnSolidityService); - appT.addService(httpApiOnPBFTService); - appT.startup(); + Args.getInstance().setFullNodeHttpEnable(true); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setPBFTHttpEnable(true); + Args.getInstance().setPBFTHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setSolidityNodeHttpEnable(true); + Args.getInstance().setSolidityHttpPort(PublicMethod.chooseRandomPort()); } @Test public void testHttpFilter() { + appT.startup(); List disabledApiList = new ArrayList<>(); disabledApiList.add("getaccount"); disabledApiList.add("getnowblock"); diff --git a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java index 081b5839f84..0db3a6a99ce 100644 --- a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java @@ -55,8 +55,11 @@ public class LiteFnQueryGrpcInterceptorTest { @BeforeClass public static void init() throws IOException { Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + Args.getInstance().setRpcEnable(true); Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcSolidityEnable(true); Args.getInstance().setRpcOnSolidityPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcPBFTEnable(true); Args.getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort()); String fullnode = String.format("%s:%d", Args.getInstance().getNodeLanIp(), Args.getInstance().getRpcPort()); diff --git a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java index 5fd4711273e..a9068c228b6 100644 --- a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.Set; -import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -19,28 +18,32 @@ import org.junit.Before; import org.junit.Test; import org.tron.common.BaseTest; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.args.Args; -import org.tron.core.services.http.FullNodeHttpApiService; -import org.tron.core.services.interfaceOnPBFT.http.PBFT.HttpApiOnPBFTService; -import org.tron.core.services.interfaceOnSolidity.http.solidity.HttpApiOnSolidityService; @Slf4j public class LiteFnQueryHttpFilterTest extends BaseTest { private final String ip = "127.0.0.1"; private int fullHttpPort; - @Resource - private FullNodeHttpApiService httpApiService; - @Resource - private HttpApiOnSolidityService httpApiOnSolidityService; - @Resource - private HttpApiOnPBFTService httpApiOnPBFTService; private final CloseableHttpClient httpClient = HttpClients.createDefault(); static { Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false); + Args.getInstance().setRpcEnable(false); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(true); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setPBFTHttpEnable(true); + Args.getInstance().setPBFTHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setSolidityNodeHttpEnable(true); + Args.getInstance().setSolidityHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); } /** @@ -48,9 +51,6 @@ public class LiteFnQueryHttpFilterTest extends BaseTest { */ @Before public void init() { - appT.addService(httpApiService); - appT.addService(httpApiOnSolidityService); - appT.addService(httpApiOnPBFTService); appT.startup(); } diff --git a/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java b/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java index 38af756f790..57fcc5a2202 100644 --- a/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java @@ -56,8 +56,11 @@ public class RpcApiAccessInterceptorTest { @BeforeClass public static void init() throws IOException { Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + Args.getInstance().setRpcEnable(true); Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcSolidityEnable(true); Args.getInstance().setRpcOnSolidityPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcPBFTEnable(true); Args.getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort()); String fullNode = String.format("%s:%d", Args.getInstance().getNodeLanIp(), Args.getInstance().getRpcPort()); diff --git a/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java b/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java index f363b7fbefc..e9cd9cb1f26 100644 --- a/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java @@ -1,7 +1,6 @@ package org.tron.core.services.http; import com.google.gson.JsonObject; -import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.bouncycastle.util.encoders.Hex; @@ -9,10 +8,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.tron.common.BaseTest; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.client.Configuration; +import org.tron.common.utils.PublicMethod; import org.tron.common.utils.client.utils.HttpMethed; import org.tron.core.Constant; import org.tron.core.capsule.ContractCapsule; @@ -25,31 +23,24 @@ @Slf4j public class TriggerSmartContractServletTest extends BaseTest { - private static final String httpNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list") - .get(0); + private static String httpNode; private static final byte[] ownerAddr = Hex.decode("410000000000000000000000000000000000000000"); private static final byte[] contractAddr = Hex.decode( "41000000000000000000000000000000000000dEaD"); - @Resource - private FullNodeHttpApiService httpApiService; - @BeforeClass public static void init() throws Exception { Args.setParam( new String[]{"--output-directory", dbPath(), "--debug", "--witness"}, Constant.TEST_CONF); Args.getInstance().needSyncCheck = false; - - // build app context - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - beanFactory.setAllowCircularReferences(false); + Args.getInstance().setFullNodeHttpEnable(true); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + httpNode = String.format("%s:%d", "127.0.0.1", + Args.getInstance().getFullNodeHttpPort()); } @Before public void before() { - appT.addService(httpApiService); - // start services appT.startup(); diff --git a/framework/src/test/java/org/tron/keystroe/CredentialsTest.java b/framework/src/test/java/org/tron/keystroe/CredentialsTest.java index ce992c3443f..2642129e00a 100644 --- a/framework/src/test/java/org/tron/keystroe/CredentialsTest.java +++ b/framework/src/test/java/org/tron/keystroe/CredentialsTest.java @@ -1,6 +1,5 @@ package org.tron.keystroe; -import lombok.var; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -11,24 +10,24 @@ public class CredentialsTest { @Test public void test_equality() { - var aObject = new Object(); - var si = Mockito.mock(SignInterface.class); - var si2 = Mockito.mock(SignInterface.class); - var si3 = Mockito.mock(SignInterface.class); - var address = "TQhZ7W1RudxFdzJMw6FvMnujPxrS6sFfmj".getBytes(); - var address2 = "TNCmcTdyrYKMtmE1KU2itzeCX76jGm5Not".getBytes(); + Object aObject = new Object(); + SignInterface si = Mockito.mock(SignInterface.class); + SignInterface si2 = Mockito.mock(SignInterface.class); + SignInterface si3 = Mockito.mock(SignInterface.class); + byte[] address = "TQhZ7W1RudxFdzJMw6FvMnujPxrS6sFfmj".getBytes(); + byte[] address2 = "TNCmcTdyrYKMtmE1KU2itzeCX76jGm5Not".getBytes(); Mockito.when(si.getAddress()).thenReturn(address); Mockito.when(si2.getAddress()).thenReturn(address); Mockito.when(si3.getAddress()).thenReturn(address2); - var aCredential = Credentials.create(si); + Credentials aCredential = Credentials.create(si); Assert.assertFalse(aObject.equals(aCredential)); Assert.assertFalse(aCredential.equals(aObject)); Assert.assertFalse(aCredential.equals(null)); - var anotherCredential = Credentials.create(si); - Assert.assertTrue(aCredential.equals(anotherCredential)); - var aCredential2 = Credentials.create(si2); + Credentials anotherCredential = Credentials.create(si); Assert.assertTrue(aCredential.equals(anotherCredential)); - var aCredential3 = Credentials.create(si3); + Credentials aCredential2 = Credentials.create(si2); + Assert.assertTrue(aCredential.equals(anotherCredential)); + Credentials aCredential3 = Credentials.create(si3); Assert.assertFalse(aCredential.equals(aCredential3)); } } diff --git a/framework/src/test/java/org/tron/program/SolidityNodeTest.java b/framework/src/test/java/org/tron/program/SolidityNodeTest.java index a77fa2fa8c6..a95d07c0c11 100755 --- a/framework/src/test/java/org/tron/program/SolidityNodeTest.java +++ b/framework/src/test/java/org/tron/program/SolidityNodeTest.java @@ -1,12 +1,8 @@ package org.tron.program; -import java.io.File; -import java.io.IOException; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; import org.tron.common.BaseTest; import org.tron.common.client.DatabaseGrpcClient; @@ -26,41 +22,10 @@ public class SolidityNodeTest extends BaseTest { SolidityNodeHttpApiService solidityNodeHttpApiService; static { - try { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); - } catch (IOException e) { - Assert.fail("create temp directory failed."); - } + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setSolidityNode(true); } - /** - * init db. - */ - @BeforeClass - public static void init() { - } - - /** - * remo db when after test. - */ - @AfterClass - public static void removeDb() { - Args.clearParam(); - } - - private static Boolean deleteFolder(File index) { - if (!index.isDirectory() || index.listFiles().length <= 0) { - return index.delete(); - } - for (File file : index.listFiles()) { - if (null != file && !deleteFolder(file)) { - return false; - } - } - return index.delete(); - } - @Test public void testSolidityArgs() { Assert.assertNotNull(Args.getInstance().getTrustNodeAddr()); @@ -69,7 +34,6 @@ public void testSolidityArgs() { @Test public void testSolidityGrpcCall() { - rpcApiService.init(Args.getInstance()); rpcApiService.start(); DatabaseGrpcClient databaseGrpcClient = null; String address = Args.getInstance().getTrustNodeAddr(); @@ -99,7 +63,8 @@ public void testSolidityGrpcCall() { @Test public void testSolidityNodeHttpApiService() { - solidityNodeHttpApiService.init(Args.getInstance()); + solidityNodeHttpApiService.start(); + // start again solidityNodeHttpApiService.start(); solidityNodeHttpApiService.stop(); Assert.assertTrue(true); diff --git a/framework/src/test/resources/config-localtest.conf b/framework/src/test/resources/config-localtest.conf index 1d7ae09af7c..44c051e1079 100644 --- a/framework/src/test/resources/config-localtest.conf +++ b/framework/src/test/resources/config-localtest.conf @@ -117,14 +117,30 @@ node { ] http { + fullNodeEnable = false fullNodePort = 8090 + solidityEnable = false solidityPort = 8091 + PBFTEnable = false + PBFTPort = 8092 + } + + jsonrpc { + httpFullNodeEnable = false + httpFullNodePort = 8545 + httpSolidityEnable = false + httpSolidityPort = 8555 + httpPBFTEnable = false + httpPBFTPort = 8565 } rpc { + enable = false port = 50051 - # default value is 50061 - # solidityPort = 50061 + solidityEnable = false + solidityPort = 50061 + PBFTEnable = false + PBFTPort = 50071 # Number of gRPC thread, default availableProcessors / 2 # thread = 16 diff --git a/framework/src/test/resources/config-test-index.conf b/framework/src/test/resources/config-test-index.conf index 6eb3621e747..cff08fd3abb 100644 --- a/framework/src/test/resources/config-test-index.conf +++ b/framework/src/test/resources/config-test-index.conf @@ -76,9 +76,23 @@ node { version = 43 # 43: testnet; 101: debug } + http { + fullNodeEnable = false + solidityEnable = false + PBFTEnable = false + } + + jsonrpc { + httpFullNodeEnable = false + httpSolidityEnable = false + httpPBFTEnable = false + } + rpc { port = 50051 - + enable = false + solidityEnable = false + PBFTEnable = false # Number of gRPC thread, default availableProcessors / 2 # thread = 16 diff --git a/framework/src/test/resources/config-test-mainnet.conf b/framework/src/test/resources/config-test-mainnet.conf index ad72d2afaaa..de9170a0ec4 100644 --- a/framework/src/test/resources/config-test-mainnet.conf +++ b/framework/src/test/resources/config-test-mainnet.conf @@ -82,6 +82,24 @@ node { version = 43 # 43: testnet; 101: debug } + http { + fullNodeEnable = false + solidityEnable = false + PBFTEnable = false + } + + jsonrpc { + httpFullNodeEnable = false + httpSolidityEnable = false + httpPBFTEnable = false + } + + rpc { + enable = false + solidityEnable = false + PBFTEnable = false + } + } sync { diff --git a/framework/src/test/resources/config-test.conf b/framework/src/test/resources/config-test.conf index 62337f02fc5..997f3e98b37 100644 --- a/framework/src/test/resources/config-test.conf +++ b/framework/src/test/resources/config-test.conf @@ -107,10 +107,15 @@ node { } http { - fullNodeEnable = true - fullNodePort = 8090 - solidityEnable = true - solidityPort = 8091 + fullNodeEnable = false + solidityEnable = false + PBFTEnable = false + } + + jsonrpc { + httpFullNodeEnable = false + httpSolidityEnable = false + httpPBFTEnable = false } # use your ipv6 address for node discovery and tcp connection, default false @@ -172,6 +177,9 @@ node { } rpc { + enable = false + solidityEnable = false + PBFTEnable = false port = 50051 PBFTPort = 50072 diff --git a/gradle/jdk17/java-tron.vmoptions b/gradle/jdk17/java-tron.vmoptions new file mode 100644 index 00000000000..1c49ca93787 --- /dev/null +++ b/gradle/jdk17/java-tron.vmoptions @@ -0,0 +1,8 @@ +-XX:+UseZGC +-Xlog:gc*:file=gc-%t.log:time,uptime,level,tags:filecount=50,filesize=100M +-XX:ReservedCodeCacheSize=256m +-XX:+UseCodeCacheFlushing +-XX:MetaspaceSize=256m +-XX:MaxMetaspaceSize=512m +-XX:MaxDirectMemorySize=1g +-XX:+HeapDumpOnOutOfMemoryError \ No newline at end of file diff --git a/platform/build.gradle b/platform/build.gradle new file mode 100644 index 00000000000..d692bbc3814 --- /dev/null +++ b/platform/build.gradle @@ -0,0 +1,47 @@ +import org.gradle.nativeplatform.platform.internal.Architectures + +description = "platform – a distributed consensus arithmetic for blockchain." + + +static def isX86() { + def arch = System.getProperty("os.arch").toLowerCase() + return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch) +} + +if (isX86()) { + ext { + leveldbGroup = "org.fusesource.leveldbjni" + leveldbName = "leveldbjni-all" + leveldbVersion = "1.8" + rocksDBVersion = "5.15.10" + } +} else { + ext { + leveldbGroup = "com.halibobor" + leveldbName = "leveldbjni-all" + leveldbVersion = "1.18.3" + rocksDBVersion = "7.7.3" + } +} + +sourceSets { + x86 { + java { + srcDir 'src/main/java/x86' + } + } + arm { + java { + srcDir 'src/main/java/arm' + } + } +} + +dependencies { + api group: leveldbGroup, name: leveldbName, version: leveldbVersion + api group: 'org.rocksdb', name: 'rocksdbjni', version: rocksDBVersion +} + +tasks.withType(JavaCompile).configureEach { + source = isX86() ? sourceSets.x86.java : sourceSets.arm.java +} diff --git a/platform/src/main/java/arm/org/tron/common/math/MathWrapper.java b/platform/src/main/java/arm/org/tron/common/math/MathWrapper.java new file mode 100644 index 00000000000..bbafefae7db --- /dev/null +++ b/platform/src/main/java/arm/org/tron/common/math/MathWrapper.java @@ -0,0 +1,413 @@ +package org.tron.common.math; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class MathWrapper { + + + private static final Map powData = Collections.synchronizedMap(new HashMap<>()); + private static final String POW_B1 = "3f40624dd2f1a9fc"; // 1/2000 = 0.0005 + private static final String POW_B2 = "409f400000000000"; // 2000 + + /** + * This static block is used to initialize the data map. + */ + static { + addPowData("3ff000000669e439", POW_B1, "3ff000000000d22a"); + addPowData("3ff000000b4fe3ac", POW_B1, "3ff00000000172ac"); + addPowData("3ff0000015d11937", POW_B1, "3ff000000002cae4"); + addPowData("3ff000001adebd1f", POW_B1, "3ff000000003707a"); + addPowData("3ff000002fc6a33f", POW_B1, "3ff0000000061d86"); + addPowData("3ff0000046d74585", POW_B1, "3ff0000000091150"); + addPowData("3ff000005454cb56", POW_B1, "3ff00000000acb5e"); + addPowData("3ff000005d4df1d8", POW_B1, "3ff00000000bf166"); + addPowData("3ff0000071929b3b", POW_B1, "3ff00000000e898c"); + addPowData("3ff00000a9d6d98d", POW_B1, "3ff000000015bd4a"); + addPowData("3ff00000c2a51ab7", POW_B1, "3ff000000018ea20"); + addPowData("3ff000012f2af5bf", POW_B1, "3ff000000026ce32"); + addPowData("3ff00001413724bf", POW_B1, "3ff0000000291d94"); + addPowData("3ff0000153bd4e6d", POW_B1, "3ff00000002b7c94"); + addPowData("3ff000015f75ad2a", POW_B1, "3ff00000002cfca0"); + addPowData("3ff0000198da81dd", POW_B1, "3ff000000034554e"); + addPowData("3ff00001b178bb95", POW_B1, "3ff0000000377bfc"); + addPowData("3ff00001ce277ce7", POW_B1, "3ff00000003b27dc"); + addPowData("3ff0000294b2be1a", POW_B1, "3ff00000005491bc"); + addPowData("3ff00002f453d343", POW_B1, "3ff000000060cf4e"); + addPowData("3ff000045a0b2035", POW_B1, "3ff00000008e98e6"); + addPowData("3ff000045d0cfef6", POW_B1, "3ff00000008efb72"); + addPowData("3ff00004e5545390", POW_B1, "3ff0000000a06d00"); + addPowData("3ff000057b83c83f", POW_B1, "3ff0000000b3a640"); + addPowData("3ff00005980b881e", POW_B1, "3ff0000000b74d20"); + addPowData("3ff00005983e8eb0", POW_B1, "3ff0000000b753a8"); + addPowData("3ff00005c7692d61", POW_B1, "3ff0000000bd5d34"); + addPowData("3ff00006666f30ff", POW_B1, "3ff0000000d1b80e"); + addPowData("3ff0000736bc4e32", POW_B1, "3ff0000000ec61a0"); + addPowData("3ff000078694d925", POW_B1, "3ff0000000f699fe"); + addPowData("3ff0000965922b01", POW_B1, "3ff000000133e966"); + addPowData("3ff00009d3df2e9c", POW_B1, "3ff00000014207b4"); + addPowData("3ff0000a7fc1031c", POW_B1, "3ff00000015807e2"); + addPowData("3ff0000b24e284fd", POW_B1, "3ff00000016d2ad6"); + addPowData("3ff0000ba3ef2a27", POW_B1, "3ff00000017d6df2"); + addPowData("3ff0000cc84e613f", POW_B1, "3ff0000001a2da46"); + addPowData("3ff0000d3f510930", POW_B1, "3ff0000001b215f6"); + addPowData("3ff0000ed6a63814", POW_B1, "3ff0000001e63942"); + addPowData("3ff0000faaddda28", POW_B1, "3ff0000002016318"); + addPowData("3ff0000fca014900", POW_B1, "3ff0000002055f6c"); + addPowData("3ff00010e0b096e8", POW_B1, "3ff0000002290b3a"); + addPowData("3ff00011fc8e48d6", POW_B1, "3ff00000024d60ca"); + addPowData("3ff00013f7a36c74", POW_B1, "3ff00000028e4892"); + addPowData("3ff0001463399c1f", POW_B1, "3ff00000029c0de8"); + addPowData("3ff00015993ff1af", POW_B1, "3ff0000002c3bc98"); + addPowData("3ff00015c8f06afe", POW_B1, "3ff0000002c9d73e"); + addPowData("3ff00015ca4ae425", POW_B1, "3ff0000002ca0398"); + addPowData("3ff0001632cccf1b", POW_B1, "3ff0000002d76406"); + addPowData("3ff000163356b88b", POW_B1, "3ff0000002d775ac"); + addPowData("3ff00016f40da515", POW_B1, "3ff0000002f02068"); + addPowData("3ff00019f2cf3156", POW_B1, "3ff00000035244e2"); + addPowData("3ff0001a642c16b8", POW_B1, "3ff000000360c778"); + addPowData("3ff0001b5d3e01b7", POW_B1, "3ff000000380a8c8"); + addPowData("3ff0001c9734868b", POW_B1, "3ff0000003a8d872"); + addPowData("3ff0001d25c4a5a3", POW_B1, "3ff0000003bb17d2"); + addPowData("3ff0002175e6b56b", POW_B1, "3ff0000004486afa"); + addPowData("3ff00021d4f4d524", POW_B1, "3ff00000045495a4"); + addPowData("3ff00021f6080e3c", POW_B1, "3ff000000458d16a"); + addPowData("3ff00022373a14e0", POW_B1, "3ff00000046129aa"); + addPowData("3ff000228ada77a7", POW_B1, "3ff00000046bddda"); + addPowData("3ff0002514302bc2", POW_B1, "3ff0000004befa86"); + addPowData("3ff00028864aa46e", POW_B1, "3ff00000052fe238"); + addPowData("3ff0002cc166be3c", POW_B1, "3ff0000005ba841e"); + addPowData("3ff0002d663f7849", POW_B1, "3ff0000005cf9d94"); + addPowData("3ff00030ecbec180", POW_B1, "3ff0000006432148"); + addPowData("3ff00032bc7bd1fb", POW_B1, "3ff00000067e7c58"); + addPowData("3ff00033d5ab51c8", POW_B1, "3ff0000006a279c8"); + addPowData("3ff000342811fe2a", POW_B1, "3ff0000006ad05c4"); + addPowData("3ff0003757f8a604", POW_B1, "3ff00000071573d6"); + addPowData("3ff0003fd1c236d7", POW_B1, "3ff00000082b2b64"); + addPowData("3ff00040f8b820de", POW_B1, "3ff000000850ec12"); + addPowData("3ff00042afe6956a", POW_B1, "3ff0000008892244"); + addPowData("3ff000472fce0067", POW_B1, "3ff00000091c9160"); + addPowData("3ff000489c0f28bd", POW_B1, "3ff00000094b3072"); + addPowData("3ff00051c09cc796", POW_B1, "3ff000000a76c20e"); + addPowData("3ff00056dbfd9971", POW_B1, "3ff000000b1e16c8"); + addPowData("3ff00057dfaf3d77", POW_B1, "3ff000000b3f53b8"); + addPowData("3ff000591fba3154", POW_B1, "3ff000000b684a00"); + addPowData("3ff0005b7357c2d4", POW_B1, "3ff000000bb48572"); + addPowData("3ff0005db6c24365", POW_B1, "3ff000000bfeae14"); + addPowData("3ff00066e3aaf20c", POW_B1, "3ff000000d2b4fea"); + addPowData("3ff00067740a0dfe", POW_B1, "3ff000000d3dca36"); + addPowData("3ff00068def18101", POW_B1, "3ff000000d6c3cac"); + addPowData("3ff0006e631be9f7", POW_B1, "3ff000000e20f9c6"); + addPowData("3ff00077944ddc87", POW_B1, "3ff000000f4e26d2"); + addPowData("3ff0007e094cbb50", POW_B1, "3ff000001021b5d6"); + addPowData("3ff0007f93d4171e", POW_B1, "3ff0000010543432"); + addPowData("3ff0008b8fa77733", POW_B1, "3ff0000011dcd5e8"); + addPowData("3ff0008c9af73595", POW_B1, "3ff0000011ff0c00"); + addPowData("3ff000918683e6b9", POW_B1, "3ff0000012a03f4c"); + addPowData("3ff0009ea781c5dc", POW_B1, "3ff00000144e644e"); + addPowData("3ff000a1bfba1cad", POW_B1, "3ff0000014b3c7d0"); + addPowData("3ff000a2fd62cd32", POW_B1, "3ff0000014dc6f40"); + addPowData("3ff000a87b8e3d21", POW_B1, "3ff0000015906556"); + addPowData("3ff000a98a72819b", POW_B1, "3ff0000015b3107c"); + addPowData("3ff000ab7bfa76bc", POW_B1, "3ff0000015f2bcf0"); + addPowData("3ff000ab8a035de5", POW_B1, "3ff0000015f488c0"); + addPowData("3ff000b83b92666f", POW_B1, "3ff000001794683e"); + addPowData("3ff000bb1c2e1917", POW_B1, "3ff0000017f2ad26"); + addPowData("3ff000c0e8df0274", POW_B1, "3ff0000018b0aeb2"); + addPowData("3ff000c3dcd52810", POW_B1, "3ff0000019116d74"); + addPowData("3ff000c66ab34f1a", POW_B1, "3ff0000019651b5e"); + addPowData("3ff000c6c0333d8d", POW_B1, "3ff0000019700c7e"); + addPowData("3ff000da5dac4a20", POW_B1, "3ff000001bf2ab68"); + addPowData("3ff000dad9042c59", POW_B1, "3ff000001c027448"); + addPowData("3ff000def05fa9c8", POW_B1, "3ff000001c887cdc"); + addPowData("3ff000e7d0d1886a", POW_B1, "3ff000001dab4c32"); + addPowData("3ff000ee89e5c6e1", POW_B1, "3ff000001e878be0"); + addPowData("3ff000efedd98c6e", POW_B1, "3ff000001eb51910"); + addPowData("3ff000f2785d7ac7", POW_B1, "3ff000001f085840"); + addPowData("3ff0010403f34767", POW_B1, "3ff0000021472146"); + addPowData("3ff0010b331a0d17", POW_B1, "3ff0000022327b72"); + addPowData("3ff0010cd9aeb281", POW_B1, "3ff0000022688f08"); + addPowData("3ff00121ef66cfaf", POW_B1, "3ff00000251b4868"); + addPowData("3ff0012e43815868", POW_B1, "3ff0000026af266e"); + addPowData("3ff0012eaddc6e6c", POW_B1, "3ff0000026bcc27e"); + addPowData("3ff001342f8076a1", POW_B1, "3ff0000027712428"); + addPowData("3ff0013bca543227", POW_B1, "3ff00000286a42d2"); + addPowData("3ff0013c2556de0d", POW_B1, "3ff000002875e826"); + addPowData("3ff00142945996d8", POW_B1, "3ff000002948a8f8"); + addPowData("3ff0014b030edd2b", POW_B1, "3ff000002a5ce37e"); + addPowData("3ff00152d0067fdc", POW_B1, "3ff000002b5c6b3c"); + addPowData("3ff00157b53c4b1b", POW_B1, "3ff000002bfcc712"); + addPowData("3ff0015c35ba4a3e", POW_B1, "3ff000002c903f7c"); + addPowData("3ff0016a01a8e426", POW_B1, "3ff000002e542eac"); + addPowData("3ff0016e89d3a3d4", POW_B1, "3ff000002ee8a1d4"); + addPowData("3ff0019142307bb4", POW_B1, "3ff000003359ed28"); + addPowData("3ff0019b46fd6dd3", POW_B1, "3ff0000034a21802"); + addPowData("3ff001a09de2304b", POW_B1, "3ff000003550fcb6"); + addPowData("3ff001aa5e824b31", POW_B1, "3ff0000036906d46"); + addPowData("3ff001d58a281371", POW_B1, "3ff000003c166f1a"); + addPowData("3ff001eb2c463f76", POW_B1, "3ff000003edafd18"); + addPowData("3ff001ed83fcb397", POW_B1, "3ff000003f27b742"); + addPowData("3ff00208430b92aa", POW_B1, "3ff000004293b74e"); + addPowData("3ff0020e7a8cf479", POW_B1, "3ff00000435f53c0"); + addPowData("3ff0021a2f14a0ee", POW_B1, "3ff0000044deb040"); + addPowData("3ff00225d2bdab65", POW_B1, "3ff00000465be328"); + addPowData("3ff0023b7ef88d11", POW_B1, "3ff000004921ae72"); + addPowData("3ff0025118554352", POW_B1, "3ff000004be50c14"); + addPowData("3ff0026155666d19", POW_B1, "3ff000004df8d8d4"); + addPowData("3ff002741437f128", POW_B1, "3ff00000505ebbd4"); + addPowData("3ff00277c54a46dc", POW_B1, "3ff0000050d7a15a"); + addPowData("3ff0027e7383d6a3", POW_B1, "3ff0000051b26818"); + addPowData("3ff002c4fc4fdc0a", POW_B1, "3ff000005ab8317e"); + addPowData("3ff002c85c832a94", POW_B1, "3ff000005b26bc70"); + addPowData("3ff002cb8db1cdd2", POW_B1, "3ff000005b8f43a8"); + addPowData("3ff002ff8dc81d17", POW_B1, "3ff0000062360202"); + addPowData("3ff00307dd1df5e8", POW_B1, "3ff0000063461b4c"); + addPowData("3ff00314b1e73ecf", POW_B1, "3ff0000064ea3ef8"); + addPowData("3ff0032fda05447d", POW_B1, "3ff0000068636fe0"); + addPowData("3ff003443fe32ca3", POW_B1, "3ff000006aff4f62"); + addPowData("3ff00358e0494db1", POW_B1, "3ff000006da2a7fc"); + addPowData("3ff0035d6b21692b", POW_B1, "3ff000006e3760e2"); + addPowData("3ff00364ba163146", POW_B1, "3ff000006f26a9dc"); + addPowData("3ff00370ee36a27f", POW_B1, "3ff0000070b637f4"); + addPowData("3ff0039d1f6e2a69", POW_B1, "3ff00000765d10a0"); + addPowData("3ff003f5ccdc2a0e", POW_B1, "3ff0000081b42a4c"); + addPowData("3ff0040f75988e6a", POW_B1, "3ff0000084fc2434"); + addPowData("3ff0041cf1d045a6", POW_B1, "3ff0000086b595c6"); + addPowData("3ff0041d9e7db622", POW_B1, "3ff0000086cbaa66"); + addPowData("3ff0043174f1cecf", POW_B1, "3ff0000089550ca2"); + addPowData("3ff00435791bd0f7", POW_B1, "3ff0000089d88502"); + addPowData("3ff00466bb29aef9", POW_B1, "3ff000009024e9a4"); + addPowData("3ff004824e602aa4", POW_B1, "3ff0000093ab82ba"); + addPowData("3ff0048e35a7cb3d", POW_B1, "3ff00000953121ae"); + addPowData("3ff0048fbb17c5da", POW_B1, "3ff000009562ec96"); + addPowData("3ff004901a2243db", POW_B1, "3ff00000956f136c"); + addPowData("3ff00496fe59bc98", POW_B1, "3ff000009650a4ca"); + addPowData("3ff004a6d1ff4ea8", POW_B1, "3ff000009856aba0"); + addPowData("3ff004b668c99125", POW_B1, "3ff000009a54e898"); + addPowData("3ff005033e4be951", POW_B1, "3ff00000a4279f34"); + addPowData("3ff005468a327822", POW_B1, "3ff00000acc20750"); + addPowData("3ff005583aa2b489", POW_B1, "3ff00000af04eb28"); + addPowData("3ff0058e587f1f45", POW_B1, "3ff00000b5efdb84"); + addPowData("3ff00594e6478777", POW_B1, "3ff00000b6c6527e"); + addPowData("3ff005c517af10c9", POW_B1, "3ff00000bcef536c"); + addPowData("3ff005fd34c3ed15", POW_B1, "3ff00000c41b6c0c"); + addPowData("3ff00605a05f9aa0", POW_B1, "3ff00000c52eefa6"); + addPowData("3ff00659bb10a908", POW_B1, "3ff00000cfeeb5f0"); + addPowData("3ff0068cd52978ae", POW_B1, "3ff00000d676966c"); + addPowData("3ff006e4da5039f7", POW_B1, "3ff00000e1b61b90"); + addPowData("3ff006e82e891fef", POW_B1, "3ff00000e223023e"); + addPowData("3ff006ea73f88946", POW_B1, "3ff00000e26d4ea2"); + addPowData("3ff006f9bbd18d8d", POW_B1, "3ff00000e4612d2c"); + addPowData("3ff0071031085c9b", POW_B1, "3ff00000e73fd148"); + addPowData("3ff007183010ac0b", POW_B1, "3ff00000e84562c6"); + addPowData("3ff0076b514de586", POW_B1, "3ff00000f2e491be"); + addPowData("3ff007a23c6d5b72", POW_B1, "3ff00000f9e8d688"); + addPowData("3ff007ba0d6b9092", POW_B1, "3ff00000fcf3cb14"); + addPowData("3ff00818a10a8fa7", POW_B1, "3ff000010908e8cc"); + addPowData("3ff0081d9a5961f3", POW_B1, "3ff0000109ab922e"); + addPowData("3ff00842204a3715", POW_B1, "3ff000010e55fa30"); + addPowData("3ff0088ee1bcbc5c", POW_B1, "3ff000011823f4e8"); + addPowData("3ff008feca56dfb2", POW_B1, "3ff00001266f2416"); + addPowData("3ff009153b12f7fb", POW_B1, "3ff00001294cd942"); + addPowData("3ff0091653a67e2a", POW_B1, "3ff000012970aed8"); + addPowData("3ff0091e30077029", POW_B1, "3ff000012a71b252"); + addPowData("3ff0091e8cbf5d10", POW_B1, "3ff000012a7d89c6"); + addPowData("3ff00939e8deaf04", POW_B1, "3ff000012dfc1048"); + addPowData("3ff0094792ff27e8", POW_B1, "3ff000012fbad0ac"); + addPowData("3ff009645e4bb389", POW_B1, "3ff0000133683264"); + addPowData("3ff009b0b2616930", POW_B1, "3ff000013d27849e"); + addPowData("3ff009b9e70187a2", POW_B1, "3ff000013e547404"); + addPowData("3ff009de0cb6ef67", POW_B1, "3ff0000142f21a62"); + addPowData("3ff009ea31bdbe75", POW_B1, "3ff00001447f19aa"); + addPowData("3ff009f707e9a97b", POW_B1, "3ff000014622b662"); + addPowData("3ff009fb36d3c998", POW_B1, "3ff0000146ab74ec"); + addPowData("3ff00a28820b8780", POW_B1, "3ff000014c7401ae"); + addPowData("3ff00a3632db72be", POW_B1, "3ff000014e3382a6"); + addPowData("3ff00a37999dc7cf", POW_B1, "3ff000014e61513c"); + addPowData("3ff00aa7c8696175", POW_B1, "3ff000015cb3fc44"); + addPowData("3ff00abd92d5068e", POW_B1, "3ff000015f7c2a02"); + addPowData("3ff00aed7ecfd407", POW_B1, "3ff00001659a5334"); + addPowData("3ff00b1fa2b4a6a9", POW_B1, "3ff000016c00e92e"); + addPowData("3ff00b2d0eb64e9f", POW_B1, "3ff000016db786be"); + addPowData("3ff00b69e36600ef", POW_B1, "3ff00001757b59f8"); + addPowData("3ff00bef8115b65d", POW_B1, "3ff0000186893de0"); + addPowData("3ff00bf4c7765387", POW_B1, "3ff000018735966e"); + addPowData("3ff00bfe8ddc73ff", POW_B1, "3ff000018874f61e"); + addPowData("3ff00c15de2b0d5e", POW_B1, "3ff000018b6eaab6"); + addPowData("3ff00c7dd4479905", POW_B1, "3ff0000198b316ac"); + addPowData("3ff00d276f3b5ce5", POW_B1, "3ff00001ae576102"); + addPowData("3ff00d27ce901c9a", POW_B1, "3ff00001ae638ad2"); + addPowData("3ff00d67c2b33446", POW_B1, "3ff00001b68c6810"); + addPowData("3ff00dafadce5c27", POW_B1, "3ff00001bfb9439e"); + addPowData("3ff00dcf80fe76bb", POW_B1, "3ff00001c3c89e06"); + addPowData("3ff00e00380e10d7", POW_B1, "3ff00001c9ff83c8"); + addPowData("3ff00e5ccd725b39", POW_B1, "3ff00001d5ced49a"); + addPowData("3ff00e86a21944c7", POW_B1, "3ff00001db24b940"); + addPowData("3ff00e86a7859088", POW_B1, "3ff00001db256a52"); + addPowData("3ff00eb271b30fab", POW_B1, "3ff00001e0bb385a"); + addPowData("3ff00f01ca36b0b7", POW_B1, "3ff00001ead9d548"); + addPowData("3ff00f3fdf937c0f", POW_B1, "3ff00001f2c4b382"); + addPowData("3ff00f83f7bdfa67", POW_B1, "3ff00001fb73ac9e"); + addPowData("3ff0103649af599a", POW_B1, "3ff00002123055bc"); + addPowData("3ff010e5e83c7501", POW_B1, "3ff000022893e022"); + addPowData("3ff01146bafecacc", POW_B1, "3ff0000234eb6822"); + addPowData("3ff011b575f20dec", POW_B1, "3ff00002430864f4"); + addPowData("3ff011c0fef22410", POW_B1, "3ff000024480bffe"); + addPowData("3ff011cd94e46714", POW_B1, "3ff00002461b60b0"); + addPowData("3ff0123e52985644", POW_B1, "3ff0000254797fd0"); + addPowData("3ff0124f4152a403", POW_B1, "3ff0000256a1e184"); + addPowData("3ff0126d052860e2", POW_B1, "3ff000025a6cde26"); + addPowData("3ff01270a65c85d5", POW_B1, "3ff000025ae345f4"); + addPowData("3ff012c4fd4385cd", POW_B1, "3ff0000265a26b38"); + addPowData("3ff012d826f868c8", POW_B1, "3ff0000268137b10"); + addPowData("3ff0131d07497794", POW_B1, "3ff0000270da035c"); + addPowData("3ff01340687303d7", POW_B1, "3ff00002755bedb6"); + addPowData("3ff01349f3ac164b", POW_B1, "3ff000027693328a"); + addPowData("3ff0142094f13c33", POW_B1, "3ff0000291ea8804"); + addPowData("3ff014797ba4c0ef", POW_B1, "3ff000029d3d4906"); + addPowData("3ff014b591802818", POW_B1, "3ff00002a4e451b6"); + addPowData("3ff014cf1b9413aa", POW_B1, "3ff00002a824f9aa"); + addPowData("3ff014da477e1774", POW_B1, "3ff00002a9913162"); + addPowData("3ff0150325b205a6", POW_B1, "3ff00002aec58ca0"); + addPowData("3ff01545322f876f", POW_B1, "3ff00002b72eba66"); + addPowData("3ff015cba20ec276", POW_B1, "3ff00002c84cef0e"); + addPowData("3ff016571b207ee8", POW_B1, "3ff00002da0eb434"); + addPowData("3ff016d3dfdc8cc0", POW_B1, "3ff00002e9f0b5ea"); + addPowData("3ff01743c6cc53ca", POW_B1, "3ff00002f82f0348"); + addPowData("3ff0177da6425b0e", POW_B1, "3ff00002ff8ca296"); + addPowData("3ff01789d91cbe83", POW_B1, "3ff00003011a146c"); + addPowData("3ff017ac17ac002d", POW_B1, "3ff000030575c5da"); + addPowData("3ff0189be8b70297", POW_B1, "3ff0000323fa0fe8"); + addPowData("3ff018abdf39553b", POW_B1, "3ff0000326020250"); + addPowData("3ff0192278704be3", POW_B1, "3ff000033518c576"); + addPowData("3ff019be4095d6ae", POW_B1, "3ff0000348e9f02a"); + addPowData("3ff019ce7bda4503", POW_B1, "3ff000034afa7cee"); + addPowData("3ff01a4586c04fe7", POW_B1, "3ff000035a1ea55a"); + addPowData("3ff01b15d687a1cf", POW_B1, "3ff00003749c73ac"); + addPowData("3ff01bec8f058641", POW_B1, "3ff000038fe982c2"); + addPowData("3ff01c1791d40d0a", POW_B1, "3ff00003956153b8"); + addPowData("3ff01c1d9e395eba", POW_B1, "3ff0000396262bf8"); + addPowData("3ff01d11a2a555de", POW_B1, "3ff00003b52aba6c"); + addPowData("3ff01d1c6f0356e4", POW_B1, "3ff00003b68a12bc"); + addPowData("3ff01d2883db0d7b", POW_B1, "3ff00003b8132994"); + addPowData("3ff01e71e773ffc2", POW_B1, "3ff00003e1eea894"); + addPowData("3ff01f434d3c5e64", POW_B1, "3ff00003fc88ecc0"); + addPowData("3ff01f6112a7fe03", POW_B1, "3ff0000400511134"); + addPowData("3ff020fb74e9f170", POW_B1, "3ff00004346fbfa2"); + addPowData("3ff021a0782fbc23", POW_B1, "3ff0000449634c62"); + addPowData("3ff0232e074df506", POW_B1, "3ff000047bda0f6c"); + addPowData("3ff02414e9f5c03b", POW_B1, "3ff0000499267fd0"); + addPowData("3ff02430709f51ec", POW_B1, "3ff000049ca49698"); + addPowData("3ff024c8eb334fe8", POW_B1, "3ff00004affcebd4"); + addPowData("3ff02505e61f7b8d", POW_B1, "3ff00004b7b94920"); + addPowData("3ff025cadab76a1f", POW_B1, "3ff00004d0b4be2e"); + addPowData("3ff025e4a878d29f", POW_B1, "3ff00004d3fa8b08"); + addPowData("3ff0262e9bbe0441", POW_B1, "3ff00004dd5b75f0"); + addPowData("3ff0270f120aff91", POW_B1, "3ff00004f9d1f76e"); + addPowData("3ff02754e840e5b2", POW_B1, "3ff0000502acb29a"); + addPowData("3ff02c36701515db", POW_B1, "3ff00005a1002d44"); + addPowData("3ff032d08c7e2e21", POW_B1, "3ff0000676db002c"); + addPowData("3ff035a55ff1c78a", POW_B1, "3ff00006d27732bc"); + addPowData("3ff03644918d0785", POW_B1, "3ff00006e693debe"); + addPowData("3ff037bb1dedc8cd", POW_B1, "3ff0000715e28914"); + addPowData("3ff0395604cd3567", POW_B1, "3ff0000749c3c032"); + addPowData("3ff039bf04e42f96", POW_B1, "3ff000075704c2c6"); + addPowData("3ff03e7bdeeecc32", POW_B1, "3ff00007f004ed7a"); + addPowData("3ff03ed24e556ded", POW_B1, "3ff00007faea95ee"); + addPowData("3ff03ef1c681f0bd", POW_B1, "3ff00007fee23120"); + addPowData("3ff03fcb5661fa8f", POW_B1, "3ff000081a4eb43e"); + addPowData("3ff042d910585bee", POW_B1, "3ff000087ccc6c26"); + addPowData("3ff0450fda5471a3", POW_B1, "3ff00008c42a03da"); + addPowData("3ff04641fc8b11ca", POW_B1, "3ff00008eab1bc98"); + addPowData("3ff047a41ad06417", POW_B1, "3ff0000917400204"); + addPowData("3ff04db90c5c127d", POW_B1, "3ff00009daf8d8ee"); + addPowData("3ff04f9e73a25ac8", POW_B1, "3ff0000a17eef48e"); + addPowData("3ff04fcbf8abc9fd", POW_B1, "3ff0000a1da61602"); + addPowData("3ff0511862bf450d", POW_B1, "3ff0000a4760eee0"); + addPowData("3ff051210e0bfeb6", POW_B1, "3ff0000a48777d74"); + addPowData("3ff055982b0f8b04", POW_B1, "3ff0000ad7de456c"); + addPowData("3ff05727a94317f9", POW_B1, "3ff0000b09f2a4ac"); + addPowData("3ff05e9f2de8eae8", POW_B1, "3ff0000bf9504088"); + addPowData("3ff066a0bcc57b6b", POW_B1, "3ff0000cf97de4b2"); + addPowData("3ff068689beee8b2", POW_B1, "3ff0000d3267db9a"); + addPowData("3ff06c311b09de1e", POW_B1, "3ff0000dab3d2c1e"); + addPowData("3ff06fbdc15a990b", POW_B1, "3ff0000e1c81b8d0"); + addPowData("3ff07003413b4e40", POW_B1, "3ff0000e252a9014"); + addPowData("3ff0707b97ed6426", POW_B1, "3ff0000e3428b132"); + addPowData("3ff077df0910b501", POW_B1, "3ff0000f1f96de9e"); + addPowData("3ff07f468476cd37", POW_B1, "3ff000100b1bf6fa"); + addPowData("3ff08da4fce37b7d", POW_B1, "3ff00011d2fefcd4"); + addPowData("3ff08ee23b88ee24", POW_B1, "3ff00011fa3db176"); + addPowData("3ff0907c57df2523", POW_B1, "3ff000122cf4fcd0"); + addPowData("3ff09d1632ec4b9a", POW_B1, "3ff00013bb369796"); + addPowData("3ff09e92f87b35af", POW_B1, "3ff00013ea2501a4"); + addPowData("3ff0a900bef42c6d", POW_B1, "3ff0001532be2c26"); + addPowData("3ff0b33bfdb9a6c8", POW_B1, "3ff000167457a5ce"); + addPowData("3ff0b385e0945b49", POW_B1, "3ff000167d6737f2"); + addPowData("3ff0c1dd413c5db1", POW_B1, "3ff000183edd3e2a"); + addPowData("3ff0c68383edcd8b", POW_B1, "3ff00018d041d5b4"); + addPowData("3ff0d0d3019dddb8", POW_B1, "3ff0001a121dc50e"); + addPowData("3ff0dd223ceffaf9", POW_B1, "3ff0001b915e94ac"); + addPowData("3ff0ef73f1a9aa75", POW_B1, "3ff0001dc9b6eb1a"); + addPowData("3ff15e3c3258a73d", POW_B1, "3ff0002b045ced4c"); + addPowData("3ff29c4ea7efe276", POW_B1, "3ff0004f3e9a3c94"); + addPowData("3ff2e90398bec6e7", POW_B1, "3ff000579e8208fa"); + addPowData("3ff318ed7b598d20", POW_B1, "3ff0005cc8807672"); + addPowData("3ff348ec880ef24d", POW_B1, "3ff00061e7db55c4"); + addPowData("3ff37391b11ff076", POW_B1, "3ff000666a5c8088"); + addPowData("3ff515fde2e99b0d", POW_B1, "3ff00090b8cf57de"); + addPowData("3ff6a89b5ffae2dd", POW_B1, "3ff000b67158530a"); + addPowData("3ff99efec0fbc5d8", POW_B1, "3ff000f6e0b478fe"); + addPowData("3ffffcf9acb020be", POW_B1, "3ff0016b472e0602"); + addPowData("3ff000df8a0eadf8", POW_B2, "3ff8817d68bc901b"); + addPowData("3ff00004ec241f48", POW_B2, "3ff026a33089cf0d"); + addPowData("3ff0152243bac553", POW_B1, "3ff00002b2bbfc38"); // for x86 jdk17 on 4143944 + } + + private static void addPowData(String a, String b, String ret) { + powData.put(new PowData(hexToDouble(a), hexToDouble(b)), hexToDouble(ret)); + } + + + // for arm jdk17 + public static double pow(double a, double b) { + double strictResult = StrictMath.pow(a, b); + return powData.getOrDefault(new PowData(a, b), strictResult); + } + + private static double hexToDouble(String input) { + // Convert the hex string to a long + long hexAsLong = Long.parseLong(input, 16); + // and then convert the long to a double + return Double.longBitsToDouble(hexAsLong); + } + + private static class PowData { + final double a; + final double b; + + public PowData(double a, double b) { + this.a = a; + this.b = b; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PowData powData = (PowData) o; + return Double.compare(powData.a, a) == 0 && Double.compare(powData.b, b) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(a, b); + } + } +} diff --git a/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java b/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java new file mode 100644 index 00000000000..2528be87800 --- /dev/null +++ b/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java @@ -0,0 +1,124 @@ +package org.tron.common.utils; + +import java.math.BigInteger; + +public class MarketComparator { + + public static final int TOKEN_ID_LENGTH = Long.toString(Long.MAX_VALUE).getBytes().length; // 19 + + + public static int comparePriceKey(byte[] o1, byte[] o2) { + //compare pair + byte[] pair1 = new byte[TOKEN_ID_LENGTH * 2]; + byte[] pair2 = new byte[TOKEN_ID_LENGTH * 2]; + + System.arraycopy(o1, 0, pair1, 0, TOKEN_ID_LENGTH * 2); + System.arraycopy(o2, 0, pair2, 0, TOKEN_ID_LENGTH * 2); + + int pairResult = compareUnsigned(pair1, pair2); + if (pairResult != 0) { + return pairResult; + } + + //compare price + byte[] getSellTokenQuantity1 = new byte[8]; + byte[] getBuyTokenQuantity1 = new byte[8]; + + byte[] getSellTokenQuantity2 = new byte[8]; + byte[] getBuyTokenQuantity2 = new byte[8]; + + int longByteNum = 8; + + System.arraycopy(o1, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH, + getSellTokenQuantity1, 0, longByteNum); + System.arraycopy(o1, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH + longByteNum, + getBuyTokenQuantity1, 0, longByteNum); + + System.arraycopy(o2, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH, + getSellTokenQuantity2, 0, longByteNum); + System.arraycopy(o2, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH + longByteNum, + getBuyTokenQuantity2, 0, longByteNum); + + long sellTokenQuantity1 = toLong(getSellTokenQuantity1); + long buyTokenQuantity1 = toLong(getBuyTokenQuantity1); + long sellTokenQuantity2 = toLong(getSellTokenQuantity2); + long buyTokenQuantity2 = toLong(getBuyTokenQuantity2); + + if ((sellTokenQuantity1 == 0 || buyTokenQuantity1 == 0) + && (sellTokenQuantity2 == 0 || buyTokenQuantity2 == 0)) { + return 0; + } + + if (sellTokenQuantity1 == 0 || buyTokenQuantity1 == 0) { + return -1; + } + + if (sellTokenQuantity2 == 0 || buyTokenQuantity2 == 0) { + return 1; + } + + return comparePrice(sellTokenQuantity1, buyTokenQuantity1, + sellTokenQuantity2, buyTokenQuantity2); + + } + + /** + * Note: the params should be the same token pair, or you should change the order. + * All the quantity should be bigger than 0. + * */ + public static int comparePrice(long price1SellQuantity, long price1BuyQuantity, + long price2SellQuantity, long price2BuyQuantity) { + try { + return Long.compare(Math.multiplyExact(price1BuyQuantity, price2SellQuantity), + Math.multiplyExact(price2BuyQuantity, price1SellQuantity)); + + } catch (ArithmeticException ex) { + // do nothing here, because we will use BigInteger to compute again + } + + BigInteger price1BuyQuantityBI = BigInteger.valueOf(price1BuyQuantity); + BigInteger price1SellQuantityBI = BigInteger.valueOf(price1SellQuantity); + BigInteger price2BuyQuantityBI = BigInteger.valueOf(price2BuyQuantity); + BigInteger price2SellQuantityBI = BigInteger.valueOf(price2SellQuantity); + + return price1BuyQuantityBI.multiply(price2SellQuantityBI) + .compareTo(price2BuyQuantityBI.multiply(price1SellQuantityBI)); + } + + /** + * copy from org.bouncycastle.util.Arrays.compareUnsigned + */ + private static int compareUnsigned(byte[] a, byte[] b) { + if (a == b) { + return 0; + } + if (a == null) { + return -1; + } + if (b == null) { + return 1; + } + int minLen = Math.min(a.length, b.length); + for (int i = 0; i < minLen; ++i) { + int aVal = a[i] & 0xFF; + int bVal = b[i] & 0xFF; + if (aVal < bVal) { + return -1; + } + if (aVal > bVal) { + return 1; + } + } + if (a.length < b.length) { + return -1; + } + if (a.length > b.length) { + return 1; + } + return 0; + } + + public static long toLong(byte[] b) { + return (b == null || b.length == 0) ? 0 : new BigInteger(1, b).longValue(); + } +} diff --git a/chainbase/src/main/java/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java b/platform/src/main/java/arm/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java similarity index 87% rename from chainbase/src/main/java/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java rename to platform/src/main/java/arm/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java index c4c519f68f1..efb7219b211 100644 --- a/chainbase/src/main/java/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java +++ b/platform/src/main/java/arm/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java @@ -1,7 +1,5 @@ package org.tron.common.utils; -import org.tron.core.capsule.utils.MarketUtils; - public class MarketOrderPriceComparatorForLevelDB implements org.iq80.leveldb.DBComparator { @Override @@ -26,7 +24,7 @@ public byte[] findShortSuccessor(byte[] key) { */ @Override public int compare(byte[] o1, byte[] o2) { - return MarketUtils.comparePriceKey(o1, o2); + return MarketComparator.comparePriceKey(o1, o2); } } diff --git a/platform/src/main/java/arm/org/tron/common/utils/MarketOrderPriceComparatorForRocksDB.java b/platform/src/main/java/arm/org/tron/common/utils/MarketOrderPriceComparatorForRocksDB.java new file mode 100644 index 00000000000..26c246faf0e --- /dev/null +++ b/platform/src/main/java/arm/org/tron/common/utils/MarketOrderPriceComparatorForRocksDB.java @@ -0,0 +1,32 @@ +package org.tron.common.utils; + +import java.nio.ByteBuffer; +import org.rocksdb.AbstractComparator; +import org.rocksdb.ComparatorOptions; + +public class MarketOrderPriceComparatorForRocksDB extends AbstractComparator { + + public MarketOrderPriceComparatorForRocksDB(final ComparatorOptions copt) { + super(copt); + } + + @Override + public String name() { + return "MarketOrderPriceComparator"; + } + + @Override + public int compare(final ByteBuffer a, final ByteBuffer b) { + return MarketComparator.comparePriceKey(convertDataToBytes(a), convertDataToBytes(b)); + } + + /** + * DirectSlice.data().array will throw UnsupportedOperationException. + * */ + public byte[] convertDataToBytes(ByteBuffer buf) { + byte[] bytes = new byte[buf.remaining()]; + buf.get(bytes); + return bytes; + } + +} diff --git a/common/src/main/java/org/tron/common/math/MathWrapper.java b/platform/src/main/java/x86/org/tron/common/math/MathWrapper.java similarity index 95% rename from common/src/main/java/org/tron/common/math/MathWrapper.java rename to platform/src/main/java/x86/org/tron/common/math/MathWrapper.java index 519dafb9d42..471c8f0a72d 100644 --- a/common/src/main/java/org/tron/common/math/MathWrapper.java +++ b/platform/src/main/java/x86/org/tron/common/math/MathWrapper.java @@ -8,6 +8,7 @@ @Deprecated public class MathWrapper { + // for x86 jdk8 public static double pow(double a, double b) { return Math.pow(a, b); } diff --git a/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java b/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java new file mode 100644 index 00000000000..2528be87800 --- /dev/null +++ b/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java @@ -0,0 +1,124 @@ +package org.tron.common.utils; + +import java.math.BigInteger; + +public class MarketComparator { + + public static final int TOKEN_ID_LENGTH = Long.toString(Long.MAX_VALUE).getBytes().length; // 19 + + + public static int comparePriceKey(byte[] o1, byte[] o2) { + //compare pair + byte[] pair1 = new byte[TOKEN_ID_LENGTH * 2]; + byte[] pair2 = new byte[TOKEN_ID_LENGTH * 2]; + + System.arraycopy(o1, 0, pair1, 0, TOKEN_ID_LENGTH * 2); + System.arraycopy(o2, 0, pair2, 0, TOKEN_ID_LENGTH * 2); + + int pairResult = compareUnsigned(pair1, pair2); + if (pairResult != 0) { + return pairResult; + } + + //compare price + byte[] getSellTokenQuantity1 = new byte[8]; + byte[] getBuyTokenQuantity1 = new byte[8]; + + byte[] getSellTokenQuantity2 = new byte[8]; + byte[] getBuyTokenQuantity2 = new byte[8]; + + int longByteNum = 8; + + System.arraycopy(o1, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH, + getSellTokenQuantity1, 0, longByteNum); + System.arraycopy(o1, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH + longByteNum, + getBuyTokenQuantity1, 0, longByteNum); + + System.arraycopy(o2, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH, + getSellTokenQuantity2, 0, longByteNum); + System.arraycopy(o2, TOKEN_ID_LENGTH + TOKEN_ID_LENGTH + longByteNum, + getBuyTokenQuantity2, 0, longByteNum); + + long sellTokenQuantity1 = toLong(getSellTokenQuantity1); + long buyTokenQuantity1 = toLong(getBuyTokenQuantity1); + long sellTokenQuantity2 = toLong(getSellTokenQuantity2); + long buyTokenQuantity2 = toLong(getBuyTokenQuantity2); + + if ((sellTokenQuantity1 == 0 || buyTokenQuantity1 == 0) + && (sellTokenQuantity2 == 0 || buyTokenQuantity2 == 0)) { + return 0; + } + + if (sellTokenQuantity1 == 0 || buyTokenQuantity1 == 0) { + return -1; + } + + if (sellTokenQuantity2 == 0 || buyTokenQuantity2 == 0) { + return 1; + } + + return comparePrice(sellTokenQuantity1, buyTokenQuantity1, + sellTokenQuantity2, buyTokenQuantity2); + + } + + /** + * Note: the params should be the same token pair, or you should change the order. + * All the quantity should be bigger than 0. + * */ + public static int comparePrice(long price1SellQuantity, long price1BuyQuantity, + long price2SellQuantity, long price2BuyQuantity) { + try { + return Long.compare(Math.multiplyExact(price1BuyQuantity, price2SellQuantity), + Math.multiplyExact(price2BuyQuantity, price1SellQuantity)); + + } catch (ArithmeticException ex) { + // do nothing here, because we will use BigInteger to compute again + } + + BigInteger price1BuyQuantityBI = BigInteger.valueOf(price1BuyQuantity); + BigInteger price1SellQuantityBI = BigInteger.valueOf(price1SellQuantity); + BigInteger price2BuyQuantityBI = BigInteger.valueOf(price2BuyQuantity); + BigInteger price2SellQuantityBI = BigInteger.valueOf(price2SellQuantity); + + return price1BuyQuantityBI.multiply(price2SellQuantityBI) + .compareTo(price2BuyQuantityBI.multiply(price1SellQuantityBI)); + } + + /** + * copy from org.bouncycastle.util.Arrays.compareUnsigned + */ + private static int compareUnsigned(byte[] a, byte[] b) { + if (a == b) { + return 0; + } + if (a == null) { + return -1; + } + if (b == null) { + return 1; + } + int minLen = Math.min(a.length, b.length); + for (int i = 0; i < minLen; ++i) { + int aVal = a[i] & 0xFF; + int bVal = b[i] & 0xFF; + if (aVal < bVal) { + return -1; + } + if (aVal > bVal) { + return 1; + } + } + if (a.length < b.length) { + return -1; + } + if (a.length > b.length) { + return 1; + } + return 0; + } + + public static long toLong(byte[] b) { + return (b == null || b.length == 0) ? 0 : new BigInteger(1, b).longValue(); + } +} diff --git a/platform/src/main/java/x86/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java b/platform/src/main/java/x86/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java new file mode 100644 index 00000000000..efb7219b211 --- /dev/null +++ b/platform/src/main/java/x86/org/tron/common/utils/MarketOrderPriceComparatorForLevelDB.java @@ -0,0 +1,30 @@ +package org.tron.common.utils; + +public class MarketOrderPriceComparatorForLevelDB implements org.iq80.leveldb.DBComparator { + + @Override + public String name() { + return "MarketOrderPriceComparator"; + } + + @Override + public byte[] findShortestSeparator(byte[] start, byte[] limit) { + return new byte[0]; + } + + @Override + public byte[] findShortSuccessor(byte[] key) { + return new byte[0]; + } + + /** + * Note, for this compare, we should ensure token and quantity are all bigger than 0. Otherwise, + * when quantity is 0, the result of compare this key with others will be 0, but actually the + * result should be -1. + */ + @Override + public int compare(byte[] o1, byte[] o2) { + return MarketComparator.comparePriceKey(o1, o2); + } + +} diff --git a/chainbase/src/main/java/org/tron/common/utils/MarketOrderPriceComparatorForRockDB.java b/platform/src/main/java/x86/org/tron/common/utils/MarketOrderPriceComparatorForRocksDB.java similarity index 70% rename from chainbase/src/main/java/org/tron/common/utils/MarketOrderPriceComparatorForRockDB.java rename to platform/src/main/java/x86/org/tron/common/utils/MarketOrderPriceComparatorForRocksDB.java index d3812f0f6bc..be406ff658d 100644 --- a/chainbase/src/main/java/org/tron/common/utils/MarketOrderPriceComparatorForRockDB.java +++ b/platform/src/main/java/x86/org/tron/common/utils/MarketOrderPriceComparatorForRocksDB.java @@ -3,11 +3,10 @@ import org.rocksdb.ComparatorOptions; import org.rocksdb.DirectSlice; import org.rocksdb.util.DirectBytewiseComparator; -import org.tron.core.capsule.utils.MarketUtils; -public class MarketOrderPriceComparatorForRockDB extends DirectBytewiseComparator { +public class MarketOrderPriceComparatorForRocksDB extends DirectBytewiseComparator { - public MarketOrderPriceComparatorForRockDB(final ComparatorOptions copt) { + public MarketOrderPriceComparatorForRocksDB(final ComparatorOptions copt) { super(copt); } @@ -18,7 +17,7 @@ public String name() { @Override public int compare(final DirectSlice a, final DirectSlice b) { - return MarketUtils.comparePriceKey(convertDataToBytes(a), convertDataToBytes(b)); + return MarketComparator.comparePriceKey(convertDataToBytes(a), convertDataToBytes(b)); } /** diff --git a/plugins/README.md b/plugins/README.md index 0db6f2e6143..90f8bce46e1 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -34,15 +34,13 @@ DB convert provides a helper which can convert LevelDB data to RocksDB data, par - ``: Input path for leveldb, default: output-directory/database. - ``: Output path for rocksdb, default: output-directory-dst/database. -- `--safe`: In safe mode, read data from leveldb then put into rocksdb, it's a very time-consuming procedure. If not, just change engine.properties from leveldb to rocksdb, rocksdb - is compatible with leveldb for the current version. This may not be the case in the future, default: false. - `-h | --help`: Provide the help info. ### Examples: ```shell script # full command - java -jar Toolkit.jar db convert [-h] [--safe] + java -jar Toolkit.jar db convert [-h] # examples java -jar Toolkit.jar db convert output-directory/database /tmp/database ``` diff --git a/plugins/build.gradle b/plugins/build.gradle index b85a435dc30..40f75db1de0 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -4,14 +4,12 @@ plugins { apply plugin: 'application' apply plugin: 'checkstyle' +apply plugin: 'com.github.johnrengelman.shadow' -jacoco { - toolVersion = "0.8.4" -} def versions = [ checkstyle: '8.7', ] -mainClassName = 'org.tron.plugins.ArchiveManifest' +mainClassName = 'org.tron.plugins.Toolkit' group 'org.tron' version '1.0.0' @@ -19,7 +17,7 @@ configurations { checkstyleConfig } -configurations.getByName('checkstyleConfig') { +configurations.named('checkstyleConfig') { transitive = false } @@ -32,10 +30,9 @@ dependencies { implementation group: 'com.typesafe', name: 'config', version: '1.3.2' implementation group: 'me.tongfei', name: 'progressbar', version: '0.9.3' implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69' - implementation group: 'org.rocksdb', name: 'rocksdbjni', version: '5.15.10' - implementation 'io.github.tronprotocol:leveldbjni-all:1.18.2' - implementation 'io.github.tronprotocol:leveldb:1.18.2' + implementation 'com.halibobor:leveldb:1.18.3' implementation project(":protocol") + implementation(project(":platform")) } check.dependsOn 'lint' @@ -49,7 +46,7 @@ checkstyleMain { source = 'src/main/java' } -task lint(type: Checkstyle) { +tasks.register('lint', Checkstyle) { // Cleaning the old log because of the creation of the new ones (not sure if totaly needed) delete fileTree(dir: "${project.rootDir}/app/build/reports") source 'src' @@ -62,7 +59,7 @@ task lint(type: Checkstyle) { ignoreFailures = false } -tasks.matching { it instanceof Test }.all { +tasks.matching { it instanceof Test }.configureEach { testLogging.events = ["failed", "passed", "skipped"] } @@ -90,31 +87,6 @@ jacocoTestReport { getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec")) } -def binaryRelease(taskName, jarName, mainClass) { - return tasks.create("${taskName}", Jar) { - baseName = jarName - version = null - from(sourceSets.main.output) { - include "/**" - } - - from { - configurations.runtimeClasspath.collect { // https://docs.gradle.org/current/userguide/upgrading_version_6.html#changes_6.3 - it.isDirectory() ? it : zipTree(it) - } - } - - // exclude these files for bouncycastle - exclude "META-INF/*.SF" - exclude "META-INF/*.DSA" - exclude "META-INF/*.RSA" - - manifest { - attributes "Main-Class": "${mainClass}" - } - } -} - def createScript(project, mainClass, name) { project.tasks.create(name: name, type: CreateStartScripts) { outputDir = new File(project.buildDir, 'scripts') @@ -130,29 +102,36 @@ def createScript(project, mainClass, name) { } } } -applicationDistribution.from("../gradle/java-tron.vmoptions") { - into "bin" +if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + applicationDistribution.from("${project.rootDir}/gradle/jdk17/java-tron.vmoptions") { + into "bin" + } +} else { + applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") { + into "bin" + } } -createScript(project, 'org.tron.plugins.ArchiveManifest', 'ArchiveManifest') createScript(project, 'org.tron.plugins.Toolkit', 'Toolkit') -def releaseBinary = hasProperty('binaryRelease') ? getProperty('binaryRelease') : 'true' -def skipArchive = hasProperty('skipArchive') ? true : false -def skipAll = hasProperty('skipAll') ? true : false -if (releaseBinary == 'true') { - artifacts { - archives(binaryRelease('buildToolkitJar', 'Toolkit', 'org.tron.plugins.Toolkit')) - } - if (!skipAll) { - if (!skipArchive) { - artifacts { - archives(binaryRelease('buildArchiveManifestJar', 'ArchiveManifest', 'org.tron.plugins.ArchiveManifest')) - } - } - } +shadowJar { + baseName = 'Toolkit' + classifier = null + version = null + // exclude these files for bouncycastle + exclude "META-INF/*.SF" + exclude "META-INF/*.DSA" + exclude "META-INF/*.RSA" + mergeServiceFiles() // https://github.com/grpc/grpc-java/issues/10853 +} +shadowDistZip { + enabled = false +} + +startShadowScripts { + enabled = false } -task copyToParent(type: Copy) { +tasks.register('copyToParent', Copy) { into "../build/distributions" from "$buildDir/distributions" include "*.zip" diff --git a/plugins/src/main/java/org/tron/plugins/DbConvert.java b/plugins/src/main/java/org/tron/plugins/DbConvert.java index a75b235bbcf..c5e69b74418 100644 --- a/plugins/src/main/java/org/tron/plugins/DbConvert.java +++ b/plugins/src/main/java/org/tron/plugins/DbConvert.java @@ -49,13 +49,7 @@ public class DbConvert implements Callable { description = "Output path for rocksdb. Default: ${DEFAULT-VALUE}") private File dest; - @CommandLine.Option(names = {"--safe"}, - description = "In safe mode, read data from leveldb then put rocksdb." - + "If not, just change engine.properties from leveldb to rocksdb," - + "rocksdb is compatible with leveldb for current version." - + "This may not be the case in the future." - + "Default: ${DEFAULT-VALUE}") - private boolean safe; + private final boolean safe = true; @CommandLine.Option(names = {"-h", "--help"}) private boolean help; diff --git a/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForLevelDB.java b/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForLevelDB.java deleted file mode 100644 index 0879f770e1f..00000000000 --- a/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForLevelDB.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.tron.plugins.comparator; - -import org.iq80.leveldb.DBComparator; -import org.tron.plugins.utils.MarketUtils; - -public class MarketOrderPriceComparatorForLevelDB implements DBComparator { - - @Override - public String name() { - return "MarketOrderPriceComparator"; - } - - @Override - public byte[] findShortestSeparator(byte[] start, byte[] limit) { - return new byte[0]; - } - - @Override - public byte[] findShortSuccessor(byte[] key) { - return new byte[0]; - } - - @Override - public int compare(byte[] o1, byte[] o2) { - return MarketUtils.comparePriceKey(o1, o2); - } - -} \ No newline at end of file diff --git a/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java b/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java deleted file mode 100644 index cd718bdd2d7..00000000000 --- a/plugins/src/main/java/org/tron/plugins/comparator/MarketOrderPriceComparatorForRockDB.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.tron.plugins.comparator; - -import org.rocksdb.ComparatorOptions; -import org.rocksdb.DirectSlice; -import org.rocksdb.util.DirectBytewiseComparator; -import org.tron.plugins.utils.MarketUtils; - -public class MarketOrderPriceComparatorForRockDB extends DirectBytewiseComparator { - - public MarketOrderPriceComparatorForRockDB(final ComparatorOptions copt) { - super(copt); - } - - @Override - public String name() { - return "MarketOrderPriceComparator"; - } - - @Override - public int compare(final DirectSlice a, final DirectSlice b) { - return MarketUtils.comparePriceKey(convertDataToBytes(a), convertDataToBytes(b)); - } - - /** - * DirectSlice.data().array will throw UnsupportedOperationException. - * */ - public byte[] convertDataToBytes(DirectSlice directSlice) { - int capacity = directSlice.data().capacity(); - byte[] bytes = new byte[capacity]; - - for (int i = 0; i < capacity; i++) { - bytes[i] = directSlice.get(i); - } - - return bytes; - } - -} \ No newline at end of file diff --git a/plugins/src/main/java/org/tron/plugins/utils/DBUtils.java b/plugins/src/main/java/org/tron/plugins/utils/DBUtils.java index 19547e2b5a5..7c5a57507ed 100644 --- a/plugins/src/main/java/org/tron/plugins/utils/DBUtils.java +++ b/plugins/src/main/java/org/tron/plugins/utils/DBUtils.java @@ -16,8 +16,8 @@ import org.rocksdb.Options; import org.rocksdb.RocksDB; import org.rocksdb.RocksDBException; -import org.tron.plugins.comparator.MarketOrderPriceComparatorForLevelDB; -import org.tron.plugins.comparator.MarketOrderPriceComparatorForRockDB; +import org.tron.common.utils.MarketOrderPriceComparatorForLevelDB; +import org.tron.common.utils.MarketOrderPriceComparatorForRocksDB; import org.tron.protos.Protocol; public class DBUtils { @@ -114,7 +114,7 @@ private static Options newDefaultRocksDbOptions(boolean forBulkLoad) { public static RocksDB newRocksDb(Path db) throws RocksDBException { try (Options options = newDefaultRocksDbOptions(false)) { if (MARKET_PAIR_PRICE_TO_ORDER.equalsIgnoreCase(db.getFileName().toString())) { - options.setComparator(new MarketOrderPriceComparatorForRockDB(new ComparatorOptions())); + options.setComparator(new MarketOrderPriceComparatorForRocksDB(new ComparatorOptions())); } return RocksDB.open(options, db.toString()); } @@ -123,7 +123,7 @@ public static RocksDB newRocksDb(Path db) throws RocksDBException { public static RocksDB newRocksDbForBulkLoad(Path db) throws RocksDBException { try (Options options = newDefaultRocksDbOptions(true)) { if (MARKET_PAIR_PRICE_TO_ORDER.equalsIgnoreCase(db.getFileName().toString())) { - options.setComparator(new MarketOrderPriceComparatorForRockDB(new ComparatorOptions())); + options.setComparator(new MarketOrderPriceComparatorForRocksDB(new ComparatorOptions())); } return RocksDB.open(options, db.toString()); } @@ -133,7 +133,7 @@ public static RocksDB newRocksDbForBulkLoad(Path db) throws RocksDBException { public static RocksDB newRocksDbReadOnly(Path db) throws RocksDBException { try (Options options = newDefaultRocksDbOptions(false)) { if (MARKET_PAIR_PRICE_TO_ORDER.equalsIgnoreCase(db.getFileName().toString())) { - options.setComparator(new MarketOrderPriceComparatorForRockDB(new ComparatorOptions())); + options.setComparator(new MarketOrderPriceComparatorForRocksDB(new ComparatorOptions())); } return RocksDB.openReadOnly(options, db.toString()); } diff --git a/plugins/src/test/java/org/tron/plugins/DbConvertTest.java b/plugins/src/test/java/org/tron/plugins/DbConvertTest.java index 150e47c9f65..d4c0547b610 100644 --- a/plugins/src/test/java/org/tron/plugins/DbConvertTest.java +++ b/plugins/src/test/java/org/tron/plugins/DbConvertTest.java @@ -15,13 +15,6 @@ public void testRun() throws IOException { Assert.assertEquals(0, cli.execute(args)); } - @Test - public void testRunWithSafe() throws IOException { - String[] args = new String[] { "db", "convert", INPUT_DIRECTORY, - temporaryFolder.newFolder().toString(),"--safe" }; - Assert.assertEquals(0, cli.execute(args)); - } - @Test public void testHelp() { String[] args = new String[] {"db", "convert", "-h"}; diff --git a/plugins/src/test/java/org/tron/plugins/DbLiteTest.java b/plugins/src/test/java/org/tron/plugins/DbLiteTest.java index 5cb8c26c4bc..ca11bc5ffd1 100644 --- a/plugins/src/test/java/org/tron/plugins/DbLiteTest.java +++ b/plugins/src/test/java/org/tron/plugins/DbLiteTest.java @@ -69,13 +69,15 @@ public void shutdown() throws InterruptedException { context.close(); } - public void init() throws IOException { + public void init(String dbType) throws IOException { dbPath = folder.newFolder().toString(); - Args.setParam(new String[]{"-d", dbPath, "-w", "--p2p-disable", "true"}, + Args.setParam(new String[]{ + "-d", dbPath, "-w", "--p2p-disable", "true", "--storage-db-engine", dbType}, "config-localtest.conf"); // allow account root Args.getInstance().setAllowAccountStateRoot(1); Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcEnable(true); databaseDir = Args.getInstance().getStorage().getDbDirectory(); // init dbBackupConfig to avoid NPE Args.getInstance().dbBackupConfig = DbBackupConfig.getInstance(); @@ -90,7 +92,7 @@ void testTools(String dbType, int checkpointVersion) throws InterruptedException, IOException { logger.info("dbType {}, checkpointVersion {}", dbType, checkpointVersion); dbPath = String.format("%s_%s_%d", dbPath, dbType, System.currentTimeMillis()); - init(); + init(dbType); final String[] argsForSnapshot = new String[]{"-o", "split", "-t", "snapshot", "--fn-data-path", dbPath + File.separator + databaseDir, "--dataset-path", @@ -102,7 +104,6 @@ void testTools(String dbType, int checkpointVersion) final String[] argsForMerge = new String[]{"-o", "merge", "--fn-data-path", dbPath + File.separator + databaseDir, "--dataset-path", dbPath + File.separator + "history"}; - Args.getInstance().getStorage().setDbEngine(dbType); Args.getInstance().getStorage().setCheckpointVersion(checkpointVersion); DbLite.setRecentBlks(3); // start fullNode diff --git a/protocol/build.gradle b/protocol/build.gradle index ce4091afff1..14a57305112 100644 --- a/protocol/build.gradle +++ b/protocol/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.google.protobuf' def protobufVersion = '3.25.5' -def grpcVersion = '1.52.1' +def grpcVersion = '1.60.0' dependencies { api group: 'com.google.protobuf', name: 'protobuf-java', version: protobufVersion @@ -20,7 +20,7 @@ dependencies { api group: 'com.google.api.grpc', name: 'proto-google-common-protos', version: '2.15.0' } -tasks.matching { it instanceof Test }.all { +tasks.matching { it instanceof Test }.configureEach { testLogging.events = ["failed", "passed", "skipped"] } diff --git a/settings.gradle b/settings.gradle index eb304444378..af32bfca702 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,4 +8,5 @@ include 'common' include 'example:actuator-example' include 'crypto' include 'plugins' +include 'platform' diff --git a/start.sh b/start.sh index 89f13cf25a7..cfc78f75a56 100644 --- a/start.sh +++ b/start.sh @@ -355,17 +355,43 @@ startService() { exit fi - nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log \ - -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \ - -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \ - -XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \ - -XX:NewRatio=2 -jar \ - $JAR_NAME $FULL_START_OPT >>start.log 2>&1 & + runService checkPid echo "info: start java-tron with pid $pid on $HOSTNAME" echo "info: if you need to stop the service, execute: sh start.sh --stop" } +runService() { + # check the java version is jdk8 or jdk17 + java_version=$($JAVACMD -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }') + if [[ $java_version =~ '1.8' ]]; then + echo 'info: java version is jdk8' + nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log \ + -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \ + -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \ + -XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \ + -XX:NewRatio=2 -jar \ + $JAR_NAME $FULL_START_OPT >>start.log 2>&1 & + elif [[ $java_version =~ '17' ]]; then + # check the gc log directory. if not exists, create it + if [[ ! -d 'gc' ]]; then + mkdir -p 'gc' + fi + + nohup $JAVACMD -Xms$JVM_MS -Xmx$JVM_MX \ + -XX:+UseZGC \ + -Xlog:gc*:file=gc/gc-%t.log:time,uptime,level,tags:filecount=50,filesize=100M \ + -XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing \ + -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \ + -XX:MaxDirectMemorySize=$MAX_DIRECT_MEMORY -XX:+HeapDumpOnOutOfMemoryError \ + -jar $JAR_NAME $FULL_START_OPT >>start.log 2>&1 & + + else + echo 'warn: java version is not jdk8 or jdk17' + exit + fi +} + rebuildManifest() { if [[ $REBUILD_MANIFEST = false ]]; then echo 'info: disable rebuild manifest!' @@ -377,7 +403,7 @@ rebuildManifest() { return fi - ARCHIVE_JAR='ArchiveManifest.jar' + ARCHIVE_JAR='Toolkit.jar' if [[ -f $ARCHIVE_JAR ]]; then echo 'info: execute rebuild manifest.' $JAVACMD -jar $ARCHIVE_JAR -d $REBUILD_DIR -m $REBUILD_MANIFEST_SIZE -b $REBUILD_BATCH_SIZE