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

Evm temp rebase #415

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
66854d0
Add migration handler for disabling seqno (#394)
philipsu522 Jan 11, 2024
e12efbc
Revert removing events for cachekv (#396)
yzang2019 Jan 17, 2024
f01454c
fix(baseapp): Ensure Panic Recovery in Prepare & Process Handlers (#401)
alexanderbez Jan 24, 2024
5a1afb8
No longer disable dynamic dep generation during ACL dependency genera…
udpatil Jan 25, 2024
219175b
[SeiDB] Fix concurrent map access (#411)
yzang2019 Jan 30, 2024
117a276
Expose parent on CacheKV (#352)
codchen Nov 17, 2023
4202cb2
Set TxIndex before generating dependencies (#358)
codchen Nov 22, 2023
73699cf
change DeliverTx to take typed tx (#360)
codchen Dec 4, 2023
c793b7a
Integrate with pending txs in mempool (#381)
codchen Dec 16, 2023
32045d5
Add checkTx cb (#382)
codchen Dec 20, 2023
b619457
Add wei support in bank keeper (#386)
codchen Dec 28, 2023
45519df
Add ACL constants for Bank Wei prefix (#387)
codchen Dec 28, 2023
0c96d91
[EVM] Add pending nonce support (#390)
stevenlanders Jan 4, 2024
10c710d
rebase
codchen Jan 11, 2024
15475f7
[EVM] Allow multiple txs from same account in a block (#397)
stevenlanders Jan 19, 2024
b01e4c1
[EVM] Update tendermint to include removetx fix (#399)
stevenlanders Jan 19, 2024
1cec441
Expose VersionExists (#400)
codchen Jan 23, 2024
c08ed09
Add `DeleteAll` method to store type (#402)
codchen Jan 24, 2024
19f5920
update tendermint version for expire metric (#403)
stevenlanders Jan 24, 2024
9ba90f6
[EVM] update tendermint with dupe fixes (#405)
stevenlanders Jan 25, 2024
ef1aad3
bump versions (#410)
codchen Jan 29, 2024
a58fee0
[EVM] Update tendermint v0.2.36-rebase-4 (#412)
stevenlanders Jan 30, 2024
db45a14
Revert "Revert removing events for cachekv (#396)"
yzang2019 Feb 1, 2024
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
98 changes: 75 additions & 23 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/legacytm"
"github.com/cosmos/cosmos-sdk/utils"
)

// InitChain implements the ABCI interface. It runs the initialization logic
Expand Down Expand Up @@ -204,7 +205,7 @@ func (app *BaseApp) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (res abc
// internal CheckTx state if the AnteHandler passes. Otherwise, the ResponseCheckTx
// will contain releveant error information. Regardless of tx execution outcome,
// the ResponseCheckTx will contain relevant gas execution context.
func (app *BaseApp) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
func (app *BaseApp) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abci.ResponseCheckTxV2, error) {
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx")

var mode runTxMode
Expand All @@ -221,25 +222,42 @@ func (app *BaseApp) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abc
}

sdkCtx := app.getContextForTx(mode, req.Tx)
gInfo, result, _, priority, err := app.runTx(sdkCtx, mode, req.Tx)
tx, err := app.txDecoder(req.Tx)
if err != nil {
res := sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
return &abci.ResponseCheckTxV2{ResponseCheckTx: &res}, err
}
gInfo, result, _, priority, pendingTxChecker, expireTxHandler, txCtx, err := app.runTx(sdkCtx, mode, tx, sha256.Sum256(req.Tx))
if err != nil {
res := sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)
return &res, err
return &abci.ResponseCheckTxV2{ResponseCheckTx: &res}, err
}

return &abci.ResponseCheckTx{
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
Data: result.Data,
Priority: priority,
}, nil
res := &abci.ResponseCheckTxV2{
ResponseCheckTx: &abci.ResponseCheckTx{
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
Data: result.Data,
Priority: priority,
},
ExpireTxHandler: expireTxHandler,
EVMNonce: txCtx.EVMNonce(),
EVMSenderAddress: txCtx.EVMSenderAddress(),
IsEVM: txCtx.IsEVM(),
}
if pendingTxChecker != nil {
res.IsPendingTransaction = true
res.Checker = pendingTxChecker
}

return res, nil
}

// DeliverTx implements the ABCI interface and executes a tx in DeliverTx mode.
// State only gets persisted if all messages are valid and get executed successfully.
// Otherwise, the ResponseDeliverTx will contain releveant error information.
// Regardless of tx execution outcome, the ResponseDeliverTx will contain relevant
// gas execution context.
func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, tx sdk.Tx, checksum [32]byte) (res abci.ResponseDeliverTx) {
defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx")
defer func() {
for _, streamingListener := range app.abciListeners {
Expand All @@ -259,7 +277,7 @@ func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx) (res a
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted")
}()

gInfo, result, anteEvents, _, err := app.runTx(ctx.WithTxBytes(req.Tx).WithVoteInfos(app.voteInfos), runTxModeDeliver, req.Tx)
gInfo, result, anteEvents, _, _, _, _, err := app.runTx(ctx.WithTxBytes(req.Tx).WithVoteInfos(app.voteInfos), runTxModeDeliver, tx, checksum)
if err != nil {
resultStr = "failed"
// if we have a result, use those events instead of just the anteEvents
Expand Down Expand Up @@ -912,7 +930,7 @@ func splitPath(requestPath string) (path []string) {
}

// ABCI++
func (app *BaseApp) PrepareProposal(ctx context.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
func (app *BaseApp) PrepareProposal(ctx context.Context, req *abci.RequestPrepareProposal) (resp *abci.ResponsePrepareProposal, err error) {
defer telemetry.MeasureSince(time.Now(), "abci", "prepare_proposal")

header := tmproto.Header{
Expand Down Expand Up @@ -946,21 +964,40 @@ func (app *BaseApp) PrepareProposal(ctx context.Context, req *abci.RequestPrepar

app.preparePrepareProposalState()

defer func() {
if err := recover(); err != nil {
app.logger.Error(
"panic recovered in PrepareProposal",
"height", req.Height,
"time", req.Time,
"panic", err,
)

resp = &abci.ResponsePrepareProposal{
TxRecords: utils.Map(req.Txs, func(tx []byte) *abci.TxRecord {
return &abci.TxRecord{Action: abci.TxRecord_UNMODIFIED, Tx: tx}
}),
}
}
}()

if app.prepareProposalHandler != nil {
res, err := app.prepareProposalHandler(app.prepareProposalState.ctx, req)
resp, err = app.prepareProposalHandler(app.prepareProposalState.ctx, req)
if err != nil {
return nil, err
}

if cp := app.GetConsensusParams(app.prepareProposalState.ctx); cp != nil {
res.ConsensusParamUpdates = cp
resp.ConsensusParamUpdates = cp
}
return res, nil
} else {
return nil, errors.New("no prepare proposal handler")

return resp, nil
}

return nil, errors.New("no prepare proposal handler")
}

func (app *BaseApp) ProcessProposal(ctx context.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
func (app *BaseApp) ProcessProposal(ctx context.Context, req *abci.RequestProcessProposal) (resp *abci.ResponseProcessProposal, err error) {
defer telemetry.MeasureSince(time.Now(), "abci", "process_proposal")

header := tmproto.Header{
Expand Down Expand Up @@ -1001,21 +1038,36 @@ func (app *BaseApp) ProcessProposal(ctx context.Context, req *abci.RequestProces
}

// NOTE: header hash is not set in NewContext, so we manually set it here

app.prepareProcessProposalState(gasMeter, req.Hash)

defer func() {
if err := recover(); err != nil {
app.logger.Error(
"panic recovered in ProcessProposal",
"height", req.Height,
"time", req.Time,
"hash", fmt.Sprintf("%X", req.Hash),
"panic", err,
)

resp = &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
}()

if app.processProposalHandler != nil {
res, err := app.processProposalHandler(app.processProposalState.ctx, req)
resp, err = app.processProposalHandler(app.processProposalState.ctx, req)
if err != nil {
return nil, err
}

if cp := app.GetConsensusParams(app.processProposalState.ctx); cp != nil {
res.ConsensusParamUpdates = cp
resp.ConsensusParamUpdates = cp
}
return res, nil
} else {
return nil, errors.New("no process proposal handler")

return resp, nil
}

return nil, errors.New("no process proposal handler")
}

func (app *BaseApp) FinalizeBlock(ctx context.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
Expand Down
57 changes: 37 additions & 20 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package baseapp

import (
"context"
"crypto/sha256"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -155,8 +154,9 @@ type BaseApp struct { //nolint: maligned

ChainID string

votesInfoLock sync.RWMutex
commitLock *sync.Mutex
votesInfoLock sync.RWMutex
commitLock *sync.Mutex
checkTxStateLock *sync.RWMutex

compactionInterval uint64

Expand Down Expand Up @@ -266,7 +266,8 @@ func NewBaseApp(
TracingInfo: &tracing.Info{
Tracer: &tr,
},
commitLock: &sync.Mutex{},
commitLock: &sync.Mutex{},
checkTxStateLock: &sync.RWMutex{},
}

app.TracingInfo.SetContext(context.Background())
Expand Down Expand Up @@ -501,6 +502,8 @@ func (app *BaseApp) IsSealed() bool { return app.sealed }
func (app *BaseApp) setCheckState(header tmproto.Header) {
ms := app.cms.CacheMultiStore()
ctx := sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices)
app.checkTxStateLock.Lock()
defer app.checkTxStateLock.Unlock()
if app.checkState == nil {
app.checkState = &state{
ms: ms,
Expand Down Expand Up @@ -795,15 +798,15 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context

// cacheTxContext returns a new context based off of the provided context with
// a branched multi-store.
func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, sdk.CacheMultiStore) {
func (app *BaseApp) cacheTxContext(ctx sdk.Context, checksum [32]byte) (sdk.Context, sdk.CacheMultiStore) {
ms := ctx.MultiStore()
// TODO: https://github.com/cosmos/cosmos-sdk/issues/2824
msCache := ms.CacheMultiStore()
if msCache.TracingEnabled() {
msCache = msCache.SetTracingContext(
sdk.TraceContext(
map[string]interface{}{
"txHash": fmt.Sprintf("%X", sha256.Sum256(txBytes)),
"txHash": fmt.Sprintf("%X", checksum),
},
),
).(sdk.CacheMultiStore)
Expand All @@ -819,8 +822,16 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context
// Note, gas execution info is always returned. A reference to a Result is
// returned if the tx does not run out of gas and if all the messages are valid
// and execute successfully. An error is returned otherwise.
func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, priority int64, err error) {

func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, tx sdk.Tx, checksum [32]byte) (
gInfo sdk.GasInfo,
result *sdk.Result,
anteEvents []abci.Event,
priority int64,
pendingTxChecker abci.PendingTxChecker,
expireHandler abci.ExpireTxHandler,
txCtx sdk.Context,
err error,
) {
defer telemetry.MeasureThroughputSinceWithLabels(
telemetry.TxCount,
[]metrics.Label{
Expand All @@ -843,7 +854,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
spanCtx, span := app.TracingInfo.StartWithContext("RunTx", ctx.TraceSpanContext())
defer span.End()
ctx = ctx.WithTraceSpanContext(spanCtx)
span.SetAttributes(attribute.String("txHash", fmt.Sprintf("%X", sha256.Sum256(txBytes))))
span.SetAttributes(attribute.String("txHash", fmt.Sprintf("%X", checksum)))

// NOTE: GasWanted should be returned by the AnteHandler. GasUsed is
// determined by the GasMeter. We need access to the context to get the gas
Expand All @@ -854,7 +865,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf

// only run the tx if there is block gas remaining
if mode == runTxModeDeliver && ctx.BlockGasMeter().IsOutOfGas() {
return gInfo, nil, nil, -1, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "no block gas left to run tx")
return gInfo, nil, nil, -1, nil, nil, ctx, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "no block gas left to run tx")
}

defer func() {
Expand Down Expand Up @@ -890,15 +901,14 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
defer consumeBlockGas()
}

tx, err := app.txDecoder(txBytes)
if err != nil {
return sdk.GasInfo{}, nil, nil, 0, err
if tx == nil {
return sdk.GasInfo{}, nil, nil, 0, nil, nil, ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx decode error")
}

msgs := tx.GetMsgs()

if err := validateBasicTxMsgs(msgs); err != nil {
return sdk.GasInfo{}, nil, nil, 0, err
return sdk.GasInfo{}, nil, nil, 0, nil, nil, ctx, err
}

if app.anteHandler != nil {
Expand All @@ -916,7 +926,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
// NOTE: Alternatively, we could require that AnteHandler ensures that
// writes do not happen if aborted/failed. This may have some
// performance benefits, but it'll be more difficult to get right.
anteCtx, msCache = app.cacheTxContext(ctx, txBytes)
anteCtx, msCache = app.cacheTxContext(ctx, checksum)
anteCtx = anteCtx.WithEventManager(sdk.NewEventManager())
newCtx, err := app.anteHandler(anteCtx, tx, mode == runTxModeSimulate)

Expand All @@ -940,7 +950,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
// GasMeter expected to be set in AnteHandler
gasWanted = ctx.GasMeter().Limit()
if err != nil {
return gInfo, nil, nil, 0, err
return gInfo, nil, nil, 0, nil, nil, ctx, err
}

// Dont need to validate in checkTx mode
Expand All @@ -955,11 +965,13 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
op.EmitValidationFailMetrics()
}
errMessage := fmt.Sprintf("Invalid Concurrent Execution antehandler missing %d access operations", len(missingAccessOps))
return gInfo, nil, nil, 0, sdkerrors.Wrap(sdkerrors.ErrInvalidConcurrencyExecution, errMessage)
return gInfo, nil, nil, 0, nil, nil, ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidConcurrencyExecution, errMessage)
}
}

priority = ctx.Priority()
pendingTxChecker = ctx.PendingTxChecker()
expireHandler = ctx.ExpireTxHandler()
msCache.Write()
anteEvents = events.ToABCIEvents()
anteSpan.End()
Expand All @@ -968,7 +980,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
// Create a new Context based off of the existing Context with a MultiStore branch
// in case message processing fails. At this point, the MultiStore
// is a branch of a branch.
runMsgCtx, msCache := app.cacheTxContext(ctx, txBytes)
runMsgCtx, msCache := app.cacheTxContext(ctx, checksum)

// Attempt to execute all messages and only update state if all messages pass
// and we're in DeliverTx. Note, runMsgs will never return a reference to a
Expand All @@ -986,7 +998,10 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
// append the events in the order of occurrence
result.Events = append(anteEvents, result.Events...)
}
return gInfo, result, anteEvents, priority, err
if ctx.CheckTxCallback() != nil {
ctx.CheckTxCallback()(err)
}
return gInfo, result, anteEvents, priority, pendingTxChecker, expireHandler, ctx, err
}

// runMsgs iterates through a list of messages and executes them with the provided
Expand Down Expand Up @@ -1031,7 +1046,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
err error
)

msgCtx, msgMsCache := app.cacheTxContext(ctx, []byte{})
msgCtx, msgMsCache := app.cacheTxContext(ctx, [32]byte{})
msgCtx = msgCtx.WithMessageIndex(i)

startTime := time.Now()
Expand Down Expand Up @@ -1172,5 +1187,7 @@ func (app *BaseApp) ReloadDB() error {
}

func (app *BaseApp) GetCheckCtx() sdk.Context {
app.checkTxStateLock.RLock()
defer app.checkTxStateLock.RUnlock()
return app.checkState.ctx
}
Loading