From 37adaeb99df432e70f237fa2b8345edbf937c2ec Mon Sep 17 00:00:00 2001 From: Wondertan Date: Thu, 6 Oct 2022 23:34:58 +0200 Subject: [PATCH] fix(pkg/da): ensure DAH.hash is always calculated during validation This is useful for headers downloaded from the network. Each such header goes through validation during which the hash should be calculated. Otherwise, the hash is calcualated at much later point, which is prone to races. In celestia-node we observed such races when the DAH.Hahs is read from multiple routines, where both end up calculating the hash and setting the it to the cache value making the race detector complain. Such precompute fixes this. --- pkg/da/data_availability_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/da/data_availability_header.go b/pkg/da/data_availability_header.go index 7e9f966bd9..e120f0fcd9 100644 --- a/pkg/da/data_availability_header.go +++ b/pkg/da/data_availability_header.go @@ -150,7 +150,7 @@ func (dah *DataAvailabilityHeader) ValidateBasic() error { len(dah.ColumnRoots), ) } - if err := validateHash(dah.hash); err != nil { + if err := validateHash(dah.Hash()); err != nil { return fmt.Errorf("wrong hash: %v", err) }