Skip to content

Commit

Permalink
change package name ( schema -> dbkey )
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Oct 15, 2023
1 parent 0f973ad commit 6a35ad3
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 95 deletions.
38 changes: 19 additions & 19 deletions chain/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/aergoio/aergo/v2/internal/common"
"github.com/aergoio/aergo/v2/internal/enc"
"github.com/aergoio/aergo/v2/types"
"github.com/aergoio/aergo/v2/types/schema"
"github.com/aergoio/aergo/v2/types/dbkey"
"github.com/golang/protobuf/proto"
)

Expand Down Expand Up @@ -80,7 +80,7 @@ func (cdb *ChainDB) NewTx() db.Transaction {
func (cdb *ChainDB) Init(dbType string, dataDir string) error {
if cdb.store == nil {
logger.Info().Str("datadir", dataDir).Msg("chain database initialized")
dbPath := common.PathMkdirAll(dataDir, schema.ChainDBName)
dbPath := common.PathMkdirAll(dataDir, dbkey.ChainDBName)
cdb.store = db.NewDB(db.ImplType(dbType), dbPath)
}

Expand Down Expand Up @@ -215,7 +215,7 @@ func (cdb *ChainDB) GetBestBlock() (*types.Block, error) {
}

func (cdb *ChainDB) loadChainData() error {
latestBytes := cdb.store.Get([]byte(schema.Latest))
latestBytes := cdb.store.Get([]byte(dbkey.Latest))
if latestBytes == nil || len(latestBytes) == 0 {
return nil
}
Expand Down Expand Up @@ -292,9 +292,9 @@ func (cdb *ChainDB) addGenesisBlock(genesis *types.Genesis) error {
}

cdb.connectToChain(tx, block, false)
tx.Set([]byte(schema.Genesis), genesis.Bytes())
tx.Set([]byte(dbkey.Genesis), genesis.Bytes())
if totalBalance := genesis.TotalBalance(); totalBalance != nil {
tx.Set([]byte(schema.GenesisBalance), totalBalance.Bytes())
tx.Set([]byte(dbkey.GenesisBalance), totalBalance.Bytes())
}

tx.Commit()
Expand All @@ -308,7 +308,7 @@ func (cdb *ChainDB) addGenesisBlock(genesis *types.Genesis) error {

// GetGenesisInfo returns Genesis info, which is read from cdb.
func (cdb *ChainDB) GetGenesisInfo() *types.Genesis {
if b := cdb.Get([]byte(schema.Genesis)); len(b) != 0 {
if b := cdb.Get([]byte(dbkey.Genesis)); len(b) != 0 {
genesis := types.GetGenesisFromBytes(b)
if block, err := cdb.GetBlockByNo(0); err == nil {
genesis.SetBlock(block)
Expand All @@ -327,7 +327,7 @@ func (cdb *ChainDB) GetGenesisInfo() *types.Genesis {

}

if v := cdb.Get([]byte(schema.GenesisBalance)); len(v) != 0 {
if v := cdb.Get([]byte(dbkey.GenesisBalance)); len(v) != 0 {
genesis.SetTotalBalance(v)
}

Expand Down Expand Up @@ -359,7 +359,7 @@ func (cdb *ChainDB) connectToChain(dbtx db.Transaction, block *types.Block, skip
}

// Update best block hash
dbtx.Set([]byte(schema.Latest), blockIdx)
dbtx.Set([]byte(dbkey.Latest), blockIdx)
dbtx.Set(blockIdx, block.BlockHash())

// Save the last consensus status.
Expand Down Expand Up @@ -399,7 +399,7 @@ func (cdb *ChainDB) swapChainMapping(newBlocks []*types.Block) error {
bulk.Set(blockIdx, block.BlockHash())
}

bulk.Set([]byte(schema.Latest), blockIdx)
bulk.Set([]byte(dbkey.Latest), blockIdx)

// Save the last consensus status.
cdb.cc.Save(bulk)
Expand Down Expand Up @@ -531,7 +531,7 @@ func (cdb *ChainDB) dropBlock(dropNo types.BlockNo) error {
dbTx.Delete(dropIdx)

// update latest
dbTx.Set([]byte(schema.Latest), newLatestIdx)
dbTx.Set([]byte(dbkey.Latest), newLatestIdx)

dbTx.Commit()

Expand Down Expand Up @@ -645,7 +645,7 @@ func (cdb *ChainDB) getReceipt(blockHash []byte, blockNo types.BlockNo, idx int3

func (cdb *ChainDB) getReceipts(blockHash []byte, blockNo types.BlockNo,
hardForkConfig *config.HardforkConfig) (*types.Receipts, error) {
data := cdb.store.Get(schema.ReceiptsKey(blockHash, blockNo))
data := cdb.store.Get(dbkey.ReceiptsKey(blockHash, blockNo))
if len(data) == 0 {
return nil, errors.New("cannot find a receipt")
}
Expand All @@ -661,7 +661,7 @@ func (cdb *ChainDB) getReceipts(blockHash []byte, blockNo types.BlockNo,
}

func (cdb *ChainDB) checkExistReceipts(blockHash []byte, blockNo types.BlockNo) bool {
data := cdb.store.Get(schema.ReceiptsKey(blockHash, blockNo))
data := cdb.store.Get(dbkey.ReceiptsKey(blockHash, blockNo))
if len(data) == 0 {
return false
}
Expand Down Expand Up @@ -702,13 +702,13 @@ func (cdb *ChainDB) writeReceipts(blockHash []byte, blockNo types.BlockNo, recei
gobEncoder := gob.NewEncoder(&val)
gobEncoder.Encode(receipts)

dbTx.Set(schema.ReceiptsKey(blockHash, blockNo), val.Bytes())
dbTx.Set(dbkey.ReceiptsKey(blockHash, blockNo), val.Bytes())

dbTx.Commit()
}

func (cdb *ChainDB) deleteReceipts(dbTx *db.Transaction, blockHash []byte, blockNo types.BlockNo) {
(*dbTx).Delete(schema.ReceiptsKey(blockHash, blockNo))
(*dbTx).Delete(dbkey.ReceiptsKey(blockHash, blockNo))
}

func (cdb *ChainDB) writeReorgMarker(marker *ReorgMarker) error {
Expand All @@ -721,7 +721,7 @@ func (cdb *ChainDB) writeReorgMarker(marker *ReorgMarker) error {
return err
}

dbTx.Set([]byte(schema.ReOrg), val)
dbTx.Set([]byte(dbkey.ReOrg), val)

dbTx.Commit()
return nil
Expand All @@ -731,13 +731,13 @@ func (cdb *ChainDB) deleteReorgMarker() {
dbTx := cdb.store.NewTx()
defer dbTx.Discard()

dbTx.Delete([]byte(schema.ReOrg))
dbTx.Delete([]byte(dbkey.ReOrg))

dbTx.Commit()
}

func (cdb *ChainDB) getReorgMarker() (*ReorgMarker, error) {
data := cdb.store.Get([]byte(schema.ReOrg))
data := cdb.store.Get([]byte(dbkey.ReOrg))
if len(data) == 0 {
return nil, nil
}
Expand All @@ -759,7 +759,7 @@ func (cdb *ChainDB) IsNew() bool {

func (cdb *ChainDB) Hardfork(hConfig config.HardforkConfig) config.HardforkDbConfig {
var c config.HardforkDbConfig
data := cdb.store.Get([]byte(schema.HardFork))
data := cdb.store.Get([]byte(dbkey.HardFork))
if len(data) == 0 {
return c
}
Expand All @@ -777,6 +777,6 @@ func (cdb *ChainDB) WriteHardfork(c *config.HardforkConfig) error {
if err != nil {
return err
}
cdb.store.Set([]byte(schema.HardFork), data)
cdb.store.Set([]byte(dbkey.HardFork), data)
return nil
}
42 changes: 21 additions & 21 deletions chain/chaindbForRaft.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aergoio/aergo-lib/db"
"github.com/aergoio/aergo/v2/consensus"
"github.com/aergoio/aergo/v2/types"
"github.com/aergoio/aergo/v2/types/schema"
"github.com/aergoio/aergo/v2/types/dbkey"
"github.com/aergoio/etcd/raft/raftpb"
"github.com/golang/protobuf/proto"
)
Expand Down Expand Up @@ -86,24 +86,24 @@ func (cdb *ChainDB) ClearWAL() {
defer bulk.DiscardLast()

for i := lastIdx; i >= 1; i-- {
bulk.Delete(schema.RaftEntryKey(i))
bulk.Delete(dbkey.RaftEntryKey(i))
}

bulk.Delete([]byte(schema.RaftEntryLastIdx))
bulk.Delete([]byte(dbkey.RaftEntryLastIdx))

bulk.Flush()
}

dbTx := cdb.store.NewTx()
defer dbTx.Discard()

dbTx.Delete([]byte(schema.RaftIdentity))
dbTx.Delete([]byte(dbkey.RaftIdentity))
// remove hardstate

dbTx.Delete([]byte(schema.RaftState))
dbTx.Delete([]byte(dbkey.RaftState))

// remove snapshot
dbTx.Delete([]byte(schema.RaftSnap))
dbTx.Delete([]byte(dbkey.RaftSnap))

logger.Debug().Msg("reset identify, hardstate, snapshot from datafiles")

Expand All @@ -130,14 +130,14 @@ func (cdb *ChainDB) WriteHardState(hardstate *raftpb.HardState) error {
if data, err = proto.Marshal(hardstate); err != nil {
logger.Panic().Msg("failed to marshal raft state")
}
dbTx.Set([]byte(schema.RaftState), data)
dbTx.Set([]byte(dbkey.RaftState), data)
dbTx.Commit()

return nil
}

func (cdb *ChainDB) GetHardState() (*raftpb.HardState, error) {
data := cdb.store.Get([]byte(schema.RaftState))
data := cdb.store.Get([]byte(dbkey.RaftState))

if len(data) == 0 {
return nil, ErrWalNoHardState
Expand Down Expand Up @@ -172,7 +172,7 @@ func (cdb *ChainDB) WriteRaftEntry(ents []*consensus.WalEntry, blocks []*types.B

for i := ents[0].Index; i <= last; i++ {
// delete ents[0].Index ~ lastIndex of wal
dbTx.Delete(schema.RaftEntryKey(i))
dbTx.Delete(dbkey.RaftEntryKey(i))
}
}

Expand All @@ -192,11 +192,11 @@ func (cdb *ChainDB) WriteRaftEntry(ents []*consensus.WalEntry, blocks []*types.B
}

lastIdx = entry.Index
dbTx.Set(schema.RaftEntryKey(entry.Index), data)
dbTx.Set(dbkey.RaftEntryKey(entry.Index), data)

// invert key to search raft entry corresponding to block hash
if entry.Type == consensus.EntryBlock {
dbTx.Set(schema.RaftEntryInvertKey(blocks[i].BlockHash()), types.Uint64ToBytes(entry.Index))
dbTx.Set(dbkey.RaftEntryInvertKey(blocks[i].BlockHash()), types.Uint64ToBytes(entry.Index))
}

if entry.Type == consensus.EntryConfChange {
Expand Down Expand Up @@ -225,11 +225,11 @@ func (cdb *ChainDB) WriteRaftEntry(ents []*consensus.WalEntry, blocks []*types.B
func (cdb *ChainDB) writeRaftEntryLastIndex(dbTx db.Transaction, lastIdx uint64) {
logger.Debug().Uint64("index", lastIdx).Msg("set last wal entry")

dbTx.Set([]byte(schema.RaftEntryLastIdx), types.BlockNoToBytes(lastIdx))
dbTx.Set([]byte(dbkey.RaftEntryLastIdx), types.BlockNoToBytes(lastIdx))
}

func (cdb *ChainDB) GetRaftEntry(idx uint64) (*consensus.WalEntry, error) {
data := cdb.store.Get(schema.RaftEntryKey(idx))
data := cdb.store.Get(dbkey.RaftEntryKey(idx))
if len(data) == 0 {
return nil, ErrNoWalEntry
}
Expand All @@ -251,7 +251,7 @@ func (cdb *ChainDB) GetRaftEntry(idx uint64) (*consensus.WalEntry, error) {
}

func (cdb *ChainDB) GetRaftEntryIndexOfBlock(hash []byte) (uint64, error) {
data := cdb.store.Get(schema.RaftEntryInvertKey(hash))
data := cdb.store.Get(dbkey.RaftEntryInvertKey(hash))
if len(data) == 0 {
return 0, ErrNoWalEntryForBlock
}
Expand All @@ -274,7 +274,7 @@ func (cdb *ChainDB) GetRaftEntryOfBlock(hash []byte) (*consensus.WalEntry, error
}

func (cdb *ChainDB) GetRaftEntryLastIdx() (uint64, error) {
lastBytes := cdb.store.Get([]byte(schema.RaftEntryLastIdx))
lastBytes := cdb.store.Get([]byte(dbkey.RaftEntryLastIdx))
if lastBytes == nil || len(lastBytes) == 0 {
return 0, nil
}
Expand Down Expand Up @@ -364,7 +364,7 @@ func (cdb *ChainDB) WriteSnapshot(snap *raftpb.Snapshot) error {
}

dbTx := cdb.store.NewTx()
dbTx.Set([]byte(schema.RaftSnap), data)
dbTx.Set([]byte(dbkey.RaftSnap), data)
dbTx.Commit()

return nil
Expand Down Expand Up @@ -400,7 +400,7 @@ func (cdb *ChainDB) WriteSnapshot(snap *raftpb.Snapshot) error {
*/

func (cdb *ChainDB) GetSnapshot() (*raftpb.Snapshot, error) {
data := cdb.store.Get([]byte(schema.RaftSnap))
data := cdb.store.Get([]byte(dbkey.RaftSnap))
if len(data) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -432,14 +432,14 @@ func (cdb *ChainDB) WriteIdentity(identity *consensus.RaftIdentity) error {
return ErrEncodeRaftIdentity
}

dbTx.Set([]byte(schema.RaftIdentity), val.Bytes())
dbTx.Set([]byte(dbkey.RaftIdentity), val.Bytes())
dbTx.Commit()

return nil
}

func (cdb *ChainDB) GetIdentity() (*consensus.RaftIdentity, error) {
data := cdb.store.Get([]byte(schema.RaftIdentity))
data := cdb.store.Get([]byte(dbkey.RaftIdentity))
if len(data) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -485,13 +485,13 @@ func (cdb *ChainDB) writeConfChangeProgress(dbTx db.Transaction, id uint64, prog
return err
}

dbTx.Set(schema.RaftConfChangeProgressKey(id), data)
dbTx.Set(dbkey.RaftConfChangeProgressKey(id), data)

return nil
}

func (cdb *ChainDB) GetConfChangeProgress(id uint64) (*types.ConfChangeProgress, error) {
data := cdb.store.Get(schema.RaftConfChangeProgressKey(id))
data := cdb.store.Get(dbkey.RaftConfChangeProgressKey(id))
if len(data) == 0 {
return nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions chain/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/aergoio/aergo/v2/pkg/component"
"github.com/aergoio/aergo/v2/state"
"github.com/aergoio/aergo/v2/types"
"github.com/aergoio/aergo/v2/types/schema"
"github.com/aergoio/aergo/v2/types/dbkey"
lru "github.com/hashicorp/golang-lru"
)

Expand Down Expand Up @@ -567,7 +567,7 @@ func (cs *ChainService) getNameInfo(qname string, blockNo types.BlockNo) (*types

func (cs *ChainService) getEnterpriseConf(key string) (*types.EnterpriseConfig, error) {
sdb := cs.sdb.OpenNewStateDB(cs.sdb.GetRoot())
if strings.ToUpper(key) != schema.EnterpriseAdmins {
if strings.ToUpper(key) != dbkey.EnterpriseAdmins {
return enterprise.GetConf(sdb, key)
}
return enterprise.GetAdmin(sdb)
Expand Down
4 changes: 2 additions & 2 deletions chain/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/aergoio/aergo/v2/internal/enc"
"github.com/aergoio/aergo/v2/types"
"github.com/aergoio/aergo/v2/types/schema"
"github.com/aergoio/aergo/v2/types/dbkey"
)

var (
Expand Down Expand Up @@ -192,7 +192,7 @@ func (rm *ReorgMarker) RecoverChainMapping(cdb *ChainDB) error {

logger.Info().Uint64("bestno", rm.BrBestNo).Msg("update best block")

bulk.Set([]byte(schema.Latest), types.BlockNoToBytes(rm.BrBestNo))
bulk.Set([]byte(dbkey.Latest), types.BlockNoToBytes(rm.BrBestNo))
bulk.Flush()

cdb.setLatest(bestBlock)
Expand Down
8 changes: 4 additions & 4 deletions consensus/impl/dpos/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/aergoio/aergo/v2/internal/common"
"github.com/aergoio/aergo/v2/p2p/p2pkey"
"github.com/aergoio/aergo/v2/types"
"github.com/aergoio/aergo/v2/types/schema"
"github.com/aergoio/aergo/v2/types/dbkey"
"github.com/davecgh/go-spew/spew"
)

Expand Down Expand Up @@ -240,15 +240,15 @@ func (ls *libStatus) save(tx consensus.TxWriter) error {
return err
}

tx.Set([]byte(schema.DposLibStatus), b)
tx.Set([]byte(dbkey.DposLibStatus), b)

logger.Debug().Int("proposed lib len", len(ls.Prpsd)).Msg("lib status stored to DB")

return nil
}

func reset(tx db.Transaction) {
tx.Delete([]byte(schema.DposLibStatus))
tx.Delete([]byte(dbkey.DposLibStatus))
}

func (ls *libStatus) gc(bps []string) {
Expand Down Expand Up @@ -383,7 +383,7 @@ func newConfirmInfo(block *types.Block, confirmsRequired uint16) *confirmInfo {

func (bs *bootLoader) loadLibStatus() *libStatus {
pls := newLibStatus(bs.confirmsRequired)
if err := bs.decodeStatus([]byte(schema.DposLibStatus), pls); err != nil {
if err := bs.decodeStatus([]byte(dbkey.DposLibStatus), pls); err != nil {
return nil
}
pls.load(bs.best.BlockNo())
Expand Down
Loading

0 comments on commit 6a35ad3

Please sign in to comment.