github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/core/rawdb/accessors_data_prune.go (about)

     1  package rawdb
     2  
     3  import (
     4  	"encoding/binary"
     5  
     6  	"github.com/neatio-net/neatio/chain/log"
     7  	"github.com/neatio-net/neatio/neatdb"
     8  	"github.com/neatio-net/neatio/utilities/common"
     9  )
    10  
    11  // ReadDataPruneTrieRootHash retrieves the root hash of a data prune process trie
    12  func ReadDataPruneTrieRootHash(db neatdb.Reader, scan, prune uint64) common.Hash {
    13  	data, _ := db.Get(dataPruneNumberKey(scan, prune))
    14  	if len(data) == 0 {
    15  		return common.Hash{}
    16  	}
    17  	return common.BytesToHash(data)
    18  }
    19  
    20  // WriteCanonicalHash stores the hash assigned to a canonical block number.
    21  func WriteDataPruneTrieRootHash(db neatdb.Writer, hash common.Hash, scan, prune uint64) {
    22  	if err := db.Put(dataPruneNumberKey(scan, prune), hash.Bytes()); err != nil {
    23  		log.Crit("Failed to store number to hash mapping", "err", err)
    24  	}
    25  }
    26  
    27  // DeleteCanonicalHash removes the number to hash canonical mapping.
    28  func DeleteDataPruneTrieRootHash(db neatdb.Writer, scan, prune uint64) {
    29  	if err := db.Delete(dataPruneNumberKey(scan, prune)); err != nil {
    30  		log.Crit("Failed to delete number to hash mapping", "err", err)
    31  	}
    32  }
    33  
    34  // ReadHeadScanNumber retrieves the latest scaned number.
    35  func ReadHeadScanNumber(db neatdb.Reader) *uint64 {
    36  	data, _ := db.Get(headDataScanKey)
    37  	if len(data) != 8 {
    38  		return nil
    39  	}
    40  	number := binary.BigEndian.Uint64(data)
    41  	return &number
    42  }
    43  
    44  // WriteHeadScanNumber stores the number of the latest scaned block.
    45  func WriteHeadScanNumber(db neatdb.Writer, scan uint64) {
    46  	if err := db.Put(headDataScanKey, encodeBlockNumber(scan)); err != nil {
    47  		log.Crit("Failed to store last scan number", "err", err)
    48  	}
    49  }
    50  
    51  // ReadHeadPruneNumber retrieves the latest pruned number.
    52  func ReadHeadPruneNumber(db neatdb.Reader) *uint64 {
    53  	data, _ := db.Get(headDataPruneKey)
    54  	if len(data) != 8 {
    55  		return nil
    56  	}
    57  	number := binary.BigEndian.Uint64(data)
    58  	return &number
    59  }
    60  
    61  // WriteHeadPruneNumber stores the number of the latest pruned block.
    62  func WriteHeadPruneNumber(db neatdb.Writer, prune uint64) {
    63  	if err := db.Put(headDataPruneKey, encodeBlockNumber(prune)); err != nil {
    64  		log.Crit("Failed to store last prune number", "err", err)
    65  	}
    66  }