Skip to content

Commit

Permalink
change schema names
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Oct 12, 2023
1 parent 5c9a9f1 commit a4c6350
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 100 deletions.
26 changes: 13 additions & 13 deletions chain/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (cdb *ChainDB) GetBestBlock() (*types.Block, error) {
}

func (cdb *ChainDB) loadChainData() error {
latestBytes := cdb.store.Get([]byte(schema.LatestKey))
latestBytes := cdb.store.Get([]byte(schema.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.GenesisKey), genesis.Bytes())
tx.Set([]byte(schema.Genesis), genesis.Bytes())
if totalBalance := genesis.TotalBalance(); totalBalance != nil {
tx.Set([]byte(schema.GenesisBalanceKey), totalBalance.Bytes())
tx.Set([]byte(schema.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.GenesisKey)); len(b) != 0 {
if b := cdb.Get([]byte(schema.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.GenesisBalanceKey)); len(v) != 0 {
if v := cdb.Get([]byte(schema.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.LatestKey), blockIdx)
dbtx.Set([]byte(schema.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.LatestKey), blockIdx)
bulk.Set([]byte(schema.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.LatestKey), newLatestIdx)
dbTx.Set([]byte(schema.Latest), newLatestIdx)

dbTx.Commit()

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

dbTx.Set([]byte(schema.ReOrgKey), val)
dbTx.Set([]byte(schema.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.ReOrgKey))
dbTx.Delete([]byte(schema.ReOrg))

dbTx.Commit()
}

func (cdb *ChainDB) getReorgMarker() (*ReorgMarker, error) {
data := cdb.store.Get([]byte(schema.ReOrgKey))
data := cdb.store.Get([]byte(schema.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.HardForkKey))
data := cdb.store.Get([]byte(schema.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.HardForkKey), data)
cdb.store.Set([]byte(schema.HardFork), data)
return nil
}
24 changes: 12 additions & 12 deletions chain/chaindbForRaft.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ func (cdb *ChainDB) ClearWAL() {
bulk.Delete(schema.KeyRaftEntry(i))
}

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

bulk.Flush()
}

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

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

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

// remove snapshot
dbTx.Delete([]byte(schema.RaftSnapKey))
dbTx.Delete([]byte(schema.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.RaftStateKey), data)
dbTx.Set([]byte(schema.RaftState), data)
dbTx.Commit()

return nil
}

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

if len(data) == 0 {
return nil, ErrWalNoHardState
Expand Down Expand Up @@ -225,7 +225,7 @@ 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.RaftEntryLastIdxKey), types.BlockNoToBytes(lastIdx))
dbTx.Set([]byte(schema.RaftEntryLastIdx), types.BlockNoToBytes(lastIdx))
}

func (cdb *ChainDB) GetRaftEntry(idx uint64) (*consensus.WalEntry, error) {
Expand Down Expand Up @@ -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.RaftEntryLastIdxKey))
lastBytes := cdb.store.Get([]byte(schema.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.RaftSnapKey), data)
dbTx.Set([]byte(schema.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.RaftSnapKey))
data := cdb.store.Get([]byte(schema.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.RaftIdentityKey), val.Bytes())
dbTx.Set([]byte(schema.RaftIdentity), val.Bytes())
dbTx.Commit()

return nil
}

func (cdb *ChainDB) GetIdentity() (*consensus.RaftIdentity, error) {
data := cdb.store.Get([]byte(schema.RaftIdentityKey))
data := cdb.store.Get([]byte(schema.RaftIdentity))
if len(data) == 0 {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion chain/recover.go
Original file line number Diff line number Diff line change
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.LatestKey), types.BlockNoToBytes(rm.BrBestNo))
bulk.Set([]byte(schema.Latest), types.BlockNoToBytes(rm.BrBestNo))
bulk.Flush()

cdb.setLatest(bestBlock)
Expand Down
6 changes: 3 additions & 3 deletions consensus/impl/dpos/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ func (ls *libStatus) save(tx consensus.TxWriter) error {
return err
}

tx.Set([]byte(schema.DposLibStatusKey), b)
tx.Set([]byte(schema.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.DposLibStatusKey))
tx.Delete([]byte(schema.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.DposLibStatusKey), pls); err != nil {
if err := bs.decodeStatus([]byte(schema.DposLibStatus), pls); err != nil {
return nil
}
pls.load(bs.best.BlockNo())
Expand Down
2 changes: 1 addition & 1 deletion contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func checkRedeploy(sender, receiver *state.V, contractState *state.ContractState
return newVmError(fmt.Errorf("not found contract %s", receiverAddr))
}
// get the contract creator
creator, err := contractState.GetData([]byte(schema.CreatorMetaKey))
creator, err := contractState.GetData([]byte(schema.CreatorMeta))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion contract/name/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func UpdateName(bs *state.BlockState, scs *state.ContractState, tx *types.TxBody
if err != nil {
return types.ErrTxInvalidRecipient
}
creator, err := contract.GetData([]byte(schema.CreatorMetaKey))
creator, err := contract.GetData([]byte(schema.CreatorMeta))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion contract/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ func Create(
}

// set the creator
err = contractState.SetData([]byte(schema.CreatorMetaKey), []byte(types.EncodeAddress(ctx.curContract.sender)))
err = contractState.SetData([]byte(schema.CreatorMeta), []byte(types.EncodeAddress(ctx.curContract.sender)))
if err != nil {
return "", nil, ctx.usedFee(), err
}
Expand Down
2 changes: 1 addition & 1 deletion contract/vm_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ func luaDeployContract(
}

// save the contract creator
err = contractState.SetData([]byte(schema.CreatorMetaKey), []byte(types.EncodeAddress(prevContractInfo.contractId)))
err = contractState.SetData([]byte(schema.CreatorMeta), []byte(types.EncodeAddress(prevContractInfo.contractId)))
if err != nil {
return -1, C.CString("[Contract.LuaDeployContract]:" + err.Error())
}
Expand Down
12 changes: 6 additions & 6 deletions types/schema/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ func KeyReceipts(blockHash []byte, blockNo types.BlockNo) []byte {

// raft
func KeyRaftEntry(blockNo types.BlockNo) []byte {
return append([]byte(RaftEntryPrefix), types.BlockNoToBytes(blockNo)...)
return append([]byte(RaftEntry), types.BlockNoToBytes(blockNo)...)
}

func KeyRaftEntryInvert(blockHash []byte) []byte {
return append([]byte(RaftEntryInvertPrefix), blockHash...)
return append([]byte(RaftEntryInvert), blockHash...)
}

func KeyRaftConfChangeProgress(id uint64) []byte {
return append([]byte(RaftConfChangeProgressPrefix), types.Uint64ToBytes(id)...)
return append([]byte(RaftConfChangeProgress), types.Uint64ToBytes(id)...)
}

// governance
func KeyEnterpriseConf(conf []byte) []byte {
// upper double check
return append([]byte(EnterpriseConfPrefix), bytes.ToUpper(conf)...)
return append([]byte(EnterpriseConf), bytes.ToUpper(conf)...)
}

func KeyName(name []byte) []byte {
// lower double check
return append([]byte(NamePrefix), bytes.ToLower(name)...)
return append([]byte(Name), bytes.ToLower(name)...)
}

func KeyParam(id []byte) []byte {
// upper double check
return append([]byte(SystemParamPrefix), bytes.ToUpper(id)...)
return append([]byte(SystemParam), bytes.ToUpper(id)...)
}

func KeyStaking(who []byte) []byte {
Expand Down
Loading

0 comments on commit a4c6350

Please sign in to comment.