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

Add height in exported genesis #7089

Merged
merged 70 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
7b56ee3
Add height in exported genesis
amaury1093 Aug 18, 2020
167cc8b
+1
amaury1093 Aug 18, 2020
e17275c
Add test
amaury1093 Aug 19, 2020
ef1e6f0
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 19, 2020
64e828b
Refactor ctx in setupApp
amaury1093 Aug 19, 2020
a04a42c
Use amino in export
amaury1093 Aug 20, 2020
a619220
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 20, 2020
2c7ef98
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 21, 2020
1749ca8
Use tmjson
amaury1093 Aug 21, 2020
2b1cec3
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 24, 2020
facab0e
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 24, 2020
a4ac0fc
Add custom initialVersion (set to 0 for now)
amaury1093 Aug 24, 2020
6a9e6bc
Add comment
amaury1093 Aug 24, 2020
a04b438
Add mount in initChainer
amaury1093 Aug 25, 2020
bf549ec
app.LastBlockheight
amaury1093 Aug 25, 2020
86162b3
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 25, 2020
fb99bb3
InitializeAndSeal in InitChain?
amaury1093 Aug 25, 2020
bf9d606
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 25, 2020
405c921
Merge branch 'master' into am-7018-export-height
alexanderbez Aug 26, 2020
270c323
Revert create store with initial version
amaury1093 Aug 26, 2020
5df1626
Update to latest iavl
amaury1093 Aug 26, 2020
9d16e9e
Check height in test
amaury1093 Aug 26, 2020
af9e5dc
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 26, 2020
9274552
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 27, 2020
5dfa955
Make it work
amaury1093 Aug 27, 2020
4aa9bcc
Add more tests
amaury1093 Aug 27, 2020
bcbb243
Rename interface
amaury1093 Aug 27, 2020
7fdab5d
Use struct isntead of 6 args
amaury1093 Aug 27, 2020
6839081
Fix lint
amaury1093 Aug 27, 2020
0b82fec
Remove stray fmt
amaury1093 Aug 27, 2020
ca6b7c1
Revert go mod/sum
amaury1093 Aug 27, 2020
7f0b573
Install iavl rc3
amaury1093 Aug 27, 2020
4c858a5
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 28, 2020
76c7a12
Update comments
amaury1093 Aug 28, 2020
b80e01b
Merge branch 'master' into am-7018-export-height
jackzampolin Aug 28, 2020
eb65bd1
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 31, 2020
10bc9e6
Add fee in network
amaury1093 Aug 31, 2020
314f0a3
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Aug 31, 2020
255aaa7
Typo
amaury1093 Aug 31, 2020
f6216f6
Fix logic in commit
amaury1093 Aug 31, 2020
1f1b602
Fix tests
amaury1093 Aug 31, 2020
789842a
Only set initial version on > 1
amaury1093 Aug 31, 2020
fac4d5e
Genesis block num = 1
amaury1093 Aug 31, 2020
b532d0d
Fresh chain, genesis block = 0
amaury1093 Aug 31, 2020
6ab3cf9
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 31, 2020
54b0a97
Add comments
amaury1093 Aug 31, 2020
e62a650
Merge branch 'master' into am-7018-export-height
amaury1093 Sep 1, 2020
c95c075
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 1, 2020
dbc92b7
Revert Mutable/ImmutableTree
amaury1093 Sep 1, 2020
e238ebe
Allow for zero height
amaury1093 Sep 1, 2020
b8ba3e2
Fix restart
amaury1093 Sep 1, 2020
57485ee
Add comments
amaury1093 Sep 1, 2020
7c6ba4d
Add comments, fix test
amaury1093 Sep 1, 2020
ecd6d7a
Merge branch 'master' into am-7018-export-height
amaury1093 Sep 1, 2020
66a0dc8
Fix remaining one test
amaury1093 Sep 1, 2020
f7cd6d2
Add panic test
amaury1093 Sep 1, 2020
af26c5b
Update comment
amaury1093 Sep 1, 2020
5c5b3eb
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 1, 2020
31d2986
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 2, 2020
57c1f9f
Add test for --height
amaury1093 Sep 2, 2020
2b28235
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Sep 2, 2020
aeec99f
No cast
amaury1093 Sep 2, 2020
c2d41b5
Add check that genesis file exists
amaury1093 Sep 2, 2020
d7f4353
Remove duplicate imports
amaury1093 Sep 2, 2020
5940b66
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 2, 2020
95365dc
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 2, 2020
788fb8b
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 2, 2020
6bf735c
Fail early
amaury1093 Sep 2, 2020
8712d04
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Sep 2, 2020
abdfb85
Merge branch 'master' into am-7018-export-height
clevinson Sep 2, 2020
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
15 changes: 11 additions & 4 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ import (
// InitChain implements the ABCI interface. It runs the initialization logic
// directly on the CommitMultiStore.
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time}
initHeader := tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time}

