Skip to content

Commit e106528

Browse files
Merge branch 'improve-sync-temporary-blocks' into 'master'
block synchronization is improved See merge request open-platform/chain!376
2 parents 2737524 + 3851de5 commit e106528

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/kotlin/io/openfuture/chain/core/sync/ChainSynchronizer.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.springframework.context.ApplicationListener
2828
import org.springframework.context.event.EventListener
2929
import org.springframework.stereotype.Component
3030
import java.util.concurrent.ScheduledFuture
31+
import javax.annotation.PostConstruct
3132

3233
@Component
3334
class ChainSynchronizer(
@@ -52,6 +53,11 @@ class ChainSynchronizer(
5253
private var future: ScheduledFuture<*>? = null
5354

5455

56+
@PostConstruct
57+
fun forceSynchronizationCheck() {
58+
checkLastBlock()
59+
}
60+
5561
override fun onApplicationEvent(event: DataSourceSchemaCreatedEvent) {
5662
prepareDB(nodeConfigurator.getConfig().mode)
5763
}
@@ -63,7 +69,7 @@ class ChainSynchronizer(
6369
}
6470

6571
fun prepareDB(syncMode: SyncMode) {
66-
status = SyncStatus.PROCESSING
72+
status = PROCESSING
6773
dbChecker.prepareDB(syncMode)
6874
status = SYNCHRONIZED
6975
}

src/main/kotlin/io/openfuture/chain/core/sync/SyncSession.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ class SyncSession(
6666
}
6767

6868
val temporaryBlocks = createTemporaryBlocks(epochBlocks)
69+
val lastTemporaryBlock = temporaryBlocks.last()
70+
71+
val lastSavedTemporaryBlock = temporaryBlockService.getByHeightIn(listOf(lastTemporaryBlock.height))
72+
if (null == lastSavedTemporaryBlock.firstOrNull { it.block == lastTemporaryBlock.block }) {
73+
temporaryBlockService.save(temporaryBlocks)
74+
}
6975

70-
temporaryBlockService.save(temporaryBlocks)
7176
completed = null != epochBlocks.firstOrNull { it.hash == currentGenesisBlock.hash }
7277
epochAdded++
7378
log.info("#$epochAdded epochs FROM ${epochQuantity + 1} is processed")
@@ -101,7 +106,14 @@ class SyncSession(
101106
}
102107

103108
for (index in 1 until chain.size) {
104-
if (!mainBlockValidator.verify(chain[index], chain[index - 1], chain[index] as MainBlock, false, pipeline)) {
109+
if (!mainBlockValidator.verify(
110+
chain[index],
111+
chain[index - 1],
112+
chain[index] as MainBlock,
113+
false,
114+
pipeline
115+
)
116+
) {
105117
return false
106118
}
107119
}

0 commit comments

Comments
 (0)