Skip to content
Snippets Groups Projects
Unverified Commit f9a13ef0 authored by Silas Davis's avatar Silas Davis
Browse files

Updated ABCI app for latest Tendermint


Signed-off-by: default avatarSilas Davis <silas@monax.io>
parent e2a168ea
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"time" "time"
bcm "github.com/hyperledger/burrow/blockchain" bcm "github.com/hyperledger/burrow/blockchain"
"github.com/hyperledger/burrow/consensus/tendermint/codes"
"github.com/hyperledger/burrow/execution" "github.com/hyperledger/burrow/execution"
"github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/logging"
"github.com/hyperledger/burrow/logging/structure" "github.com/hyperledger/burrow/logging/structure"
...@@ -50,29 +51,34 @@ func (app *abciApp) Info(info abci_types.RequestInfo) abci_types.ResponseInfo { ...@@ -50,29 +51,34 @@ func (app *abciApp) Info(info abci_types.RequestInfo) abci_types.ResponseInfo {
return abci_types.ResponseInfo{ return abci_types.ResponseInfo{
Data: responseInfoName, Data: responseInfoName,
Version: version.GetSemanticVersionString(), Version: version.GetSemanticVersionString(),
LastBlockHeight: tip.LastBlockHeight(), LastBlockHeight: int64(tip.LastBlockHeight()),
LastBlockAppHash: tip.AppHashAfterLastBlock(), LastBlockAppHash: tip.AppHashAfterLastBlock(),
} }
} }
func (app *abciApp) SetOption(key string, value string) string { func (app *abciApp) SetOption(option abci_types.RequestSetOption) (respSetOption abci_types.ResponseSetOption) {
return "No options available" respSetOption.Log = "SetOption not supported"
respSetOption.Code = codes.UnsupportedRequestCode
return
} }
func (app *abciApp) Query(reqQuery abci_types.RequestQuery) (respQuery abci_types.ResponseQuery) { func (app *abciApp) Query(reqQuery abci_types.RequestQuery) (respQuery abci_types.ResponseQuery) {
respQuery.Log = "Query not support" respQuery.Log = "Query not supported"
respQuery.Code = abci_types.CodeType_UnknownRequest respQuery.Code = codes.UnsupportedRequestCode
return respQuery return
} }
func (app *abciApp) CheckTx(txBytes []byte) abci_types.Result { func (app *abciApp) CheckTx(txBytes []byte) abci_types.ResponseCheckTx {
app.mtx.Lock() app.mtx.Lock()
defer app.mtx.Unlock() defer app.mtx.Unlock()
tx, err := app.txDecoder.DecodeTx(txBytes) tx, err := app.txDecoder.DecodeTx(txBytes)
if err != nil { if err != nil {
logging.TraceMsg(app.logger, "CheckTx decoding error", logging.TraceMsg(app.logger, "CheckTx decoding error",
structure.ErrorKey, err) structure.ErrorKey, err)
return abci_types.NewError(abci_types.CodeType_EncodingError, fmt.Sprintf("Encoding error: %v", err)) return abci_types.ResponseCheckTx{
Code: codes.EncodingErrorCode,
Log: fmt.Sprintf("Encoding error: %s", err),
}
} }
// TODO: map ExecTx errors to sensible ABCI error codes // TODO: map ExecTx errors to sensible ABCI error codes
receipt := txs.GenerateReceipt(app.blockchain.ChainID(), tx) receipt := txs.GenerateReceipt(app.blockchain.ChainID(), tx)
...@@ -83,33 +89,44 @@ func (app *abciApp) CheckTx(txBytes []byte) abci_types.Result { ...@@ -83,33 +89,44 @@ func (app *abciApp) CheckTx(txBytes []byte) abci_types.Result {
structure.ErrorKey, err, structure.ErrorKey, err,
"tx_hash", receipt.TxHash, "tx_hash", receipt.TxHash,
"creates_contract", receipt.CreatesContract) "creates_contract", receipt.CreatesContract)
return abci_types.NewError(abci_types.CodeType_InternalError, return abci_types.ResponseCheckTx{
fmt.Sprintf("Could not execute transaction: %s, error: %v", tx, err)) Code: codes.EncodingErrorCode,
Log: fmt.Sprintf("Could not execute transaction: %s, error: %v", tx, err),
}
} }
receiptBytes := wire.BinaryBytes(receipt) receiptBytes := wire.BinaryBytes(receipt)
logging.TraceMsg(app.logger, "CheckTx success", logging.TraceMsg(app.logger, "CheckTx success",
"tx_hash", receipt.TxHash, "tx_hash", receipt.TxHash,
"creates_contract", receipt.CreatesContract) "creates_contract", receipt.CreatesContract)
return abci_types.NewResultOK(receiptBytes, "Success") return abci_types.ResponseCheckTx{
Code: codes.TxExecutionSuccessCode,
Log: "CheckTx success - receipt in data",
Data: receiptBytes,
}
} }
func (app *abciApp) InitChain(chain abci_types.RequestInitChain) { func (app *abciApp) InitChain(chain abci_types.RequestInitChain) (respInitChain abci_types.ResponseInitChain) {
// Could verify agreement on initial validator set here // Could verify agreement on initial validator set here
return
} }
func (app *abciApp) BeginBlock(block abci_types.RequestBeginBlock) { func (app *abciApp) BeginBlock(block abci_types.RequestBeginBlock) (respBeginBlock abci_types.ResponseBeginBlock) {
app.block = &block app.block = &block
return
} }
func (app *abciApp) DeliverTx(txBytes []byte) abci_types.Result { func (app *abciApp) DeliverTx(txBytes []byte) abci_types.ResponseDeliverTx {
app.mtx.Lock() app.mtx.Lock()
defer app.mtx.Unlock() defer app.mtx.Unlock()
tx, err := app.txDecoder.DecodeTx(txBytes) tx, err := app.txDecoder.DecodeTx(txBytes)
if err != nil { if err != nil {
logging.TraceMsg(app.logger, "DeliverTx decoding error", logging.TraceMsg(app.logger, "DeliverTx decoding error",
structure.ErrorKey, err) structure.ErrorKey, err)
return abci_types.NewError(abci_types.CodeType_EncodingError, fmt.Sprintf("Encoding error: %s", err)) return abci_types.ResponseDeliverTx{
Code: codes.EncodingErrorCode,
Log: fmt.Sprintf("Encoding error: %s", err),
}
} }
receipt := txs.GenerateReceipt(app.blockchain.ChainID(), tx) receipt := txs.GenerateReceipt(app.blockchain.ChainID(), tx)
...@@ -119,22 +136,29 @@ func (app *abciApp) DeliverTx(txBytes []byte) abci_types.Result { ...@@ -119,22 +136,29 @@ func (app *abciApp) DeliverTx(txBytes []byte) abci_types.Result {
structure.ErrorKey, err, structure.ErrorKey, err,
"tx_hash", receipt.TxHash, "tx_hash", receipt.TxHash,
"creates_contract", receipt.CreatesContract) "creates_contract", receipt.CreatesContract)
return abci_types.NewError(abci_types.CodeType_InternalError, return abci_types.ResponseDeliverTx{
fmt.Sprintf("Could not execute transaction: %s, error: %s", tx, err)) Code: codes.TxExecutionErrorCode,
Log: fmt.Sprintf("Could not execute transaction: %s, error: %s", tx, err),
}
} }
logging.TraceMsg(app.logger, "DeliverTx success", logging.TraceMsg(app.logger, "DeliverTx success",
"tx_hash", receipt.TxHash, "tx_hash", receipt.TxHash,
"creates_contract", receipt.CreatesContract) "creates_contract", receipt.CreatesContract)
receiptBytes := wire.BinaryBytes(receipt) receiptBytes := wire.BinaryBytes(receipt)
return abci_types.NewResultOK(receiptBytes, "Success") return abci_types.ResponseDeliverTx{
Code: codes.TxExecutionSuccessCode,
Log: "DeliverTx success - receipt in data",
Data: receiptBytes,
}
} }
func (app *abciApp) EndBlock(height uint64) (respEndBlock abci_types.ResponseEndBlock) { func (app *abciApp) EndBlock(reqEndBlock abci_types.RequestEndBlock) (respEndBlock abci_types.ResponseEndBlock) {
return respEndBlock // Validator mutation goes here
return
} }
func (app *abciApp) Commit() abci_types.Result { func (app *abciApp) Commit() abci_types.ResponseCommit {
app.mtx.Lock() app.mtx.Lock()
defer app.mtx.Unlock() defer app.mtx.Unlock()
tip := app.blockchain.Tip() tip := app.blockchain.Tip()
...@@ -149,8 +173,10 @@ func (app *abciApp) Commit() abci_types.Result { ...@@ -149,8 +173,10 @@ func (app *abciApp) Commit() abci_types.Result {
appHash, err := app.committer.Commit() appHash, err := app.committer.Commit()
if err != nil { if err != nil {
return abci_types.NewError(abci_types.CodeType_InternalError, return abci_types.ResponseCommit{
fmt.Sprintf("Could not commit block: %s", err)) Code: codes.CommitErrorCode,
Log: fmt.Sprintf("Could not commit block: %s", err),
}
} }
logging.InfoMsg(app.logger, "Resetting transaction check cache") logging.InfoMsg(app.logger, "Resetting transaction check cache")
...@@ -160,15 +186,21 @@ func (app *abciApp) Commit() abci_types.Result { ...@@ -160,15 +186,21 @@ func (app *abciApp) Commit() abci_types.Result {
app.blockchain.CommitBlock(time.Unix(int64(app.block.Header.Time), 0), app.block.Hash, appHash) app.blockchain.CommitBlock(time.Unix(int64(app.block.Header.Time), 0), app.block.Hash, appHash)
// Perform a sanity check our block height // Perform a sanity check our block height
if app.blockchain.LastBlockHeight() != app.block.Header.Height { if app.blockchain.LastBlockHeight() != uint64(app.block.Header.Height) {
logging.InfoMsg(app.logger, "Burrow block height disagrees with Tendermint block height", logging.InfoMsg(app.logger, "Burrow block height disagrees with Tendermint block height",
structure.ScopeKey, "Commit()", structure.ScopeKey, "Commit()",
"burrow_height", app.blockchain.LastBlockHeight(), "burrow_height", app.blockchain.LastBlockHeight(),
"tendermint_height", app.block.Header.Height) "tendermint_height", app.block.Header.Height)
return abci_types.NewError(abci_types.CodeType_InternalError, return abci_types.ResponseCommit{
fmt.Sprintf("Burrow has recorded a block height of %v, "+ Code: codes.CommitErrorCode,
Log: fmt.Sprintf("Burrow has recorded a block height of %v, "+
"but Tendermint reports a block height of %v, and the two should agree.", "but Tendermint reports a block height of %v, and the two should agree.",
app.blockchain.LastBlockHeight(), app.block.Header.Height)) app.blockchain.LastBlockHeight(), app.block.Header.Height),
}
}
return abci_types.ResponseCommit{
Code: codes.TxExecutionSuccessCode,
Data: appHash,
Log: "Success - AppHash in data",
} }
return abci_types.NewResultOK(appHash, "Success")
} }
package codes
import (
abci_types "github.com/tendermint/abci/types"
)
const (
// Success
TxExecutionSuccessCode uint32 = abci_types.CodeTypeOK
// Informational
UnsupportedRequestCode uint32 = 400
// Internal errors
EncodingErrorCode uint32 = 500
TxExecutionErrorCode uint32 = 501
CommitErrorCode uint32 = 502
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment