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 --- core/rawdb/accessors_core_dkg_private_key.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'core/rawdb') 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) -- cgit v1.2.3