Skip to content

Commit 0c852d5

Browse files
committed
remove warning when tss instance had already released
1 parent 81079b6 commit 0c852d5

21 files changed

+486
-85
lines changed

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,17 @@ mod:
113113
linter:
114114
golangci-lint run
115115

116-
## make cluster: Run cluster including 4 nodes
116+
## make cluster: Run cluster including 4 nodes(including compile and clean storage)
117117
cluster:install${TAGS}
118118
@cd scripts && bash cluster.sh TAGS=${TAGS}
119119

120+
## make cluster-restart: Restart cluster including 4 nodes without compile and clean storage
121+
cluster-restart:
122+
@cd scripts && bash cluster_restart.sh TAGS=${TAGS}
123+
124+
## clean nodes storage
125+
clean-storage:
126+
@cd scripts && bash clean_storage.sh
120127
## make solo: Run one node in solo mode
121128
solo:install${TAGS}
122129
@cd scripts && bash solo.sh TAGS=${TAGS}

api/grpc/sign.go

+29-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,25 @@ func (cbs *ChainBrokerService) GetTssSigns(ctx context.Context, req *pb.GetSigns
102102
go func() {
103103
defer wg.Done()
104104
result = cbs.getRemoteTssSign(tssReq, poolPk)
105-
cbs.logger.WithFields(logrus.Fields{"result": result}).Info("get remote tss sign")
105+
cbs.logger.WithFields(logrus.Fields{"content": tssReq.Content}).Info("get remote tss sign success")
106106
}()
107107

108-
// 7. get sign by ourself
109-
culprits, sign, keysignErr := cbs.getLocalTssSign(tssFlag, tssReq, tssSigners)
108+
// 7. get sign by ourselves, if this node is contained in tssSigners
109+
var (
110+
culprits []string
111+
sign []byte
112+
signErr error
113+
)
114+
if utils.IsContained(fmt.Sprintf("%d", cbs.api.Network().LocalPeerID()), tssSigners) {
115+
culprits, sign, signErr = cbs.getLocalTssSign(tssFlag, tssReq, tssSigners)
116+
} else {
117+
// if not contained in tssSigners, ignore tss msg
118+
cbs.logger.Debugf("notifyNotParties in local %d", cbs.api.Network().LocalPeerID())
119+
err = cbs.notifyTssNotParties(tssFlag, tssReq, tssSigners)
120+
if err != nil {
121+
cbs.logger.Errorf("notifyNotParties in local %d err: %s", cbs.api.Network().LocalPeerID(), err)
122+
}
123+
}
110124
wg.Wait()
111125

112126
// 8. get a verified signature from others, return
@@ -118,7 +132,7 @@ func (cbs *ChainBrokerService) GetTssSigns(ctx context.Context, req *pb.GetSigns
118132
}, nil
119133
}
120134
// 9. get a signature by myself, return
121-
if tssFlag && keysignErr == nil {
135+
if tssFlag && signErr == nil {
122136
// 是tss节点
123137
return &pb.SignResponse{
124138
Sign: map[string][]byte{
@@ -246,8 +260,10 @@ func (cbs *ChainBrokerService) randomSignerRequest(signersALL []string) ([]strin
246260
}
247261
cbs.logger.Infof("====================== tss all signers: %s, signers: %s", strings.Join(signersALL, ","),
248262
strings.Join(tssSigners, ","))
263+
notPartiesIDs := utils.FindUnmatched(tssSigners, signersALL)
264+
249265
randomN := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
250-
extra := []byte(fmt.Sprintf("%s-%s", strings.Join(tssSigners, ","), strconv.Itoa(randomN)))
266+
extra := []byte(fmt.Sprintf("%s-%s-%s", strings.Join(tssSigners, ","), strconv.Itoa(randomN), strings.Join(notPartiesIDs, ",")))
251267
return tssSigners, extra
252268
}
253269

@@ -340,3 +356,11 @@ func getConsensusTssInfoParties(infos []*pb.TssInfo, quorum uint64) ([]string, [
340356

341357
return idsAddr, []byte(pk), nil
342358
}
359+
360+
func (cbs *ChainBrokerService) notifyTssNotParties(tssFlag bool, tssReq *pb.GetSignsRequest, singers []string) error {
361+
if tssFlag {
362+
err := cbs.api.Broker().SetTssNotParties(tssReq, singers)
363+
return err
364+
}
365+
return nil
366+
}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ require (
3333
github.com/libp2p/go-libp2p-swarm v0.2.4
3434
github.com/looplab/fsm v0.2.0
3535
github.com/magiconair/properties v1.8.5
36-
github.com/meshplus/bitxhub-core v1.28.0
36+
github.com/meshplus/bitxhub-core v1.28.1-0.20230411032641-11245b4adfc5
3737
github.com/meshplus/bitxhub-kit v1.28.0
38-
github.com/meshplus/bitxhub-model v1.28.0
38+
github.com/meshplus/bitxhub-model v1.28.1-0.20230411032618-24ca54eec606
3939
github.com/meshplus/consensus v0.0.0-20211228075008-5f469b198531
4040
github.com/meshplus/eth-kit v1.28.0
4141
github.com/meshplus/go-libp2p-cert v1.28.0

go.sum

+6-3
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
544544
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
545545
github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0=
546546
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0=
547+
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 h1:I/yrLt2WilKxlQKCM52clh5rGzTKpVctGT1lH4Dc8Jw=
548+
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
547549
github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4=
548550
github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
549551
github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw=
@@ -803,17 +805,18 @@ github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO
803805
github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE=
804806
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
805807
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
806-
github.com/meshplus/bitxhub-core v1.28.0 h1:QIp5aM7EYvxS+ORE2TLTeBRv7uUoXvyNupULA2N8A6s=
807-
github.com/meshplus/bitxhub-core v1.28.0/go.mod h1:uqQTX6LOoVVyTmJmW5fVJ64qcse6IyXrtmn2jHGDx4w=
808+
github.com/meshplus/bitxhub-core v1.28.1-0.20230411032641-11245b4adfc5 h1:J3xQCuBO4q1Nnax6a/hDRm10mcx2zp9scffH6tG5a5Q=
809+
github.com/meshplus/bitxhub-core v1.28.1-0.20230411032641-11245b4adfc5/go.mod h1:4/95iA54o3TGOH872VGxEEbs8eO195kjakTrlpPcJkY=
808810
github.com/meshplus/bitxhub-kit v1.0.0-rc1/go.mod h1:ra/AhOkPvpElI+wXrB9G6DjdcrdxFU3vMwA5MYKr9D0=
809811
github.com/meshplus/bitxhub-kit v1.0.0/go.mod h1:7cWyhXWZfrQ3+EaxkRoXfuiG3Y5R9DXYJomeZKkETW8=
810812
github.com/meshplus/bitxhub-kit v1.1.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
811813
github.com/meshplus/bitxhub-kit v1.2.1-0.20210902085548-07f4fa85bfc9/go.mod h1:wrEdhHp1tktzdwcWb4bOxYsVc+KkcrYL18IYWYeumPQ=
812814
github.com/meshplus/bitxhub-kit v1.28.0 h1:HNYlx6FzELVWqr0GjtWaNo9iMwQTb94bdsqLJo0U2LE=
813815
github.com/meshplus/bitxhub-kit v1.28.0/go.mod h1:S8qKlxfXRFS9HQgXyD4r+o1/0u6EJOQoMZyXtlEM8vM=
814816
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
815-
github.com/meshplus/bitxhub-model v1.28.0 h1:UpZC7IHaZeZHG4IUyKwqOvntx12QmceoyApRIexo5ow=
816817
github.com/meshplus/bitxhub-model v1.28.0/go.mod h1:EehJ/neXJcXy0o1jglfdD1/vsU7tsXveNr9pGZTDtrY=
818+
github.com/meshplus/bitxhub-model v1.28.1-0.20230411032618-24ca54eec606 h1:HI9WHfsIaeR4HkoqsQ3ZX2uoIqtP9tSJpF96Y0eU/HU=
819+
github.com/meshplus/bitxhub-model v1.28.1-0.20230411032618-24ca54eec606/go.mod h1:EehJ/neXJcXy0o1jglfdD1/vsU7tsXveNr9pGZTDtrY=
817820
github.com/meshplus/consensus v0.0.0-20211228075008-5f469b198531 h1:lU2XI7vWdapTLJfObY3A+e+a3rvHbnT0pHN9LEghwRk=
818821
github.com/meshplus/consensus v0.0.0-20211228075008-5f469b198531/go.mod h1:2Sv1u1sOFta9dAO6OuHyxLaN1Z6/AdrIol99qi5ZZ0k=
819822
github.com/meshplus/eth-kit v1.28.0 h1:WDvIhbE5YbNoAgoQ4Etr/eE7DfsocKodFzyaqrbWkzk=

internal/app/feedhub.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import (
44
"encoding/binary"
55
"encoding/json"
66
"fmt"
7+
"strings"
78
"time"
89

10+
"github.com/meshplus/bitxhub/pkg/tssmgr"
11+
912
"github.com/Rican7/retry"
1013
"github.com/Rican7/retry/strategy"
1114
"github.com/meshplus/bitxhub-core/governance"
@@ -94,17 +97,33 @@ func (bxh *BitXHub) listenEvent() {
9497
bxh.TssMgr.SetOrderReadyPeers(id)
9598
return
9699
default:
97-
if bxh.TssMgr.GetTssStatus() {
98-
bxh.logger.Debugf("keygen task is done")
99-
return
100-
}
101-
bxh.logger.Debugf("get tss msg to put")
100+
bxh.logger.Debug("get tss msg to put")
102101
wireMsg := &message.WireMessage{}
103102
if err := json.Unmarshal(msg.Data, wireMsg); err != nil {
104103
bxh.logger.Errorf(fmt.Sprintf("unmarshal wire msg error: %v", err))
105-
} else {
106-
bxh.TssMgr.PutTssMsg(msg, wireMsg.MsgID)
104+
return
105+
}
106+
// check if msgID tss round done
107+
done, err := bxh.TssMgr.IsTssRoundDone(wireMsg.MsgID)
108+
if err != nil {
109+
if strings.Contains(err.Error(), tssmgr.GetInfoErr) {
110+
bxh.logger.WithFields(logrus.Fields{"done": done, "err": err}).Warning("check tss round done")
111+
return
112+
}
113+
}
114+
if done {
115+
bxh.logger.Debugf("tss round done msgID:%s", wireMsg.MsgID)
116+
return
117+
}
118+
119+
if wireMsg.MsgType == message.TSSTaskDone {
120+
//bxh.logger.Errorf("==========start set tss round done")
121+
err := bxh.TssMgr.SetTssRoundDone(wireMsg.MsgID, false)
122+
if err != nil {
123+
bxh.logger.Errorf("set tss round done err:%s", err)
124+
}
107125
}
126+
bxh.TssMgr.PutTssMsg(msg, wireMsg.MsgID)
108127
}
109128
}()
110129
case ev := <-blockCh:

internal/coreapi/api/api.go

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type BrokerAPI interface {
5151

5252
FetchSignsFromOtherPeers(req *pb.GetSignsRequest) map[string][]byte
5353
FetchTssInfoFromOtherPeers() []*pb.TssInfo
54+
SetTssNotParties(tssReq *pb.GetSignsRequest, singers []string) error
55+
5456
GetSign(req *pb.GetSignsRequest, signers []string) (string, []byte, []string, error)
5557
GetBlockHeaders(start uint64, end uint64) ([]*pb.BlockHeader, error)
5658
GetQuorum() uint64
@@ -63,6 +65,7 @@ type NetworkAPI interface {
6365
PeerInfo() ([]byte, error)
6466
PierManager() peermgr.PierManager
6567
OtherPeers() map[uint64]*peer.AddrInfo
68+
LocalPeerID() uint64
6669
}
6770

6871
type ChainAPI interface {

internal/coreapi/api/mock_api/mock_api.go

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/coreapi/broker.go

+68-12
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ func (b *BrokerAPI) OrderReady() error {
170170
return b.bxh.Order.Ready()
171171
}
172172

173+
func (b *BrokerAPI) convertTssID(str string) []uint64 {
174+
peers := make([]uint64, 0)
175+
for _, id := range strings.Split(str, ",") {
176+
idInt, _ := strconv.ParseUint(id, 10, 64)
177+
if _, ok := b.bxh.PeerMgr.OtherPeers()[idInt]; ok {
178+
peers = append(peers, idInt)
179+
}
180+
}
181+
return peers
182+
}
183+
173184
func (b *BrokerAPI) FetchSignsFromOtherPeers(req *pb.GetSignsRequest) map[string][]byte {
174185
// if type is solo, needn't fetch sign from others
175186
if b.bxh.GetSoloType() {
@@ -180,17 +191,28 @@ func (b *BrokerAPI) FetchSignsFromOtherPeers(req *pb.GetSignsRequest) map[string
180191
wg = sync.WaitGroup{}
181192
lock = sync.Mutex{}
182193
)
183-
184-
signerStr := strings.Split(string(req.Extra), "-")[0]
185-
signers := []uint64{}
186-
for _, id := range strings.Split(signerStr, ",") {
187-
idInt, _ := strconv.ParseUint(id, 10, 64)
188-
if _, ok := b.bxh.PeerMgr.OtherPeers()[idInt]; ok {
189-
signers = append(signers, idInt)
194+
if req.Type == pb.GetSignsRequest_TSS_IBTP_REQUEST || req.Type == pb.GetSignsRequest_TSS_IBTP_RESPONSE {
195+
// req.Extra: <tssSigners>-<random>-<notParties>
196+
notParties := b.convertTssID(strings.Split(string(req.Extra), "-")[2])
197+
wg.Add(len(notParties))
198+
for _, pid := range notParties {
199+
go func(pid uint64, wg *sync.WaitGroup) {
200+
defer wg.Done()
201+
err := b.notifyPeerNotParties(pid, req)
202+
if err != nil {
203+
b.logger.WithFields(logrus.Fields{
204+
"pid": pid,
205+
"err": err.Error(),
206+
}).Warnf("notify other peers not belong to parties with error")
207+
}
208+
}(pid, &wg)
190209
}
210+
wg.Wait()
191211
}
192212

193-
// TODO: calculate threshold
213+
// tss req.Extra: <tssSigners>-<random>-<notParties>
214+
// multi req.Extra: <multiSigners>
215+
signers := b.convertTssID(strings.Split(string(req.Extra), "-")[0])
194216
wg.Add(len(signers))
195217
for _, pid := range signers {
196218
go func(pid uint64, result map[string][]byte, wg *sync.WaitGroup, lock *sync.Mutex) {
@@ -259,6 +281,28 @@ func (b *BrokerAPI) requestIBTPSignPeer(pid uint64, id string, typ pb.GetSignsRe
259281
return data.Address, data.Signature, nil
260282
}
261283

284+
func (b *BrokerAPI) notifyPeerNotParties(pid uint64, req *pb.GetSignsRequest) error {
285+
keysignReqData, err := req.Marshal()
286+
if err != nil {
287+
return fmt.Errorf("GetSignsRequest marshal error: %w", err)
288+
}
289+
290+
msg := pb.Message{
291+
Type: pb.Message_Tss_KEYSIGN_NOT_PARTIES,
292+
Data: keysignReqData,
293+
}
294+
295+
resp, err := b.bxh.PeerMgr.Send(pid, &msg)
296+
if err != nil {
297+
return fmt.Errorf("send message to %d failed: %w", pid, err)
298+
}
299+
300+
if string(resp.Data) != "ok" {
301+
return fmt.Errorf("remote node: %d to handle tss not partied failed", pid)
302+
}
303+
return nil
304+
}
305+
262306
func (b *BrokerAPI) requestIBTPTssSignPeer(pid uint64, req *pb.GetSignsRequest) error {
263307
keysignReqData, err := req.Marshal()
264308
if err != nil {
@@ -339,15 +383,17 @@ func (b *BrokerAPI) GetSign(req *pb.GetSignsRequest, signers []string) (string,
339383
case pb.GetSignsRequest_MULTI_IBTP_RESPONSE:
340384
addr, signData, err = utils.GetIBTPSign(b.bxh.Ledger, req.Content, false, b.bxh.GetPrivKey().PrivKey)
341385
case pb.GetSignsRequest_TSS_IBTP_REQUEST:
386+
// req.Extra: <tssSigners>-<random>-<notParties>
342387
signInfo := strings.Split(string(req.Extra), "-")
343-
if len(signInfo) != 2 {
388+
if len(signInfo) != 3 {
344389
err = fmt.Errorf("wrong tss req extra: %s", string(req.Extra))
345390
} else {
346391
signData, culpritIDs, err = utils.GetIBTPTssSign(b.bxh.TssMgr, b.bxh.Ledger, req.Content, true, signers, signInfo[1])
347392
}
348393
case pb.GetSignsRequest_TSS_IBTP_RESPONSE:
394+
// req.Extra: <tssSigners>-<random>-<notParties>
349395
signInfo := strings.Split(string(req.Extra), "-")
350-
if len(signInfo) != 2 {
396+
if len(signInfo) != 3 {
351397
err = fmt.Errorf("wrong tss req extra: %s", string(req.Extra))
352398
} else {
353399
signData, culpritIDs, err = utils.GetIBTPTssSign(b.bxh.TssMgr, b.bxh.Ledger, req.Content, false, signers, signInfo[1])
@@ -359,7 +405,7 @@ func (b *BrokerAPI) GetSign(req *pb.GetSignsRequest, signers []string) (string,
359405
}
360406
signData, err = b.bxh.Ledger.GetBlockSign(height)
361407
if err != nil {
362-
return "", nil, nil, fmt.Errorf("get block header sign: %w", err)
408+
return "", nil, nil, fmt.Errorf("get block sign: %w", err)
363409
}
364410
case pb.GetSignsRequest_MULTI_BURN:
365411
addr, signData, err = b.handleMultiSignsBurnReq(req.Content)
@@ -445,7 +491,7 @@ func (b *BrokerAPI) GetPendingNonceByAccount(account string) uint64 {
445491
return b.bxh.Order.GetPendingNonceByAccount(account)
446492
}
447493

448-
func (b *BrokerAPI) GetPendingTransactions(_ int) []pb.Transaction {
494+
func (b *BrokerAPI) GetPendingTransactions(max int) []pb.Transaction {
449495
// TODO
450496
return nil
451497
}
@@ -517,3 +563,13 @@ func (b *BrokerAPI) requestTssInfo(pid uint64) (*pb.TssInfo, error) {
517563
return info, nil
518564
}
519565
}
566+
567+
func (b *BrokerAPI) SetTssNotParties(tssReq *pb.GetSignsRequest, singers []string) error {
568+
var isReq bool
569+
if tssReq.Type == pb.GetSignsRequest_TSS_IBTP_REQUEST {
570+
isReq = true
571+
}
572+
signInfo := strings.Split(string(tssReq.Extra), "-")
573+
// req.Extra: <tssSigners>-<random>-<notParties>
574+
return utils.NotifyNotTssParties(b.bxh.TssMgr, b.bxh.Ledger, tssReq.Content, isReq, singers, signInfo[1])
575+
}

internal/coreapi/network.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ func (network *NetworkAPI) PierManager() peermgr.PierManager {
3939
func (network *NetworkAPI) OtherPeers() map[uint64]*peer.AddrInfo {
4040
return network.bxh.PeerMgr.OtherPeers()
4141
}
42+
43+
func (network *NetworkAPI) LocalPeerID() uint64 {
44+
return network.bxh.PeerMgr.GetLocalID()
45+
}

0 commit comments

Comments
 (0)