Skip to content
Snippets Groups Projects
Select Git revision
  • 3645-nil-pointer-errors-are-occasionally-thrown
  • main default protected
  • release-1.4 protected
  • partial-merkle-tree
  • 3616-migrate-block-ledger
  • 3623-backport
  • hashed-time-locks
  • 3626-expose-simulator
  • 3640-mining-support
  • 3621-csv2yaml
  • eip712-mask
  • 3565-eip712-ethan
  • 3617-instrumentation-followup
  • database
  • database-benchmark-index
  • database-no-mutex
  • 3588-blockchain-specific-key-value-database
  • 3570-generalize-pki-types
  • 3600-fee-schedule-consistency
  • 3589-code-intelligence
  • v1.4.1-snapshot
  • v1.4.1
  • v1.4.0
  • v1.4.0-alpha.1
  • v1.3.0
  • v1.3.0-rc.3
  • v1.2.13
  • v1.2.12
  • mexc-v1.2.11
  • v1.3.0-rc.2
  • v1.2.11
  • v1.2.10
  • v1.2.10-rc.8
  • v1.2.10-rc.7
  • v1.2.10-rc.6
  • v1.2.10-rc.5
  • v1.2.10-rc.4
  • v1.2.10-rc.3
  • v1.2.10-rc.2
  • mexc-v1.2.10-rc.2
40 results

merge.go

  • Ethan Reesor's avatar
    1081aa02
    feat(prot): factom genesis v2 [AC-3035] · 1081aa02
    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
    1081aa02
    History
    feat(prot): factom genesis v2 [AC-3035]
    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
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
	}))
}