-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use
GetMissingHeights()
in enqueueMissingBlocks()
& in `par…
…se blocks` cmd (#89) ## Description following the request from @maiquanghiep : https://forbole.atlassian.net/browse/BDU-489?focusedCommentId=17477 ## Checklist - [x] Targeted PR against correct branch. - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Wrote unit tests. - [x] Re-reviewed `Files changed` in the Github PR explorer.
- Loading branch information
1 parent
b73251c
commit 86c1cc5
Showing
7 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package blocks | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
parsecmdtypes "github.com/forbole/juno/v4/cmd/parse/types" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/forbole/juno/v4/parser" | ||
"github.com/forbole/juno/v4/types/config" | ||
) | ||
|
||
// newMissingCmd returns a Cobra command that allows to fix missing blocks in database | ||
func newMissingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "missing [start height]", | ||
Short: "Refetch all the missing heights in the database starting from the given start height", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
startHeight, err := strconv.ParseInt(args[0], 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("make sure the given start height is a positive integer") | ||
} | ||
|
||
parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workerCtx := parser.NewContext(parseCtx.EncodingConfig, parseCtx.Node, parseCtx.Database, parseCtx.Logger, parseCtx.Modules) | ||
worker := parser.NewWorker(workerCtx, nil, 0) | ||
|
||
dbLastHeight, err := parseCtx.Database.GetLastBlockHeight() | ||
if err != nil { | ||
return fmt.Errorf("error while getting DB last block height: %s", err) | ||
} | ||
|
||
for _, k := range parseCtx.Database.GetMissingHeights(startHeight, dbLastHeight) { | ||
err = worker.Process(k) | ||
if err != nil { | ||
return fmt.Errorf("error while re-fetching block %d: %s", k, err) | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters