Skip to content

Commit

Permalink
refactor to send txs one by one, not in bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Nov 1, 2024
1 parent d935290 commit ca4cd7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/cmd/server/.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ HEADER_VERIFIER_SC_ADDRESS="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpx
# ESDT Safe address on MultiversX to execute the transactions
ESDT_SAFE_SC_ADDRESS="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"
# Interval in milliseconds between sending bridge txs
INTERVAL_TO_SEND=60
INTERVAL_TO_SEND=1
# Server certificate for tls secured connection with clients.
# One should use the same certificate for clients as well.
# You can generate your own certificate files with the binary found in
Expand Down
2 changes: 1 addition & 1 deletion server/txSender/dataFormatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (df *dataFormatter) CreateTxsData(data *sovereign.BridgeOperations) [][]byt
}

for _, bridgeData := range data.Data {
log.Debug("creating tx data", "bridge op hash", bridgeData.Hash)
log.Debug("creating tx data", "bridge op hash", bridgeData.Hash, "nr of operations", len(bridgeData.OutGoingOperations))

registerBridgeOpData := df.createRegisterBridgeOperationsData(bridgeData)
if len(registerBridgeOpData) != 0 {
Expand Down
14 changes: 8 additions & 6 deletions server/txSender/txSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (ts *txSender) SendTxs(ctx context.Context, data *sovereign.BridgeOperation
}

func (ts *txSender) createAndSendTxs(ctx context.Context, data *sovereign.BridgeOperations) ([]string, error) {
txsToSend := make([]*coreTx.FrontendTransaction, 0)
txHashes := make([]string, 0)
txsData := ts.dataFormatter.CreateTxsData(data)

for _, txData := range txsData {
Expand Down Expand Up @@ -122,6 +122,7 @@ func (ts *txSender) createAndSendTxs(ctx context.Context, data *sovereign.Bridge
}
default:
log.Error("invalid tx data received", "data", string(txData))
continue
}

err := ts.txNonceHandler.ApplyNonceAndGasPrice(ctx, tx)
Expand All @@ -134,12 +135,13 @@ func (ts *txSender) createAndSendTxs(ctx context.Context, data *sovereign.Bridge
return nil, err
}

txsToSend = append(txsToSend, tx)
}
hash, err := ts.txNonceHandler.SendTransactions(ctx, tx)
if err != nil {
log.Error("failed to send tx", "error", err, "nonce", tx.Nonce)
return nil, err
}

txHashes, err := ts.txNonceHandler.SendTransactions(ctx, txsToSend...)
if err != nil {
return nil, err
txHashes = append(txHashes, hash...)
}

return txHashes, nil
Expand Down

0 comments on commit ca4cd7c

Please sign in to comment.