Skip to content

Commit 8be05b0

Browse files
committed
chore(deps): remove joda-time and use JDK time APIs
1. drop the joda-time 2.3 dependency. 2. replace the six new DateTime(millis) log-formatting call sites in DynamicPropertiesStore, DposTask and DposService with a new Time.getIsoTimeString helper backed by java.time; its formatter (yyyy-MM-dd'T'HH:mm:ss.SSSXXX in the system zone) reproduces joda's DateTime.toString() output byte for byte. 3. replace DateTime.now() day arithmetic in four test classes with the java.time equivalent, ZonedDateTime.now().minusDays(n)/plusDays(n) .toInstant().toEpochMilli(), keeping joda's calendar semantics one-to-one, and map plain DateTime.now().getMillis() to System.currentTimeMillis()
1 parent 7482760 commit 8be05b0

11 files changed

Lines changed: 84 additions & 66 deletions

File tree

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ subprojects {
9999
implementation group: 'org.springframework', name: 'spring-context', version: "${springVersion}"
100100
implementation "org.apache.commons:commons-lang3:3.20.0"
101101
implementation "org.apache.commons:commons-collections4:4.6.0"
102-
implementation group: 'joda-time', name: 'joda-time', version: '2.3'
103102
implementation group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: '1.84'
104103

105104
compileOnly 'org.projectlombok:lombok:1.18.34'

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import java.util.stream.IntStream;
1313
import lombok.Getter;
1414
import lombok.extern.slf4j.Slf4j;
15-
import org.joda.time.DateTime;
1615
import org.springframework.beans.factory.annotation.Autowired;
1716
import org.springframework.beans.factory.annotation.Value;
1817
import org.springframework.stereotype.Component;
1918
import org.tron.common.parameter.CommonParameter;
2019
import org.tron.common.utils.ByteArray;
2120
import org.tron.common.utils.Sha256Hash;
21+
import org.tron.common.utils.Time;
2222
import org.tron.core.capsule.BytesCapsule;
2323
import org.tron.core.config.Parameter.ChainConstant;
2424
import org.tron.core.db.TronStoreWithRevoking;
@@ -2261,8 +2261,8 @@ public void updateNextMaintenanceTime(long blockTime) {
22612261
logger.info(
22622262
"Do update nextMaintenanceTime, currentMaintenanceTime: {}, blockTime: {}, "
22632263
+ "nextMaintenanceTime: {}.",
2264-
new DateTime(currentMaintenanceTime), new DateTime(blockTime),
2265-
new DateTime(nextMaintenanceTime)
2264+
Time.getIsoTimeString(currentMaintenanceTime), Time.getIsoTimeString(blockTime),
2265+
Time.getIsoTimeString(nextMaintenanceTime)
22662266
);
22672267
}
22682268

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
package org.tron.common.utils;
22

33
import java.sql.Timestamp;
4+
import java.time.Instant;
5+
import java.time.ZoneId;
6+
import java.time.format.DateTimeFormatter;
47

58
public class Time {
69

10+
// Matches joda-time's DateTime.toString() output, byte for byte: fixed
11+
// 3-digit millis, offset as +08:00, and Z when the system zone is UTC.
12+
private static final DateTimeFormatter ISO_MILLIS_FORMAT =
13+
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
14+
715
public static long getCurrentMillis() {
816
return System.currentTimeMillis();
917
}
1018

1119
public static String getTimeString(long time) {
1220
return new Timestamp(time).toString();
1321
}
22+
23+
public static String getIsoTimeString(long time) {
24+
return Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault()).format(ISO_MILLIS_FORMAT);
25+
}
1426
}

