Skip to content

Commit 27a2002

Browse files
authored
Merge pull request tronprotocol#1534 from tronprotocol/eraseBlockWhenTimeOut
Erase block when time out
2 parents fd70b27 + c36299f commit 27a2002

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

‎src/main/java/org/tron/core/db/Manager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public void consumeBandwidth(TransactionCapsule trx, TransactionTrace trace)
583583
/**
584584
* when switch fork need erase blocks on fork branch.
585585
*/
586-
public void eraseBlock() {
586+
public synchronized void eraseBlock() {
587587
session.reset();
588588
try {
589589
BlockCapsule oldHeadBlock = getBlockById(

‎src/main/java/org/tron/core/db/PendingManager.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public void close() {
4040

4141
for (TransactionCapsule tx : dbManager.getPoppedTransactions()) {
4242
try {
43+
if (tx.getTrxTrace() != null &&
44+
tx.getTrxTrace().getTimeResultType().equals(TimeResultType.NORMAL)) {
4345
dbManager.getRepushTransactions().put(tx);
46+
}
4447
} catch (InterruptedException e) {
4548
logger.error(e.getMessage());
4649
Thread.currentThread().interrupt();

‎src/main/java/org/tron/core/services/WitnessService.java‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,26 @@ private BlockProductionCondition tryProduceBlock() throws InterruptedException {
224224
controller.getManager().lastHeadBlockIsMaintenance();
225225

226226
controller.setGeneratingBlock(true);
227-
BlockCapsule block = generateBlock(scheduledTime, scheduledWitness,
228-
controller.lastHeadBlockIsMaintenance());
229-
230-
if (block == null) {
231-
logger.warn("exception when generate block");
232-
return BlockProductionCondition.EXCEPTION_PRODUCING_BLOCK;
233-
}
227+
BlockCapsule block;
228+
synchronized (tronApp.getDbManager()) {
229+
block = generateBlock(scheduledTime, scheduledWitness,
230+
controller.lastHeadBlockIsMaintenance());
231+
232+
if (block == null) {
233+
logger.warn("exception when generate block");
234+
return BlockProductionCondition.EXCEPTION_PRODUCING_BLOCK;
235+
}
234236

235-
int blockProducedTimeOut = Args.getInstance().getBlockProducedTimeOut();
237+
int blockProducedTimeOut = Args.getInstance().getBlockProducedTimeOut();
236238

237-
if (DateTime.now().getMillis() - now
238-
> ChainConstant.BLOCK_PRODUCED_INTERVAL * blockProducedTimeOut / 100) {
239-
logger.warn("Task timeout ( > {}ms),startTime:{},endTime:{}",
240-
ChainConstant.BLOCK_PRODUCED_INTERVAL * blockProducedTimeOut / 100,
241-
new DateTime(now), DateTime.now());
242-
return BlockProductionCondition.TIME_OUT;
239+
if (DateTime.now().getMillis() - now
240+
> ChainConstant.BLOCK_PRODUCED_INTERVAL * blockProducedTimeOut / 100) {
241+
logger.warn("Task timeout ( > {}ms),startTime:{},endTime:{}",
242+
ChainConstant.BLOCK_PRODUCED_INTERVAL * blockProducedTimeOut / 100,
243+
new DateTime(now), DateTime.now());
244+
tronApp.getDbManager().eraseBlock();
245+
return BlockProductionCondition.TIME_OUT;
246+
}
243247
}
244248

245249
logger.info(

0 commit comments

Comments
 (0)