Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Jae/gaiareplay #1938

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ vagrant

# Graphviz
dependency-graph.png
data/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ifeq ($(OS),Windows_NT)
else
go build $(BUILD_FLAGS) -o build/gaiad ./cmd/gaia/cmd/gaiad
go build $(BUILD_FLAGS) -o build/gaiacli ./cmd/gaia/cmd/gaiacli
go build $(BUILD_FLAGS) -o build/gaiareplay ./cmd/gaia/cmd/gaiareplay
endif

build-linux:
Expand All @@ -53,6 +54,7 @@ endif
install: check-ledger
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiad
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiacli
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiareplay

install_examples:
go install $(BUILD_FLAGS) ./examples/basecoin/cmd/basecoind
Expand Down
140 changes: 140 additions & 0 deletions cmd/gaia/cmd/gaiareplay/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package main

import (
"fmt"
"io"
"os"
"path/filepath"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"

abci "github.com/tendermint/tendermint/abci/types"
bcm "github.com/tendermint/tendermint/blockchain"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/proxy"
tmsm "github.com/tendermint/tendermint/state"
tm "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/server"
)

func main() {
rootDir := "data"
ctx := server.NewDefaultContext()

// App DB
// appDB := dbm.NewMemDB()
appDB, err := dbm.NewGoLevelDB("app", rootDir)
if err != nil {
panic(err)
}

// TM DB
// tmDB := dbm.NewMemDB()
tmDB, err := dbm.NewGoLevelDB("tendermint", rootDir)
if err != nil {
panic(err)
}

// Blockchain DB
bcDB, err := dbm.NewGoLevelDB("blockstore", rootDir)
if err != nil {
panic(err)
}

// TraceStore
var traceStoreWriter io.Writer
var traceStoreDir = filepath.Join(rootDir, "trace.log")
traceStoreWriter, err = os.OpenFile(
traceStoreDir,
os.O_WRONLY|os.O_APPEND|os.O_CREATE,
0666,
)
if err != nil {
panic(err)
}

// Application
myapp := app.NewGaiaApp(
ctx.Logger, appDB, traceStoreWriter,
baseapp.SetPruning("everything"), // nothing
)

// Genesis
var genDocPath = filepath.Join(rootDir, "genesis.json")
genDoc, err := tm.GenesisDocFromFile(genDocPath)
if err != nil {
panic(err)
}
genState, err := tmsm.MakeGenesisState(genDoc)
if err != nil {
panic(err)
}
// tmsm.SaveState(tmDB, genState)

cc := proxy.NewLocalClientCreator(myapp)
proxyApp := proxy.NewAppConns(cc, nil)
err = proxyApp.Start()
if err != nil {
panic(err)
}
defer proxyApp.Stop()

// Send InitChain msg
validators := tm.TM2PB.Validators(genState.Validators)
csParams := tm.TM2PB.ConsensusParams(genDoc.ConsensusParams)
req := abci.RequestInitChain{
Time: genDoc.GenesisTime.Unix(),
ChainId: genDoc.ChainID,
ConsensusParams: csParams,
Validators: validators,
AppStateBytes: genDoc.AppState,
}
_, err = proxyApp.Consensus().InitChainSync(req)
if err != nil {
panic(err)
}

// Create executor
blockExec := tmsm.NewBlockExecutor(tmDB, ctx.Logger, proxyApp.Consensus(),
tmsm.MockMempool{}, tmsm.MockEvidencePool{})

// Create block store
blockStore := bcm.NewBlockStore(bcDB)

// Update this state.
state := genState
tz := []time.Duration{0, 0, 0}
for i := 1; i < 1e10; i++ {

t1 := time.Now()

// Apply block
fmt.Printf("loading and applying block %d\n", i)
blockmeta := blockStore.LoadBlockMeta(int64(i))
if blockmeta == nil {
panic(fmt.Sprintf("couldn't find block meta %d", i))
}
block := blockStore.LoadBlock(int64(i))
if block == nil {
panic(fmt.Sprintf("couldn't find block %d", i))
}

t2 := time.Now()

state, err = blockExec.ApplyBlock(state, blockmeta.BlockID, block)
if err != nil {
panic(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)
}

}
Loading