Skip to content

Commit

Permalink
Merge branch 'main' of gitlab.com:accumulatenetwork/accumulate
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed May 27, 2024
2 parents b84b4cf + 857eb66 commit 273f5fa
Show file tree
Hide file tree
Showing 73 changed files with 5,057 additions and 1,401 deletions.
9 changes: 2 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/accumulated",
"args": [
"run",
"devnet",
"-w=${workspaceFolder}/.nodes/devnet",
"${workspaceFolder}/.nodes/devnet",
]
},
{
Expand Down Expand Up @@ -524,10 +522,7 @@
"mode": "auto",
"program": "${workspaceFolder}/tools/cmd/debug",
"args": [
"comet",
"download-genesis",
"http://206.189.97.165:16592",
"${env:HOME}/Desktop/apollo-genesis.json"
"db", "analyze", "badger://${workspaceFolder}/.nodes/devnet/bvn1-1/bvnn/data/accumulate.db", "--accounts",
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as build
FROM golang:1.22 as build

ARG GIT_DESCRIBE
ARG GIT_COMMIT
Expand Down
7 changes: 5 additions & 2 deletions cmd/accumulated/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,9 @@ func initNode(cmd *cobra.Command, args []string) (string, error) {
return "", fmt.Errorf("invalid --listen %q %v", flagInitNode.ListenIP, err)
}

if listenUrl.Port() != "" {
if listenUrl.Port() == "" {
listenUrl.Host += fmt.Sprintf(":%d", basePort)
} else {
p, err := strconv.ParseInt(listenUrl.Port(), 10, 16)
if err != nil {
return "", fmt.Errorf("invalid port number %q, %v", listenUrl.Port(), err)
Expand All @@ -564,10 +566,11 @@ func initNode(cmd *cobra.Command, args []string) (string, error) {
return "", fmt.Errorf("invalid public address %v", err)
}

localAddr, port, err := resolveAddrWithPort(config.Accumulate.API.ListenAddress)
localAddr, port, err := resolveAddrWithPort(listenUrl.String())
if err != nil {
return "", fmt.Errorf("invalid node address %v", err)
}
port += int(cfg.PortOffsetAccumulateApi)
if publicAddr == "" {
publicAddr = localAddr
}
Expand Down
79 changes: 75 additions & 4 deletions cmd/accumulated/cmd_init_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ import (
"github.com/spf13/cobra"
"gitlab.com/accumulatenetwork/accumulate/exp/faucet"
"gitlab.com/accumulatenetwork/accumulate/internal/core"
coredb "gitlab.com/accumulatenetwork/accumulate/internal/database"
"gitlab.com/accumulatenetwork/accumulate/internal/database/smt/storage"
"gitlab.com/accumulatenetwork/accumulate/internal/logging"
accumulated "gitlab.com/accumulatenetwork/accumulate/internal/node/daemon"
"gitlab.com/accumulatenetwork/accumulate/internal/node/genesis"
ioutil2 "gitlab.com/accumulatenetwork/accumulate/internal/util/io"
"gitlab.com/accumulatenetwork/accumulate/pkg/database"
"gitlab.com/accumulatenetwork/accumulate/pkg/url"
"gitlab.com/accumulatenetwork/accumulate/protocol"
"gitlab.com/accumulatenetwork/accumulate/test/testing"
)

var cmdInitNetwork = &cobra.Command{
Expand All @@ -43,8 +47,15 @@ var cmdInitGenesis = &cobra.Command{
Args: cobra.ExactArgs(1),
}

var cmdInitPrepareGenesis = &cobra.Command{
Use: "prepare-genesis <output> <inputs...>",
Short: "Ingests data from snapshots and produces a single, stripped-down snapshot for genesis",
Run: prepareGenesis,
Args: cobra.MinimumNArgs(2),
}

func init() {
cmdInit.AddCommand(cmdInitGenesis)
cmdInit.AddCommand(cmdInitGenesis, cmdInitPrepareGenesis)
}

func loadNetworkConfiguration(file string) (ret *accumulated.NetworkInit, err error) {
Expand Down Expand Up @@ -129,7 +140,68 @@ func initGenesis(cmd *cobra.Command, args []string) {
}
}

func initNetworkLocalFS(cmd *cobra.Command, netInit *accumulated.NetworkInit) {
func prepareGenesis(cmd *cobra.Command, args []string) {
// Timer for updating progress
tick := time.NewTicker(time.Second / 2)
defer tick.Stop()

db := coredb.OpenInMemory(nil)
db.SetObserver(testing.NullObserver{})
for _, path := range args[1:] {
fmt.Println("Processing", path)
file, err := os.Open(path)
check(err)
defer file.Close()
_, err = genesis.Extract(db, file, func(u *url.URL) bool {
select {
case <-tick.C:
h := database.NewKey("Account", u).Hash()
fmt.Printf("\033[A\r\033[KProcessing [%x] %v\n", h[:4], u)
default:
return true
}

// Retain everything
return true
})
check(err)
}

file, err := os.Create(args[0])
check(err)
defer file.Close()

// Collect
var metrics coredb.CollectMetrics
fmt.Println("Collecting into", args[0])
err = db.Collect(file, nil, &coredb.CollectOptions{
Metrics: &metrics,
Predicate: func(r database.Record) (bool, error) {
select {
case <-tick.C:
default:
return true, nil
}

// Print progress
switch r.Key().Get(0) {
case "Account":
k := r.Key().SliceJ(2)
h := k.Hash()
fmt.Printf("\033[A\r\033[KCollecting [%x] (%d) %v\n", h[:4], metrics.Messages.Count, k.Get(1))

case "Message", "Transaction":
fmt.Printf("\033[A\r\033[KCollecting (%d/%d) %x\n", metrics.Messages.Collecting, metrics.Messages.Count, r.Key().Get(1).([32]byte))
}

// Retain everything
return true, nil
},
})
check(err)
}

func initNetworkLocalFS(_ *cobra.Command, netInit *accumulated.NetworkInit) {
if flagInit.LogLevels != "" {
_, _, err := logging.ParseLogLevel(flagInit.LogLevels, io.Discard)
checkf(err, "--log-level")
Expand Down Expand Up @@ -222,8 +294,7 @@ func buildGenesis(network *accumulated.NetworkInit) map[string][]byte {
})
}

values := new(core.GlobalValues)
genDocs, err := accumulated.BuildGenesisDocs(network, values, time.Now(), newLogger(), factomAddresses, snapshots)
genDocs, err := accumulated.BuildGenesisDocs(network, network.Globals, time.Now(), newLogger(), factomAddresses, snapshots)
checkf(err, "build genesis documents")
return genDocs
}
Expand Down
Loading

0 comments on commit 273f5fa

Please sign in to comment.