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

[R4R]support blockhash context #167

Merged
merged 3 commits into from
Oct 23, 2019
Merged
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
3 changes: 2 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ IMPROVEMENTS

* Gaia

* SDK
* SDK
* [\#167](https://github.com/binance-chain/bnc-cosmos-sdk/pull/167) [sdk] add blockhash context

* Tendermint

Expand Down
4 changes: 2 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,11 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
// nil, since it is reset on Commit.
if app.DeliverState == nil {
app.SetDeliverState(req.Header)
app.DeliverState.Ctx = app.DeliverState.Ctx.WithVoteInfos(req.LastCommitInfo.GetVotes())
app.DeliverState.Ctx = app.DeliverState.Ctx.WithVoteInfos(req.LastCommitInfo.GetVotes()).WithBlockHash(req.Hash)
} else {
// In the first block, app.DeliverState.Ctx will already be initialized
// by InitChain. Context is now updated with Header information.
app.DeliverState.Ctx = app.DeliverState.Ctx.WithBlockHeader(req.Header).WithBlockHeight(req.Header.Height)
app.DeliverState.Ctx = app.DeliverState.Ctx.WithBlockHash(req.Hash).WithBlockHeader(req.Header).WithBlockHeight(req.Header.Height)
}

if app.beginBlocker != nil {
Expand Down
9 changes: 9 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const (
contextKeyMultiStore contextKey = iota
contextKeyBlockHeader
contextKeyBlockHeight
contextKeyBlockHash
contextKeyConsensusParams
contextKeyChainID
contextKeyRunTxMode
Expand All @@ -149,6 +150,10 @@ func (c Context) BlockHeader() abci.Header { return c.Value(contextKeyBlockHeade

func (c Context) BlockHeight() int64 { return c.Value(contextKeyBlockHeight).(int64) }

func (c Context) BlockHash() []byte {
return c.Value(contextKeyBlockHash).([]byte)
}

func (c Context) ConsensusParams() abci.ConsensusParams {
return c.Value(contextKeyConsensusParams).(abci.ConsensusParams)
}
Expand Down Expand Up @@ -193,6 +198,10 @@ func (c Context) WithBlockHeader(header abci.Header) Context {
return c.withValue(contextKeyBlockHeader, header)
}

func (c Context) WithBlockHash(hash []byte) Context {
return c.withValue(contextKeyBlockHash, hash)
}

func (c Context) WithBlockTime(newTime time.Time) Context {
newHeader := c.BlockHeader()
newHeader.Time = newTime
Expand Down