1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)
}
|