diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-11 09:02:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-11 09:02:21 +0800 |
commit | f1ed7d074fe1d574a84c308c6ad878dc2d153654 (patch) | |
tree | 25a6fd9088ac34c7f0ffdf8ec4d48b26bf6ae70e /core | |
parent | 675a9441784b14ee4bd996832c4431adc291c5af (diff) | |
download | dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.tar dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.tar.gz dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.tar.bz2 dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.tar.lz dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.tar.xz dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.tar.zst dexon-f1ed7d074fe1d574a84c308c6ad878dc2d153654.zip |
core: add reset to dkg private key db (#355)
* vendor: sync to latest core
* core: dkg private key db
Diffstat (limited to 'core')
-rw-r--r-- | core/rawdb/accessors_core_dkg_private_key.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/core/rawdb/accessors_core_dkg_private_key.go b/core/rawdb/accessors_core_dkg_private_key.go index ac51ca5ec..036e311aa 100644 --- a/core/rawdb/accessors_core_dkg_private_key.go +++ b/core/rawdb/accessors_core_dkg_private_key.go @@ -8,6 +8,11 @@ import ( "github.com/dexon-foundation/dexon/rlp" ) +type dkgPrivateKey struct { + PK *coreDKG.PrivateKey + Reset uint64 +} + func ReadCoreDKGPrivateKeyRLP(db DatabaseReader, round uint64) rlp.RawValue { data, _ := db.Get(coreDKGPrivateKeyKey(round)) return data @@ -21,24 +26,29 @@ func WriteCoreDKGPrivateKeyRLP(db DatabaseWriter, round uint64, rlp rlp.RawValue return err } -func HasCoreDKGPrivateKey(db DatabaseReader, round uint64) (bool, error) { - return db.Has(coreDKGPrivateKeyKey(round)) -} - -func ReadCoreDKGPrivateKey(db DatabaseReader, round uint64) *coreDKG.PrivateKey { +func ReadCoreDKGPrivateKey(db DatabaseReader, round, reset uint64) *coreDKG.PrivateKey { data := ReadCoreDKGPrivateKeyRLP(db, round) if len(data) == 0 { return nil } - key := new(coreDKG.PrivateKey) + key := &dkgPrivateKey{ + PK: new(coreDKG.PrivateKey), + } if err := rlp.Decode(bytes.NewReader(data), key); err != nil { log.Error("Invalid core DKG private key RLP", "round", round, "err", err) return nil } - return key + if key.Reset != reset { + return nil + } + return key.PK } -func WriteCoreDKGPrivateKey(db DatabaseWriter, round uint64, key *coreDKG.PrivateKey) error { +func WriteCoreDKGPrivateKey(db DatabaseWriter, round, reset uint64, pk *coreDKG.PrivateKey) error { + key := &dkgPrivateKey{ + PK: pk, + Reset: reset, + } data, err := rlp.EncodeToBytes(key) if err != nil { log.Crit("Failed to RLP encode core DKG private key", "round", round, "err", err) |