Skip to content

Commit

Permalink
Merge branch 'testnet'
Browse files Browse the repository at this point in the history
  • Loading branch information
ggq89 committed Dec 18, 2019
2 parents 9406f3d + 728fe7b commit 6a3b458
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 161 deletions.
2 changes: 1 addition & 1 deletion bdd/dct/deposit_test_cases/DepositContractTest.robot
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Business_11
Business_12
[Documentation] 没收上一个测试用例的jury dev节点,但是基金会不同意
log jury
${result} applyForForfeitureDeposit ${foundationAddr} ${juryAddr_01} Developer nothing to do #某个地址申请没收该节点保证金(全部)
${result} applyForForfeitureDeposit ${foundationAddr} ${juryAddr_01} Jury nothing to do #某个地址申请没收该节点保证金(全部)
log ${result}
${result} getListForForfeitureApplication
log ${result}
Expand Down
25 changes: 14 additions & 11 deletions consensus/mediatorplugin/threshold_sign.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ func (mp *MediatorPlugin) signUnitTBLS(localMed common.Address, unitHash common.
// 3. 群签名
dks, err := dkgr.DistKeyShare()
if err != nil {
log.Debugf(err.Error())
log.Debugf("the mediator(%v)'s dkg get dks err:%v", localMed.Str(), err.Error())
return
}

sigShare, err := tbls.Sign(mp.suite, dks.PriShare(), unitHash[:])
if err != nil {
log.Debugf(err.Error())
log.Debugf("the mediator(%v)'s TBLS sign the unit(%v) err:%v",
localMed.Str(), unitHash.TerminalString(), err.Error())
return
}

Expand Down Expand Up @@ -253,18 +254,18 @@ func (mp *MediatorPlugin) AddToTBLSRecoverBuf(event *SigShareEvent) {
medSigSharesBuf, ok := mp.toTBLSRecoverBuf[localMed]
if !ok {
// 不是本地mediator生产的 unit
err = fmt.Errorf("the mediator(%v) of the unit(hash: %v, # %v ) is not local",
errStr := fmt.Errorf("the mediator(%v) of the unit(hash: %v, # %v ) is not local",
localMed.Str(), newUnitHash.TerminalString(), header.NumberU64())
log.Debugf(err.Error())
log.Debugf(errStr.Error())
return
}

// 当buf不存在时,说明已经成功recover出群签名, 或者已经过了unit确认时间,不需要群签名,忽略该签名分片
sigShareSet, ok := medSigSharesBuf[newUnitHash]
if !ok {
err = fmt.Errorf("the unit(hash: %v, # %v ) need not to recover group-sign by the mediator(%v)",
errStr := fmt.Errorf("the unit(hash: %v, # %v ) need not to recover group-sign by the mediator(%v)",
newUnitHash.TerminalString(), header.NumberU64(), localMed.Str())
log.Debugf(err.Error())
log.Debugf(errStr.Error())
return
}

Expand Down Expand Up @@ -293,7 +294,7 @@ func (mp *MediatorPlugin) recoverUnitTBLS(localMed common.Address, unitHash comm

sigShareSet, ok := sigSharesBuf[unitHash]
if !ok {
log.Debugf("the mediator(%v) need not to recover group-sign of the unit(%v), " +
log.Debugf("the mediator(%v) need not to recover group-sign of the unit(%v), "+
"or this unit has been recovered to group-sign by this mediator",
localMed.Str(), unitHash.TerminalString())
return
Expand All @@ -308,8 +309,9 @@ func (mp *MediatorPlugin) recoverUnitTBLS(localMed common.Address, unitHash comm
mp.dkgLock.RLock()
defer mp.dkgLock.RUnlock()
var (
mSize, threshold int
dkgr *dkg.DistKeyGenerator
mSize int
threshold int
dkgr *dkg.DistKeyGenerator
)

dag := mp.dag
Expand Down Expand Up @@ -346,7 +348,7 @@ func (mp *MediatorPlugin) recoverUnitTBLS(localMed common.Address, unitHash comm

dks, err := dkgr.DistKeyShare()
if err != nil {
log.Debugf(err.Error())
log.Debugf("the mediator(%v)'s dkg get dks err:%v", localMed.Str(), err.Error())
return
}

Expand All @@ -355,7 +357,8 @@ func (mp *MediatorPlugin) recoverUnitTBLS(localMed common.Address, unitHash comm
pubPoly := share.NewPubPoly(suite, suite.Point().Base(), dks.Commitments())
groupSig, err := tbls.Recover(suite, pubPoly, unitHash[:], sigShareSet.popSigShares(), threshold, mSize)
if err != nil {
log.Debugf(err.Error())
log.Debugf("the mediator(%v)'s TBLS recover the unit(%v) group-sign err:%v",
localMed.Str(), unitHash.TerminalString(), err.Error())
return
}

Expand Down
16 changes: 9 additions & 7 deletions consensus/mediatorplugin/vss_protocol.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (mp *MediatorPlugin) newDKGAndInitVSSBuf() {
initSec := mp.mediators[localMed].InitPrivKey
dkgr, err := dkg.NewDistKeyGenerator(mp.suite, initSec, initPubs, curThreshold)
if err != nil {
log.Debugf(err.Error())
log.Debugf("New the mediator(%v)'s DistKeyGenerator get err: %v", localMed.Str(), err.Error())
continue
}
mp.activeDKGs[localMed] = dkgr
Expand Down Expand Up @@ -211,7 +211,7 @@ func (mp *MediatorPlugin) processVSSDeal(localMed common.Address, deal *dkg.Deal

dkgr, ok := mp.activeDKGs[localMed]
if !ok || dkgr == nil {
log.Debugf("the mediator(%v)'s dkg is not existed, or it is not active", localMed.String())
log.Debugf("the mediator(%v)'s dkg is not existed, or it is not active mediator", localMed.String())
return
}

Expand All @@ -221,13 +221,15 @@ func (mp *MediatorPlugin) processVSSDeal(localMed common.Address, deal *dkg.Deal

resp, err := dkgr.ProcessDeal(deal)
if err != nil {
log.Debugf("dkg cannot process this deal: " + err.Error())
log.Debugf("the mediator(%v)'s dkg cannot process the mediator(%v)'s deal: %v",
localMed.Str(), vrfrMed.Str(), err.Error())
return
}

if resp.Response.Status != vss.StatusApproval {
err = fmt.Errorf("dkg gave this deal a complaint: %v", localMed.String())
log.Debugf(err.Error())
errStr := fmt.Errorf("the mediator(%v)'s dkg gave the mediator(%v)'s deal a complaint: %v",
localMed.Str(), vrfrMed.Str(), resp.Response.Status)
log.Debugf(errStr.Error())
return
}

Expand All @@ -251,7 +253,7 @@ func (mp *MediatorPlugin) broadcastVSSDeals() {
for localMed, dkg := range mp.activeDKGs {
deals, err := dkg.Deals()
if err != nil {
log.Debugf(err.Error())
log.Debugf("the mediator(%v)'s dkg get deals err: %v", localMed.Str(), err.Error())
continue
}
log.Debugf("the mediator(%v) broadcast vss deals", localMed.Str())
Expand Down Expand Up @@ -375,7 +377,7 @@ func (mp *MediatorPlugin) processVSSResp(localMed common.Address, resp *dkg.Resp

jstf, err := dkgr.ProcessResponse(resp)
if err != nil {
log.Debugf(err.Error())
log.Debugf("the mediator(%v)'s dkg process response err: %v", localMed.Str(), err.Error())
return
}

Expand Down
36 changes: 32 additions & 4 deletions contracts/syscontract/deposit/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func getToday(stub shim.ChaincodeStubInterface) string {
}

// 社区申请没收某节点的保证金数量
func applyForForfeitureDeposit(stub shim.ChaincodeStubInterface, forfeitureAddress string, role string, reason string) pb.Response {
func applyForForfeitureDeposit(stub shim.ChaincodeStubInterface, forfeitureAddress, role, reason string) pb.Response {
log.Info("ApplyForForfeitureDeposit")

// 需要判断是否基金会发起的
Expand All @@ -393,7 +393,7 @@ func applyForForfeitureDeposit(stub shim.ChaincodeStubInterface, forfeitureAddre
//}
// 被没收地址
// 判断没收地址是否正确
f, err := common.StringToAddress(forfeitureAddress)
_, err := common.StringToAddress(forfeitureAddress)
if err != nil {
return shim.Error(err.Error())
}
Expand All @@ -407,7 +407,7 @@ func applyForForfeitureDeposit(stub shim.ChaincodeStubInterface, forfeitureAddre
listForForfeiture = make(map[string]*modules.Forfeiture)
} else {
//
if _, ok := listForForfeiture[f.String()]; ok {
if _, ok := listForForfeiture[forfeitureAddress]; ok {
return shim.Error("node was in the forfeiture list")
}
}
Expand All @@ -420,13 +420,41 @@ func applyForForfeitureDeposit(stub shim.ChaincodeStubInterface, forfeitureAddre
log.Error("Stub.GetInvokeAddress err:", "error", err)
return shim.Error(err.Error())
}

// 判断 forfeitureAddress 是否在 role 列表中
list := ""
switch strings.ToLower(role) {
case strings.ToLower(modules.Mediator):
list = modules.MediatorList
case strings.ToLower(modules.Jury):
list = modules.JuryList
case strings.ToLower(modules.Developer):
list = modules.DeveloperList
default:
errStr := fmt.Sprintf("%v is unexpected role, please enter validate role.", role)
log.Debugf(errStr)
return shim.Error(errStr)
}

b, err := isInCandidate(stub, forfeitureAddress, list)
if err != nil {
log.Debugf("isInCandidate error: %s", err.Error())
return shim.Error(err.Error())
}
if !b {
errStr := fmt.Sprintf("%v is not in %v list", forfeitureAddress, role)
log.Debugf(errStr)
return shim.Error(errStr)
}

// 存储信息
forfeiture := &modules.Forfeiture{}
forfeiture.ApplyAddress = invokeAddr.String()
forfeiture.ForfeitureRole = role
forfeiture.Extra = reason
forfeiture.ApplyTime = getTime(stub)
listForForfeiture[f.String()] = forfeiture
listForForfeiture[forfeitureAddress] = forfeiture

// 保存列表
err = saveListForForfeiture(stub, listForForfeiture)
if err != nil {
Expand Down
48 changes: 25 additions & 23 deletions contracts/syscontract/deposit/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,16 @@ func (d *DepositChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response
// }
// st := strconv.FormatInt(b, 10)
// return shim.Success([]byte(st))
case modules.HandleMediatorInCandidateList:
log.Info("Enter DepositChaincode Contract " + modules.HandleMediatorInCandidateList + " Invoke")
return d.HandleMediatorInCandidateList(stub, args)
case modules.HandleJuryInCandidateList:
log.Info("Enter DepositChaincode Contract " + modules.HandleJuryInCandidateList + " Invoke")
return d.HandleJuryInCandidateList(stub, args)
case modules.HandleDevInList:
log.Info("Enter DepositChaincode Contract " + modules.HandleDevInList + " Invoke")
return d.HandleDevInList(stub, args)
// comment by albert, 重复的接口(并且有漏洞),请走没收流程
//case modules.HandleMediatorInCandidateList:
// log.Info("Enter DepositChaincode Contract " + modules.HandleMediatorInCandidateList + " Invoke")
// return d.HandleMediatorInCandidateList(stub, args)
//case modules.HandleJuryInCandidateList:
// log.Info("Enter DepositChaincode Contract " + modules.HandleJuryInCandidateList + " Invoke")
// return d.HandleJuryInCandidateList(stub, args)
//case modules.HandleDevInList:
// log.Info("Enter DepositChaincode Contract " + modules.HandleDevInList + " Invoke")
// return d.HandleDevInList(stub, args)
case modules.GetAllMediator:
log.Info("Enter DepositChaincode Contract " + modules.GetAllMediator + " Query")
return d.GetAllMediator(stub)
Expand Down Expand Up @@ -798,20 +799,21 @@ func (d DepositChaincode) QueryPledgeWithdraw(stub shim.ChaincodeStubInterface)

// 质押

// 移除超级节点候选列表
func (d DepositChaincode) HandleMediatorInCandidateList(stub shim.ChaincodeStubInterface, addresses []string) pb.Response {
return handleNodeInList(stub, addresses, modules.Mediator)
}

// 移除陪审员候选列表
func (d DepositChaincode) HandleJuryInCandidateList(stub shim.ChaincodeStubInterface, addresses []string) pb.Response {
return handleNodeInList(stub, addresses, modules.Jury)
}

// 移除开发者列表
func (d DepositChaincode) HandleDevInList(stub shim.ChaincodeStubInterface, addresses []string) pb.Response {
return handleNodeInList(stub, addresses, modules.Developer)
}
// comment by albert, 重复的接口(并且有漏洞),请走没收流程
//// 移除超级节点候选列表
//func (d DepositChaincode) HandleMediatorInCandidateList(stub shim.ChaincodeStubInterface, addresses []string) pb.Response {
// return handleNodeInList(stub, addresses, modules.Mediator)
//}
//
//// 移除陪审员候选列表
//func (d DepositChaincode) HandleJuryInCandidateList(stub shim.ChaincodeStubInterface, addresses []string) pb.Response {
// return handleNodeInList(stub, addresses, modules.Jury)
//}
//
//// 移除开发者列表
//func (d DepositChaincode) HandleDevInList(stub shim.ChaincodeStubInterface, addresses []string) pb.Response {
// return handleNodeInList(stub, addresses, modules.Developer)
//}

func (d DepositChaincode) GetAllMediator(stub shim.ChaincodeStubInterface) pb.Response {
values, err := stub.GetStateByPrefix(string(constants.MEDIATOR_INFO_PREFIX) +
Expand Down
Loading

0 comments on commit 6a3b458

Please sign in to comment.