Skip to content

Commit 7d04376

Browse files
fix(chain-db): use chain tip for tx confirmations
1 parent 4df9b4e commit 7d04376

4 files changed

Lines changed: 49 additions & 7 deletions

File tree

newm-chain-db/src/main/kotlin/io/newm/chain/database/repository/LedgerRepositoryImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,9 +1576,9 @@ class LedgerRepositoryImpl : LedgerRepository {
15761576

15771577
override fun queryTransactionConfirmationCounts(txIds: List<String>): Map<String, Long> =
15781578
transaction {
1579-
val tipBlockExpression = LedgerUtxosTable.blockCreated.max()
1579+
val tipBlockExpression = ChainTable.blockNumber.max()
15801580
val tipBlock: Long =
1581-
LedgerUtxosTable.select(tipBlockExpression).firstOrNull()?.let {
1581+
ChainTable.select(tipBlockExpression).firstOrNull()?.let {
15821582
it[tipBlockExpression]
15831583
} ?: 0L
15841584

@@ -1590,7 +1590,7 @@ class LedgerRepositoryImpl : LedgerRepository {
15901590
.associate { row ->
15911591
val txId = row[LedgerUtxosTable.txId]
15921592
val blockCreated = row[LedgerUtxosTable.blockCreated]
1593-
txId to max(tipBlock - blockCreated, 0L)
1593+
txId to max(tipBlock - blockCreated + 1L, 0L)
15941594
}
15951595

15961596
txIds.associateWith { txId -> (ledgerMap[txId] ?: 0L) }

newm-chain-db/src/test/kotlin/io/newm/chain/database/repository/QueryTransactionInfoRepositoryTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,40 @@ class QueryTransactionInfoRepositoryTest {
214214
}
215215
}
216216

217+
@Test
218+
fun `queryTransactionConfirmationCounts uses chain tip and is inclusive`() {
219+
(100L..106L).forEach { blockNumber ->
220+
insertChainBlock(blockNumber = blockNumber, slotNumber = 1000L + blockNumber)
221+
}
222+
insertLedgerUtxo(
223+
address = "addr_test_dest1",
224+
txId = "target-tx",
225+
txIx = 0,
226+
lovelace = "2500",
227+
blockCreated = 100L,
228+
)
229+
230+
val result = repository.queryTransactionConfirmationCounts(listOf("target-tx", "missing-tx"))
231+
232+
assertThat(result["target-tx"]).isEqualTo(7L)
233+
assertThat(result["missing-tx"]).isEqualTo(0L)
234+
}
235+
236+
@Test
237+
fun `queryTransactionConfirmationCounts returns zero when chain tip is missing`() {
238+
insertLedgerUtxo(
239+
address = "addr_test_dest1",
240+
txId = "target-tx",
241+
txIx = 0,
242+
lovelace = "2500",
243+
blockCreated = 100L,
244+
)
245+
246+
val result = repository.queryTransactionConfirmationCounts(listOf("target-tx"))
247+
248+
assertThat(result["target-tx"]).isEqualTo(0L)
249+
}
250+
217251
private fun insertChainBlock(
218252
blockNumber: Long,
219253
slotNumber: Long,

newm-chain/build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ tasks.withType<ShadowJar> {
114114
}
115115
}
116116

117-
tasks.withType<Jar> {
117+
tasks.withType<Jar>().configureEach {
118118
manifest {
119119
attributes(
120-
"Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()),
121120
"Main-Class" to "io.newm.chain.ApplicationKt"
122121
)
123122
}
123+
doFirst {
124+
manifest.attributes(
125+
"Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date())
126+
)
127+
}
124128
}
125129

126130
// Ensure start scripts tasks depend on shadowJar since we use it as the main jar

newm-server/build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ dependencies {
146146
"integTestImplementation"(Dependencies.Typesafe.CONFIG)
147147
}
148148

149-
tasks.withType<Jar> {
149+
tasks.withType<Jar>().configureEach {
150150
manifest {
151151
attributes(
152-
"Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()),
153152
"Main-Class" to "io.newm.server.ApplicationKt"
154153
)
155154
}
155+
doFirst {
156+
manifest.attributes(
157+
"Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date())
158+
)
159+
}
156160
}
157161

158162
tasks.withType<ShadowJar> {

0 commit comments

Comments
 (0)