if req.InitialHeight > 0 {
err := app.cms.SetInitialVersion(req.InitialHeight)
if err != nil {
panic(err)
}
}

// initialize the deliver state and check state with a correct header
app.setDeliverState(initHeader)
Expand Down Expand Up @@ -60,13 +67,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
sort.Sort(abci.ValidatorUpdates(res.Validators))

for i := range res.Validators {
if proto.Equal(&res.Validators[i], &req.Validators[i]) {
if !proto.Equal(&res.Validators[i], &req.Validators[i]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not correctly implemented before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah seems so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol wow.....

panic(fmt.Errorf("genesisValidators[%d] != req.Validators[%d] ", i, i))
}
}
}

// NOTE: We don't commit, but BeginBlock for block 1 starts from this
// NOTE: We don't commit, but BeginBlock for block `initial_height` starts from this
// deliverState.
return res
}
Expand Down Expand Up @@ -97,7 +104,7 @@ func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery {
return abci.ResponseQuery{}
}

// FilterPeerByIDfilters peers by node ID.
// FilterPeerByID filters peers by node ID.
func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
if app.idPeerFilter != nil {
return app.idPeerFilter(info)
Expand Down
6 changes: 0 additions & 6 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) {
}
}

// MountStoreWithDB mounts a store to the provided key in the BaseApp
// multistore, using a specified DB.
func (app *BaseApp) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shortcut for app.cms.MountStoreWithDB, but in the code we always use app.cms.MountStoreWithDB directly. This function was never.called.

app.cms.MountStoreWithDB(key, typ, db)
}

// MountStore mounts a store to the provided key in the BaseApp multistore,
// using the default DB.
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/btcsuite/btcutil v1.0.2
github.com/confio/ics23/go v0.0.0-20200804135932-65ad804e8539
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/cosmos/iavl v0.15.0-rc2
github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25
github.com/gogo/gateway v1.1.0
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fj
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/iavl v0.15.0-rc2 h1:4HI/LYLjWUnou8dehPD+NqEsDc8uamJOU2yHcqdTKv8=
github.com/cosmos/iavl v0.15.0-rc2/go.mod h1:bXLXbwmww0kYtAYRCYNXR/k44lWaK8rIZJlCmqSK8lQ=
github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050 h1:BUVAB5KQg+uH/dTuaXhm+AKh/LC9OoYJqPezPKvONnY=
github.com/cosmos/iavl v0.15.0-rc2.0.20200826144708-9ea987bad050/go.mod h1:tzsrhsQoOLtkvm1ASF1MpiipQDw0EMGcQWtAgo6S56Y=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down Expand Up @@ -165,6 +167,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo=
Expand Down Expand Up @@ -246,11 +249,13 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-gateway v1.14.7 h1:Nk5kuHrnWUTf/0GL1a/vchH/om9Ap2/HnVna+jYZgTY=
github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
Expand Down Expand Up @@ -600,6 +605,7 @@ golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxT
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 h1:A1gGSx58LAGVHUUsOf7IiR0u8Xb6W51gRwfDBhkdcaw=
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand All @@ -615,6 +621,7 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -637,6 +644,7 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -672,12 +680,14 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
Expand Down Expand Up @@ -713,6 +723,7 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
Expand Down Expand Up @@ -742,6 +753,7 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
Expand All @@ -759,6 +771,7 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs=
Expand Down
31 changes: 16 additions & 15 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package server
// DONTCOVER

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

