Skip to content

Commit 4fc8855

Browse files
authored
feat: drop leaderless party (#52)
* Refactor request msg_id * Drop leaderless parties * Fix naming * Remove sorting * Enforce version, improve logging * Fix tests * Remove dial to self * Drop legacy proto * Lint * Merge files * Address PR comments [1] * Address PR comments [2] * Fix log
1 parent 9ed8657 commit 4fc8855

28 files changed

+490
-919
lines changed

blame/policy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (m *Manager) GetUnicastBlame(lastMsgType string) ([]Node, error) {
7878
peersID, ok := m.lastUnicastPeer[lastMsgType]
7979
m.lastMsgLocker.RUnlock()
8080
if !ok {
81-
return nil, fmt.Errorf("fail to find peers of the given msg type %w", ErrTssTimeOut)
81+
return nil, fmt.Errorf("fail to find peers of the given msg type %w", ErrTimeoutTSS)
8282
}
8383
for _, el := range peersID {
8484
peersMap[el.String()] = true
@@ -91,7 +91,7 @@ func (m *Manager) GetUnicastBlame(lastMsgType string) ([]Node, error) {
9191
_, blamePeers, err := m.GetBlamePubKeysLists(onlinePeers)
9292
if err != nil {
9393
m.logger.Error().Err(err).Msg("fail to get the blamed peers")
94-
return nil, fmt.Errorf("fail to get the blamed peers %w", ErrTssTimeOut)
94+
return nil, fmt.Errorf("fail to get the blamed peers %w", ErrTimeoutTSS)
9595
}
9696
var blameNodes []Node
9797
for _, el := range blamePeers {
@@ -105,7 +105,7 @@ func (m *Manager) GetBroadcastBlame(lastMessageType string) ([]Node, error) {
105105
blamePeers, err := m.tssTimeoutBlame(lastMessageType, m.partyInfo.PartyIDMap)
106106
if err != nil {
107107
m.logger.Error().Err(err).Msg("fail to get the blamed peers")
108-
return nil, fmt.Errorf("fail to get the blamed peers %w", ErrTssTimeOut)
108+
return nil, fmt.Errorf("fail to get the blamed peers %w", ErrTimeoutTSS)
109109
}
110110
var blameNodes []Node
111111
for _, el := range blamePeers {

blame/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
ErrHashFromOwner = errors.New(" hash sent from data owner")
2020
ErrNotEnoughPeer = errors.New("not enough nodes to evaluate hash")
2121
ErrNotMajority = errors.New("message we received does not match the majority")
22-
ErrTssTimeOut = errors.New("error Tss Timeout")
22+
ErrTimeoutTSS = errors.New("error timeout TSS")
2323
ErrHashCheck = errors.New("error in processing hash check")
2424
ErrHashInconsistency = errors.New("fail to agree on the hash value")
2525
)

keygen/ecdsa/keygen_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *TssECDSAKeygenTestSuite) SetUpSuite(c *C) {
9595
}
9696

9797
func (s *TssECDSAKeygenTestSuite) TearDownSuite(c *C) {
98-
for i, _ := range s.comms {
98+
for i := range s.comms {
9999
tempFilePath := path.Join(os.TempDir(), strconv.Itoa(i), "ecdsa")
100100
err := os.RemoveAll(tempFilePath)
101101
c.Assert(err, IsNil)

keygen/ecdsa/tss_keygen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (tKeyGen *TssKeyGen) processKeyGen(errChan chan struct{},
217217
blameMgr.GetBlame().IsUnicast = isUnicast
218218
}
219219
}
220-
return nil, blame.ErrTssTimeOut
220+
return nil, blame.ErrTimeoutTSS
221221

222222
case msg := <-outCh:
223223
tKeyGen.logger.Debug().Msgf(">>>>>>>>>>msg: %s", msg.String())

keygen/eddsa/tss_keygen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (tKeyGen *KeyGen) processKeyGen(errChan chan struct{},
205205
blameMgr.GetBlame().IsUnicast = isUnicast
206206
}
207207
}
208-
return nil, blame.ErrTssTimeOut
208+
return nil, blame.ErrTimeoutTSS
209209

210210
case msg := <-outCh:
211211
tKeyGen.logger.Debug().Msgf(">>>>>>>>>>msg: %s", msg.String())

keygen/keygen.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,70 @@
11
package keygen
22

33
import (
4-
bcrypto "github.com/bnb-chain/tss-lib/crypto"
4+
"bytes"
5+
"strings"
56

7+
"github.com/bnb-chain/tss-lib/crypto"
8+
9+
"github.com/zeta-chain/go-tss/blame"
610
"github.com/zeta-chain/go-tss/common"
711
"github.com/zeta-chain/go-tss/p2p"
812
)
913

10-
type TssKeyGen interface {
11-
GenerateNewKey(keygenReq Request) (*bcrypto.ECPoint, error)
14+
// Service TSS key generation service
15+
type Service interface {
16+
GenerateNewKey(request Request) (*crypto.ECPoint, error)
1217
GetTssKeyGenChannels() chan *p2p.Message
1318
GetTssCommonStruct() *common.TssCommon
1419
}
20+
21+
// Request request to do keygen
22+
type Request struct {
23+
Keys []string `json:"keys"`
24+
BlockHeight int64 `json:"block_height"`
25+
Version string `json:"tss_version"`
26+
Algo common.Algo `json:"algo,omitempty"`
27+
}
28+
29+
// NewRequest constructs Request.
30+
func NewRequest(keys []string, blockHeight int64, version string, algo common.Algo) Request {
31+
return Request{
32+
Keys: keys,
33+
BlockHeight: blockHeight,
34+
Version: version,
35+
Algo: algo,
36+
}
37+
}
38+
39+
// MsgID returns the hash of the request.
40+
func (r *Request) MsgID() (string, error) {
41+
var b bytes.Buffer
42+
43+
b.WriteString(r.Version)
44+
b.WriteByte(';')
45+
b.WriteString(string(r.Algo))
46+
b.WriteByte(';')
47+
b.WriteString(strings.Join(r.Keys, ","))
48+
49+
return common.MsgToHashString(b.Bytes())
50+
}
51+
52+
// Response keygen response
53+
type Response struct {
54+
Algo common.Algo `json:"algo"`
55+
PubKey string `json:"pub_key"`
56+
PoolAddress string `json:"pool_address"`
57+
Status common.Status `json:"status"`
58+
Blame blame.Blame `json:"blame"`
59+
}
60+
61+
// NewResponse create a new instance of keygen.Response
62+
func NewResponse(algo common.Algo, pk, addr string, status common.Status, blame blame.Blame) Response {
63+
return Response{
64+
Algo: algo,
65+
PubKey: pk,
66+
PoolAddress: addr,
67+
Status: status,
68+
Blame: blame,
69+
}
70+
}

keygen/request.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

keygen/response.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

keysign/ecdsa/tss_keysign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (tKeySign *TssKeySign) processKeySign(
288288
}
289289
}
290290

291-
return nil, blame.ErrTssTimeOut
291+
return nil, blame.ErrTimeoutTSS
292292
case msg := <-outCh:
293293
tKeySign.logger.Debug().Msgf(">>>>>>>>>>key sign msg: %s", msg.String())
294294
tKeySign.tssCommonStruct.GetBlameMgr().SetLastMsg(msg)

keysign/eddsa/tss_keysign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (tKeySign *KeySign) processKeySign(
287287
}
288288
}
289289

290-
return nil, blame.ErrTssTimeOut
290+
return nil, blame.ErrTimeoutTSS
291291
case msg := <-outCh:
292292
tKeySign.logger.Debug().Msgf(">>>>>>>>>>key sign msg: %s", msg.String())
293293
tKeySign.tssCommonStruct.GetBlameMgr().SetLastMsg(msg)

0 commit comments

Comments
 (0)