Skip to content

Commit

Permalink
Merge pull request #572 from lochjin/dev1.2
Browse files Browse the repository at this point in the history
BUG:Missing index info for genesis transactions
  • Loading branch information
dindinw authored Nov 15, 2023
2 parents 3d91a4f + 525d3f2 commit 9535974
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
5 changes: 5 additions & 0 deletions core/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ func (b *BlockChain) createChainState() error {
if err != nil {
return err
}
// genesis tx index
err = b.DB().PutTxIdxEntrys(genesisBlock, ib)
if err != nil {
return err
}
return b.bd.Commit()
}

Expand Down
4 changes: 0 additions & 4 deletions database/chaindb/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,6 @@ func (cdb *ChainDB) DeleteEstimateFee() error {
return rawdb.DeleteEstimateFee(cdb.db)
}

func (cdb *ChainDB) TryUpgrade(di *common.DatabaseInfo, interrupt <-chan struct{}) error {
return nil
}

func (cdb *ChainDB) StartTrack(info string) error {
if cdb.diff != nil {
return nil
Expand Down
24 changes: 24 additions & 0 deletions database/chaindb/chaindb_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package chaindb

import (
"github.com/Qitmeer/qng/database/common"
"github.com/Qitmeer/qng/database/rawdb"
"github.com/Qitmeer/qng/params"
)

func (cdb *ChainDB) TryUpgrade(di *common.DatabaseInfo, interrupt <-chan struct{}) error {
if di.Version() == common.CurrentDatabaseVersion {
// To fix old data, re index old genesis transaction data.
txId := params.ActiveNetParams.GenesisBlock.Transactions()[0].Hash()
_, blockHash, err := cdb.GetTxIdxEntry(txId, false)
if err != nil {
return err
}
if blockHash == nil {
log.Info("Re index genesis transaction for database")
return rawdb.WriteTxLookupEntriesByBlock(cdb.db, params.ActiveNetParams.GenesisBlock, 0)
}
return nil
}
return nil
}
11 changes: 11 additions & 0 deletions database/legacychaindb/legacychaindb_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ import (
"github.com/Qitmeer/qng/database/legacydb"
l "github.com/Qitmeer/qng/log"
"github.com/Qitmeer/qng/meerdag"
"github.com/Qitmeer/qng/params"
"github.com/schollz/progressbar/v3"
"math"
)

func (cdb *LegacyChainDB) TryUpgrade(di *common.DatabaseInfo, interrupt <-chan struct{}) error {
if di.Version() == common.CurrentDatabaseVersion {
// To fix old data, re index old genesis transaction data.
txId := params.ActiveNetParams.GenesisBlock.Transactions()[0].Hash()
_, blockHash, err := cdb.GetTxIdxEntry(txId, false)
if err != nil {
return err
}
if blockHash == nil {
log.Info("Re index genesis transaction for legacy database")
return cdb.doPutTxIndexEntrys(params.ActiveNetParams.GenesisBlock, 0)
}
return nil
} else if di.Version() > 13 {
return fmt.Errorf("The data is temporarily incompatible.")
Expand Down
10 changes: 0 additions & 10 deletions services/index/index_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ func (m *Manager) Init() error {
return err
}
}
if m.consensus.BlockChain().GetMainOrder() == 0 {
sblock, block, err := m.consensus.BlockChain().FetchBlockByOrder(0)
if err != nil {
return err
}
err = m.ConnectBlock(sblock, block, nil)
if err != nil {
return err
}
}
return nil
}

Expand Down

0 comments on commit 9535974

Please sign in to comment.