Expand Down Expand Up @@ -64,7 +64,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight)
jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs)

appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs)
exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
}
Expand All @@ -74,29 +74,30 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return err
}

doc.AppState = appState
doc.Validators = validators
doc.AppState = exported.AppState
doc.Validators = exported.Validators
doc.InitialHeight = exported.Height
doc.ConsensusParams = &tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: cp.Block.MaxBytes,
MaxGas: cp.Block.MaxGas,
MaxBytes: exported.ConsensusParams.Block.MaxBytes,
MaxGas: exported.ConsensusParams.Block.MaxGas,
TimeIotaMs: doc.ConsensusParams.Block.TimeIotaMs,
},
Evidence: tmproto.EvidenceParams{
MaxAgeNumBlocks: cp.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: cp.Evidence.MaxAgeDuration,
MaxNum: cp.Evidence.MaxNum,
ProofTrialPeriod: cp.Evidence.ProofTrialPeriod,
MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration,
MaxNum: exported.ConsensusParams.Evidence.MaxNum,
ProofTrialPeriod: exported.ConsensusParams.Evidence.ProofTrialPeriod,
},
Validator: tmproto.ValidatorParams{
PubKeyTypes: cp.Validator.PubKeyTypes,
PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes,
},
}

// NOTE: for now we're just using standard JSON marshaling for the root GenesisDoc.
// These types are in Tendermint, don't support proto and as far as we know, don't need it.
// All of the protobuf/amino state is inside AppState
encoded, err := json.MarshalIndent(doc, "", " ")
// NOTE: Tendermint uses a custom JSON decoder for GenesisDoc
// (except for stuff inside AppState). Inside AppState, we're free
// to encode as protobuf or amino.
encoded, err := tmjson.Marshal(doc)
if err != nil {
return err
}
Expand Down
77 changes: 57 additions & 20 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import (
"path"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -29,6 +33,56 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
tempDir, clean := testutil.NewTestCaseDir(t)
defer clean()

_, ctx, genDoc, cmd := setupApp(t, tempDir)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas)

require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration)
require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes)
}

func TestExportCmd_Height(t *testing.T) {
tempDir, clean := testutil.NewTestCaseDir(t)
defer clean()

app, ctx, _, cmd := setupApp(t, tempDir)

// Fast forward to block 3.
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}})
app.Commit()

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err := tmjson.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, int64(4), exportedGenDoc.InitialHeight)
}

func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) {
err := createConfigFolder(tempDir)
if err != nil {
t.Fatalf("error creating config folder: %s", err)
Expand All @@ -44,6 +98,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) {

genDoc := newDefaultGenesisDoc()
err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())
require.NoError(t, err)

app.InitChain(
abci.RequestInitChain{
Expand All @@ -56,33 +111,15 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
app.Commit()

cmd := ExportCmd(
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (types.ExportedApp, error) {
return app.ExportAppStateAndValidators(true, []string{})
}, tempDir)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, ServerContextKey, serverCtx)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err = json.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas)

require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration)
require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks)

require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes)
return app, ctx, genDoc, cmd
}

func createConfigFolder(dir string) error {
Expand Down
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func (ms multiStore) SetInterBlockCache(_ sdk.MultiStorePersistentCache) {
panic("not implemented")
}

func (ms multiStore) SetInitialVersion(version int64) error {
panic("not implemented")
}

var _ sdk.KVStore = kvStore{}

type kvStore struct {
Expand Down
Loading