From 0340e71c1b4624d1e45fa99600e4f3e6fe5762a4 Mon Sep 17 00:00:00 2001 From: Philemon Ukane Date: Sat, 28 Feb 2026 22:50:20 +0100 Subject: [PATCH] fix unsigned underflow in per-block net calculation The per-block net value was previously computed using uint64, which caused underflow when sent > received within a block. This resulted in incorrect large positive values due to unsigned wraparound. Net flow per-block can legitimately be negative, the calculation now uses int64 which correctly represents block level balance changes and prevents overflow. Signed-off-by: Philemon Ukane --- db/dcrpg/queries.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dcrpg/queries.go b/db/dcrpg/queries.go index f85afbd0b..4823239a1 100644 --- a/db/dcrpg/queries.go +++ b/db/dcrpg/queries.go @@ -4027,7 +4027,7 @@ func parseRowsSentReceived(rows *sql.Rows) (*dbtypes.ChartsData, error) { // given block. If the difference is positive then the value is unspent amount // otherwise if the value is zero then all amount is spent and if the net amount // is negative then for the given block more amount was sent than received. - items.Net = append(items.Net, toCoin(received-sent)) + items.Net = append(items.Net, toCoin(int64(received)-int64(sent))) } if err := rows.Err(); err != nil { return nil, err