fix(reconciliation): 收紧确认页与并发处置

为什么:净室评审发现两处可复发风险——扫描在实例返回小于请求页时可能提前结束;并发重复处置可能各写一条审计。
做什么:扫描以 total 为准继续翻页(total 未知才按短页结束);处置前对 finding 行 FOR UPDATE 并只接受 open;R4 sha256 统一 trim。
验证:go test ./internal/reconciliation ./internal/platform/postgres;make verify 全绿。
This commit is contained in:
Zhero & Rin
2026-12-01 12:33:46 +08:00
committed by 姚章浩
parent cf833a0a77
commit dafb1898c1
3 changed files with 49 additions and 22 deletions
+14 -18
View File
@@ -11,28 +11,24 @@ import (
)
func TestMatrixCoversEveryLedgerAndUpstreamState(t *testing.T) {
rows := []string{"planned", "pending", "processing", "finalizing", "completed", "failed", "stalled", "cancelled"}
columns := []string{"pending", "processing", "finalizing", "completed", "failed", "cancelled", "deleting"}
for _, row := range rows {
for _, column := range columns {
verdict := classify(row, column)
if verdict == verdictSkip && row != "" {
t.Fatalf("classify(%s,%s) unexpectedly skipped", row, column)
}
if row == "completed" && column == "completed" && verdict != verdictConsistent {
t.Fatalf("completed/completed = %v", verdict)
}
if row == "stalled" && column == "completed" && verdict != verdictMismatch {
t.Fatalf("stalled/completed = %v", verdict)
}
if column == "deleting" && verdict != verdictDeleting {
t.Fatalf("%s/deleting = %v", row, verdict)
want := map[string][]verdict{
"planned": {verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictDeleting},
"pending": {verdictConsistent, verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictDeleting},
"processing": {verdictMismatch, verdictConsistent, verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictDeleting},
"finalizing": {verdictMismatch, verdictMismatch, verdictConsistent, verdictMismatch, verdictMismatch, verdictMismatch, verdictDeleting},
"completed": {verdictMismatch, verdictMismatch, verdictMismatch, verdictConsistent, verdictMismatch, verdictMismatch, verdictDeleting},
"failed": {verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictConsistent, verdictMismatch, verdictDeleting},
"stalled": {verdictStalled, verdictStalled, verdictStalled, verdictMismatch, verdictStalled, verdictStalled, verdictDeleting},
"cancelled": {verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictMismatch, verdictConsistent, verdictDeleting},
}
for row, expected := range want {
for index, column := range columns {
if got := classify(row, column); got != expected[index] {
t.Fatalf("classify(%s,%s) = %v, want %v", row, column, got, expected[index])
}
}
}
if classify("completed", "pending") != verdictMismatch || classify("cancelled", "cancelled") != verdictConsistent {
t.Fatal("explicit completed/cancelled rows are wrong")
}
if AllowedWriteback("completed", "pending") || AllowedWriteback("stalled", "completed") ||
!AllowedWriteback("failed", "pending") || AllowedWriteback("planned", "pending") ||
AllowedWriteback("pending", "cancelled") || AllowedWriteback("pending", "deleting") {