aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-04-06 10:34:00 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:55 +0800
commit7e0cf4521822a40db9cb9049fd5622be8d3a4e20 (patch)
tree1cbf8a907509d4515fff3dd8c6f3e53d3af9ac3a /vendor/github.com/dexon-foundation
parent9041a4c140f07e41ca35ee5fe09af5d54c1fa044 (diff)
downloadgo-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.tar
go-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.tar.gz
go-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.tar.bz2
go-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.tar.lz
go-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.tar.xz
go-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.tar.zst
go-tangerine-7e0cf4521822a40db9cb9049fd5622be8d3a4e20.zip
vendor: sync to latest core
Diffstat (limited to 'vendor/github.com/dexon-foundation')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go8
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/dkg.go64
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go2
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go2
4 files changed, 53 insertions, 23 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