Skip to content

Commit

Permalink
Merge pull request #573 from lochjin/main
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 4579f0a + 4e7e5cc commit e17b95c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
5 changes: 5 additions & 0 deletions core/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,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
5 changes: 0 additions & 5 deletions database/chaindb/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/Qitmeer/qng/config"
"github.com/Qitmeer/qng/consensus/model"
"github.com/Qitmeer/qng/core/types"
"github.com/Qitmeer/qng/database/common"
"github.com/Qitmeer/qng/database/rawdb"
"github.com/Qitmeer/qng/meerdag"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down Expand Up @@ -411,10 +410,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 New(cfg *config.Config) (*ChainDB, error) {
cdb := &ChainDB{
cfg: cfg,
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 e17b95c

Please sign in to comment.