@@ -14,7 +14,6 @@ import (
1414 "github.com/ava-labs/avalanchego/vms/platformvm/blocks"
1515 "github.com/ava-labs/avalanchego/vms/platformvm/fx"
1616 "github.com/ava-labs/avalanchego/vms/platformvm/txs"
17- "github.com/ava-labs/avalanchego/vms/proposervm/block"
1817 "gorm.io/gorm"
1918)
2019
@@ -69,26 +68,37 @@ func (xi *txBatchIndexer) Reset(containerLen int) {
6968}
7069
7170func (xi * txBatchIndexer ) AddContainer (index uint64 , container indexer.Container ) error {
72- blk , err := block .Parse (container .Bytes )
73- if err != nil {
74- return err
75- }
76- innerBlk , err := blocks .Parse (blocks .GenesisCodec , blk .Block ())
71+ innerBlk , err := chain .ParsePChainBlock (container .Bytes )
7772 if err != nil {
7873 return err
7974 }
8075
8176 switch innerBlkType := innerBlk .(type ) {
8277 case * blocks.ApricotProposalBlock :
8378 tx := innerBlkType .Tx
84- err = xi .addTx (& container , database .PChainProposalBlock , innerBlk .Height (), tx )
79+ err = xi .addTx (& container , database .PChainProposalBlock , innerBlk .Height (), 0 , tx )
8580 case * blocks.ApricotCommitBlock :
86- xi .addEmptyTx (& container , database .PChainCommitBlock , innerBlk .Height ())
81+ xi .addEmptyTx (& container , database .PChainCommitBlock , innerBlk .Height (), 0 )
8782 case * blocks.ApricotAbortBlock :
88- xi .addEmptyTx (& container , database .PChainAbortBlock , innerBlk .Height ())
83+ xi .addEmptyTx (& container , database .PChainAbortBlock , innerBlk .Height (), 0 )
8984 case * blocks.ApricotStandardBlock :
9085 for _ , tx := range innerBlkType .Txs () {
91- err = xi .addTx (& container , database .PChainStandardBlock , innerBlk .Height (), tx )
86+ err = xi .addTx (& container , database .PChainStandardBlock , innerBlk .Height (), 0 , tx )
87+ if err != nil {
88+ break
89+ }
90+ }
91+ // Banff blocks were introduced in Avalanche 1.9.0
92+ case * blocks.BanffProposalBlock :
93+ tx := innerBlkType .Tx
94+ err = xi .addTx (& container , database .PChainProposalBlock , innerBlk .Height (), innerBlkType .Time , tx )
95+ case * blocks.BanffCommitBlock :
96+ xi .addEmptyTx (& container , database .PChainCommitBlock , innerBlk .Height (), innerBlkType .Time )
97+ case * blocks.BanffAbortBlock :
98+ xi .addEmptyTx (& container , database .PChainAbortBlock , innerBlk .Height (), innerBlkType .Time )
99+ case * blocks.BanffStandardBlock :
100+ for _ , tx := range innerBlkType .Txs () {
101+ err = xi .addTx (& container , database .PChainStandardBlock , innerBlk .Height (), innerBlkType .Time , tx )
92102 if err != nil {
93103 break
94104 }
@@ -103,7 +113,7 @@ func (xi *txBatchIndexer) ProcessBatch() error {
103113 return xi .inOutIndexer .ProcessBatch ()
104114}
105115
106- func (xi * txBatchIndexer ) addTx (container * indexer.Container , blockType database.PChainBlockType , height uint64 , tx * txs.Tx ) error {
116+ func (xi * txBatchIndexer ) addTx (container * indexer.Container , blockType database.PChainBlockType , height uint64 , blockTime uint64 , tx * txs.Tx ) error {
107117 txID := tx .ID ().String ()
108118 dbTx := & database.PChainTx {}
109119 dbTx .TxID = & txID
@@ -112,6 +122,10 @@ func (xi *txBatchIndexer) addTx(container *indexer.Container, blockType database
112122 dbTx .BlockHeight = height
113123 dbTx .Timestamp = chain .TimestampToTime (container .Timestamp )
114124 dbTx .Bytes = container .Bytes
125+ if blockTime != 0 {
126+ time := time .Unix (int64 (blockTime ), 0 )
127+ dbTx .BlockTime = & time
128+ }
115129
116130 var err error = nil
117131 switch unsignedTx := tx .Unsigned .(type ) {
@@ -127,26 +141,36 @@ func (xi *txBatchIndexer) addTx(container *indexer.Container, blockType database
127141 err = xi .updateExportTx (dbTx , unsignedTx )
128142 case * txs.AdvanceTimeTx :
129143 xi .updateAdvanceTimeTx (dbTx , unsignedTx )
130- case * txs.AddSubnetValidatorTx :
131- err = xi .updateGeneralBaseTx (dbTx , database .PChainAddSubnetValidatorTx , & unsignedTx .BaseTx )
132144 case * txs.CreateChainTx :
133145 err = xi .updateGeneralBaseTx (dbTx , database .PChainCreateChainTx , & unsignedTx .BaseTx )
134146 case * txs.CreateSubnetTx :
135147 err = xi .updateGeneralBaseTx (dbTx , database .PChainCreateSubnetTx , & unsignedTx .BaseTx )
148+ case * txs.RemoveSubnetValidatorTx :
149+ err = xi .updateGeneralBaseTx (dbTx , database .PChainRemoveSubnetValidatorTx , & unsignedTx .BaseTx )
150+ case * txs.TransformSubnetTx :
151+ err = xi .updateGeneralBaseTx (dbTx , database .PChainTransformSubnetTx , & unsignedTx .BaseTx )
152+ // We leave out the following transaction types as they are rejected by Flare nodes
153+ // - AddSubnetValidatorTx
154+ // - AddPermissionlessValidatorTx
155+ // - AddPermissionlessDelegatorTx
136156 default :
137157 err = fmt .Errorf ("p-chain transaction %v with type %T in block %d is not indexed" , dbTx .TxID , unsignedTx , height )
138158 }
139159 return err
140160}
141161
142- func (xi * txBatchIndexer ) addEmptyTx (container * indexer.Container , blockType database.PChainBlockType , height uint64 ) {
162+ func (xi * txBatchIndexer ) addEmptyTx (container * indexer.Container , blockType database.PChainBlockType , height uint64 , blockTime uint64 ) {
143163 dbTx := & database.PChainTx {}
144164 dbTx .BlockID = container .ID .String ()
145165 dbTx .BlockType = blockType
146166 dbTx .BlockHeight = height
147167 dbTx .Timestamp = chain .TimestampToTime (container .Timestamp )
148168 dbTx .Bytes = container .Bytes
149169 dbTx .TxID = nil
170+ if blockTime != 0 {
171+ time := time .Unix (int64 (blockTime ), 0 )
172+ dbTx .BlockTime = & time
173+ }
150174
151175 xi .newTxs = append (xi .newTxs , dbTx )
152176}
0 commit comments