refactor(*): add more log to proof verification
This commit is contained in:
parent
bda3e60bb7
commit
b0466cd993
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -43,10 +44,16 @@ func (pl *VerifyPool) CheckProof(tx *pb.Transaction) (bool, error) {
|
||||||
if ibtp := pl.extractIBTP(tx); ibtp != nil {
|
if ibtp := pl.extractIBTP(tx); ibtp != nil {
|
||||||
ok, err := pl.verifyProof(ibtp, tx.Extra)
|
ok, err := pl.verifyProof(ibtp, tx.Extra)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
pl.logger.WithFields(logrus.Fields{
|
||||||
|
"hash": tx.TransactionHash.String(),
|
||||||
|
"id": ibtp.ID(),
|
||||||
|
"error": err}).Error("ibtp verify error")
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
pl.logger.WithFields(logrus.Fields{"hash": tx.TransactionHash.String(), "id": ibtp.ID()}).Debug("ibtp verify fail")
|
pl.logger.WithFields(logrus.Fields{
|
||||||
|
"hash": tx.TransactionHash.String(),
|
||||||
|
"id": ibtp.ID()}).Error("ibtp verify fail")
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
tx.Extra = nil
|
tx.Extra = nil
|
||||||
|
@ -82,21 +89,21 @@ func (pl *VerifyPool) extractIBTP(tx *pb.Transaction) *pb.IBTP {
|
||||||
|
|
||||||
func (pl *VerifyPool) verifyProof(ibtp *pb.IBTP, proof []byte) (bool, error) {
|
func (pl *VerifyPool) verifyProof(ibtp *pb.IBTP, proof []byte) (bool, error) {
|
||||||
if proof == nil {
|
if proof == nil {
|
||||||
return false, nil
|
return false, fmt.Errorf("empty proof")
|
||||||
}
|
}
|
||||||
proofHash := sha256.Sum256(proof)
|
proofHash := sha256.Sum256(proof)
|
||||||
if !bytes.Equal(proofHash[:], ibtp.Proof) {
|
if !bytes.Equal(proofHash[:], ibtp.Proof) {
|
||||||
return false, nil
|
return false, fmt.Errorf("proof hash is not correct")
|
||||||
}
|
}
|
||||||
|
|
||||||
app := &appchainMgr.Appchain{}
|
app := &appchainMgr.Appchain{}
|
||||||
ok, data := pl.getAccountState(constant.AppchainMgrContractAddr, contracts.AppchainKey(ibtp.From))
|
ok, data := pl.getAccountState(constant.AppchainMgrContractAddr, contracts.AppchainKey(ibtp.From))
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, nil
|
return false, fmt.Errorf("cannot get registered appchain")
|
||||||
}
|
}
|
||||||
err := json.Unmarshal(data, app)
|
err := json.Unmarshal(data, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, fmt.Errorf("unmarshal appchain data fail: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
validateAddr := validator.FabricRuleAddr
|
validateAddr := validator.FabricRuleAddr
|
||||||
|
@ -104,13 +111,11 @@ func (pl *VerifyPool) verifyProof(ibtp *pb.IBTP, proof []byte) (bool, error) {
|
||||||
ok, data = pl.getAccountState(constant.RuleManagerContractAddr, contracts.RuleKey(ibtp.From))
|
ok, data = pl.getAccountState(constant.RuleManagerContractAddr, contracts.RuleKey(ibtp.From))
|
||||||
if ok {
|
if ok {
|
||||||
if err := json.Unmarshal(data, rl); err != nil {
|
if err := json.Unmarshal(data, rl); err != nil {
|
||||||
return false, err
|
return false, fmt.Errorf("unmarshal rule data error: %w", err)
|
||||||
}
|
}
|
||||||
validateAddr = rl.Address
|
validateAddr = rl.Address
|
||||||
} else {
|
} else {
|
||||||
if app.ChainType != "fabric" {
|
return false, fmt.Errorf("appchain didn't register rule")
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, err = pl.ve.Validate(validateAddr, ibtp.From, proof, ibtp.Payload, app.Validators)
|
ok, err = pl.ve.Validate(validateAddr, ibtp.From, proof, ibtp.Payload, app.Validators)
|
||||||
|
|
Loading…
Reference in New Issue