2019-11-25 13:46:36 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-12-04 10:05:35 +00:00
|
|
|
"fmt"
|
2020-01-15 12:47:13 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"time"
|
2019-12-04 10:05:35 +00:00
|
|
|
|
2020-01-15 12:47:13 +00:00
|
|
|
"github.com/ledgerwatch/bolt"
|
2019-11-25 13:46:36 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/state/stateless"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-12-03 09:55:15 +00:00
|
|
|
stateGrowthCmd := &cobra.Command{
|
|
|
|
Use: "stateGrowth",
|
|
|
|
Short: "stateGrowth",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2020-01-15 12:47:13 +00:00
|
|
|
localDb, err := bolt.Open(file()+"_sg", 0600, &bolt.Options{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-12-16 14:54:30 +00:00
|
|
|
ctx := getContext()
|
2020-01-15 12:47:13 +00:00
|
|
|
remoteDb, err := connectRemoteDb(ctx, remoteDbAddress)
|
2019-12-03 09:55:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-04 10:05:35 +00:00
|
|
|
fmt.Println("Processing started...")
|
2020-01-15 12:47:13 +00:00
|
|
|
stateless.NewStateGrowth1Reporter(ctx, remoteDb, localDb).StateGrowth1(ctx)
|
|
|
|
stateless.NewStateGrowth2Reporter(ctx, remoteDb, localDb).StateGrowth2(ctx)
|
2019-12-03 09:55:15 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:46:36 +00:00
|
|
|
withChaindata(stateGrowthCmd)
|
2019-12-03 09:55:15 +00:00
|
|
|
withRemoteDb(stateGrowthCmd)
|
|
|
|
rootCmd.AddCommand(stateGrowthCmd)
|
2019-11-25 13:46:36 +00:00
|
|
|
}
|
2020-01-15 12:47:13 +00:00
|
|
|
|
|
|
|
// Generate name off the file for snapshot
|
|
|
|
// Each day has it's own partition
|
|
|
|
// It means that you can only continue execution of report from last snapshot.Save() checkpoint - read buckets forward from last key
|
|
|
|
// But not re-read bucket
|
|
|
|
func file() string {
|
|
|
|
dir := path.Join(os.TempDir(), "turbo_geth_reports")
|
|
|
|
if err := os.MkdirAll(dir, 0770); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return path.Join(dir, time.Now().Format("2006-01-02"))
|
|
|
|
}
|