From 59bbc4e79f9fae09fe7e4c6223f162f9bc504cb8 Mon Sep 17 00:00:00 2001 From: haijuncai Date: Fri, 24 Sep 2021 15:49:47 +0800 Subject: [PATCH] Refactor some code that prints the log of the signature process --- dcrm/base.go | 1 - dcrm/localdb.go | 12 +++++------- dcrm/msg.go | 11 +++-------- dcrm/sign.go | 36 +++++++++++------------------------- 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/dcrm/base.go b/dcrm/base.go index e44a264..6c211ce 100644 --- a/dcrm/base.go +++ b/dcrm/base.go @@ -1457,7 +1457,6 @@ func GetAllReplyFromGroup(wid int,gid string,rt RpcType,initiator string) []Node if strings.EqualFold(mm,node2) { reply,ok := ret[mms[k+1]] if ok && reply != nil { - common.Info("===================GetAllReplyFromGroup,it is sign=================","key",key,"from",mms[k+1],"Accept",reply.Accept,"raw",mdss) if reply.Accept == "true" { sta = "Agree" } else { diff --git a/dcrm/localdb.go b/dcrm/localdb.go index ca9fb4e..a22e7c1 100644 --- a/dcrm/localdb.go +++ b/dcrm/localdb.go @@ -227,13 +227,12 @@ func SavePubKeyDataToDb() { if kd.Data == "CLEAN" { err := db.Delete(kd.Key) if err != nil { - common.Info("=================SavePubKeyDataToDb, db is not nil and delete fail ===============","key",kd.Key) + common.Error("=================SavePubKeyDataToDb, delete data from local db fail ===============","key",kd.Key,"err",err) } } else { err := db.Put(kd.Key, []byte(kd.Data)) - common.Info("=================SavePubKeyDataToDb, db is not nil ===============","key",kd.Key,"err",err) if err != nil { - common.Info("=================SavePubKeyDataToDb, db is not nil and save fail ===============","key",kd.Key) + common.Error("=================SavePubKeyDataToDb,save data to local db fail ===============","key",kd.Key,"err",err) dir := GetDbDir() dbtmp, err := ethdb.NewLDBDatabase(dir, cache, handles) //bug @@ -248,19 +247,19 @@ func SavePubKeyDataToDb() { } } if err != nil { - common.Debug("=================SavePubKeyDataToDb, re-get db fail and save fail ===============","key",kd.Key) + common.Error("=================SavePubKeyDataToDb, re-get db fail and save data to local db fail ===============","key",kd.Key,"err",err) } else { db = dbtmp err = db.Put(kd.Key, []byte(kd.Data)) if err != nil { - common.Debug("=================SavePubKeyDataToDb, re-get db success and save fail ===============","key",kd.Key) + common.Error("=================SavePubKeyDataToDb, re-get db success and save data to local db fail ===============","key",kd.Key,"err",err) } } } } } else { - common.Debug("=================SavePubKeyDataToDb, save to db fail ,db is nil ===============","key",kd.Key) + common.Error("=================SavePubKeyDataToDb, save to db fail ,db is nil ===============","key",kd.Key) } time.Sleep(time.Duration(1000000)) //na, 1 s = 10e9 na @@ -476,7 +475,6 @@ func GetValueFromDb(key string) (bool,interface{}) { ss, err := UnCompress(string(da)) if err != nil { - common.Error("========================GetValueFromDb, uncompress err=======================","err",err,"key",key) return true,da } diff --git a/dcrm/msg.go b/dcrm/msg.go index b4b3a0e..6d7a0d9 100644 --- a/dcrm/msg.go +++ b/dcrm/msg.go @@ -305,7 +305,6 @@ func GetRawReply(l *list.List) map[string]*RawReply { acceptsig,ok := txdata.(*TxDataAcceptSign) if ok { - common.Info("=================GetRawReply,the list item is TxDataAcceptSign================","key",keytmp,"from",from,"accept",acceptsig.Accept,"raw",raw) accept := "false" if acceptsig.Accept == "AGREE" { accept = "true" @@ -686,10 +685,8 @@ func (self *RecvMsg) Run(workid int, ch chan interface{}) bool { //w.Clear2() //Sign_ec2(sd.Key, sd.Save, sd.Sku1, sd.Txhash, sd.Keytype, sd.Pkx, sd.Pky, ch1, workid) Sign_ec3(sd.Key,sd.Txhash,sd.Keytype,sd.Pkx,sd.Pky,ch1,workid,pre) - common.Info("===============RecvMsg.Run, ec3 sign finish ===================","WaitMsgTimeGG20",WaitMsgTimeGG20) ret, _, cherr := GetChannelValue(WaitMsgTimeGG20 + 10, ch1) if ret != "" && cherr == nil { - ww, err2 := FindWorker(sd.MsgPrex) if err2 != nil || ww == nil { res2 := RpcDcrmRes{Ret: "", Tip: "dcrm back-end internal error:no find worker", Err: fmt.Errorf("no find worker")} @@ -697,7 +694,7 @@ func (self *RecvMsg) Run(workid int, ch chan interface{}) bool { return false } - common.Info("===============RecvMsg.Run, ec3 sign success ===================","i",i,"get ret",ret,"cherr",cherr,"msgprex",sd.MsgPrex,"key",sd.Key) + common.Info("===============RecvMsg.Run, sign success ===================","get result",ret,"msgprex",sd.MsgPrex,"key",sd.Key,"tx hash",sd.Txhash,"pick key",sd.PickKey) ww.rsv.PushBack(ret) res2 := RpcDcrmRes{Ret: ret, Tip: "", Err: nil} @@ -705,8 +702,7 @@ func (self *RecvMsg) Run(workid int, ch chan interface{}) bool { return true } - common.Info("===============RecvMsg.Run,ec3 sign fail===================","ret",ret,"cherr",cherr,"msgprex",sd.MsgPrex,"key",sd.Key) - //time.Sleep(time.Duration(3) * time.Second) //1000 == 1s + common.Info("===============RecvMsg.Run,sign fail===================","cherr",cherr,"msgprex",sd.MsgPrex,"key",sd.Key,"tx hash",sd.Txhash,"pick key",sd.PickKey) } res2 := RpcDcrmRes{Ret: "", Tip: "sign fail", Err: fmt.Errorf("sign fail")} @@ -1411,7 +1407,6 @@ func DisAcceptMsg(raw string,workid int) { return } - common.Info("======================DisAcceptMsg,the msg is accept sign tx,and check reply success and will set timeout channel.===========================","sig key",acceptsig.Key,"from",from) w.bacceptsignres <- true exsit,da := GetValueFromPubKeyData(acceptsig.Key) if !exsit { @@ -2741,7 +2736,7 @@ func InitAcceptData(raw string,workid int,sender string,ch chan interface{}) err acceptsig,ok := txdata.(*TxDataAcceptSign) if ok { - common.Info("===============InitAcceptData, it is acceptsign and check accept sign raw success=====================","key ",acceptsig.Key,"from ",from,"accept",acceptsig.Accept,"raw",raw) + common.Info("===============InitAcceptData, get sign accept data=====================","key ",acceptsig.Key,"from ",from,"accept",acceptsig.Accept,"raw",raw) w, err := FindWorker(acceptsig.Key) if err != nil || w == nil { common.Info("===============InitAcceptData, it is acceptsign and no find worker=====================","key ",acceptsig.Key,"from ",from) diff --git a/dcrm/sign.go b/dcrm/sign.go index a58caa4..73ccb49 100644 --- a/dcrm/sign.go +++ b/dcrm/sign.go @@ -77,9 +77,10 @@ func InitAcceptData2(sbd *SignBrocastData,workid int,sender string,ch chan inter } key,from,nonce,txdata,err := CheckRaw(sbd.Raw) - common.Info("=====================InitAcceptData2,get result from call CheckRaw ================","key",key,"from",from,"err",err,"raw",sbd.Raw,"tx data",txdata) + common.Info("=====================InitAcceptData2,get sign command data ================","key",key,"from",from,"raw",sbd.Raw,"tx data",txdata) + if err != nil { - common.Debug("===============InitAcceptData2,check raw===================","err ",err,"key",key,"from",from,"raw",sbd.Raw) + common.Error("===============InitAcceptData2,get sign command data and check data fail===================","err ",err,"key",key,"from",from,"raw",sbd.Raw) res := RpcDcrmRes{Ret: "", Tip: err.Error(), Err: err} ch <- res return err @@ -360,19 +361,17 @@ func InitAcceptData2(sbd *SignBrocastData,workid int,sender string,ch chan inter } } - common.Info("===============InitAcceptData2,begin to sign=================","sig.MsgHash ",sig.MsgHash,"sig.Mode ",sig.Mode,"key ",key) + common.Info("===============InitAcceptData2,begin to sign=================","unsign txhash",sig.MsgHash,"key ",key) rch := make(chan interface{}, 1) sign(w.sid, from,sig.PubKey,sig.MsgHash,sig.Keytype,nonce,sig.Mode,sbd.PickHash,rch) chret, tip, cherr := GetChannelValue(waitallgg20+20, rch) - common.Info("================== InitAcceptData2,finish sig.================","return sign result ",chret,"err ",cherr,"key ",key) + common.Info("================== InitAcceptData2,sign finish.================","return sign result ",chret,"key ",key,"err",cherr) if chret != "" { - //common.Debug("===================InitAcceptData2,DeletePrePubData,11111===============","current total number of the data ",GetTotalCount(sig.PubKey),"key",key) DtPreSign.Lock() for _,vv := range sbd.PickHash { DeletePrePubDataBak(pub,vv.PickKey) } DtPreSign.Unlock() - //common.Debug("===================InitAcceptData2,DeletePrePubData,22222===============","current total number of the data ",GetTotalCount(sig.PubKey),"key",key) res := RpcDcrmRes{Ret: chret, Tip: "", Err: nil} ch <- res @@ -492,10 +491,9 @@ func InitAcceptData2(sbd *SignBrocastData,workid int,sender string,ch chan inter } func RpcAcceptSign(raw string) (string, string, error) { - common.Debug("=====================RpcAcceptSign call CheckRaw ================","raw",raw) _,from,_,txdata,err := CheckRaw(raw) if err != nil { - common.Info("=====================RpcAcceptSign,call CheckRaw finish================","raw",raw,"err",err) + common.Error("=====================RpcAcceptSign,get sign accept data and check data fail================","raw",raw,"from",from,"err",err) return "Failure",err.Error(),err } @@ -508,7 +506,6 @@ func RpcAcceptSign(raw string) (string, string, error) { if exsit { ac,ok := da.(*AcceptSignData) if ok && ac != nil { - common.Info("=====================RpcAcceptSign,call CheckRaw finish ================","key",acceptsig.Key,"from",from,"accept",acceptsig.Accept,"raw",raw) SendMsgToDcrmGroup(raw, ac.GroupId) SetUpMsgList(raw,cur_enode) return "Success", "", nil @@ -784,7 +781,7 @@ func sign(wsid string,account string,pubkey string,unsignhash []string,keytype s } else { sign_ec(wsid,unsignhash,save,sku1,dcrmpkx,dcrmpky,keytype,pickhash,rch) ret, tip, cherr := GetChannelValue(waitall,rch) - common.Info("=================sign,call sign_ec finish.==============","return result",ret,"err",cherr,"key",wsid) + common.Info("=================sign,call sign_ec finish.==============","return result",ret,"sign key",wsid,"err",cherr) if cherr != nil { res := RpcDcrmRes{Ret: "", Tip: tip, Err: cherr} ch <- res @@ -840,14 +837,12 @@ func sign(wsid string,account string,pubkey string,unsignhash []string,keytype s return } - common.Info("================sign,the terminal sign res is success==============","key",wsid) res := RpcDcrmRes{Ret: result, Tip: tip, Err: err} ch <- res return } if cherrtmp != nil { - common.Info("================sign,the terminal sign res is failure================","err",cherrtmp,"key",wsid) res := RpcDcrmRes{Ret: "", Tip: "dcrm back-end internal error:sign fail", Err: cherrtmp} ch <- res return @@ -922,29 +917,22 @@ func sign_ec(msgprex string, txhash []string, save string, sku1 *big.Int, dcrmpk val,err := Encode2(sd) if err != nil { - common.Info("======================sign_ec, encode error==================","unsign txhash",vv,"msgprex",msgprex,"key",key,"pick key",pickkey,"err",err) - //res := RpcDcrmRes{Ret: "", Tip: "dcrm back-end internal error:marshal sign data error", Err: err} - //ch <- res + common.Error("======================sign_ec, encode error==================","unsign txhash",vv,"msgprex",msgprex,"key",key,"pick key",pickkey,"err",err) return } - common.Debug("======================sign_ec, encode success=================","vv",vv,"msgprex",msgprex,"key",key) rch := make(chan interface{}, 1) SetUpMsgList3(val,cur_enode,rch) _, _,cherr := GetChannelValue(waitall,rch) if cherr != nil { - - common.Info("======================sign_ec, get finish error====================","vv",vv,"msgprex",msgprex,"key",key,"cherr",cherr) - //res := RpcDcrmRes{Ret: "", Tip: "dcrm back-end internal error: sign fail", Err: cherr} - //ch <- res + common.Error("======================sign_ec, get sign finish error====================","unsign txhash",vv,"msgprex",msgprex,"key",key,"pick key",pickkey,"cherr",cherr) return } - common.Info("======================sign_ec, get finish success===================","vv",vv,"msgprex",msgprex,"key",key) }(v) } wg.Wait() - common.Info("======================sign_ec, all sign finish===================","msgprex",msgprex,"w.rsv",w.rsv) + common.Info("======================sign_ec, all txhash sign finish===================","msgprex",msgprex) var ret string iter := w.rsv.Front() @@ -957,8 +945,8 @@ func sign_ec(msgprex string, txhash []string, save string, sku1 *big.Int, dcrmpk ret += "NULL" tmps := strings.Split(ret, ":") - common.Debug("======================sign_ec=====================","return result",ret,"len(tmps)",len(tmps),"len(tmp)",len(tmp),"key",msgprex) if len(tmps) == (len(tmp) + 1) { + common.Info("======================sign_ec,the sign terminal result is success.=====================","return result",ret,"sign key",msgprex) res := RpcDcrmRes{Ret: ret, Tip: "", Err: nil} ch <- res return "" @@ -2858,9 +2846,7 @@ func DECDSASignRoundEleven(msgprex string, cointype string, w *RPCReqWorker, idS // 1. Receive Broadcast // s: s1, s2, s3 - common.Info("===================send SS1 finish, ", "prex = ", msgprex, "", "====================") _, tip, cherr := GetChannelValue(WaitMsgTimeGG20, w.bss1) - common.Info("===================finish get SS1, ", "err = ", cherr, "prex = ", msgprex, "", "====================") /////////////////////////request data from dcrm group suss := false if cherr != nil {