mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
[NOD-35] Refactor fmt.Sprintf to always have the template argument as string literal
* [NOD-35] Refactor fmt.Sprintf to always have the template argument as string literal * [NOD-35] Remove redundant fmt.Sprintf's
This commit is contained in:
parent
2db55f219f
commit
c9ef176f4c
@ -621,7 +621,6 @@ func ExtractCoinbaseHeight(coinbaseTx *util.Tx) (int32, error) {
|
|||||||
str := "the coinbase signature script" +
|
str := "the coinbase signature script" +
|
||||||
"must start with the " +
|
"must start with the " +
|
||||||
"length of the serialized block height"
|
"length of the serialized block height"
|
||||||
str = fmt.Sprintf(str)
|
|
||||||
return 0, ruleError(ErrMissingCoinbaseHeight, str)
|
return 0, ruleError(ErrMissingCoinbaseHeight, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +641,6 @@ func ExtractCoinbaseHeight(coinbaseTx *util.Tx) (int32, error) {
|
|||||||
str := "the coinbase signature script " +
|
str := "the coinbase signature script " +
|
||||||
"must start with the " +
|
"must start with the " +
|
||||||
"serialized block height"
|
"serialized block height"
|
||||||
str = fmt.Sprintf(str, serializedLen)
|
|
||||||
return 0, ruleError(ErrMissingCoinbaseHeight, str)
|
return 0, ruleError(ErrMissingCoinbaseHeight, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,8 +725,7 @@ func validateMedianTime(header *wire.BlockHeader, bluestParent *blockNode) error
|
|||||||
// median time of the last several blocks (medianTimeBlocks).
|
// median time of the last several blocks (medianTimeBlocks).
|
||||||
medianTime := bluestParent.PastMedianTime()
|
medianTime := bluestParent.PastMedianTime()
|
||||||
if header.Timestamp.Before(medianTime) {
|
if header.Timestamp.Before(medianTime) {
|
||||||
str := "block timestamp of %s is not after expected %s"
|
str := fmt.Sprintf("block timestamp of %s is not after expected %s", header.Timestamp, medianTime)
|
||||||
str = fmt.Sprintf(str, header.Timestamp, medianTime)
|
|
||||||
return ruleError(ErrTimeTooOld, str)
|
return ruleError(ErrTimeTooOld, str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -747,8 +744,7 @@ func (dag *BlockDAG) validateDifficulty(header *wire.BlockHeader, bluestParent *
|
|||||||
}
|
}
|
||||||
blockDifficulty := header.Bits
|
blockDifficulty := header.Bits
|
||||||
if blockDifficulty != expectedDifficulty {
|
if blockDifficulty != expectedDifficulty {
|
||||||
str := "block difficulty of %d is not the expected value of %d"
|
str := fmt.Sprintf("block difficulty of %d is not the expected value of %d", blockDifficulty, expectedDifficulty)
|
||||||
str = fmt.Sprintf(str, blockDifficulty, expectedDifficulty)
|
|
||||||
return ruleError(ErrUnexpectedDifficulty, str)
|
return ruleError(ErrUnexpectedDifficulty, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,17 +23,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// The Bitcoin protocol encodes block height as int32, so max number of
|
|
||||||
// blocks is 2^31. Max block size per the protocol is 32MiB per block.
|
|
||||||
// So the theoretical max at the time this comment was written is 64PiB
|
|
||||||
// (pebibytes). With files @ 512MiB each, this would require a maximum
|
|
||||||
// of 134,217,728 files. Thus, choose 9 digits of precision for the
|
|
||||||
// filenames. An additional benefit is 9 digits provides 10^9 files @
|
|
||||||
// 512MiB each for a total of ~476.84PiB (roughly 7.4 times the current
|
|
||||||
// theoretical max), so there is room for the max block size to grow in
|
|
||||||
// the future.
|
|
||||||
blockFilenameTemplate = "%09d.fdb"
|
|
||||||
|
|
||||||
// maxOpenFiles is the max number of open files to maintain in the
|
// maxOpenFiles is the max number of open files to maintain in the
|
||||||
// open blocks cache. Note that this does not include the current
|
// open blocks cache. Note that this does not include the current
|
||||||
// write file, so there will typically be one more than this value open.
|
// write file, so there will typically be one more than this value open.
|
||||||
@ -225,7 +214,17 @@ func serializeBlockLoc(loc blockLocation) []byte {
|
|||||||
|
|
||||||
// blockFilePath return the file path for the provided block file number.
|
// blockFilePath return the file path for the provided block file number.
|
||||||
func blockFilePath(dbPath string, fileNum uint32) string {
|
func blockFilePath(dbPath string, fileNum uint32) string {
|
||||||
fileName := fmt.Sprintf(blockFilenameTemplate, fileNum)
|
// The Bitcoin protocol encodes block height as int32, so max number of
|
||||||
|
// blocks is 2^31. Max block size per the protocol is 32MiB per block.
|
||||||
|
// So the theoretical max at the time this comment was written is 64PiB
|
||||||
|
// (pebibytes). With files @ 512MiB each, this would require a maximum
|
||||||
|
// of 134,217,728 files. Thus, choose 9 digits of precision for the
|
||||||
|
// filenames. An additional benefit is 9 digits provides 10^9 files @
|
||||||
|
// 512MiB each for a total of ~476.84PiB (roughly 7.4 times the current
|
||||||
|
// theoretical max), so there is room for the max block size to grow in
|
||||||
|
// the future.
|
||||||
|
|
||||||
|
fileName := fmt.Sprintf("%09d.fdb", fileNum)
|
||||||
return filepath.Join(dbPath, fileName)
|
return filepath.Join(dbPath, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,6 @@ func TestRandomUint64(t *testing.T) {
|
|||||||
tries := 1 << 8 // 2^8
|
tries := 1 << 8 // 2^8
|
||||||
watermark := uint64(1 << 56) // 2^56
|
watermark := uint64(1 << 56) // 2^56
|
||||||
maxHits := 5
|
maxHits := 5
|
||||||
badRNG := "The random number generator on this system is clearly " +
|
|
||||||
"terrible since we got %d values less than %d in %d runs " +
|
|
||||||
"when only %d was expected"
|
|
||||||
|
|
||||||
numHits := 0
|
numHits := 0
|
||||||
for i := 0; i < tries; i++ {
|
for i := 0; i < tries; i++ {
|
||||||
@ -49,7 +46,9 @@ func TestRandomUint64(t *testing.T) {
|
|||||||
numHits++
|
numHits++
|
||||||
}
|
}
|
||||||
if numHits > maxHits {
|
if numHits > maxHits {
|
||||||
str := fmt.Sprintf(badRNG, numHits, watermark, tries, maxHits)
|
str := fmt.Sprintf("The random number generator on this system is clearly "+
|
||||||
|
"terrible since we got %d values less than %d in %d runs "+
|
||||||
|
"when only %d was expected", numHits, watermark, tries, maxHits)
|
||||||
t.Errorf("Random Uint64 iteration %d failed - %v %v", i,
|
t.Errorf("Random Uint64 iteration %d failed - %v %v", i,
|
||||||
str, numHits)
|
str, numHits)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user