From 4ea03bc9dd47296a9ca170841dcc5d26f26dc2d4 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Sat, 4 Feb 2017 14:47:36 -0800 Subject: [PATCH 1/3] Change ABCI app to implement abci.BlockchainAware interface --- app/app.go | 31 ++++++++++++++----------------- types/plugin.go | 5 +++-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/app.go b/app/app.go index 56f4447cd4..21fe2e3d08 100644 --- a/app/app.go +++ b/app/app.go @@ -1,7 +1,6 @@ package app import ( - "fmt" "strings" abci "github.com/tendermint/abci/types" @@ -42,7 +41,7 @@ func (app *Basecoin) GetState() *sm.State { return app.state.CacheWrap() } -// TMSP::Info +// ABCI::Info func (app *Basecoin) Info() abci.ResponseInfo { return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)} } @@ -51,7 +50,7 @@ func (app *Basecoin) RegisterPlugin(plugin types.Plugin) { app.plugins.RegisterPlugin(plugin) } -// TMSP::SetOption +// ABCI::SetOption func (app *Basecoin) SetOption(key string, value string) (log string) { PluginName, key := splitKey(key) if PluginName != PluginNameBase { @@ -81,7 +80,7 @@ func (app *Basecoin) SetOption(key string, value string) (log string) { } } -// TMSP::DeliverTx +// ABCI::DeliverTx func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) { if len(txBytes) > maxTxSize { return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum") @@ -102,14 +101,12 @@ func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) { return res } -// TMSP::CheckTx +// ABCI::CheckTx func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) { if len(txBytes) > maxTxSize { return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum") } - fmt.Printf("%X\n", txBytes) - // Decode tx var tx types.Tx err := wire.ReadBinaryBytes(txBytes, &tx) @@ -125,7 +122,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) { return abci.OK } -// TMSP::Query +// ABCI::Query func (app *Basecoin) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) { if len(reqQuery.Data) == 0 { resQuery.Log = "Query cannot be zero length" @@ -142,7 +139,7 @@ func (app *Basecoin) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu return } -// TMSP::Commit +// ABCI::Commit func (app *Basecoin) Commit() (res abci.Result) { // Commit state @@ -157,25 +154,25 @@ func (app *Basecoin) Commit() (res abci.Result) { return res } -// TMSP::InitChain +// ABCI::InitChain func (app *Basecoin) InitChain(validators []*abci.Validator) { for _, plugin := range app.plugins.GetList() { plugin.InitChain(app.state, validators) } } -// TMSP::BeginBlock -func (app *Basecoin) BeginBlock(height uint64) { +// ABCI::BeginBlock +func (app *Basecoin) BeginBlock(hash []byte, header *abci.Header) { for _, plugin := range app.plugins.GetList() { - plugin.BeginBlock(app.state, height) + plugin.BeginBlock(app.state, hash, header) } } -// TMSP::EndBlock -func (app *Basecoin) EndBlock(height uint64) (diffs []*abci.Validator) { +// ABCI::EndBlock +func (app *Basecoin) EndBlock(height uint64) (res abci.ResponseEndBlock) { for _, plugin := range app.plugins.GetList() { - moreDiffs := plugin.EndBlock(app.state, height) - diffs = append(diffs, moreDiffs...) + pluginRes := plugin.EndBlock(app.state, height) + res.Diffs = append(res.Diffs, pluginRes.Diffs...) } return } diff --git a/types/plugin.go b/types/plugin.go index 55d3bb969f..ac95cac679 100644 --- a/types/plugin.go +++ b/types/plugin.go @@ -2,6 +2,7 @@ package types import ( "fmt" + abci "github.com/tendermint/abci/types" ) @@ -16,8 +17,8 @@ type Plugin interface { // Other ABCI message handlers SetOption(store KVStore, key string, value string) (log string) InitChain(store KVStore, vals []*abci.Validator) - BeginBlock(store KVStore, height uint64) - EndBlock(store KVStore, height uint64) []*abci.Validator + BeginBlock(store KVStore, hash []byte, header *abci.Header) + EndBlock(store KVStore, height uint64) abci.ResponseEndBlock } //---------------------------------------- From 8af20facc3a5e4b764fec4b8ba529d2d2cc7285f Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Sat, 4 Feb 2017 14:47:51 -0800 Subject: [PATCH 2/3] Update plugins for new interface --- plugins/counter/counter.go | 6 +++--- plugins/ibc/ibc.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index 9c115089b5..8d78d9b545 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -93,9 +93,9 @@ func (cp *CounterPlugin) RunTx(store types.KVStore, ctx types.CallContext, txByt func (cp *CounterPlugin) InitChain(store types.KVStore, vals []*abci.Validator) { } -func (cp *CounterPlugin) BeginBlock(store types.KVStore, height uint64) { +func (cp *CounterPlugin) BeginBlock(store types.KVStore, hash []byte, header *abci.Header) { } -func (cp *CounterPlugin) EndBlock(store types.KVStore, height uint64) []*abci.Validator { - return nil +func (cp *CounterPlugin) EndBlock(store types.KVStore, height uint64) (res abci.ResponseEndBlock) { + return } diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 8d6e0c3893..91b8c54985 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -374,11 +374,11 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { func (ibc *IBCPlugin) InitChain(store types.KVStore, vals []*abci.Validator) { } -func (ibc *IBCPlugin) BeginBlock(store types.KVStore, height uint64) { +func (cp *IBCPlugin) BeginBlock(store types.KVStore, hash []byte, header *abci.Header) { } -func (ibc *IBCPlugin) EndBlock(store types.KVStore, height uint64) []*abci.Validator { - return nil +func (cp *IBCPlugin) EndBlock(store types.KVStore, height uint64) (res abci.ResponseEndBlock) { + return } //-------------------------------------------------------------------------------- From c23c01882499a9bbdfd58b334fe924f8862659f5 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Sat, 4 Feb 2017 15:02:51 -0800 Subject: [PATCH 3/3] Assert that Basecoin ABCI app implements abci.BlockchainAware --- app/app.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/app.go b/app/app.go index 21fe2e3d08..621d17a6ec 100644 --- a/app/app.go +++ b/app/app.go @@ -188,3 +188,9 @@ func splitKey(key string) (prefix string, suffix string) { } return key, "" } + +// (not meant to be called) +// assert that Basecoin implements `abci.BlockchainAware` at compile-time +func _assertABCIBlockchainAware(basecoin *Basecoin) abci.BlockchainAware { + return basecoin +}