erigon-pulse/cmd/headers/commands/root.go

61 lines
1.2 KiB
Go
Raw Normal View History

package commands
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/ledgerwatch/turbo-geth/cmd/utils"
"github.com/ledgerwatch/turbo-geth/internal/debug"
"github.com/ledgerwatch/turbo-geth/log"
"github.com/spf13/cobra"
)
Headers poc 5 - Intermediate (#1145) * Add headers persistence * Print flushBuffer * Fix indexing problem * Not skip hard-coded headers if the files are empty * Fix lint * print anchor state after init * Properly construct file names * Add check sub-command * Fix lint * Fix lint * Fix lint * Print more info when recovering * Fix recovering * Fix recovery * Add anchors also as tips * 2-level priority queue for tips * Initialise tipQueue in anchor * update maxTipHeight * fix type * Add anchors to the anchorQueue and rebuild anchorQueue on deletion * Fix NPE * fix recovery * User buffersize, add hard coded headers to buffer * Reinit anchorQueue * Schedule requests after recovery * No fix * Remove duplicates * Report duplicate headers * Log buffer additions * Fix for duplicate headers * Try to fix duplicate headers again * remove TODO comment * Use LLRB instead of heap for anchors * Print reserveTip info * Correctly replace anchors in the tree * Remove excessive logging * Print tips attached to the anchor * Print tips better * limitTips instead of reserveTip * Print forked headers * Use pointers in llrb * Print tipStretch * Print limitTips * Mininise AnchorItem * Put anchors into the tree * Fix totalDiff calculation, but is it needed? * Remove totalDifficulty from anchors * CheckInitiation * Fix tests * Fix lint, print more at check initiation * Better output for hard-coded anchors * Print hard-coded anchors better * Prioritise anchors with short stretches * Prioritise by chainSize * Use linked list instead of heap for requestQueue * Fix problem of no requests * Push front * Fix lint * Not verify PoW for too far in the past and future * Fix Calculation of totalDifficulty when Connect * Fix hard tips * Another fix for tips
2020-09-27 20:32:05 +00:00
var (
filesDir string // Directory when the files should be stored
)
func init() {
utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricFlags...))
}
func rootContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(ch)
select {
case <-ch:
log.Info("Got interrupt, shutting down...")
case <-ctx.Done():
}
cancel()
}()
return ctx
}
var rootCmd = &cobra.Command{
Use: "headers",
Short: "headers is Proof Of Concept for new header/block downloading algorithms",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if err := debug.SetupCobra(cmd); err != nil {
panic(err)
}
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
debug.Exit()
},
}
func Execute() {
if err := rootCmd.ExecuteContext(rootContext()); err != nil {
fmt.Println(err)
os.Exit(1)
}
}