Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cosmos/cosmos-sdk into kocu/cometbf…
Browse files Browse the repository at this point in the history
…t-v2
  • Loading branch information
kocubinski committed May 29, 2024
2 parents 64471d2 + ac49374 commit 05180c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
15 changes: 0 additions & 15 deletions core/context/context.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
package context

// ExecMode defines the execution mode which can be set on a Context.
type ExecMode uint8

// All possible execution modes.
const (
ExecModeCheck ExecMode = iota
ExecModeReCheck
ExecModeSimulate
ExecModePrepareProposal
ExecModeProcessProposal
ExecModeVoteExtension
ExecModeVerifyVoteExtension
ExecModeFinalize
)

const (
ExecModeKey = iota
CometInfoKey
Expand Down
18 changes: 18 additions & 0 deletions server/v2/stf/internal/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package internal

import "cosmossdk.io/core/transaction"

// All possible transaction execution modes.
// For backwards compatibility and easier casting, the ExecMode values must be:
// 1) set equivalent to cosmos/cosmos-sdk/types package.
// 2) a superset of core/transaction/service.go:ExecMode with same numeric values.
const (
ExecModeCheck transaction.ExecMode = iota
ExecModeReCheck
ExecModeSimulate
ExecModePrepareProposal
ExecModeProcessProposal
ExecModeVoteExtension
ExecModeVerifyVoteExtension
ExecModeFinalize
)
26 changes: 13 additions & 13 deletions server/v2/stf/stf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (

appmanager "cosmossdk.io/core/app"
appmodulev2 "cosmossdk.io/core/appmodule/v2"
corecontext "cosmossdk.io/core/context"
"cosmossdk.io/core/event"
"cosmossdk.io/core/gas"
"cosmossdk.io/core/header"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
stfgas "cosmossdk.io/server/v2/stf/gas"
"cosmossdk.io/server/v2/stf/internal"
)

// STF is a struct that manages the state transition component of the app.
Expand Down Expand Up @@ -87,7 +87,7 @@ func (s STF[T]) DeliverBlock(
return nil, nil, fmt.Errorf("unable to set initial header info, %w", err)
}

exCtx := s.makeContext(ctx, appmanager.ConsensusIdentity, newState, corecontext.ExecModeFinalize)
exCtx := s.makeContext(ctx, appmanager.ConsensusIdentity, newState, internal.ExecModeFinalize)
exCtx.setHeaderInfo(hi)
consMessagesResponses, err := s.runConsensusMessages(exCtx, block.ConsensusMessages)
if err != nil {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (s STF[T]) DeliverBlock(
if err = isCtxCancelled(ctx); err != nil {
return nil, nil, err
}
txResults[i] = s.deliverTx(ctx, newState, txBytes, corecontext.ExecModeFinalize, hi)
txResults[i] = s.deliverTx(ctx, newState, txBytes, transaction.ExecModeFinalize, hi)
}
// reset events
exCtx.events = make([]event.Event, 0)
Expand All @@ -153,7 +153,7 @@ func (s STF[T]) deliverTx(
ctx context.Context,
state store.WriterMap,
tx T,
execMode corecontext.ExecMode,
execMode transaction.ExecMode,
hi header.Info,
) appmanager.TxResult {
// recover in the case of a panic
Expand Down Expand Up @@ -208,7 +208,7 @@ func (s STF[T]) validateTx(
if err != nil {
return 0, nil, err
}
validateCtx := s.makeContext(ctx, appmanager.RuntimeIdentity, validateState, corecontext.ExecModeCheck)
validateCtx := s.makeContext(ctx, appmanager.RuntimeIdentity, validateState, transaction.ExecModeCheck)
validateCtx.setHeaderInfo(hi)
validateCtx.setGasLimit(gasLimit)
err = s.doTxValidation(validateCtx, tx)
Expand All @@ -227,7 +227,7 @@ func (s STF[T]) execTx(
state store.WriterMap,
gasLimit uint64,
tx T,
execMode corecontext.ExecMode,
execMode transaction.ExecMode,
hi header.Info,
) ([]transaction.Msg, uint64, []event.Event, error) {
execState := s.branchFn(state)
Expand Down Expand Up @@ -283,7 +283,7 @@ func (s STF[T]) runTxMsgs(
state store.WriterMap,
gasLimit uint64,
tx T,
execMode corecontext.ExecMode,
execMode transaction.ExecMode,
hi header.Info,
) ([]transaction.Msg, uint64, []event.Event, error) {
txSenders, err := tx.GetSenders()
Expand Down Expand Up @@ -450,7 +450,7 @@ func (s STF[T]) Simulate(
if err != nil {
return appmanager.TxResult{}, nil
}
txr := s.deliverTx(ctx, simulationState, tx, corecontext.ExecModeSimulate, hi)
txr := s.deliverTx(ctx, simulationState, tx, internal.ExecModeSimulate, hi)

return txr, simulationState
}
Expand Down Expand Up @@ -484,7 +484,7 @@ func (s STF[T]) Query(
if err != nil {
return nil, err
}
queryCtx := s.makeContext(ctx, nil, queryState, corecontext.ExecModeSimulate)
queryCtx := s.makeContext(ctx, nil, queryState, internal.ExecModeSimulate)
queryCtx.setHeaderInfo(hi)
queryCtx.setGasLimit(gasLimit)
return s.handleQuery(queryCtx, req)
Expand All @@ -503,7 +503,7 @@ func (s STF[T]) RunWithCtx(
closure func(ctx context.Context) error,
) (store.WriterMap, error) {
branchedState := s.branchFn(state)
stfCtx := s.makeContext(ctx, nil, branchedState, corecontext.ExecModeFinalize)
stfCtx := s.makeContext(ctx, nil, branchedState, internal.ExecModeFinalize)
return branchedState, closure(stfCtx)
}

Expand Down Expand Up @@ -542,7 +542,7 @@ type executionContext struct {
// headerInfo contains the block info.
headerInfo header.Info
// execMode retains information about the exec mode.
execMode corecontext.ExecMode
execMode transaction.ExecMode

branchFn branchFn
makeGasMeter makeGasMeterFn
Expand Down Expand Up @@ -577,7 +577,7 @@ func (s STF[T]) makeContext(
ctx context.Context,
sender transaction.Identity,
store store.WriterMap,
execMode corecontext.ExecMode,
execMode transaction.ExecMode,
) *executionContext {
return newExecutionContext(
s.makeGasMeter,
Expand All @@ -597,7 +597,7 @@ func newExecutionContext(
ctx context.Context,
sender transaction.Identity,
state store.WriterMap,
execMode corecontext.ExecMode,
execMode transaction.ExecMode,
) *executionContext {
meter := makeGasMeterFn(gas.NoGasLimit)
meteredState := makeGasMeteredStoreFn(meter, state)
Expand Down

0 comments on commit 05180c1

Please sign in to comment.