-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Initialize Genesis State #416
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
40fd458
init genesis WIP, also making golint compliant
rigelrozanski 41ae60c
working
rigelrozanski da538a8
more comments cleanup
rigelrozanski 7643dea
genesis wip compiles
rigelrozanski 6eaafa4
wip genesis parsing
rigelrozanski 849139e
working
rigelrozanski 17acf9e
working
rigelrozanski 7206c43
genesis exisiting tests pass
rigelrozanski 2b9633d
working genesis tests
rigelrozanski fd1684a
...
rigelrozanski b09653c
Fix init state bug
ethanfrey 0bab936
initgen tests complete
rigelrozanski ed66256
remove genesis of checkTx
rigelrozanski 658d763
cleanup
rigelrozanski d9ebe34
fixes from review
ebuchman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ import ( | |
|
||
var mainHeaderKey = []byte("header") | ||
|
||
// BaseApp - The ABCI application | ||
// The ABCI application | ||
type BaseApp struct { | ||
logger log.Logger | ||
|
||
|
@@ -32,33 +32,38 @@ type BaseApp struct { | |
// Main (uncached) state | ||
cms sdk.CommitMultiStore | ||
|
||
// Unmarshal []byte into sdk.Tx | ||
// unmarshal []byte into sdk.Tx | ||
txDecoder sdk.TxDecoder | ||
|
||
// Ante handler for fee and auth. | ||
// unmarshal rawjsonbytes to initialize the application | ||
// TODO unexpose and call from InitChain | ||
InitStater sdk.InitStater | ||
|
||
// ante handler for fee and auth | ||
defaultAnteHandler sdk.AnteHandler | ||
|
||
// Handle any kind of message. | ||
// handle any kind of message | ||
router Router | ||
|
||
//-------------------- | ||
// Volatile | ||
|
||
// CheckTx state, a cache-wrap of `.cms`. | ||
// CheckTx state, a cache-wrap of `.cms` | ||
msCheck sdk.CacheMultiStore | ||
|
||
// DeliverTx state, a cache-wrap of `.cms`. | ||
// DeliverTx state, a cache-wrap of `.cms` | ||
msDeliver sdk.CacheMultiStore | ||
|
||
// Current block header | ||
// current block header | ||
header *abci.Header | ||
|
||
// Cached validator changes from DeliverTx. | ||
// cached validator changes from DeliverTx | ||
valUpdates []abci.Validator | ||
} | ||
|
||
var _ abci.Application = &BaseApp{} | ||
|
||
// Create and name new BaseApp | ||
func NewBaseApp(name string) *BaseApp { | ||
var baseapp = &BaseApp{ | ||
logger: makeDefaultLogger(), | ||
|
@@ -88,37 +93,42 @@ func (app *BaseApp) initMultiStore() { | |
app.cms = cms | ||
} | ||
|
||
// BaseApp Name | ||
func (app *BaseApp) Name() string { | ||
return app.name | ||
} | ||
|
||
// Mount a store to the provided key in the BaseApp multistore | ||
func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) { | ||
app.cms.MountStoreWithDB(key, typ, app.db) | ||
} | ||
|
||
// nolint | ||
func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) { | ||
app.txDecoder = txDecoder | ||
} | ||
|
||
func (app *BaseApp) SetInitStater(initStater sdk.InitStater) { | ||
app.InitStater = initStater | ||
} | ||
func (app *BaseApp) SetDefaultAnteHandler(ah sdk.AnteHandler) { | ||
app.defaultAnteHandler = ah | ||
} | ||
|
||
func (app *BaseApp) Router() Router { | ||
return app.router | ||
} | ||
|
||
/* TODO consider: | ||
func (app *BaseApp) SetBeginBlocker(...) {} | ||
func (app *BaseApp) SetEndBlocker(...) {} | ||
func (app *BaseApp) SetInitStater(...) {} | ||
*/ | ||
|
||
// TODO add description | ||
func (app *BaseApp) LoadLatestVersion(mainKey sdk.StoreKey) error { | ||
app.cms.LoadLatestVersion() | ||
return app.initFromStore(mainKey) | ||
} | ||
|
||
// Load application version | ||
func (app *BaseApp) LoadVersion(version int64, mainKey sdk.StoreKey) error { | ||
app.cms.LoadVersion(version) | ||
return app.initFromStore(mainKey) | ||
|
@@ -174,7 +184,7 @@ func (app *BaseApp) initFromStore(mainKey sdk.StoreKey) error { | |
|
||
//---------------------------------------- | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why get rid of periods? It's also in the coding conventions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my previous comment (not a sentence) |
||
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo { | ||
|
||
lastCommitID := app.cms.LastCommitID() | ||
|
@@ -186,15 +196,16 @@ func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo { | |
} | ||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOption) { | ||
// TODO: Implement | ||
return | ||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { | ||
// TODO: Use req.Validators | ||
// TODO: Use req.AppStateJSON (?) | ||
return | ||
} | ||
|
||
|
@@ -209,7 +220,7 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) { | |
return queryable.Query(req) | ||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { | ||
// NOTE: For consistency we should unset these upon EndBlock. | ||
app.header = &req.Header | ||
|
@@ -219,7 +230,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg | |
return | ||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) { | ||
|
||
// Decode the Tx. | ||
|
@@ -245,7 +256,7 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) { | |
|
||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) { | ||
|
||
// Decode the Tx. | ||
|
@@ -333,7 +344,7 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk | |
return result | ||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) { | ||
res.ValidatorUpdates = app.valUpdates | ||
app.valUpdates = nil | ||
|
@@ -343,7 +354,7 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc | |
return | ||
} | ||
|
||
// Implements ABCI. | ||
// Implements ABCI | ||
func (app *BaseApp) Commit() (res abci.ResponseCommit) { | ||
app.msDeliver.Write() | ||
commitID := app.cms.Commit() | ||
|
@@ -361,9 +372,8 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) { | |
func (app *BaseApp) getMultiStore(isCheckTx bool) sdk.MultiStore { | ||
if isCheckTx { | ||
return app.msCheck | ||
} else { | ||
return app.msDeliver | ||
} | ||
return app.msDeliver | ||
} | ||
|
||
// Return index of list with validator of same PubKey, or -1 if no match | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package baseapp | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
) | ||
|
||
// TODO: remove from here and pass the AppState | ||
// through InitChain | ||
|
||
// GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set. | ||
type GenesisDoc struct { | ||
AppState json.RawMessage `json:"app_state,omitempty"` | ||
} | ||
|
||
// GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc. | ||
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) { | ||
if genDocFile == "" { | ||
var g GenesisDoc | ||
return &g, nil | ||
} | ||
jsonBlob, err := ioutil.ReadFile(genDocFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
genDoc := GenesisDoc{} | ||
err = json.Unmarshal(jsonBlob, &genDoc) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &genDoc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to keep comments well formed (capitalized and with periods). https://github.com/tendermint/coding/blob/master/go/coding_standard.md#various
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did go-lint really complain about this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, there are not sentences, as in the spec, only sentences should start capitalized. Everything else should start lowercase and end without a period... We should further clarify this in the spec