Conversation
|
|
stopHas is fine. This just makes the check more forgiving. |
| assumeUtreexoHash := sm.chain.AssumeUtreexoHash() | ||
| if !bestHash.IsEqual(&assumeUtreexoHash) { | ||
| headerHash, err := sm.chain.HeaderHashByHeight(assumeHeight) | ||
| if err != nil || !headerHash.IsEqual(&assumeUtreexoHash) { |
There was a problem hiding this comment.
Instead of handling this err here and making editing hashStr, can we just fail if we're unable to fetch the hash for the height?
There was a problem hiding this comment.
Done. split into two separate failure cases.
|
Good catch! I do wanna add a unit test so that we never have the same bug again. If you'd like to work on that that'd be cool. Otherwise I'll just do it in a follow up! Ah also, per Go standards, the git commit should be: |
Sounds gooood. I'm planning to edit commit msg and add three cases:
Does that cover what you had in mind, or is there specific scenario you'd want to test? happy to add more if need. |
Honestly I'd need to see the code heh. Ping me when you're ready! |
384e7d6 to
b2c34a1
Compare
|
Done. Split the check into a |
b2c34a1 to
c4eff4b
Compare
| } | ||
| } | ||
|
|
||
| func (sm *SyncManager) checkUtreexoHash() error { |
There was a problem hiding this comment.
Should say checkAssumeUtreexoHash(). Also we should add a comment on what the function is doing.
| "mempool should have removed the double-spending tx on block connect") | ||
| } | ||
|
|
||
| func TestCheckUtreexoHash(t *testing.T) { |
There was a problem hiding this comment.
The test should be table-driven.
| "software as genuine and there may be attempts to steal funds. The user "+ | ||
| "should delete the datadir", sm.chain.AssumeUtreexoHash().String(), | ||
| bestHash.String(), bestHeight) | ||
| if err := sm.checkUtreexoHash(); err != nil { |
There was a problem hiding this comment.
We're not logging the error here so or in the checkUtreexoHash() so the user wouldn't know why the binary exited.
| headerHash, err := sm.chain.HeaderHashByHeight(assumeHeight) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("Failed to get header hash at assume utreexo height %d: %v", assumeHeight, err) |
There was a problem hiding this comment.
I don't love the messaging here. If the HeaderHashByHeight() couldn't fetch the hash at the assumeUtreexoHeight, it means something is really wrong here.
This information would be useful for the end user
c4eff4b to
30b2990
Compare
|
All addressed. function renamed + documented, test is table-driven, logging moved to caller. PR updated. Let me know if there's anything else. |
| "software as genuine and there may be attempts to steal funds. The user "+ | ||
| "should delete the datadir", sm.chain.AssumeUtreexoHash().String(), | ||
| bestHash.String(), bestHeight) | ||
| if err := sm.checkAssumeUtreexoHash(); err != nil { |
There was a problem hiding this comment.
We left out the "why" here. Yes the user shouldn't trust the software but why? It's because the hash was hardcoded but the hardcoded hash didn't match the downloaded best PoW chain.
From the user's perspective, they'll either get:
The user should not trust this software as genuine and there may be attempts to steal funds. The user should delete the datadir: hash mismatch at height ..."
or
The user should not trust this software as genuine and there may be attempts to steal funds. The user should delete the datadir: hash not found at height ..."
The lack of information here would leave the user confused. In the current code, we explicitly state the reason. We should be doing the same here
| assumeHeight := sm.chain.AssumeUtreexoHeight() | ||
| assumeUtreexoHash := sm.chain.AssumeUtreexoHash() | ||
| headerHash, err := sm.chain.HeaderHashByHeight(assumeHeight) | ||
|
|
There was a problem hiding this comment.
Should not have this empty line here. The error assertion branch should be right after the err definition
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "fetch error: assumeHeight not in bestHeader", |
There was a problem hiding this comment.
The returned error here is the same as "mismatch: hash at assumepointhHeight differs".
[I] calvin@nixos ~/b/u/u/netsync ((30b29907))> git diff
diff --git a/netsync/manager_test.go b/netsync/manager_test.go
index 5365939a..c2fd8f2d 100644
--- a/netsync/manager_test.go
+++ b/netsync/manager_test.go
@@ -1349,6 +1349,7 @@ func TestCheckUtreexoHash(t *testing.T) {
}
//assert
err := sm.checkAssumeUtreexoHash()
+ fmt.Println(err)
if tc.wantErr {
require.Error(t, err)
} else {[I] calvin@nixos ~/b/u/u/netsync ((30b29907))> go test -run 'TestCheckUtreexoHash/fetch_error:_assumeHeight_not_in_bestHeader'
hash mismatch at height 2: expected 0000000000000000000000000000000000000000000000000000000000000000, got 04abc77b0fceb55927320b84ae78b3de4f402f85d4a326ec236f5c17f19fe27e
PASS
ok github.com/utreexo/utreexod/netsync 0.048s
[I] calvin@nixos ~/b/u/u/netsync ((30b29907))>
There was a problem hiding this comment.
Thanks for catch. when i split the check into checkAssumeUtreexoHash(), original warn lost explicit "hardcoded vs PoW chain" framing.
I'll fix hat so the user gets the full context again.
-
update the helper error message to explicitly mention the hardcoded assumeUtreexoHash, actual chain hash, and the height.
-
update the caller warning
-
remove empty line
-
fix the "fetch error" test case
30b2990 to
01a1a32
Compare
|
The fetch error case's original purposewas to verify the error path when Thanks for catching those my mistakes. |
01a1a32 to
3f33b09
Compare
| numBlocks: 1, | ||
| assumepointHeight: 10, | ||
| hashFunc: func(b []*btcutil.Block) *chainhash.Hash { return &chainhash.Hash{} }, | ||
| wantErr: true, |
There was a problem hiding this comment.
@kcalvinalvin
Would be better to identify each error path withe custom type (like RuleError )or use sentinel + error.Is?
I wanted to ask before edit
There was a problem hiding this comment.
or it could be only in Test code, match err string using ErrContains
There was a problem hiding this comment.
oh Custom type and Sentinel both are over engineering and until Err is useful for other boundary or interface, i'll choose ErrContains
3f33b09 to
e2e33c3
Compare
BestHeader() returns the tip hash of header chain, which is can be at a height pass the assume utreexo point when headers are downloaded in a single batch.
this causes a false mismatch and os.Exit(1).
BestHeader() = chain tip = 954,553
00000000000000000001c86c3e8ddbffa6a572724f66fe9df46ba84f51fe70ef
hard coded = 943,013
00000000000000000001c595730bd4a5fb0e2b35af70882962ce7ae602f48aff