-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* chore: bump up ostracon * feat: concurrent recheckTx (#52) * chore: simply implement abci.`CheckTxSync()` and abci.`CheckTxAsync()` * chore: move `accountLock` from `anteTx()` to `checkTxWithLock()` * feat: impl `abci.CheckTxAsync()` with reactor # Conflicts: # baseapp/baseapp.go * feat: impl `accountwgs` * feat: impl `accountwgs_test` * chore: revise code after cherry-pick * chore: bump-up tendermint & iavl * chore: rename func from `startCheckTxAsyncReactor()` to `checkTxAsyncReactor()` * fix: imports for lint * fix: imports for lint * chore: rename `Waits()` to `Wait()` # Conflicts: # baseapp/abci.go # baseapp/accountlock.go # baseapp/accountwgs_test.go # baseapp/baseapp.go # baseapp/baseapp_test.go # go.mod # go.sum * fix: add a tag, `goleveldb`, to `test_cover.sh`
- Loading branch information
1 parent
2a9f3c7
commit 258163d
Showing
10 changed files
with
224 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package baseapp | ||
|
||
import ( | ||
"sync" | ||
|
||
sdk "github.com/line/lbm-sdk/v2/types" | ||
) | ||
|
||
type AccountWGs struct { | ||
mtx sync.Mutex | ||
wgs map[string]*sync.WaitGroup | ||
} | ||
|
||
func NewAccountWGs() *AccountWGs { | ||
return &AccountWGs{ | ||
wgs: make(map[string]*sync.WaitGroup), | ||
} | ||
} | ||
|
||
func (aw *AccountWGs) Register(tx sdk.Tx) (waits []*sync.WaitGroup, signals []*AccountWG) { | ||
signers := getUniqSigners(tx) | ||
|
||
aw.mtx.Lock() | ||
defer aw.mtx.Unlock() | ||
for _, signer := range signers { | ||
if wg := aw.wgs[signer]; wg != nil { | ||
waits = append(waits, wg) | ||
} | ||
sig := waitGroup1() | ||
aw.wgs[signer] = sig | ||
signals = append(signals, NewAccountWG(signer, sig)) | ||
} | ||
|
||
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() | ||
|
||
for _, signal := range signals { | ||
signal.wg.Done() | ||
if aw.wgs[signal.acc] == signal.wg { | ||
delete(aw.wgs, signal.acc) | ||
} | ||
} | ||
} | ||
|
||
func getUniqSigners(tx sdk.Tx) []string { | ||
seen := map[string]bool{} | ||
var signers []string | ||
for _, msg := range tx.GetMsgs() { | ||
for _, addr := range msg.GetSigners() { | ||
if !seen[addr.String()] { | ||
signers = append(signers, string(addr)) | ||
seen[addr.String()] = true | ||
} | ||
} | ||
} | ||
return signers | ||
} | ||
|
||
type AccountWG struct { | ||
acc string | ||
wg *sync.WaitGroup | ||
} | ||
|
||
func NewAccountWG(acc string, wg *sync.WaitGroup) *AccountWG { | ||
return &AccountWG{ | ||
acc: acc, | ||
wg: wg, | ||
} | ||
} | ||
|
||
func waitGroup1() (wg *sync.WaitGroup) { | ||
wg = &sync.WaitGroup{} | ||
wg.Add(1) | ||
return wg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.