From f1ed7d074fe1d574a84c308c6ad878dc2d153654 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Thu, 11 Apr 2019 09:02:21 +0800 Subject: core: add reset to dkg private key db (#355) * vendor: sync to latest core * core: dkg private key db --- dex/db/db.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'dex') diff --git a/dex/db/db.go b/dex/db/db.go index 2930400b2..5cb809055 100644 --- a/dex/db/db.go +++ b/dex/db/db.go @@ -69,27 +69,24 @@ func (d *DB) PutBlock(block coreTypes.Block) error { return nil } -func (d *DB) HasDKGPrivateKey(round uint64) (bool, error) { - return rawdb.HasCoreDKGPrivateKey(d.db, round) -} - -func (d *DB) GetDKGPrivateKey(round uint64) (coreDKG.PrivateKey, error) { - key := rawdb.ReadCoreDKGPrivateKey(d.db, round) +func (d *DB) GetDKGPrivateKey(round, reset uint64) (coreDKG.PrivateKey, error) { + key := rawdb.ReadCoreDKGPrivateKey(d.db, round, reset) if key == nil { return coreDKG.PrivateKey{}, coreDb.ErrDKGPrivateKeyDoesNotExist } return *key, nil } -func (d *DB) PutDKGPrivateKey(round uint64, key coreDKG.PrivateKey) error { - has, err := d.HasDKGPrivateKey(round) - if err != nil { - return err - } - if has { +func (d *DB) PutDKGPrivateKey(round, reset uint64, key coreDKG.PrivateKey) error { + _, err := d.GetDKGPrivateKey(round, reset) + if err == nil { return coreDb.ErrDKGPrivateKeyExists } - return rawdb.WriteCoreDKGPrivateKey(d.db, round, &key) + if err != coreDb.ErrDKGPrivateKeyDoesNotExist { + return err + } + + return rawdb.WriteCoreDKGPrivateKey(d.db, round, reset, &key) } func (d *DB) PutCompactionChainTipInfo(hash coreCommon.Hash, height uint64) error { -- cgit v1.2.3