Skip to content

Commit e2d0849

Browse files
committed
Merge branch 'multiple_block_tx_fix' into 'main'
Fix indexing Banff proposal blocks See merge request flarenetwork/network/flare-p-chain-indexer!2
2 parents a958339 + dd6dc2c commit e2d0849

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

indexer/pchain/batch_indexer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ func (xi *txBatchIndexer) AddContainer(index uint64, container indexer.Container
9999
}
100100
// Banff blocks were introduced in Avalanche 1.9.0
101101
case *block.BanffProposalBlock:
102-
tx := innerBlkType.Tx
103-
err = xi.addTx(&container, database.PChainProposalBlock, innerBlk.Height(), innerBlkType.Time, tx)
102+
for _, tx := range innerBlkType.Txs() {
103+
err = xi.addTx(&container, database.PChainProposalBlock, innerBlk.Height(), innerBlkType.Time, tx)
104+
if err != nil {
105+
break
106+
}
107+
}
104108
case *block.BanffCommitBlock:
105109
xi.addEmptyTx(&container, database.PChainCommitBlock, innerBlk.Height(), innerBlkType.Time)
106110
case *block.BanffAbortBlock:

indexer/pchain/migrations.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
func init() {
1212
migrations.Container.Add("2023-02-10-00-00", "Create initial state for P-Chain transactions", createPChainTxState)
1313
migrations.Container.Add("2024-11-07-00-00", "Alter type column size in p_chain_txes table", alterPChainTxType)
14+
migrations.Container.Add("2025-09-30-00-00", "Delete all P-chain transactions", deleteTransactions)
1415
}
1516

1617
func createPChainTxState(db *gorm.DB) error {
@@ -25,3 +26,22 @@ func createPChainTxState(db *gorm.DB) error {
2526
func alterPChainTxType(db *gorm.DB) error {
2627
return db.Exec("ALTER TABLE p_chain_txes CHANGE COLUMN type type VARCHAR(40)").Error
2728
}
29+
30+
// Delete all P-chain transactions and reset the state to start indexing from the beginning
31+
func deleteTransactions(db *gorm.DB) error {
32+
return db.Transaction(func(tx *gorm.DB) error {
33+
if err := tx.Exec("DELETE FROM p_chain_tx_inputs").Error; err != nil {
34+
return err
35+
}
36+
if err := tx.Exec("DELETE FROM p_chain_tx_outputs").Error; err != nil {
37+
return err
38+
}
39+
if err := tx.Exec("DELETE FROM p_chain_txes").Error; err != nil {
40+
return err
41+
}
42+
if err := tx.Exec("UPDATE states SET next_db_index = 0, last_chain_index = 0 WHERE name = ?", StateName).Error; err != nil {
43+
return err
44+
}
45+
return nil
46+
})
47+
}

indexer/shared/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
const (
8-
ApplicationVersion = "2.2.1"
8+
ApplicationVersion = "2.2.2"
99
)
1010

1111
var (

0 commit comments

Comments
 (0)