forked from taikoxyz/taiko-mono
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'taikoxyz:main' into patch-2
- Loading branch information
Showing
26 changed files
with
447 additions
and
100 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -27,3 +27,5 @@ var ( | |
) | ||
|
||
type HTTPOnly bool | ||
|
||
type ProfitableOnly bool |
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 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 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 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 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,23 @@ | ||
package message | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
) | ||
|
||
func (p *Processor) getLatestNonce(ctx context.Context, auth *bind.TransactOpts) error { | ||
pendingNonce, err := p.destEthClient.PendingNonceAt(ctx, p.relayerAddr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if pendingNonce > p.destNonce { | ||
p.setLatestNonce(pendingNonce) | ||
} | ||
|
||
auth.Nonce = big.NewInt(int64(p.destNonce)) | ||
|
||
return nil | ||
} |
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,19 @@ | ||
package message | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer/mock" | ||
) | ||
|
||
func Test_getLatestNonce(t *testing.T) { | ||
p := newTestProcessor(true) | ||
|
||
err := p.getLatestNonce(context.Background(), &bind.TransactOpts{}) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, p.destNonce, mock.PendingNonce) | ||
} |
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,41 @@ | ||
package message | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/pkg/errors" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts" | ||
) | ||
|
||
func (p *Processor) isProfitable(ctx context.Context, message contracts.IBridgeMessage, proof []byte) (bool, error) { | ||
processingFee := message.ProcessingFee | ||
|
||
if processingFee == nil || processingFee.Cmp(big.NewInt(0)) != 1 { | ||
return false, nil | ||
} | ||
|
||
auth, err := bind.NewKeyedTransactorWithChainID(p.ecdsaKey, message.DestChainId) | ||
if err != nil { | ||
return false, errors.Wrap(err, "bind.NewKeyedTransactorWithChainID") | ||
} | ||
|
||
auth.NoSend = true | ||
|
||
auth.Context = ctx | ||
|
||
// estimate gas with auth.NoSend set to true | ||
tx, err := p.destBridge.ProcessMessage(auth, message, proof) | ||
if err != nil { | ||
return false, errors.Wrap(err, "p.destBridge.ProcessMessage") | ||
} | ||
|
||
cost := tx.Cost() | ||
|
||
if processingFee.Cmp(cost) != 1 { | ||
return false, nil | ||
} | ||
|
||
return true, nil | ||
} |
Oops, something went wrong.