aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-18 10:02:30 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:19 +0800
commit70ab62c1b72c6fef8dd2c8e405d7f9823f70f475 (patch)
tree114f68dd0281d972b18e875c3f34a83af7d5962d /core
parentaa34cc1069a815ed66ec8fae0988fc4f29687bfd (diff)
downloadgo-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.tar
go-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.tar.gz
go-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.tar.bz2
go-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.tar.lz
go-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.tar.xz
go-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.tar.zst
go-tangerine-70ab62c1b72c6fef8dd2c8e405d7f9823f70f475.zip
vendor: sync to latest core (#91)
- Implement new methods in db to cache DKG private key. - Implement new methods in db to cache compaction chain tip.
Diffstat (limited to 'core')
-rw-r--r--core/rawdb/accessors_core_chain_tip.go49
-rw-r--r--core/rawdb/accessors_core_dkg_private_key.go48
-rw-r--r--core/rawdb/schema.go12
3 files changed, 108 insertions, 1 deletions
diff --git a/core/rawdb/accessors_core_chain_tip.go b/core/rawdb/accessors_core_chain_tip.go
new file mode 100644
index 000000000..95fa8854f
--- /dev/null
+++ b/core/rawdb/accessors_core_chain_tip.go
@@ -0,0 +1,49 @@
+package rawdb
+
+import (
+ "bytes"
+
+ coreCommon "github.com/dexon-foundation/dexon-consensus/common"
+ "github.com/dexon-foundation/dexon/log"
+ "github.com/dexon-foundation/dexon/rlp"
+)
+
+func ReadCoreCompactionChainTipRLP(db DatabaseReader) (rlp.RawValue, error) {
+ return db.Get(coreCompactionChainTipKey)
+}
+
+func WriteCoreCompactionChainTipRLP(db DatabaseWriter, rlp rlp.RawValue) error {
+ if err := db.Put(coreCompactionChainTipKey, rlp); err != nil {
+ log.Crit("Failed to store core compaction chain tip")
+ return err
+ }
+ return nil
+}
+
+func ReadCoreCompactionChainTip(db DatabaseReader) (coreCommon.Hash, uint64) {
+ data, err := ReadCoreCompactionChainTipRLP(db)
+ if err != nil {
+ return coreCommon.Hash{}, 0
+ }
+ v := struct {
+ Height uint64
+ Hash coreCommon.Hash
+ }{}
+ if err := rlp.Decode(bytes.NewReader(data), &v); err != nil {
+ log.Error("Invalid core compaction chain tip RLP", "err", err)
+ return coreCommon.Hash{}, 0
+ }
+ return v.Hash, v.Height
+}
+
+func WriteCoreCompactionChainTip(db DatabaseWriter, hash coreCommon.Hash, height uint64) error {
+ data, err := rlp.EncodeToBytes(&struct {
+ Height uint64
+ Hash coreCommon.Hash
+ }{height, hash})
+ if err != nil {
+ log.Crit("Failed to RLP encode core compaction chain tip", "err", err)
+ return err
+ }
+ return WriteCoreCompactionChainTipRLP(db, data)
+}
diff --git a/core/rawdb/accessors_core_dkg_private_key.go b/core/rawdb/accessors_core_dkg_private_key.go
new file mode 100644
index 000000000..ac51ca5ec
--- /dev/null
+++ b/core/rawdb/accessors_core_dkg_private_key.go
@@ -0,0 +1,48 @@
+package rawdb
+
+import (
+ "bytes"
+
+ coreDKG "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg"
+ "github.com/dexon-foundation/dexon/log"
+ "github.com/dexon-foundation/dexon/rlp"
+)
+
+func ReadCoreDKGPrivateKeyRLP(db DatabaseReader, round uint64) rlp.RawValue {
+ data, _ := db.Get(coreDKGPrivateKeyKey(round))
+ return data
+}
+
+func WriteCoreDKGPrivateKeyRLP(db DatabaseWriter, round uint64, rlp rlp.RawValue) error {
+ err := db.Put(coreDKGPrivateKeyKey(round), rlp)
+ if err != nil {
+ log.Crit("Failed to store core DKG private key", "err", err, "round", round)
+ }
+ return err
+}
+
+func HasCoreDKGPrivateKey(db DatabaseReader, round uint64) (bool, error) {
+ return db.Has(coreDKGPrivateKeyKey(round))
+}
+
+func ReadCoreDKGPrivateKey(db DatabaseReader, round uint64) *coreDKG.PrivateKey {
+ data := ReadCoreDKGPrivateKeyRLP(db, round)
+ if len(data) == 0 {
+ return nil
+ }
+ key := 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
+}
+
+func WriteCoreDKGPrivateKey(db DatabaseWriter, round uint64, key *coreDKG.PrivateKey) error {
+ data, err := rlp.EncodeToBytes(key)
+ if err != nil {
+ log.Crit("Failed to RLP encode core DKG private key", "round", round, "err", err)
+ return err
+ }
+ return WriteCoreDKGPrivateKeyRLP(db, round, data)
+}
diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go
index 9a820a578..87a56c0ba 100644
--- a/core/rawdb/schema.go
+++ b/core/rawdb/schema.go
@@ -53,7 +53,9 @@ var (
txLookupPrefix = []byte("l") // txLookupPrefix + hash -> transaction/receipt lookup metadata
bloomBitsPrefix = []byte("B") // bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash -> bloom bits
- coreBlockPrefix = []byte("D")
+ coreBlockPrefix = []byte("D")
+ coreDKGPrivateKeyPrefix = []byte("DPK")
+ coreCompactionChainTipKey = []byte("CoreChainTip")
preimagePrefix = []byte("secure-key-") // preimagePrefix + hash -> preimage
configPrefix = []byte("ethereum-config-") // config prefix for the db
@@ -120,6 +122,14 @@ func coreBlockKey(hash common.Hash) []byte {
return append(coreBlockPrefix, hash.Bytes()...)
}
+// coreDKGPrivateKeyKey = coreDKGPrivateKeyPrefix + round
+func coreDKGPrivateKeyKey(round uint64) []byte {
+ ret := make([]byte, len(coreDKGPrivateKeyPrefix)+8)
+ copy(ret, coreDKGPrivateKeyPrefix)
+ binary.LittleEndian.PutUint64(ret[len(coreDKGPrivateKeyPrefix):], round)
+ return ret
+}
+
// bloomBitsKey = bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash
func bloomBitsKey(bit uint, section uint64, hash common.Hash) []byte {
key := append(append(bloomBitsPrefix, make([]byte, 10)...), hash.Bytes()...)