lib/protocol: Use constants instead of init time hashing (fixes #5624) (#5625)

This constructs the map of hashes of zero blocks from constants instead
of calculating it at startup time. A new test verifies that the map is
correct.
This commit is contained in:
Jakob Borg
2019-03-27 20:20:30 +01:00
committed by GitHub
parent 8d1eff7e41
commit bf3834e367
2 changed files with 24 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ package protocol
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
@@ -610,3 +611,13 @@ func TestIsEquivalent(t *testing.T) {
}
}
}
func TestSha256OfEmptyBlock(t *testing.T) {
// every block size should have a correct entry in sha256OfEmptyBlock
for blockSize := MinBlockSize; blockSize <= MaxBlockSize; blockSize *= 2 {
expected := sha256.Sum256(make([]byte, blockSize))
if sha256OfEmptyBlock[blockSize] != expected {
t.Error("missing or wrong hash for block of size", blockSize)
}
}
}