Skip to content

Commit

Permalink
Add checkTx cb (#382)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context

## Testing performed to validate your change
  • Loading branch information
codchen authored and udpatil committed Mar 27, 2024
1 parent 21ebda4 commit 35d67ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,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 @@ -274,7 +275,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 @@ -529,6 +531,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 @@ -978,6 +982,9 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, tx sdk.Tx, checksum [
// append the events in the order of occurrence
result.Events = append(anteEvents, result.Events...)
}
if ctx.CheckTxCallback() != nil {
ctx.CheckTxCallback()(err)
}
return gInfo, result, anteEvents, priority, pendingTxChecker, err
}

Expand Down Expand Up @@ -1168,5 +1175,7 @@ func (app *BaseApp) ReloadDB() error {
}

func (app *BaseApp) GetCheckCtx() sdk.Context {
app.checkTxStateLock.RLock()
defer app.checkTxStateLock.RUnlock()
return app.checkState.ctx
}
10 changes: 10 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Context struct {
eventManager *EventManager
priority int64 // The tx priority, only relevant in CheckTx
pendingTxChecker abci.PendingTxChecker // Checker for pending transaction, only relevant in CheckTx
checkTxCallback func(error) // callback to make at the end of CheckTx. Input param is the error (nil-able) of `runMsgs`

txBlockingChannels acltypes.MessageAccessOpsChannelMapping
txCompletionChannels acltypes.MessageAccessOpsChannelMapping
Expand Down Expand Up @@ -121,6 +122,10 @@ func (c Context) PendingTxChecker() abci.PendingTxChecker {
return c.pendingTxChecker
}

func (c Context) CheckTxCallback() func(error) {
return c.checkTxCallback
}

func (c Context) TxCompletionChannels() acltypes.MessageAccessOpsChannelMapping {
return c.txCompletionChannels
}
Expand Down Expand Up @@ -359,6 +364,11 @@ func (c Context) WithPendingTxChecker(checker abci.PendingTxChecker) Context {
return c
}

func (c Context) WithCheckTxCallback(checkTxCallback func(error)) Context {
c.checkTxCallback = checkTxCallback
return c
}

// TODO: remove???
func (c Context) IsZero() bool {
return c.ms == nil
Expand Down

0 comments on commit 35d67ce

Please sign in to comment.