consensus/src/main/java/org/tron/consensus/dpos/DposService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import lombok.Getter;
1515
import lombok.Setter;
1616
import lombok.extern.slf4j.Slf4j;
17-
import org.joda.time.DateTime;
1817
import org.springframework.beans.factory.annotation.Autowired;
1918
import org.springframework.stereotype.Component;
2019
import org.tron.common.args.GenesisBlock;
2120
import org.tron.common.parameter.CommonParameter;
2221
import org.tron.common.utils.ByteArray;
22+
import org.tron.common.utils.Time;
2323
import org.tron.consensus.ConsensusDelegate;
2424
import org.tron.consensus.base.BlockHandle;
2525
import org.tron.consensus.base.ConsensusInterface;
@@ -134,14 +134,14 @@ public boolean validBlock(BlockCapsule blockCapsule) {
134134
if (slot == 0
135135
&& consensusDelegate.getDynamicPropertiesStore().allowConsensusLogicOptimization()) {
136136
logger.warn("ValidBlock failed: slot error, witness: {}, timeStamp: {}",
137-
ByteArray.toHexString(witnessAddress.toByteArray()), new DateTime(timeStamp));
137+
ByteArray.toHexString(witnessAddress.toByteArray()), Time.getIsoTimeString(timeStamp));
138138
return false;
139139
}
140140
final ByteString scheduledWitness = dposSlot.getScheduledWitness(slot);
141141
if (!scheduledWitness.equals(witnessAddress)) {
142142
logger.warn("ValidBlock failed: sWitness: {}, bWitness: {}, bTimeStamp: {}, slot: {}",
143143
ByteArray.toHexString(scheduledWitness.toByteArray()),
144-
ByteArray.toHexString(witnessAddress.toByteArray()), new DateTime(timeStamp), slot);
144+
ByteArray.toHexString(witnessAddress.toByteArray()), Time.getIsoTimeString(timeStamp), slot);
145145
return false;
146146
}
147147

