Skip to content

Commit

Permalink
chore: Apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jan 14, 2025
1 parent bd4c2c2 commit 1d721ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 1 addition & 3 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ func (app *BaseApp) ApplySnapshotChunk(req *abci.RequestApplySnapshotChunk) (*ab
// will contain relevant error information. Regardless of tx execution outcome,
// the ResponseCheckTx will contain relevant gas execution context.
func (app *BaseApp) CheckTxSync(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx")

var mode execMode

switch req.Type {
Expand All @@ -356,7 +354,7 @@ func (app *BaseApp) CheckTxSync(req *abci.RequestCheckTx) (*abci.ResponseCheckTx

waits, signals := app.checkAccountWGs.Register(app.cdc, tx)

app.checkAccountWGs.Wait(waits)
waitWgs(waits)
defer app.checkAccountWGs.Done(signals)

gInfo, err := app.checkTx(mode, req.Tx, tx)
Expand Down
18 changes: 7 additions & 11 deletions baseapp/accountwgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ func (aw *AccountWGs) Register(cdc codec.Codec, tx sdk.Tx) (waits []*sync.WaitGr
return waits, signals
}

func (aw *AccountWGs) Wait(waits []*sync.WaitGroup) {
for _, wait := range waits {
wait.Wait()
}
}

func (aw *AccountWGs) Done(signals []*AccountWG) {
aw.mtx.Lock()
defer aw.mtx.Unlock()
Expand All @@ -70,11 +64,7 @@ func (aw *AccountWGs) Done(signals []*AccountWG) {
func getUniqSigners(cdc codec.Codec, tx sdk.Tx) (signers []string) {
seen := map[string]bool{}
for _, msg := range tx.GetMsgs() {
msgSigners, _, err := cdc.GetMsgV1Signers(msg)
if err != nil {
// ! need to handle error?
}

msgSigners, _, _ := cdc.GetMsgV1Signers(msg)
for _, msgSigner := range msgSigners {
addr := sdk.AccAddress(msgSigner).String()
if !seen[addr] {
Expand All @@ -86,6 +76,12 @@ func getUniqSigners(cdc codec.Codec, tx sdk.Tx) (signers []string) {
return signers
}

func waitWgs(waits []*sync.WaitGroup) {
for _, wait := range waits {
wait.Wait()
}
}

type AccountWG struct {
acc string
wg *sync.WaitGroup
Expand Down
12 changes: 9 additions & 3 deletions baseapp/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ type RequestCheckTxAsync struct {
txBytes []byte
txType abci.CheckTxType
callback abci.CheckTxCallback
prepare *sync.WaitGroup
tx sdk.Tx
err error

// prepare is a WaitGroup used to ensure that transaction decoding and basic validation (preCheckTx)
// is completed before the reactor processes the transaction.
// This synchronization is necessary because:
// 1. preCheckTx is executed in a separate goroutine for better performance
// 2. The reactor must wait for this initial validation before proceeding with account-based ordering
// 3. It prevents potential race conditions between transaction preparation and processing
prepare *sync.WaitGroup
}

func (app *BaseApp) checkTxAsyncReactor() {
Expand All @@ -43,7 +50,7 @@ func (app *BaseApp) prepareCheckTx(req *RequestCheckTxAsync) {
}

func (app *BaseApp) checkTxAsync(req *RequestCheckTxAsync, waits []*sync.WaitGroup, signals []*AccountWG) {
app.checkAccountWGs.Wait(waits)
waitWgs(waits)
defer app.checkAccountWGs.Done(signals)

var mode execMode
Expand All @@ -56,7 +63,6 @@ func (app *BaseApp) checkTxAsync(req *RequestCheckTxAsync, waits []*sync.WaitGro
}

gInfo, err := app.checkTx(mode, req.txBytes, req.tx)

if err != nil {
req.callback(sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, nil, false))
return
Expand Down

0 comments on commit 1d721ac

Please sign in to comment.