Merge gaiareplay into gaiad to reduce number of binaries (#4272)

This commit is contained in:
Alessio Treglia 2019-05-06 17:43:37 +01:00 committed by GitHub
parent 8bb2569abc
commit 5060187d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 55 deletions

View File

@ -0,0 +1,2 @@
#4272 Merge gaiareplay functionality into gaiad replay.
Drop `gaiareplay` in favor of new `gaiad replay` command.

View File

@ -81,7 +81,6 @@ ifeq ($(OS),Windows_NT)
else
go build -mod=readonly $(BUILD_FLAGS) -o build/gaiad ./cmd/gaia/cmd/gaiad
go build -mod=readonly $(BUILD_FLAGS) -o build/gaiacli ./cmd/gaia/cmd/gaiacli
go build -mod=readonly $(BUILD_FLAGS) -o build/gaiareplay ./cmd/gaia/cmd/gaiareplay
endif
build-linux: go.sum
@ -93,7 +92,6 @@ update_gaia_lite_docs:
install: go.sum check-ledger update_gaia_lite_docs
go install -mod=readonly $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiad
go install -mod=readonly $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiacli
go install -mod=readonly $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiareplay
install_debug: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiadebug

View File

@ -72,7 +72,6 @@ ifeq ($(OS),Windows_NT)
else
go build -mod=readonly $(BUILD_FLAGS) -o build/gaiad ../../cmd/gaia/cmd/gaiad
go build -mod=readonly $(BUILD_FLAGS) -o build/gaiacli ../../cmd/gaia/cmd/gaiacli
go build -mod=readonly $(BUILD_FLAGS) -o build/gaiareplay ../../cmd/gaia/cmd/gaiareplay
endif
build-linux: ../../go.sum
@ -81,7 +80,6 @@ build-linux: ../../go.sum
install: ../../go.sum check-ledger
go install -mod=readonly $(BUILD_FLAGS) ../../cmd/gaia/cmd/gaiad
go install -mod=readonly $(BUILD_FLAGS) ../../cmd/gaia/cmd/gaiacli
go install -mod=readonly $(BUILD_FLAGS) ../../cmd/gaia/cmd/gaiareplay
install-debug: ../../go.sum
go install -mod=readonly $(BUILD_FLAGS) ../../cmd/gaia/cmd/gaiadebug

View File

@ -51,6 +51,7 @@ func main() {
rootCmd.AddCommand(gaiaInit.AddGenesisAccountCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.ValidateGenesisCmd(ctx, cdc))
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
rootCmd.AddCommand(replayCmd())
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)

View File

@ -7,8 +7,6 @@ import (
"path/filepath"
"time"
"github.com/cosmos/cosmos-sdk/store"
cpm "github.com/otiai10/copy"
"github.com/spf13/cobra"
@ -22,46 +20,33 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
rootDir string
)
var rootCmd = &cobra.Command{
Use: "gaiareplay",
Short: "Replay gaia transactions",
Run: func(cmd *cobra.Command, args []string) {
run(rootDir)
},
}
func init() {
// cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&rootDir, "root", "r", "root dir")
}
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
func replayCmd() *cobra.Command {
return &cobra.Command{
Use: "replay <root-dir>",
Short: "Replay gaia transactions",
RunE: func(_ *cobra.Command, args []string) error {
return replayTxs(args[0])
},
Args: cobra.ExactArgs(1),
}
}
func run(rootDir string) {
func replayTxs(rootDir string) error {
if false {
// Copy the rootDir to a new directory, to preserve the old one.
fmt.Println("Copying rootdir over")
fmt.Fprintln(os.Stderr, "Copying rootdir over")
oldRootDir := rootDir
rootDir = oldRootDir + "_replay"
if cmn.FileExists(rootDir) {
cmn.Exit(fmt.Sprintf("temporary copy dir %v already exists", rootDir))
}
err := cpm.Copy(oldRootDir, rootDir)
if err != nil {
panic(err)
if err := cpm.Copy(oldRootDir, rootDir); err != nil {
return err
}
}
@ -71,25 +56,25 @@ func run(rootDir string) {
// App DB
// appDB := dbm.NewMemDB()
fmt.Println("Opening app database")
fmt.Fprintln(os.Stderr, "Opening app database")
appDB, err := sdk.NewLevelDB("application", dataDir)
if err != nil {
panic(err)
return err
}
// TM DB
// tmDB := dbm.NewMemDB()
fmt.Println("Opening tendermint state database")
fmt.Fprintln(os.Stderr, "Opening tendermint state database")
tmDB, err := sdk.NewLevelDB("state", dataDir)
if err != nil {
panic(err)
return err
}
// Blockchain DB
fmt.Println("Opening blockstore database")
fmt.Fprintln(os.Stderr, "Opening blockstore database")
bcDB, err := sdk.NewLevelDB("blockstore", dataDir)
if err != nil {
panic(err)
return err
}
// TraceStore
@ -101,11 +86,11 @@ func run(rootDir string) {
0666,
)
if err != nil {
panic(err)
return err
}
// Application
fmt.Println("Creating application")
fmt.Fprintln(os.Stderr, "Creating application")
myapp := app.NewGaiaApp(
ctx.Logger, appDB, traceStoreWriter, true, uint(1),
baseapp.SetPruning(store.PruneEverything), // nothing
@ -115,11 +100,11 @@ func run(rootDir string) {
var genDocPath = filepath.Join(configDir, "genesis.json")
genDoc, err := tm.GenesisDocFromFile(genDocPath)
if err != nil {
panic(err)
return err
}
genState, err := tmsm.MakeGenesisState(genDoc)
if err != nil {
panic(err)
return err
}
// tmsm.SaveState(tmDB, genState)
@ -127,7 +112,7 @@ func run(rootDir string) {
proxyApp := proxy.NewAppConns(cc)
err = proxyApp.Start()
if err != nil {
panic(err)
return err
}
defer func() {
_ = proxyApp.Stop()
@ -136,7 +121,7 @@ func run(rootDir string) {
state := tmsm.LoadState(tmDB)
if state.LastBlockHeight == 0 {
// Send InitChain msg
fmt.Println("Sending InitChain msg")
fmt.Fprintln(os.Stderr, "Sending InitChain msg")
validators := tm.TM2PB.ValidatorUpdates(genState.Validators)
csParams := tm.TM2PB.ConsensusParams(genDoc.ConsensusParams)
req := abci.RequestInitChain{
@ -148,11 +133,11 @@ func run(rootDir string) {
}
res, err := proxyApp.Consensus().InitChainSync(req)
if err != nil {
panic(err)
return err
}
newValidatorz, err := tm.PB2TM.ValidatorUpdates(res.Validators)
if err != nil {
panic(err)
return err
}
newValidators := tm.NewValidatorSet(newValidatorz)
@ -163,17 +148,17 @@ func run(rootDir string) {
}
// Create executor
fmt.Println("Creating block executor")
fmt.Fprintln(os.Stderr, "Creating block executor")
blockExec := tmsm.NewBlockExecutor(tmDB, ctx.Logger, proxyApp.Consensus(),
tmsm.MockMempool{}, tmsm.MockEvidencePool{})
// Create block store
fmt.Println("Creating block store")
fmt.Fprintln(os.Stderr, "Creating block store")
blockStore := bcm.NewBlockStore(bcDB)
tz := []time.Duration{0, 0, 0}
for i := int(state.LastBlockHeight) + 1; ; i++ {
fmt.Println("Running block ", i)
fmt.Fprintln(os.Stderr, "Running block ", i)
t1 := time.Now()
// Apply block
@ -181,26 +166,25 @@ func run(rootDir string) {
blockmeta := blockStore.LoadBlockMeta(int64(i))
if blockmeta == nil {
fmt.Printf("Couldn't find block meta %d... done?\n", i)
return
return nil
}
block := blockStore.LoadBlock(int64(i))
if block == nil {
panic(fmt.Sprintf("couldn't find block %d", i))
return fmt.Errorf("couldn't find block %d", i)
}
t2 := time.Now()
state, err = blockExec.ApplyBlock(state, blockmeta.BlockID, block)
if err != nil {
panic(err)
return err
}
t3 := time.Now()
tz[0] += t2.Sub(t1)
tz[1] += t3.Sub(t2)
fmt.Printf("new app hash: %X\n", state.AppHash)
fmt.Println(tz)
fmt.Fprintf(os.Stderr, "new app hash: %X\n", state.AppHash)
fmt.Fprintln(os.Stderr, tz)
}
}