Select Git revision
-
Ethan Reesor authored
Closes AC-3035. Reimplement Factom genesis/import. Old way: import Factom by submitting transactions. New way: write accounts and transactions directly to a database, create a snapshot, then import that snapshot in genesis. Also it turns out that loading large snapshots is broken, so I had to significantly rework how that works. **If any item is not complete, the merge request is not ready to be reviewed and must be marked `Draft:`.** - [x] The merge request title is in the format `<change type>(<change scope>): <short description> [<task id>]` - For example, `feat(cli): add QR code generation [AC-123]` - For details, see [CONTRIBUTING.md](/CONTRIBUTING.md) - [x] The description includes `Closes <jira task ID>` (or rarely `Updates <jira task ID>`) - [~] The change is fully validated by tests that are run during CI - In most cases this means a test in "validate.sh" - In some cases, a Go test may be acceptable - Validation is not applicable to things like documentation updates - Purely UI/UX changes can be manually validated, such as changes to human-readable output - For all other changes, automated validation tests are an absolute requirement unless a maintainer specifically explains why they are not in a comment on this merge request - [x] The change is marked with one of the validation labels - ~"validation::ci/cd" for changes validated by CI tests - ~"validation::manual" for changes validated by hand - ~"validation::deferred" for changes validated by a follow up merge request - ~"validation::not applicable" for changes where validation is not applicable - [ ] CI is passing - [ ] Merge conflicts are resolved - [ ] All discussions are resolved Related to AC-3035
Ethan Reesor authoredCloses AC-3035. Reimplement Factom genesis/import. Old way: import Factom by submitting transactions. New way: write accounts and transactions directly to a database, create a snapshot, then import that snapshot in genesis. Also it turns out that loading large snapshots is broken, so I had to significantly rework how that works. **If any item is not complete, the merge request is not ready to be reviewed and must be marked `Draft:`.** - [x] The merge request title is in the format `<change type>(<change scope>): <short description> [<task id>]` - For example, `feat(cli): add QR code generation [AC-123]` - For details, see [CONTRIBUTING.md](/CONTRIBUTING.md) - [x] The description includes `Closes <jira task ID>` (or rarely `Updates <jira task ID>`) - [~] The change is fully validated by tests that are run during CI - In most cases this means a test in "validate.sh" - In some cases, a Go test may be acceptable - Validation is not applicable to things like documentation updates - Purely UI/UX changes can be manually validated, such as changes to human-readable output - For all other changes, automated validation tests are an absolute requirement unless a maintainer specifically explains why they are not in a comment on this merge request - [x] The change is marked with one of the validation labels - ~"validation::ci/cd" for changes validated by CI tests - ~"validation::manual" for changes validated by hand - ~"validation::deferred" for changes validated by a follow up merge request - ~"validation::not applicable" for changes where validation is not applicable - [ ] CI is passing - [ ] Merge conflicts are resolved - [ ] All discussions are resolved Related to AC-3035
merge.go 1.71 KiB
package main
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"github.com/spf13/cobra"
"gitlab.com/accumulatenetwork/accumulate/internal/database"
"gitlab.com/accumulatenetwork/accumulate/internal/database/snapshot"
"gitlab.com/accumulatenetwork/accumulate/internal/errors"
)
var cmdMerge = &cobra.Command{
Use: "merge <output> <input directory>",
Short: "Merge Factom snapshots",
Args: cobra.MinimumNArgs(2),
Run: merge,
}
func init() {
cmd.AddCommand(cmdMerge)
cmdMerge.Flags().StringVarP(&flagConvert.LogLevel, "log-level", "l", "error", "Set the logging level")
cmdMerge.Flags().IntVarP(&flagConvert.StartFrom, "start-from", "s", 0, "Factom height to start from")
cmdMerge.Flags().IntVar(&flagConvert.StopAt, "stop-at", 0, "Factom height to stop at (if zero, run to completion)")
}
func merge(_ *cobra.Command, args []string) {
height := flagConvert.StartFrom
ok := true
onInterrupt(func() { ok = false })
logger := newLogger()
db, rm := tempBadger(logger)
defer rm()
defer db.Close()
for ok {
filename := filepath.Join(args[1], fmt.Sprintf("factom-%d.snapshot", height))
input, err := os.Open(filename)
if errors.Is(err, fs.ErrNotExist) {
break
}
checkf(err, "read %s", filename)
fmt.Printf("Importing %s\n", filename)
check(snapshot.Restore(db, input, logger))
height += 2000
if flagConvert.StopAt > 0 && height >= flagConvert.StopAt {
break
}
}
fmt.Println("Interrupted")
// Create a snapshot
fmt.Printf("Saving as %s\n", args[0])
f, err := os.Create(args[0])
checkf(err, "open snapshot")
defer f.Close()
check(db.View(func(batch *database.Batch) error {
_, err := snapshot.Collect(batch, f, func(*database.Account) (bool, error) { return true, nil })
return err
}))
}