Fix header sync and recovery handling

This commit is contained in:
Vexta Project 2026-08-15 14:47:35 +00:00
commit e0e2a65d1c
4 changed files with 43 additions and 13 deletions

View file

@ -192,8 +192,13 @@ object HeaderSync {
val buffer = ByteBuffer.wrap(payload).order(ByteOrder.LITTLE_ENDIAN)
val count = readCompactSize(buffer)
if (count > 2000) {
throw IllegalStateException("too many headers: $count")
val maximumPossibleHeaders =
buffer.remaining() / 81
if (count < 0 || count > maximumPossibleHeaders) {
throw IllegalStateException(
"invalid headers count: $count"
)
}
repeat(count) {

View file

@ -148,13 +148,23 @@ class MainActivity : Activity() {
runOnUiThread {
if (intent.getBooleanExtra("sync_only", false)) {
setResult(
RESULT_OK,
android.content.Intent().putExtra(
"verified_height",
chain.last().height
if (chain.last().height > 0) {
setResult(
RESULT_OK,
android.content.Intent().putExtra(
"verified_height",
chain.last().height
)
)
)
} else {
setResult(
RESULT_CANCELED,
android.content.Intent().putExtra(
"sync_error",
results.joinToString("\n\n")
)
)
}
finish()
} else {
status.text =
@ -317,8 +327,13 @@ class MainActivity : Activity() {
val buffer = ByteBuffer.wrap(payload).order(ByteOrder.LITTLE_ENDIAN)
val count = readCompactSize(buffer)
if (count > 2000) {
throw IllegalStateException("too many headers: $count")
val maximumPossibleHeaders =
buffer.remaining() / 81
if (count < 0 || count > maximumPossibleHeaders) {
throw IllegalStateException(
"invalid headers count: $count"
)
}
repeat(count) {

View file

@ -871,8 +871,18 @@ class WalletActivity : FragmentActivity() {
runBlockchainScan()
} else {
blockchainScanRunning = false
val syncError = data?.getStringExtra(
"sync_error"
)?.trim()
blockchainScanStatus?.text =
"Block-header synchronization failed."
if (syncError.isNullOrBlank()) {
"Block-header synchronization failed."
} else {
"Block-header synchronization failed:\n" +
syncError
}
}
return