diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-11 09:02:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-15 22:09:55 +0800 |
commit | 42577929821c56994da7a950f9646ac3f54ce4c6 (patch) | |
tree | e9860bd074ec5aa87508c39ad7a68ba630c57d83 /vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go | |
parent | e9798937a5978224bc54dd5627bdfa5b9ca3340f (diff) | |
download | go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.tar go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.tar.gz go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.tar.bz2 go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.tar.lz go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.tar.xz go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.tar.zst go-tangerine-42577929821c56994da7a950f9646ac3f54ce4c6.zip |
core: add reset to dkg private key db (#355)
* vendor: sync to latest core
* core: dkg private key db
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go index 971f758d5..6555de855 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go @@ -49,7 +49,7 @@ type MemBackedDB struct { compactionChainTipHash common.Hash compactionChainTipHeight uint64 dkgPrivateKeysLock sync.RWMutex - dkgPrivateKeys map[uint64]*dkg.PrivateKey + dkgPrivateKeys map[uint64]*dkgPrivateKey dkgProtocolLock sync.RWMutex dkgProtocolInfo *DKGProtocolInfo persistantFilePath string @@ -61,7 +61,7 @@ func NewMemBackedDB(persistantFilePath ...string) ( dbInst = &MemBackedDB{ blockHashSequence: common.Hashes{}, blocksByHash: make(map[common.Hash]*types.Block), - dkgPrivateKeys: make(map[uint64]*dkg.PrivateKey), + dkgPrivateKeys: make(map[uint64]*dkgPrivateKey), } if len(persistantFilePath) == 0 || len(persistantFilePath[0]) == 0 { return @@ -168,34 +168,29 @@ func (m *MemBackedDB) GetCompactionChainTipInfo() ( return m.compactionChainTipHash, m.compactionChainTipHeight } -// HasDKGPrivateKey check existence of DKG private key of one round. -func (m *MemBackedDB) HasDKGPrivateKey(round uint64) (bool, error) { - m.dkgPrivateKeysLock.RLock() - defer m.dkgPrivateKeysLock.RUnlock() - _, exists := m.dkgPrivateKeys[round] - return exists, nil -} - // GetDKGPrivateKey get DKG private key of one round. -func (m *MemBackedDB) GetDKGPrivateKey(round uint64) ( +func (m *MemBackedDB) GetDKGPrivateKey(round, reset uint64) ( dkg.PrivateKey, error) { m.dkgPrivateKeysLock.RLock() defer m.dkgPrivateKeysLock.RUnlock() - if prv, exists := m.dkgPrivateKeys[round]; exists { - return *prv, nil + if prv, exists := m.dkgPrivateKeys[round]; exists && prv.Reset == reset { + return prv.PK, nil } return dkg.PrivateKey{}, ErrDKGPrivateKeyDoesNotExist } // PutDKGPrivateKey save DKG private key of one round. func (m *MemBackedDB) PutDKGPrivateKey( - round uint64, prv dkg.PrivateKey) error { + round, reset uint64, prv dkg.PrivateKey) error { m.dkgPrivateKeysLock.Lock() defer m.dkgPrivateKeysLock.Unlock() - if _, exists := m.dkgPrivateKeys[round]; exists { + if prv, exists := m.dkgPrivateKeys[round]; exists && prv.Reset == reset { return ErrDKGPrivateKeyExists } - m.dkgPrivateKeys[round] = &prv + m.dkgPrivateKeys[round] = &dkgPrivateKey{ + PK: prv, + Reset: reset, + } return nil } |