Skip to content

Commit e17b95c

Browse files
authored
Merge pull request #573 from lochjin/main
BUG:Missing index info for genesis transactions
2 parents 4579f0a + 4e7e5cc commit e17b95c

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

core/blockchain/blockchain.go

+5
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ func (b *BlockChain) createChainState() error {
338338
if err != nil {
339339
return err
340340
}
341+
// genesis tx index
342+
err = b.DB().PutTxIdxEntrys(genesisBlock, ib)
343+
if err != nil {
344+
return err
345+
}
341346
return b.bd.Commit()
342347
}
343348

database/chaindb/chaindb.go

-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/Qitmeer/qng/config"
77
"github.com/Qitmeer/qng/consensus/model"
88
"github.com/Qitmeer/qng/core/types"
9-
"github.com/Qitmeer/qng/database/common"
109
"github.com/Qitmeer/qng/database/rawdb"
1110
"github.com/Qitmeer/qng/meerdag"
1211
"github.com/ethereum/go-ethereum/ethdb"
@@ -411,10 +410,6 @@ func (cdb *ChainDB) DeleteEstimateFee() error {
411410
return rawdb.DeleteEstimateFee(cdb.db)
412411
}
413412

414-
func (cdb *ChainDB) TryUpgrade(di *common.DatabaseInfo, interrupt <-chan struct{}) error {
415-
return nil
416-
}
417-
418413
func New(cfg *config.Config) (*ChainDB, error) {
419414
cdb := &ChainDB{
420415
cfg: cfg,

database/chaindb/chaindb_upgrade.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package chaindb
2+
3+
import (
4+
"github.com/Qitmeer/qng/database/common"
5+
"github.com/Qitmeer/qng/database/rawdb"
6+
"github.com/Qitmeer/qng/params"
7+
)
8+
9+
func (cdb *ChainDB) TryUpgrade(di *common.DatabaseInfo, interrupt <-chan struct{}) error {
10+
if di.Version() == common.CurrentDatabaseVersion {
11+
// To fix old data, re index old genesis transaction data.
12+
txId := params.ActiveNetParams.GenesisBlock.Transactions()[0].Hash()
13+
_, blockHash, err := cdb.GetTxIdxEntry(txId, false)
14+
if err != nil {
15+
return err
16+
}
17+
if blockHash == nil {
18+
log.Info("Re index genesis transaction for database")
19+
return rawdb.WriteTxLookupEntriesByBlock(cdb.db, params.ActiveNetParams.GenesisBlock, 0)
20+
}
21+
return nil
22+
}
23+
return nil
24+
}

database/legacychaindb/legacychaindb_upgrade.go

+11
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ import (
1111
"github.com/Qitmeer/qng/database/legacydb"
1212
l "github.com/Qitmeer/qng/log"
1313
"github.com/Qitmeer/qng/meerdag"
14+
"github.com/Qitmeer/qng/params"
1415
"github.com/schollz/progressbar/v3"
1516
"math"
1617
)
1718

1819
func (cdb *LegacyChainDB) TryUpgrade(di *common.DatabaseInfo, interrupt <-chan struct{}) error {
1920
if di.Version() == common.CurrentDatabaseVersion {
21+
// To fix old data, re index old genesis transaction data.
22+
txId := params.ActiveNetParams.GenesisBlock.Transactions()[0].Hash()
23+
_, blockHash, err := cdb.GetTxIdxEntry(txId, false)
24+
if err != nil {
25+
return err
26+
}
27+
if blockHash == nil {
28+
log.Info("Re index genesis transaction for legacy database")
29+
return cdb.doPutTxIndexEntrys(params.ActiveNetParams.GenesisBlock, 0)
30+
}
2031
return nil
2132
} else if di.Version() > 13 {
2233
return fmt.Errorf("The data is temporarily incompatible.")

services/index/index_manager.go

-10
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ func (m *Manager) Init() error {
7373
return err
7474
}
7575
}
76-
if m.consensus.BlockChain().GetMainOrder() == 0 {
77-
sblock, block, err := m.consensus.BlockChain().FetchBlockByOrder(0)
78-
if err != nil {
79-
return err
80-
}
81-
err = m.ConnectBlock(sblock, block, nil)
82-
if err != nil {
83-
return err
84-
}
85-
}
8676
return nil
8777
}
8878

0 commit comments

Comments
 (0)