Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into NOBIDS/local-deplo…
Browse files Browse the repository at this point in the history
…yment-update
  • Loading branch information
remoterami committed Oct 17, 2024
2 parents d1d5652 + 504c82d commit e8d7417
Show file tree
Hide file tree
Showing 132 changed files with 12,739 additions and 4,866 deletions.
9 changes: 6 additions & 3 deletions backend/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ func Run() {
if dummyApi {
dataAccessor = dataaccess.NewDummyService()
} else {
dataAccessor = dataaccess.NewDataAccessService(cfg)
dataAccessor.StartDataAccessServices()
service := dataaccess.NewDataAccessService(cfg)
service.StartDataAccessServices()
dataAccessor = service
}
defer dataAccessor.Close()

router := api.NewApiRouter(dataAccessor, cfg)
dummy := dataaccess.NewDummyService()

router := api.NewApiRouter(dataAccessor, dummy, cfg)
router.Use(api.GetCorsMiddleware(cfg.CorsAllowedHosts))

if utils.Config.Metrics.Enabled {
Expand Down
1,589 changes: 1,589 additions & 0 deletions backend/cmd/evm_node_indexer/main.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions backend/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gobitfly/beaconchain/cmd/blobindexer"
"github.com/gobitfly/beaconchain/cmd/eth1indexer"
"github.com/gobitfly/beaconchain/cmd/ethstore_exporter"
"github.com/gobitfly/beaconchain/cmd/evm_node_indexer"
"github.com/gobitfly/beaconchain/cmd/exporter"
"github.com/gobitfly/beaconchain/cmd/misc"
"github.com/gobitfly/beaconchain/cmd/monitoring"
Expand Down Expand Up @@ -63,6 +64,8 @@ func main() {
user_service.Run()
case "monitoring":
monitoring.Run()
case "evm_node_indexer":
evm_node_indexer.Run()
default:
log.Fatal(nil, fmt.Sprintf("unknown target: %s", target), 0)
}
Expand Down
124 changes: 124 additions & 0 deletions backend/cmd/misc/commands/app_bundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package commands

import (
"flag"
"fmt"
"strings"

"github.com/gobitfly/beaconchain/cmd/misc/misctypes"
"github.com/gobitfly/beaconchain/pkg/commons/db"
"github.com/gobitfly/beaconchain/pkg/commons/log"

"github.com/pkg/errors"
)

type AppBundleCommand struct {
FlagSet *flag.FlagSet
Config appBundleCommandConfig
}

type appBundleCommandConfig struct {
DryRun bool
Force bool // bypass summary confirm
BundleURL string
BundleVersionCode int64
NativeVersionCode int64
TargetInstalls int64
}

func (s *AppBundleCommand) ParseCommandOptions() {
s.FlagSet.Int64Var(&s.Config.BundleVersionCode, "version-code", 0, "Version code of that bundle (Default: Next)")
s.FlagSet.Int64Var(&s.Config.NativeVersionCode, "min-native-version", 0, "Minimum required native version (Default: Current)")
s.FlagSet.Int64Var(&s.Config.TargetInstalls, "target-installs", -1, "How many people to roll out to (Default: All)")
s.FlagSet.StringVar(&s.Config.BundleURL, "bundle-url", "", "URL to bundle that contains the update, bundle.zip")
s.FlagSet.BoolVar(&s.Config.Force, "force", false, "Skips summary and confirmation")
}

func (s *AppBundleCommand) Requires() misctypes.Requires {
return misctypes.Requires{
UserDBs: true,
}
}

func (s *AppBundleCommand) Run() error {
if s.Config.BundleURL == "" {
s.showHelp()
return errors.New("Please provide a valid bundle URL via --bundle-url")
}
if s.Config.BundleVersionCode == 0 {
fileName := strings.Split(s.Config.BundleURL, "/")
if len(fileName) == 0 {
return errors.New("Invalid bundle URL")
}

split := strings.Split(fileName[len(fileName)-1], "_")
if len(split) < 2 {
return errors.New("Invalid bundle URL")
}

// split[1] is the version code
_, err := fmt.Sscanf(split[1], "%d", &s.Config.BundleVersionCode)
if err != nil {
return errors.Wrap(err, "Error parsing version code")
}
}
if s.Config.NativeVersionCode <= 0 {
err := db.FrontendReaderDB.Get(&s.Config.NativeVersionCode, "SELECT MAX(min_native_version) FROM mobile_app_bundles")
if err != nil {
return errors.Wrap(err, "Error getting max native version")
}
}

if s.Config.TargetInstalls < 0 {
s.Config.TargetInstalls = -1
}

if !s.Config.Force {
// Summary
log.Infof("=== Bundle Summary ===")
log.Infof("Bundle URL: %s", s.Config.BundleURL)
log.Infof("Bundle Version Code: %d", s.Config.BundleVersionCode)
log.Infof("Minimum Native Version: %d", s.Config.NativeVersionCode)
if s.Config.TargetInstalls == -1 {
log.Infof("Target Installs: All")
} else {
log.Infof("Target Installs: %d", s.Config.TargetInstalls)
}
log.Infof("======================\n")

// ask for y/n input
log.Infof("Do you want to add this bundle? (y/n)\n")
var input string
_, err := fmt.Scanln(&input)
if err != nil {
return errors.Wrap(err, "Error reading input")
}

if input != "y" {
log.Infof("Bundle not added\n")
return nil
}
}

if s.Config.DryRun {
log.Infof("Dry run, not adding bundle\n")
return nil
}

_, err := db.FrontendWriterDB.Exec("INSERT INTO mobile_app_bundles (bundle_url, bundle_version, min_native_version, target_count) VALUES ($1, $2, $3, $4)", s.Config.BundleURL, s.Config.BundleVersionCode, s.Config.NativeVersionCode, s.Config.TargetInstalls)
if err != nil {
return errors.Wrap(err, "Error inserting app bundle")
}

log.Infof("Bundle added successfully")
return nil
}

func (s *AppBundleCommand) showHelp() {
log.Infof("Usage: app_bundle [options]")
log.Infof("Options:")
log.Infof(" --version-code int\tVersion code of that bundle")
log.Infof(" --min-native-version int\tMinimum required native version (Default: Current)")
log.Infof(" --target-installs int\tHow many people to roll out to (Default: All)")
log.Infof(" --bundle-url string\tURL to bundle that contains the update, bundle.zip")
}
10 changes: 5 additions & 5 deletions backend/cmd/misc/commands/validator_stats_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ func (s *StatsMigratorCommand) ParseCommandOptions() {
s.FlagSet.IntVar(&s.NumberOfPartitions, "partitions", 0, "Number of partitions. Recommended 2 - 128 for PostgreSQL 15")
}

func (s *StatsMigratorCommand) StartStatsPartitionCommand() error {
func (s *StatsMigratorCommand) Run() error {
if s.CurrentTable == "" {
showHelp()
s.showHelp()
return errors.New("Please specify a valid current-table name via --current-table")
}
if s.DestinationTable == "" {
showHelp()
s.showHelp()
return errors.New("Please specify a valid destination-table name via --destination-table")
}
if s.NumberOfPartitions <= 0 {
showHelp()
s.showHelp()
return errors.New("Please specify a valid number of partitions via --partitions. Number of partitions must be > 0")
}

Expand All @@ -64,7 +64,7 @@ func (s *StatsMigratorCommand) StartStatsPartitionCommand() error {
return nil
}

func showHelp() {
func (s *StatsMigratorCommand) showHelp() {
log.Infof("Usage: %s --current-table=validator_stats --destination-table=validator_stats_partitioned --partitions=64\n", "validator_stats_partition")
log.Infof("Usage: %s --current-table=validator_stats --destination-table=validator_stats_partitioned --partitions=64 --drop-existing\n", "validator_stats_partition")
log.Infof("Usage: %s --current-table=validator_stats --destination-table=validator_stats_partitioned --partitions=64 --drop-existing --batch-size=20000 --sleep-between-batches=1s --rename-destination-on-complete=true\n", "validator_stats_partition")
Expand Down
Loading

0 comments on commit e8d7417

Please sign in to comment.