Skip to content

Commit

Permalink
chore: check IsFinalized on callback function to prevent creating red…
Browse files Browse the repository at this point in the history
…undant tasks
  • Loading branch information
DNK90 committed Aug 16, 2023
1 parent 4c8143a commit 4ff316d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/bridge/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
1 change: 1 addition & 0 deletions cmd/bridge/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
14 changes: 14 additions & 0 deletions listener/ronin.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ func (l *RoninListener) RandomSeedRequestedCallback(fromChainId *big.Int, tx bri
if err = l.utilsWrapper.UnpackLog(*contractAbi, event, "RandomSeedRequested", data); err != nil {
return err
}
// call to contract to see if the request is finalized or not?
caller, err := contract.NewRoninVRFCoordinatorCaller(common.HexToAddress(task.VRFConfig.ContractAddress), l.client)
if err != nil {
log.Error("error while init new VRF caller", "err", err, "contractAddress", task.VRFConfig.ContractAddress)
return err
}
isFinalized, err := task.IsFinalized(caller, event.ReqHash)
if err != nil {
log.Error("error while checking random request is finalized or not", "err", err)
return err
}
if isFinalized {
return nil
}
// get chainID
chainId, err := l.GetChainID()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions task/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (r *task) sendFullFillRandomSeedTransactions(task *models.Task) (doneTasks,
goto ERROR
}
// req is finalized, GOTO update done
finalized, err = isFinalized(caller, event.ReqHash)
finalized, err = IsFinalized(caller, event.ReqHash)
if err != nil {
goto ERROR
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func isAssigned(signer utils.ISign, assignee common.Address) bool {
return true
}

func isFinalized(caller *contract.RoninVRFCoordinatorCaller, req [32]byte) (bool, error) {
func IsFinalized(caller *contract.RoninVRFCoordinatorCaller, req [32]byte) (bool, error) {
result, err := caller.RequestFinalized(nil, req)
if err != nil {
return false, err
Expand Down

0 comments on commit 4ff316d

Please sign in to comment.