From 01f837cabe728108ceaa008308ea63473f5025bd Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Sat, 6 Apr 2019 10:34:00 +0800 Subject: vendor: sync to latest core --- .../dexon-consensus/core/agreement-mgr.go | 8 +++ .../dexon-consensus/core/crypto/dkg/dkg.go | 64 +++++++++++++++------- .../dexon-consensus/core/dkg-tsig-protocol.go | 2 +- .../dexon-consensus/core/types/dkg/dkg.go | 2 +- vendor/vendor.json | 46 ++++++++-------- 5 files changed, 76 insertions(+), 46 deletions(-) diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go index 582a72e7d..4e6f230dc 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go @@ -578,6 +578,14 @@ Loop: } default: } + if !mgr.recv.isNotary { + select { + case <-setting.ticker.Tick(): + continue Loop + case <-mgr.ctx.Done(): + break Loop + } + } if err = agr.nextState(); err != nil { mgr.logger.Error("Failed to proceed to next state", "nodeID", mgr.ID.String(), diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/dkg.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/dkg.go index 796609dc9..b89ad100d 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/dkg.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/dkg.go @@ -21,6 +21,8 @@ import ( "encoding/json" "fmt" "io" + "sync" + "sync/atomic" "github.com/dexon-foundation/bls/ffi/go/bls" "github.com/dexon-foundation/dexon/rlp" @@ -210,23 +212,30 @@ func (prvs *PrivateKeyShares) DecodeRLP(s *rlp.Stream) error { return nil } +type publicKeySharesCache struct { + share []PublicKey + index map[ID]int +} + // PublicKeyShares represents a public key shares for DKG protocol. type PublicKeyShares struct { - shareCaches []PublicKey - shareCacheIndex map[ID]int + cache atomic.Value + lock sync.Mutex masterPublicKey []bls.PublicKey } // Equal checks equality of two PublicKeyShares instance. func (pubs *PublicKeyShares) Equal(other *PublicKeyShares) bool { + cache := pubs.cache.Load().(*publicKeySharesCache) + cacheOther := other.cache.Load().(*publicKeySharesCache) // Check shares. - for dID, idx := range pubs.shareCacheIndex { - otherIdx, exists := other.shareCacheIndex[dID] + for dID, idx := range cache.index { + otherIdx, exists := cacheOther.index[dID] if !exists { continue } - if !pubs.shareCaches[idx].publicKey.IsEqual( - &other.shareCaches[otherIdx].publicKey) { + if !cache.share[idx].publicKey.IsEqual( + &cacheOther.share[otherIdx].publicKey) { return false } } @@ -267,7 +276,7 @@ func (pubs *PublicKeyShares) DecodeRLP(s *rlp.Stream) error { ps.masterPublicKey = append(ps.masterPublicKey, key) } - *pubs = *ps + *pubs = *ps.Move() return nil } @@ -349,13 +358,12 @@ func NewPrivateKeyShares(t int) (*PrivateKeyShares, *PublicKeyShares) { prv.SetByCSPRNG() msk := prv.GetMasterSecretKey(t) mpk := bls.GetMasterPublicKey(msk) + pubShare := NewEmptyPublicKeyShares() + pubShare.masterPublicKey = mpk return &PrivateKeyShares{ - masterPrivateKey: msk, - shareIndex: make(map[ID]int), - }, &PublicKeyShares{ - shareCacheIndex: make(map[ID]int), - masterPublicKey: mpk, - } + masterPrivateKey: msk, + shareIndex: make(map[ID]int), + }, pubShare } // NewEmptyPrivateKeyShares creates an empty private key shares. @@ -442,16 +450,25 @@ func (prvs *PrivateKeyShares) Share(ID ID) (*PrivateKey, bool) { // NewEmptyPublicKeyShares creates an empty public key shares. func NewEmptyPublicKeyShares() *PublicKeyShares { - return &PublicKeyShares{ - shareCacheIndex: make(map[ID]int), + cache := &publicKeySharesCache{ + index: make(map[ID]int), } + pubShares := &PublicKeyShares{} + pubShares.cache.Store(cache) + return pubShares +} + +// Move will invalidate itself. Do not access to original reference. +func (pubs *PublicKeyShares) Move() *PublicKeyShares { + return pubs } // Share returns the share for the ID. func (pubs *PublicKeyShares) Share(ID ID) (*PublicKey, error) { - idx, exist := pubs.shareCacheIndex[ID] + cache := pubs.cache.Load().(*publicKeySharesCache) + idx, exist := cache.index[ID] if exist { - return &pubs.shareCaches[idx], nil + return &cache.share[idx], nil } var pk PublicKey if err := pk.publicKey.Set(pubs.masterPublicKey, &ID); err != nil { @@ -465,14 +482,19 @@ func (pubs *PublicKeyShares) Share(ID ID) (*PublicKey, error) { // AddShare adds a share. func (pubs *PublicKeyShares) AddShare(ID ID, share *PublicKey) error { - if idx, exist := pubs.shareCacheIndex[ID]; exist { - if !share.publicKey.IsEqual(&pubs.shareCaches[idx].publicKey) { + cache := pubs.cache.Load().(*publicKeySharesCache) + if idx, exist := cache.index[ID]; exist { + if !share.publicKey.IsEqual(&cache.share[idx].publicKey) { return ErrDuplicatedShare } return nil } - pubs.shareCacheIndex[ID] = len(pubs.shareCaches) - pubs.shareCaches = append(pubs.shareCaches, *share) + pubs.lock.Lock() + defer pubs.lock.Unlock() + cache = pubs.cache.Load().(*publicKeySharesCache) + cache.index[ID] = len(cache.share) + cache.share = append(cache.share, *share) + pubs.cache.Store(cache) return nil } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go index e4ae14c2c..0612bda4b 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go @@ -230,7 +230,7 @@ func newDKGProtocol( Round: round, Reset: reset, DKGID: typesDKG.NewID(ID), - PublicKeyShares: *pubShare, + PublicKeyShares: *pubShare.Move(), }) return &dkgProtocol{ diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go index e9b22bcb0..868f0da17 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go @@ -130,7 +130,7 @@ func (d *MasterPublicKey) DecodeRLP(s *rlp.Stream) error { Round: dec.Round, Reset: dec.Reset, DKGID: id, - PublicKeyShares: *dec.PublicKeyShares, + PublicKeyShares: *dec.PublicKeyShares.Move(), Signature: dec.Signature, } return err diff --git a/vendor/vendor.json b/vendor/vendor.json index b0334bc4b..c83f22117 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -141,16 +141,16 @@ { "checksumSHA1": "In6vBHYUsX7DUIGiFN2hQggBgvI=", "path": "github.com/dexon-foundation/dexon-consensus/common", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { - "checksumSHA1": "7V+3tAuEC/s/sgOU2AxH/J6iMd0=", + "checksumSHA1": "IlhmhtgzSWYb1GTPVpYXHUMkSwM=", "path": "github.com/dexon-foundation/dexon-consensus/core", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, @@ -165,64 +165,64 @@ { "checksumSHA1": "tQSbYCu5P00lUhKsx3IbBZCuSLY=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { - "checksumSHA1": "mMdctxTa/jNwAwZjjYoyEZdLoF8=", + "checksumSHA1": "mayhQ9KxdXeuzyssXiG5yW4ynGU=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { "checksumSHA1": "BhLKK8RveoLaeXc9UyUKMwQqchU=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { "checksumSHA1": "hj/KetWUHp+1CX+50V0QnCthfWc=", "path": "github.com/dexon-foundation/dexon-consensus/core/db", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { "checksumSHA1": "DILLD61kp1c3JZnyLZK84mMK9Jw=", "path": "github.com/dexon-foundation/dexon-consensus/core/syncer", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { "checksumSHA1": "zIgCdN4FJiAuPGMhB+/9YGK/Wgk=", "path": "github.com/dexon-foundation/dexon-consensus/core/types", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { - "checksumSHA1": "QVeatfLQUBE8/vwjvVImyQiTijE=", + "checksumSHA1": "lbG7yqVgzo2CV/CQPYjG78xp5jg=", "path": "github.com/dexon-foundation/dexon-consensus/core/types/dkg", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, { "checksumSHA1": "YooeNHTYxH05Ky5vnoyZsQR4/08=", "path": "github.com/dexon-foundation/dexon-consensus/core/utils", - "revision": "1ebfe09074d9eb80ae6a3380d1b706035fd4c9c9", - "revisionTime": "2019-04-03T07:55:43Z", + "revision": "d433231363d622acb26f8fa9b072470c179dbc62", + "revisionTime": "2019-04-04T14:16:31Z", "version": "single-chain", "versionExact": "single-chain" }, -- cgit