fix(baseapp): fix BaseApp.getContext data races (#24042)
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io> Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
This commit is contained in:
co-authored by
Alex | Interchain Labs
Tyler
parent
6577e1eeef
commit
ba35a41fdd
@@ -7,6 +7,7 @@ import (
|
||||
"math"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@@ -61,6 +62,7 @@ var _ servertypes.ABCI = (*BaseApp)(nil)
|
||||
// BaseApp reflects the ABCI application implementation.
|
||||
type BaseApp struct {
|
||||
// initialized on creation
|
||||
mu sync.Mutex // mu protects the fields below.
|
||||
logger log.Logger
|
||||
name string // application name from abci.BlockInfo
|
||||
db dbm.DB // common DB backend
|
||||
@@ -659,6 +661,9 @@ func (app *BaseApp) getBlockGasMeter(ctx sdk.Context) storetypes.GasMeter {
|
||||
|
||||
// retrieve the context for the tx w/ txBytes and other memoized values.
|
||||
func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context {
|
||||
app.mu.Lock()
|
||||
defer app.mu.Unlock()
|
||||
|
||||
modeState := app.getState(mode)
|
||||
if modeState == nil {
|
||||
panic(fmt.Sprintf("state is nil for mode %v", mode))
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ var _ genesis.TxHandler = (*BaseApp)(nil)
|
||||
|
||||
// ExecuteGenesisTx implements genesis.GenesisState from
|
||||
// cosmossdk.io/core/genesis to set initial state in genesis
|
||||
func (ba BaseApp) ExecuteGenesisTx(tx []byte) error {
|
||||
func (ba *BaseApp) ExecuteGenesisTx(tx []byte) error {
|
||||
res := ba.deliverTx(tx)
|
||||
|
||||
if res.Code != types.CodeTypeOK {
|
||||
|
||||
Reference in New Issue
Block a user