Skip to content

Commit

Permalink
Refactor some code that prints the log of the signature process
Browse files Browse the repository at this point in the history
  • Loading branch information
haijuncai committed Sep 24, 2021
1 parent cc4004f commit 59bbc4e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 41 deletions.
1 change: 0 additions & 1 deletion dcrm/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions dcrm/localdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 3 additions & 8 deletions dcrm/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -686,27 +685,24 @@ 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")}
ch <- res2
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}
ch <- res2
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")}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 11 additions & 25 deletions dcrm/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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 ""
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 59bbc4e

Please sign in to comment.