Skip to content

Commit 6411c8c

Browse files
committed
Use block time for the start time of add validator and add delegator transactions after Durango fork time
1 parent ce24a16 commit 6411c8c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

indexer/pchain/batch_indexer.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type txBatchIndexer struct {
3636
inOutIndexer *shared.InputOutputIndexer
3737
newTxs []*database.PChainTx
3838
dataTransformer *PChainDataTransformer
39+
40+
durangoTime time.Time
3941
}
4042

4143
func NewPChainDataTransformer(txTransformer func(tx *database.PChainTx) *database.PChainTx) *PChainDataTransformer {
@@ -50,6 +52,11 @@ func NewPChainBatchIndexer(
5052
rpcClient chain.RPCClient,
5153
dataTransformer *PChainDataTransformer,
5254
) *txBatchIndexer {
55+
var durangoTime time.Time
56+
if time, ok := shared.DurangoTimes[ctx.Config().Chain.ChainAddressHRP]; ok {
57+
durangoTime = time
58+
}
59+
5360
updater := newPChainInputUpdater(ctx, rpcClient)
5461
return &txBatchIndexer{
5562
db: ctx.DB(),
@@ -59,6 +66,8 @@ func NewPChainBatchIndexer(
5966
inOutIndexer: shared.NewInputOutputIndexer(updater),
6067
newTxs: make([]*database.PChainTx, 0),
6168
dataTransformer: dataTransformer,
69+
70+
durangoTime: durangoTime,
6271
}
6372
}
6473

@@ -296,12 +305,18 @@ func (xi *txBatchIndexer) updateDelegatorTx(
296305
}
297306

298307
// Common code for Add[Permissionless]DelegatorTx and Add[Permissionless]ValidatorTx
308+
// We assume that dbTx.blockTime is set to the block time before calling this function
299309
func (xi *txBatchIndexer) updateAddStakerTx(
300310
dbTx *database.PChainTx,
301311
tx StakerTx,
302312
txIns []*avax.TransferableInput,
303313
) error {
304-
startTime := tx.StartTime()
314+
var startTime time.Time
315+
if xi.isDurango(dbTx.BlockTime) {
316+
startTime = *dbTx.BlockTime
317+
} else {
318+
startTime = tx.StartTime()
319+
}
305320
endTime := tx.EndTime()
306321
dbTx.NodeID = tx.NodeID().String()
307322
dbTx.StartTime = &startTime
@@ -329,7 +344,11 @@ func (xi *txBatchIndexer) updateAddStakerTx(
329344
return nil
330345
}
331346

332-
func getAddStakerTxOutputs(txID string, tx StakerTx) ([]shared.Output, error) {
347+
func (xi *txBatchIndexer) isDurango(blockTime *time.Time) bool {
348+
return blockTime != nil && !blockTime.Before(xi.durangoTime)
349+
}
350+
351+
func getAddStakerTxOutputs(txID string, tx PermissionlessStakerTx) ([]shared.Output, error) {
333352
outs, err := shared.OutputsFromTxOuts(txID, tx.Outputs(), 0, PChainDefaultInputOutputCreator)
334353
if err != nil {
335354
return nil, err

indexer/pchain/in_updater.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ func (iu *pChainInputUpdater) updateFromChain(
7373
switch unsignedTx := tx.Unsigned.(type) {
7474
case *txs.AddValidatorTx:
7575
outs, err = iu.getAddStakerTxAndRewardTxOutputs(txId, unsignedTx)
76+
case *txs.AddPermissionlessValidatorTx:
77+
outs, err = iu.getAddStakerTxAndRewardTxOutputs(txId, unsignedTx)
7678
case *txs.AddDelegatorTx:
7779
outs, err = iu.getAddStakerTxAndRewardTxOutputs(txId, unsignedTx)
80+
case *txs.AddPermissionlessDelegatorTx:
81+
outs, err = iu.getAddStakerTxAndRewardTxOutputs(txId, unsignedTx)
7882
default:
7983
txOuts := tx.Unsigned.Outputs()
8084
outs, err = shared.OutputsFromTxOuts(txId, txOuts, 0, PChainDefaultInputOutputCreator)

indexer/shared/constants.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
package shared
22

3+
import (
4+
"time"
5+
)
6+
37
const (
48
ApplicationVersion = "2.1.0"
59
)
10+
11+
var (
12+
// Map from network name (HRP) to Durango fork time
13+
DurangoTimes = map[string]time.Time{
14+
"flare": time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
15+
"costwo": time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
16+
"localflare": time.Date(2025, time.May, 15, 14, 0, 0, 0, time.UTC),
17+
"coston": time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
18+
"songbird": time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
19+
"local": time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
20+
}
21+
)

0 commit comments

Comments
 (0)