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 /core | |
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 '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) |