Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove concurrent transactions and messages handling #86

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
- ([\#74](https://github.com/forbole/juno/pull/74)) Added database block count to prometheus to improve alert monitoring
- ([\#75](https://github.com/forbole/juno/pull/75)) Allow modules to handle MsgExec inner messages
- ([\#76](https://github.com/forbole/juno/pull/76)) Return 0 as height for `GetLastBlockHeight()` method if there are no blocks saved in database
- ([\#77](https://github.com/forbole/juno/pull/77)) Add wait group to handle messages concurrently
- ([\#79](https://github.com/forbole/juno/pull/79)) Use `sqlx` instead of `sql` while dealing with a PostgreSQL database
- ([\#83](https://github.com/forbole/juno/pull/83)) Bump `github.com/tendermint/tendermint` to `v0.34.22`
- ([\#84](https://github.com/forbole/juno/pull/84)) Replace database configuration params with URI
- ([\#86](https://github.com/forbole/juno/pull/86)) Revert concurrent handling of transactions and messages

## v3.4.0
### Changes
Expand Down
27 changes: 7 additions & 20 deletions parser/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package parser
import (
"encoding/json"
"fmt"
"sync"
"time"

"github.com/cosmos/cosmos-sdk/x/authz"
Expand Down Expand Up @@ -328,23 +327,18 @@ func (w Worker) handleMessage(index int, msg sdk.Msg, tx *types.Tx) {
// ExportTxs accepts a slice of transactions and persists then inside the database.
// An error is returned if the write fails.
func (w Worker) ExportTxs(txs []*types.Tx) error {
var wg sync.WaitGroup

// handle all transactions inside the block
for _, tx := range txs {
// Save the transaction
// save the transaction
err := w.saveTx(tx)
if err != nil {
return fmt.Errorf("error while storing txs: %s", err)
}

// Handle the transaction concurrently
wg.Add(1)
go func(tx *types.Tx) {
defer wg.Done()
w.handleTx(tx)
}(tx)
// call the tx handlers
w.handleTx(tx)

// Parse all the messages contained inside the transaction
// handle all messages contained inside the transaction
sdkMsgs := make([]sdk.Msg, len(tx.Body.Messages))
for i, msg := range tx.Body.Messages {
var stdMsg sdk.Msg
Expand All @@ -355,19 +349,12 @@ func (w Worker) ExportTxs(txs []*types.Tx) error {
sdkMsgs[i] = stdMsg
}

// Handle all the messages concurrently
// call the msg handlers
for i, sdkMsg := range sdkMsgs {
wg.Add(1)
go func(i int, sdkMsg sdk.Msg) {
defer wg.Done()
w.handleMessage(i, sdkMsg, tx)
}(i, sdkMsg)
w.handleMessage(i, sdkMsg, tx)
}
}

// Wait all transactions and messages to be parsed
wg.Wait()

totalBlocks := w.db.GetTotalBlocks()
logging.DbBlockCount.WithLabelValues("total_blocks_in_db").Set(float64(totalBlocks))

Expand Down