consensus/src/main/java/org/tron/consensus/dpos/DposTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.concurrent.ExecutorService;
77
import lombok.Setter;
88
import lombok.extern.slf4j.Slf4j;
9-
import org.joda.time.DateTime;
109
import org.springframework.beans.factory.annotation.Autowired;
1110
import org.springframework.stereotype.Component;
1211
import org.springframework.util.ObjectUtils;
@@ -15,6 +14,7 @@
1514
import org.tron.common.parameter.CommonParameter;
1615
import org.tron.common.utils.ByteArray;
1716
import org.tron.common.utils.Sha256Hash;
17+
import org.tron.common.utils.Time;
1818
import org.tron.consensus.ConsensusDelegate;
1919
import org.tron.consensus.base.Param.Miner;
2020
import org.tron.consensus.base.State;
@@ -123,7 +123,7 @@ private State produceBlock() {
123123
BlockHeader.raw raw = blockCapsule.getInstance().getBlockHeader().getRawData();
124124
logger.info("Produce block successfully, num: {}, time: {}, witness: {}, ID:{}, parentID:{}",
125125
raw.getNumber(),
126-
new DateTime(raw.getTimestamp()),
126+
Time.getIsoTimeString(raw.getTimestamp()),
127127
ByteArray.toHexString(raw.getWitnessAddress().toByteArray()),
128128
new Sha256Hash(raw.getNumber(), Sha256Hash.of(CommonParameter
129129
.getInstance().isECKeyCryptoEngine(), raw.toByteArray())),

framework/src/test/java/org/tron/common/utils/RandomGeneratorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.stream.Collectors;
1111
import lombok.extern.slf4j.Slf4j;
12-
import org.joda.time.DateTime;
1312
import org.junit.Before;
1413
import org.junit.Ignore;
1514
import org.junit.Test;
@@ -42,7 +41,7 @@ public void shuffle() {
4241
final List<WitnessCapsule> witnessCapsuleListBefore = this.getWitnessList();
4342
logger.info("updateWitnessSchedule,before: " + getWitnessStringList(witnessCapsuleListBefore));
4443
final List<WitnessCapsule> witnessCapsuleListAfter = new RandomGenerator<WitnessCapsule>()
45-
.shuffle(witnessCapsuleListBefore, DateTime.now().getMillis());
44+
.shuffle(witnessCapsuleListBefore, System.currentTimeMillis());
4645
logger.info("updateWitnessSchedule,after: " + getWitnessStringList(witnessCapsuleListAfter));
4746
}
4847

framework/src/test/java/org/tron/core/BandwidthProcessorTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.google.protobuf.Any;
66
import com.google.protobuf.ByteString;
77
import java.nio.charset.StandardCharsets;
8+
import java.time.ZonedDateTime;
89
import lombok.extern.slf4j.Slf4j;
9-
import org.joda.time.DateTime;
1010
import org.junit.Assert;
1111
import org.junit.Before;
1212
import org.junit.Test;
@@ -64,8 +64,8 @@ public class BandwidthProcessorTest extends BaseTest {
6464
TO_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
6565
ASSET_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a3456";
6666
ASSET_ADDRESS_V2 = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a7890";
67-
START_TIME = DateTime.now().minusDays(1).getMillis();
68-
END_TIME = DateTime.now().getMillis();
67+
START_TIME = ZonedDateTime.now().minusDays(1).toInstant().toEpochMilli();
68+
END_TIME = System.currentTimeMillis();
6969
}
7070

7171
/**
@@ -616,7 +616,7 @@ public void sameTokenNameCloseConsumeSuccess() {
616616
AccountType.Normal,
617617
chainBaseManager.getDynamicPropertiesStore().getAssetIssueFee());
618618
ownerCapsule.setBalance(10_000_000L);
619-
long expireTime = DateTime.now().getMillis() + 6 * 86_400_000;
619+
long expireTime = System.currentTimeMillis() + 6 * 86_400_000;
620620
ownerCapsule.setFrozenForBandwidth(2_000_000L, expireTime);
621621
chainBaseManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
622622

@@ -627,7 +627,7 @@ public void sameTokenNameCloseConsumeSuccess() {
627627
AccountType.Normal,
628628
chainBaseManager.getDynamicPropertiesStore().getAssetIssueFee());
629629
toAddressCapsule.setBalance(10_000_000L);
630-
long expireTime2 = DateTime.now().getMillis() + 6 * 86_400_000;
630+
long expireTime2 = System.currentTimeMillis() + 6 * 86_400_000;
631631
toAddressCapsule.setFrozenForBandwidth(2_000_000L, expireTime2);
632632
chainBaseManager.getAccountStore().put(toAddressCapsule.getAddress().toByteArray(),
633633
toAddressCapsule);
@@ -731,7 +731,7 @@ public void sameTokenNameOpenConsumeSuccess() {
731731
AccountType.Normal,
732732
chainBaseManager.getDynamicPropertiesStore().getAssetIssueFee());
733733
ownerCapsule.setBalance(10_000_000L);
734-
long expireTime = DateTime.now().getMillis() + 6 * 86_400_000;
734+
long expireTime = System.currentTimeMillis() + 6 * 86_400_000;
735735
ownerCapsule.setFrozenForBandwidth(2_000_000L, expireTime);
736736
chainBaseManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
737737

@@ -742,7 +742,7 @@ public void sameTokenNameOpenConsumeSuccess() {
742742
AccountType.Normal,
743743
chainBaseManager.getDynamicPropertiesStore().getAssetIssueFee());
744744
toAddressCapsule.setBalance(10_000_000L);
745-
long expireTime2 = DateTime.now().getMillis() + 6 * 86_400_000;
745+
long expireTime2 = System.currentTimeMillis() + 6 * 86_400_000;
746746
toAddressCapsule.setFrozenForBandwidth(2_000_000L, expireTime2);
747747
chainBaseManager.getAccountStore().put(toAddressCapsule.getAddress().toByteArray(),
748748
toAddressCapsule);
@@ -816,7 +816,7 @@ public void sameTokenNameCloseTransferToAccountNotExist() {
816816
AccountType.Normal,
817817
chainBaseManager.getDynamicPropertiesStore().getAssetIssueFee());
818818
ownerCapsule.setBalance(10_000_000L);
819-
long expireTime = DateTime.now().getMillis() + 6 * 86_400_000;
819+
long expireTime = System.currentTimeMillis() + 6 * 86_400_000;
820820
ownerCapsule.setFrozenForBandwidth(2_000_000L, expireTime);
821821
chainBaseManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
822822

@@ -827,7 +827,7 @@ public void sameTokenNameCloseTransferToAccountNotExist() {
827827
AccountType.Normal,
828828
chainBaseManager.getDynamicPropertiesStore().getAssetIssueFee());
829829
toAddressCapsule.setBalance(10_000_000L);
830-
long expireTime2 = DateTime.now().getMillis() + 6 * 86_400_000;
830+
long expireTime2 = System.currentTimeMillis() + 6 * 86_400_000;
831831
toAddressCapsule.setFrozenForBandwidth(2_000_000L, expireTime2);
832832
chainBaseManager.getAccountStore().delete(toAddressCapsule.getAddress().toByteArray());
833833

framework/src/test/java/org/tron/core/WalletTest.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
import com.google.protobuf.Any;
3131
import com.google.protobuf.ByteString;
3232

33+
import java.time.ZonedDateTime;
3334
import java.util.ArrayList;
3435
import java.util.Arrays;
3536
import javax.annotation.Resource;
3637
import lombok.SneakyThrows;
3738
import lombok.extern.slf4j.Slf4j;
38-
import org.joda.time.DateTime;
3939
import org.junit.Assert;
4040
import org.junit.Before;
4141
import org.junit.Ignore;
@@ -113,21 +113,29 @@ public class WalletTest extends BaseTest {
113113
public static final long BLOCK_NUM_THREE = 3;
114114
public static final long BLOCK_NUM_FOUR = 4;
115115
public static final long BLOCK_NUM_FIVE = 5;
116-
public static final long BLOCK_TIMESTAMP_ONE = DateTime.now().minusDays(4).getMillis();
117-
public static final long BLOCK_TIMESTAMP_TWO = DateTime.now().minusDays(3).getMillis();
118-
public static final long BLOCK_TIMESTAMP_THREE = DateTime.now().minusDays(2).getMillis();
119-
public static final long BLOCK_TIMESTAMP_FOUR = DateTime.now().minusDays(1).getMillis();
120-
public static final long BLOCK_TIMESTAMP_FIVE = DateTime.now().getMillis();
116+
public static final long BLOCK_TIMESTAMP_ONE =
117+
ZonedDateTime.now().minusDays(4).toInstant().toEpochMilli();
118+
public static final long BLOCK_TIMESTAMP_TWO =
119+
ZonedDateTime.now().minusDays(3).toInstant().toEpochMilli();
120+
public static final long BLOCK_TIMESTAMP_THREE =
121+
ZonedDateTime.now().minusDays(2).toInstant().toEpochMilli();
122+
public static final long BLOCK_TIMESTAMP_FOUR =
123+
ZonedDateTime.now().minusDays(1).toInstant().toEpochMilli();
124+
public static final long BLOCK_TIMESTAMP_FIVE = System.currentTimeMillis();
121125
public static final long BLOCK_WITNESS_ONE = 12;
122126
public static final long BLOCK_WITNESS_TWO = 13;
123127
public static final long BLOCK_WITNESS_THREE = 14;
124128
public static final long BLOCK_WITNESS_FOUR = 15;
125129
public static final long BLOCK_WITNESS_FIVE = 16;
126-
public static final long TRANSACTION_TIMESTAMP_ONE = DateTime.now().minusDays(4).getMillis();
127-
public static final long TRANSACTION_TIMESTAMP_TWO = DateTime.now().minusDays(3).getMillis();
128-
public static final long TRANSACTION_TIMESTAMP_THREE = DateTime.now().minusDays(2).getMillis();
129-
public static final long TRANSACTION_TIMESTAMP_FOUR = DateTime.now().minusDays(1).getMillis();
130-
public static final long TRANSACTION_TIMESTAMP_FIVE = DateTime.now().getMillis();
130+
public static final long TRANSACTION_TIMESTAMP_ONE =
131+
ZonedDateTime.now().minusDays(4).toInstant().toEpochMilli();
132+
public static final long TRANSACTION_TIMESTAMP_TWO =
133+
ZonedDateTime.now().minusDays(3).toInstant().toEpochMilli();
134+
public static final long TRANSACTION_TIMESTAMP_THREE =
135+
ZonedDateTime.now().minusDays(2).toInstant().toEpochMilli();
136+
public static final long TRANSACTION_TIMESTAMP_FOUR =
137+
ZonedDateTime.now().minusDays(1).toInstant().toEpochMilli();
138+
public static final long TRANSACTION_TIMESTAMP_FIVE = System.currentTimeMillis();
131139
@Resource
132140
private Wallet wallet;
133141
private static Block block1;

0 commit comments

Comments
 (0)