main: verify network pow limits#1302
Conversation
5c217fb to
40a5fe8
Compare
davecgh
left a comment
There was a problem hiding this comment.
The extra tests are welcome, but please put them in blockchain, not chaincfg. This would introduce a dependency from chaincfg on blockchain, which as previously discussed, we do not want.
networkparams_test.go
Outdated
There was a problem hiding this comment.
It's 2018 and this is new code for Decred, so there shouldn't be any copyright attributed to btcsuite.
networkparams_test.go
Outdated
There was a problem hiding this comment.
Should have a space after the // and end with a period to be consistent with the rest of the code.
networkparams_test.go
Outdated
networkparams_test.go
Outdated
networkparams_test.go
Outdated
There was a problem hiding this comment.
Please define functions before you call them. People read English left to right, top to bottom and thus that transfers to reading code as well. It's incredibly annoying to have to bounce around a file when reading code because the functions are defined after they're called.
networkparams_test.go
Outdated
networkparams_test.go
Outdated
There was a problem hiding this comment.
80 col limit as per rest of the code.
networkparams_test.go
Outdated
There was a problem hiding this comment.
80 col limit as per rest of the code.
networkparams_test.go
Outdated
There was a problem hiding this comment.
Tests should generally be silent. If you really want to print something out, it would need to be via t.Log/t.Logf.
networkparams_test.go
Outdated
There was a problem hiding this comment.
Lacks space after // and does not end with a period. Several other instances of this as well.
|
Also, when you update the PR, you'll need to amend the commit to make it follow the code contribution guildes for commit messages as this one doesn't. The PR title is close (wrong subsystem), but it's the commit itself that is more important since that is what forms history. |
|
This new file
|
86509b4 to
e8ca9c0
Compare
|
Oh, I thought I saw it in chaincfg. It's fine in the root of the project. |
|
|
|
Yeah, It would look like: t.Fatalf("Genesis block fails the consensus: genesis.Header.Bits=%v "+
"should respect network PoW limit: %v", fmt.Sprintf("%x", bits),
fmt.Sprintf("%064x", powLimitBigInt))EDIT: That said, t.Fatalf("Genesis block fails the consensus: genesis.Header.Bits=%x "+
"should respect network PoW limit: %064x", bits, powLimitBigInt) |
e8ca9c0 to
c0d3409
Compare
|
The |
networkparams_test.go
Outdated
There was a problem hiding this comment.
This code didn't exist in 2015. It's brand new. It should only be 2018.
networkparams_test.go
Outdated
There was a problem hiding this comment.
No need to call fmt.Sprintf again since t.Fatalf already supports formatting.
e.g.
t.Fatalf("PowLimit values mismatch: params.PowLimit=%064x is "+
"inconsistent with params.PowLimitBits=%x", powLimitBigInt,
powLimitCompact)
networkparams_test.go
Outdated
There was a problem hiding this comment.
Same thing here:
t.Fatalf("Genesis block fails the consensus: genesis.Header.Bits=%x "+
"should respect network PoW limit: %064x", bits, powLimitBigInt)|
The following code: Prints only the first line: This code: Prints detailed info for debug: The idea is that developer can use this information for debug when he fails the test on his laptop. I see Still I keep in inside the fail condition, so it is not printed when not necessary. |
9bf2093 to
1a2ba11
Compare
|
Ok I removed |
networkparams_test.go
Outdated
networkparams_test.go
Outdated
networkparams_test.go
Outdated
There was a problem hiding this comment.
Please don't postfix comments. It's inconsistent with 99.9% of the codebase.
networkparams_test.go
Outdated
There was a problem hiding this comment.
This is not really true, since the genesis block is valid by definition. That means it doesn't actually have to respect the difficulty, and in fact, if you notice, the genesis block is not solved.
Add tests to ensure: - network PowLimit and PowLimitBits actually match - genesis block respects network PoW limit
1a2ba11 to
42a3cfe
Compare
|
I updated the comments: |
|
@davecgh Thank you for help. |
1. Add test to check
PowLimitandPowLimitBitsparameters of the networkNetwork PoW limit has two different representations of the same difficulty value. See example at the
chaincfg/mainnetparams.go:This test ensures they properly match.
2. Add test to check genesis block respects consensus rules
Genesis block difficulty should be within the network PoW limit. See
chaincfg/genesis.go: