Skip to content

Commit

Permalink
add more error info in header check (#1244)
Browse files Browse the repository at this point in the history
* add more error info in header check

* lower log level

* merge error

Co-authored-by: JunXi Xie <[email protected]>
  • Loading branch information
laizy and xiemylogos authored Jul 2, 2020
1 parent cec9dfa commit ed15d20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions core/store/ledgerstore/ledger_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package ledgerstore
import (
"bytes"
"crypto/sha256"
"encoding/json"
"fmt"
"hash"
"math"
Expand Down Expand Up @@ -229,6 +230,8 @@ func (this *LedgerStoreImp) InitLedgerStoreWithGenesisBlock(genesisBlock *types.
this.vbftPeerInfoblock[p.ID] = p.Index
}
this.lock.Unlock()
val, _ := json.Marshal(this.vbftPeerInfoblock)
log.Infof("loading vbftPeerInfo at height: %s : %s", header.Height, string(val))
}
// check and fix imcompatible states
err = this.stateStore.CheckStorage()
Expand Down Expand Up @@ -460,8 +463,11 @@ func (this *LedgerStoreImp) verifyHeader(header *types.Header, vbftPeerInfo map[
pubkey := vconfig.PubkeyID(bookkeeper)
_, present := vbftPeerInfo[pubkey]
if !present {
log.Errorf("invalid pubkey :%v,height:%d", pubkey, header.Height)
return vbftPeerInfo, fmt.Errorf("invalid pubkey :%v", pubkey)
val, _ := json.Marshal(vbftPeerInfo)
log.Errorf("verify header error: invalid pubkey :%v, height:%d, current vbftPeerInfo :%s",
pubkey, header.Height, string(val))

return vbftPeerInfo, fmt.Errorf("verify header error: invalid pubkey : %v", pubkey)
}
}
hash := header.Hash()
Expand Down Expand Up @@ -956,6 +962,7 @@ func (this *LedgerStoreImp) saveBlock(block *types.Block, ccMsg *types.CrossChai

//empty block does not check stateMerkleRoot
if len(block.Transactions) != 0 && result.MerkleRoot != stateMerkleRoot {
log.Infof("state mismatch at block height: %d, changeset: %s", block.Header.Height, result.WriteSet.DumpToDot())
return fmt.Errorf("state merkle root mismatch. expected: %s, got: %s",
result.MerkleRoot.ToHexString(), stateMerkleRoot.ToHexString())
}
Expand Down
7 changes: 5 additions & 2 deletions core/store/overlaydb/memdb_dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/
package overlaydb

import "fmt"
import (
"encoding/hex"
"fmt"
)

func (db *MemDB) DumpToDot() string {
out := `digraph g {
Expand Down Expand Up @@ -79,7 +82,7 @@ func genNode(node int, k []byte, v []byte, h int) string {
for i := h; i > 0; i-- {
str += fmt.Sprintf("<f%d> %d | ", i, i)
}
str += fmt.Sprintf(`%s:%s"];`, k, v)
str += fmt.Sprintf(`%s:%s"];`, hex.EncodeToString(k), hex.EncodeToString(v))
str += "\n"

return str
Expand Down
2 changes: 1 addition & 1 deletion smartcontract/service/native/ontid/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type attributeJson struct {

type attribute struct {
key []byte
value []byte
valueType []byte
value []byte
}

func (this *attribute) Value() []byte {
Expand Down

0 comments on commit ed15d20

Please sign in to comment.