Skip to content

Commit

Permalink
fix: add the max number of tasks per bulk task (#8)
Browse files Browse the repository at this point in the history
Batching too many tasks into a bulk task leads to a very high gas transaction.
This commit adds a configurable number of maximum number of tasks per bulk task.
  • Loading branch information
minh-bq authored Apr 1, 2024
1 parent 61da305 commit c5a815f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ENV LISTENERS__RONIN__TASKINTERVAL ''
ENV LISTENERS__RONIN__TRANSACTIONCHECKPERIOD ''
ENV LISTENERS__RONIN__FROMHEIGHT ''
ENV LISTENERS__RONIN__GASLIMITBUMPRATIO ''
ENV LISTENERS__RONIN__MAXBULKTASKS ''

ENV LISTENERS__RONIN__MAXTASKQUERY ''
ENV LISTENERS__RONIN__MAXPROCESSINGTASKS ''
Expand Down
1 change: 1 addition & 0 deletions config/config.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"taskInterval": "10s",
"transactionCheckPeriod": "50s",
"gasLimitBumpRatio": 300,
"maxBulkTasks": 20,
"secret": {
"bridgeOperator": {
"plainPrivateKey": ""
Expand Down
1 change: 1 addition & 0 deletions config/config.mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ listeners:
taskInterval: "10s"
transactionCheckPeriod: "50s"
gasLimitBumpRatio: 300
maxBulkTasks: 20,
secret:
bridgeOperator:
plainPrivateKey: ""
Expand Down
1 change: 1 addition & 0 deletions config/config.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"taskInterval": "3s",
"transactionCheckPeriod": "5s",
"gasLimitBumpRatio": 200,
"maxBulkTasks": 20,
"secret": {
"bridgeOperator": {
"plainPrivateKey": ""
Expand Down
1 change: 1 addition & 0 deletions config/config.testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ listeners:
taskInterval: "3s"
transactionCheckPeriod: "5s"
gasLimitBumpRatio: 200
maxBulkTasks: 20,
secret:
bridgeOperator:
plainPrivateKey: ""
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/axieinfinity/bridge-v2

replace (
github.com/axieinfinity/bridge-core => github.com/ronin-chain/bridge-core v0.1.3-0.20240226101641-8d0e69b8f633
github.com/axieinfinity/bridge-core => github.com/ronin-chain/bridge-core v0.1.3-0.20240401060412-3ff265961e35
github.com/ethereum/go-ethereum => github.com/axieinfinity/ronin v1.10.4-0.20240117085004-bf2f0d1787d0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/ronin-chain/bridge-core v0.1.3-0.20240226101641-8d0e69b8f633 h1:CJi2Pk250uLizec92o2taqcHd94sfuzt5nC+vwGfCc8=
github.com/ronin-chain/bridge-core v0.1.3-0.20240226101641-8d0e69b8f633/go.mod h1:X6QX0BsMR432Ez8ShNavbC0Sp7rtVthfGWdLtg174ag=
github.com/ronin-chain/bridge-core v0.1.3-0.20240401060412-3ff265961e35 h1:kZFtDSjFRt9DcP1+bCElKJ7HHNqzRTU+6VEOkQB1ipc=
github.com/ronin-chain/bridge-core v0.1.3-0.20240401060412-3ff265961e35/go.mod h1:X6QX0BsMR432Ez8ShNavbC0Sp7rtVthfGWdLtg174ag=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
Expand Down
9 changes: 8 additions & 1 deletion task/bulk_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type bulkTask struct {
listener bridgeCore.Listener
releaseTasksCh chan int
gasLimitBumpRatio uint64
maxBulkTasks int
}

func newBulkTask(
Expand All @@ -58,6 +59,7 @@ func newBulkTask(
releaseTasksCh chan int,
util utils.Utils,
gasLimitBumpRatio uint64,
maxBulkTasks int,
) *bulkTask {
return &bulkTask{
util: util,
Expand All @@ -71,12 +73,17 @@ func newBulkTask(
listener: listener,
releaseTasksCh: releaseTasksCh,
gasLimitBumpRatio: gasLimitBumpRatio,
maxBulkTasks: maxBulkTasks,
}
}

func (r *bulkTask) collectTask(t *models.Task) {
if t.Type == r.taskType {
r.tasks = append(r.tasks, t)
if r.maxBulkTasks != 0 && len(r.tasks) >= r.maxBulkTasks {
log.Info("[bulkTask] Bulk task reaches the limit", "type", r.taskType, "num", len(r.tasks))
} else {
r.tasks = append(r.tasks, t)
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions task/ronin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type RoninTask struct {
processingIdsMap sync.Map
maxProcessingTasks int
gasLimitBumpRatio uint64
maxBulkTasks int
}

func NewRoninTask(listener bridgeCore.Listener, db *gorm.DB, util utils.Utils) (*RoninTask, error) {
Expand Down Expand Up @@ -106,6 +107,9 @@ func NewRoninTask(listener bridgeCore.Listener, db *gorm.DB, util utils.Utils) (
if config.MaxProcessingTasks > 0 {
task.maxProcessingTasks = config.MaxProcessingTasks
}
if config.MaxBulkTasks > 0 {
task.maxBulkTasks = config.MaxBulkTasks
}
return task, nil
}

Expand Down Expand Up @@ -207,6 +211,7 @@ func (r *RoninTask) processPending() error {
r.releaseTasksCh,
r.util,
r.gasLimitBumpRatio,
r.maxBulkTasks,
)
bulkSubmitWithdrawalSignaturesTask := newBulkTask(
r.listener,
Expand All @@ -220,6 +225,7 @@ func (r *RoninTask) processPending() error {
r.releaseTasksCh,
r.util,
r.gasLimitBumpRatio,
r.maxBulkTasks,
)
ackWithdrewTasks := newBulkTask(
r.listener,
Expand All @@ -233,6 +239,7 @@ func (r *RoninTask) processPending() error {
r.releaseTasksCh,
r.util,
r.gasLimitBumpRatio,
r.maxBulkTasks,
)

singleTasks := make([]Tasker, 0)
Expand Down

0 comments on commit c5a815f

Please sign in to comment.