-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Handle nil *Any in UnpackAny and add panic handler for tx decoding #7594
Changes from 8 commits
af3d5d8
978e2b9
9c876db
2451f2b
55bb84e
e77d85d
a8b8538
9405505
db112ba
ece41c5
da621d5
d468fb8
fa954f4
76df2e0
c22e713
42eaf62
28843ed
0a3eb4f
049dd5f
ddb88f3
aa020ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,11 +213,6 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc | |
func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { | ||
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx") | ||
|
||
tx, err := app.txDecoder(req.Tx) | ||
if err != nil { | ||
return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace) | ||
} | ||
|
||
var mode runTxMode | ||
|
||
switch { | ||
|
@@ -231,7 +226,7 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { | |
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type)) | ||
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. Do we still want to panic here and crash the state machine? Maybe for a separate PR but it would be good to make this method as bulletproof as possible. |
||
} | ||
|
||
gInfo, result, err := app.runTx(mode, req.Tx, tx) | ||
gInfo, result, err := app.runTx(mode, req.Tx) | ||
if err != nil { | ||
return sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace) | ||
} | ||
|
@@ -253,11 +248,6 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { | |
func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { | ||
defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx") | ||
|
||
tx, err := app.txDecoder(req.Tx) | ||
if err != nil { | ||
return sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace) | ||
} | ||
|
||
gInfo := sdk.GasInfo{} | ||
resultStr := "successful" | ||
|
||
|
@@ -268,7 +258,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx | |
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted") | ||
}() | ||
|
||
gInfo, result, err := app.runTx(runTxModeDeliver, req.Tx, tx) | ||
gInfo, result, err := app.runTx(runTxModeDeliver, req.Tx) | ||
if err != nil { | ||
resultStr = "failed" | ||
return sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace) | ||
|
@@ -673,12 +663,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res | |
case "simulate": | ||
txBytes := req.Data | ||
|
||
tx, err := app.txDecoder(txBytes) | ||
if err != nil { | ||
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to decode tx")) | ||
} | ||
|
||
gInfo, res, err := app.Simulate(txBytes, tx) | ||
gInfo, res, err := app.Simulate(txBytes) | ||
if err != nil { | ||
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to simulate tx")) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,42 @@ package baseapp | |
import ( | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
) | ||
|
||
// txEncoder creates a proto TxEncoder for testing purposes. | ||
func txEncoder(interfaceRegistry codectypes.InterfaceRegistry) sdk.TxEncoder { | ||
marshaler := codec.NewProtoCodec(interfaceRegistry) | ||
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) | ||
|
||
return txCfg.TxEncoder() | ||
} | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func (app *BaseApp) Check(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { | ||
return app.runTx(runTxModeCheck, nil, tx) | ||
// runTx expects tx bytes as argument, so we encode the tx argument into | ||
// bytes. Note that runTx will actually decode those bytes again. But since | ||
// this helper is only used in tests/simulation, it's fine. | ||
bz, err := txEncoder(app.interfaceRegistry)(tx) | ||
if err != nil { | ||
return sdk.GasInfo{}, nil, err | ||
} | ||
return app.runTx(runTxModeCheck, bz) | ||
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. I would suggest to put all these functions inside this file into a |
||
} | ||
|
||
func (app *BaseApp) Simulate(txBytes []byte, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { | ||
return app.runTx(runTxModeSimulate, txBytes, tx) | ||
func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { | ||
return app.runTx(runTxModeSimulate, txBytes) | ||
} | ||
|
||
func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { | ||
return app.runTx(runTxModeDeliver, nil, tx) | ||
// See comment for Check(). | ||
bz, err := txEncoder(app.interfaceRegistry)(tx) | ||
if err != nil { | ||
return sdk.GasInfo{}, nil, err | ||
} | ||
return app.runTx(runTxModeDeliver, bz) | ||
} | ||
|
||
// Context with current {check, deliver}State of the app used by tests. | ||
|
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.
Can telemetry panic?