github.com/Finschia/finschia-sdk@v0.48.1/baseapp/reactor.go (about) 1 package baseapp 2 3 import ( 4 "sync" 5 6 ocabci "github.com/Finschia/ostracon/abci/types" 7 8 sdk "github.com/Finschia/finschia-sdk/types" 9 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 10 ) 11 12 func (app *BaseApp) startReactors() { 13 go app.checkTxAsyncReactor() 14 } 15 16 type RequestCheckTxAsync struct { 17 txBytes []byte 18 recheck bool 19 callback ocabci.CheckTxCallback 20 prepare *sync.WaitGroup 21 tx sdk.Tx 22 err error 23 } 24 25 func (app *BaseApp) checkTxAsyncReactor() { 26 for req := range app.chCheckTx { 27 req.prepare.Wait() 28 if req.err != nil { 29 req.callback(sdkerrors.ResponseCheckTx(req.err, 0, 0, app.trace)) 30 continue 31 } 32 33 waits, signals := app.checkAccountWGs.Register(req.tx) 34 35 go app.checkTxAsync(req, waits, signals) 36 } 37 } 38 39 func (app *BaseApp) prepareCheckTx(req *RequestCheckTxAsync) { 40 defer req.prepare.Done() 41 req.tx, req.err = app.preCheckTx(req.txBytes) 42 } 43 44 func (app *BaseApp) checkTxAsync(req *RequestCheckTxAsync, waits []*sync.WaitGroup, signals []*AccountWG) { 45 app.checkAccountWGs.Wait(waits) 46 defer app.checkAccountWGs.Done(signals) 47 48 gInfo, err := app.checkTx(req.txBytes, req.tx, req.recheck) 49 50 if err != nil { 51 req.callback(sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)) 52 return 53 } 54 55 req.callback(ocabci.ResponseCheckTx{ 56 GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? 57 GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? 58 }) 59 }