aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go7
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/dkg.go25
2 files changed, 22 insertions, 10 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
index e657c6449..adaf51d62 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
@@ -57,6 +57,8 @@ var (
"cannot verify block randomness")
)
+type selfAgreementResult types.AgreementResult
+
// consensusBAReceiver implements agreementReceiver.
type consensusBAReceiver struct {
consensus *Consensus
@@ -286,7 +288,8 @@ func (recv *consensusBAReceiver) ConfirmBlock(
IsEmptyBlock: isEmptyBlockConfirmed,
Randomness: block.Randomness,
}
- recv.consensus.baMgr.touchAgreementResult(result)
+ // touchAgreementResult does not support concurrent access.
+ recv.consensus.msgChan <- (*selfAgreementResult)(result)
recv.consensus.logger.Debug("Broadcast AgreementResult",
"result", result)
recv.consensus.network.BroadcastAgreementResult(result)
@@ -1217,6 +1220,8 @@ MessageLoop:
return
}
switch val := msg.(type) {
+ case *selfAgreementResult:
+ con.baMgr.touchAgreementResult((*types.AgreementResult)(val))
case *types.Block:
if ch, exist := func() (chan<- *types.Block, bool) {
con.lock.RLock()
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 b89ad100d..ab43f5130 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
@@ -450,11 +450,10 @@ func (prvs *PrivateKeyShares) Share(ID ID) (*PrivateKey, bool) {
// NewEmptyPublicKeyShares creates an empty public key shares.
func NewEmptyPublicKeyShares() *PublicKeyShares {
- cache := &publicKeySharesCache{
- index: make(map[ID]int),
- }
pubShares := &PublicKeyShares{}
- pubShares.cache.Store(cache)
+ pubShares.cache.Store(&publicKeySharesCache{
+ index: make(map[ID]int),
+ })
return pubShares
}
@@ -481,9 +480,9 @@ func (pubs *PublicKeyShares) Share(ID ID) (*PublicKey, error) {
}
// AddShare adds a share.
-func (pubs *PublicKeyShares) AddShare(ID ID, share *PublicKey) error {
+func (pubs *PublicKeyShares) AddShare(shareID ID, share *PublicKey) error {
cache := pubs.cache.Load().(*publicKeySharesCache)
- if idx, exist := cache.index[ID]; exist {
+ if idx, exist := cache.index[shareID]; exist {
if !share.publicKey.IsEqual(&cache.share[idx].publicKey) {
return ErrDuplicatedShare
}
@@ -492,9 +491,17 @@ func (pubs *PublicKeyShares) AddShare(ID ID, share *PublicKey) error {
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)
+ newCache := &publicKeySharesCache{
+ index: make(map[ID]int, len(cache.index)+1),
+ share: make([]PublicKey, len(cache.share), len(cache.share)+1),
+ }
+ for k, v := range cache.index {
+ newCache.index[k] = v
+ }
+ copy(newCache.share, cache.share)
+ newCache.index[shareID] = len(newCache.share)
+ newCache.share = append(newCache.share, *share)
+ pubs.cache.Store(newCache)
return nil
}