aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2019-05-13 08:42:12 +0800
committerSonic <sonic@dexon.org>2019-05-13 08:42:12 +0800
commitad2e2dbf2115319c35b806abe823b8cf27e4e96e (patch)
tree8781caffb5070f74ae1612d66bc4a5041aa08cae
parent31f99d2c7da15226627ea71acd8bd55093c6e7f8 (diff)
downloaddexon-s-lds.tar.gz
dexon-s-lds.tar.zst
dexon-s-lds.zip
-rw-r--r--core/rawdb/accessors_chain.go14
-rw-r--r--core/rawdb/schema.go2
-rw-r--r--light/lightchain.go14
3 files changed, 30 insertions, 0 deletions
diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go
index 41a79b21d..6d6405d6e 100644
--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain.go
@@ -109,6 +109,20 @@ func WriteHeadFastBlockHash(db DatabaseWriter, hash common.Hash) {
}
}
+func ReadHeadGovStateHash(db DatabaseReader) common.Hash {
+ data, _ := db.Get(headGovStateKey)
+ if len(data) == 0 {
+ return common.Hash{}
+ }
+ return common.BytesToHash(data)
+}
+
+func WriteHeadGovStateHash(db DatabaseWriter) common.Hash {
+ if err := db.Put(headGovStateKey); err != nil {
+ log.Crit("Failed to store last gov state's header hash", "err", err)
+ }
+}
+
// ReadFastTrieProgress retrieves the number of tries nodes fast synced to allow
// reporting correct numbers across restarts.
func ReadFastTrieProgress(db DatabaseReader) uint64 {
diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go
index 5b92891df..cd7c1dbc9 100644
--- a/core/rawdb/schema.go
+++ b/core/rawdb/schema.go
@@ -38,6 +38,8 @@ var (
// headFastBlockKey tracks the latest known incomplete block's hash during fast sync.
headFastBlockKey = []byte("LastFast")
+ headGovStateKey = []byte("LastGovState")
+
// fastTrieProgressKey tracks the number of trie entries imported during fast sync.
fastTrieProgressKey = []byte("TrieSync")
diff --git a/light/lightchain.go b/light/lightchain.go
index ac04a9728..7028ed976 100644
--- a/light/lightchain.go
+++ b/light/lightchain.go
@@ -305,6 +305,20 @@ func (self *LightChain) GetBlockByNumber(ctx context.Context, number uint64) (*t
return self.GetBlock(ctx, hash, number)
}
+func (self *LightChain) CurrentGovState() *types.GovState {
+ hash := rawdb.ReadHeadGovStateHash(self.chainDb)
+ if hash == (common.Hash{}) {
+ log.Warn("Head gov state hash not found")
+ return nil
+ }
+ govState, err := self.GetGovStateByHash(hash)
+ if err != nil {
+ log.Warn("Get gov state by hash fail, err=%v", err)
+ return nil
+ }
+ return govState
+}
+
func (self *LightChain) GetGovStateByHash(hash common.Hash) (*types.GovState, error) {
header := self.GetHeaderByHash(hash)
if header == nil {