Skip to content

Commit e9c62f7

Browse files
committed
feat: handle block not found
1 parent fc7d2c3 commit e9c62f7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

repository/handlers/blocks.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (repo *BlocksRepo) GetBlockDatePairs(ts int64) *schemas.BlockDate {
9393
return repo.blockDatePairs.Get(ts)
9494
}
9595

96-
func (repo *BlocksRepo) fetchBlockTime(blockNum int64) uint64 {
96+
func (repo *BlocksRepo) _fetchBlockTime(blockNum int64) (uint64, error) {
9797
b, err := repo.client.BlockByNumber(context.Background(), big.NewInt(blockNum))
9898
// if err != nil && err.Error() == "server returned empty uncle list but block header indicates uncles" {
9999
// repo.blocks[blockNum] = &core.Block{BlockNumber: blockNum}
@@ -104,11 +104,23 @@ func (repo *BlocksRepo) fetchBlockTime(blockNum int64) uint64 {
104104
if strings.Contains(err.Error(), "invalid transaction v, r, s values") && ds.IsTestnet(repo.client) {
105105
b, err := repo.client.BlockByNumber(context.Background(), big.NewInt(blockNum-1))
106106
log.CheckFatal(err)
107-
return b.Time() + 1
107+
return b.Time() + 1, nil
108108
}
109+
return 0, err
110+
}
111+
return b.Time(), nil
112+
}
113+
114+
func (repo *BlocksRepo) fetchBlockTime(blockNum int64) uint64 {
115+
bTime, err := repo._fetchBlockTime(blockNum)
116+
if err != nil && strings.Contains(err.Error(), "not found") {
117+
time.Sleep(1 * time.Second)
118+
bTime, err = repo._fetchBlockTime(blockNum)
119+
}
120+
if err != nil {
109121
log.Fatalf("%s: %d", err, blockNum)
110122
}
111-
return b.Time()
123+
return bTime
112124
}
113125

114126
func (repo *BlocksRepo) setBlock(blockNum int64) {

0 commit comments

Comments
 (0)