Skip to content

Commit

Permalink
chore(relayer): update relayer to latest protocol changes (#13059)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
Co-authored-by: shadab-taiko <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2023
1 parent 51d1f67 commit 2d93c95
Show file tree
Hide file tree
Showing 20 changed files with 864 additions and 1,629 deletions.
945 changes: 0 additions & 945 deletions packages/relayer/TaikoL1.json

This file was deleted.

6 changes: 3 additions & 3 deletions packages/relayer/abigen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ names=("Bridge" "IHeaderSync" "TaikoL2" "TaikoL1")
for (( i = 0; i < ${#paths[@]}; ++i ));
do
jq .abi ../protocol/artifacts/contracts/${paths[i]}/${names[i]}.json > ${names[i]}.json
echo $abi
lower=$(echo "${names[i]}" | tr '[:upper:]' '[:lower:]')
abigen --abi ${names[i]}.json \
--pkg contracts \
--pkg $lower \
--type ${names[i]} \
--out contracts/${names[i]}.go
--out contracts/$lower/${names[i]}.go
done

exit 0
14 changes: 7 additions & 7 deletions packages/relayer/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
)

type Bridge interface {
WatchMessageSent(
opts *bind.WatchOpts,
sink chan<- *contracts.BridgeMessageSent,
signal [][32]byte,
sink chan<- *bridge.BridgeMessageSent,
msgHash [][32]byte,
) (event.Subscription, error)
FilterMessageSent(opts *bind.FilterOpts, signal [][32]byte) (*contracts.BridgeMessageSentIterator, error)
GetMessageStatus(opts *bind.CallOpts, signal [32]byte) (uint8, error)
ProcessMessage(opts *bind.TransactOpts, message contracts.IBridgeMessage, proof []byte) (*types.Transaction, error)
IsMessageReceived(opts *bind.CallOpts, signal [32]byte, srcChainId *big.Int, proof []byte) (bool, error) // nolint
FilterMessageSent(opts *bind.FilterOpts, msgHash [][32]byte) (*bridge.BridgeMessageSentIterator, error)
GetMessageStatus(opts *bind.CallOpts, msgHash [32]byte) (uint8, error)
ProcessMessage(opts *bind.TransactOpts, message bridge.IBridgeMessage, proof []byte) (*types.Transaction, error)
IsMessageReceived(opts *bind.CallOpts, msgHash [32]byte, srcChainId *big.Int, proof []byte) (bool, error) // nolint
}

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions packages/relayer/indexer/handle_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
)

// handleEvent handles an individual MessageSent event
func (svc *Service) handleEvent(
ctx context.Context,
chainID *big.Int,
event *contracts.BridgeMessageSent,
event *bridge.BridgeMessageSent,
) error {
raw := event.Raw

log.Infof("event found for signal: %v", common.Hash(event.Signal).Hex())
log.Infof("event found for msgHash: %v", common.Hash(event.MsgHash).Hex())

// handle chain re-org by checking Removed property, no need to
// return error, just continue and do not process.
if raw.Removed {
log.Warnf("event signal was removed: %v", common.Hash(event.Signal).Hex())
log.Warnf("event msgHash was removed: %v", common.Hash(event.MsgHash).Hex())
return nil
}

if event.Signal == relayer.ZeroHash {
log.Warn("Zero signal found. This is unexpected. Returning early")
if event.MsgHash == relayer.ZeroHash {
log.Warn("Zero msgHash found. This is unexpected. Returning early")
return nil
}

eventStatus, err := svc.eventStatusFromSignal(ctx, event.Message.GasLimit, event.Signal)
eventStatus, err := svc.eventStatusFromMsgHash(ctx, event.Message.GasLimit, event.MsgHash)
if err != nil {
return errors.Wrap(err, "svc.eventStatusFromSignal")
return errors.Wrap(err, "svc.eventStatusFromMsgHash")
}

marshaled, err := json.Marshal(event)
Expand All @@ -55,7 +55,7 @@ func (svc *Service) handleEvent(
}

if !canProcessMessage(ctx, eventStatus, event.Message.Owner, svc.relayerAddr) {
log.Warnf("cant process signal: %v, eventStatus: %v", common.Hash(event.Signal).Hex(), eventStatus)
log.Warnf("cant process msgHash: %v, eventStatus: %v", common.Hash(event.MsgHash).Hex(), eventStatus)
return nil
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func canProcessMessage(
return false
}

func (svc *Service) eventStatusFromSignal(
func (svc *Service) eventStatusFromMsgHash(
ctx context.Context,
gasLimit *big.Int,
signal [32]byte,
Expand Down
10 changes: 5 additions & 5 deletions packages/relayer/indexer/handle_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Test_canProcessMessage(t *testing.T) {
}
}

func Test_eventStatusFromSignal(t *testing.T) {
func Test_eventStatusFromMsgHash(t *testing.T) {
tests := []struct {
name string
ctx context.Context
Expand All @@ -95,23 +95,23 @@ func Test_eventStatusFromSignal(t *testing.T) {
"eventStatusNewOnlyOwner, 0GasLimit",
context.Background(),
common.Big0,
mock.SuccessSignal,
mock.SuccessMsgHash,
nil,
relayer.EventStatusNewOnlyOwner,
},
{
"eventStatusNewOnlyOwner, nilGasLimit",
context.Background(),
nil,
mock.SuccessSignal,
mock.SuccessMsgHash,
nil,
relayer.EventStatusNewOnlyOwner,
},
{
"eventStatusNewOnlyOwner, non0GasLimit",
context.Background(),
big.NewInt(100),
mock.SuccessSignal,
mock.SuccessMsgHash,
nil,
relayer.EventStatusNew,
},
Expand All @@ -121,7 +121,7 @@ func Test_eventStatusFromSignal(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
svc, _ := newTestService()

status, err := svc.eventStatusFromSignal(tt.ctx, tt.gasLimit, tt.signal)
status, err := svc.eventStatusFromMsgHash(tt.ctx, tt.gasLimit, tt.signal)
if tt.wantErr != nil {
assert.EqualError(t, tt.wantErr, err.Error())
} else {
Expand Down
18 changes: 10 additions & 8 deletions packages/relayer/indexer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/iheadersync"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/taikol1"
"github.com/taikoxyz/taiko-mono/packages/relayer/message"
"github.com/taikoxyz/taiko-mono/packages/relayer/proof"
)
Expand Down Expand Up @@ -46,7 +48,7 @@ type Service struct {
numGoroutines int
subscriptionBackoff time.Duration

taikol1 *contracts.TaikoL1
taikol1 *taikol1.TaikoL1
}

type NewServiceOpts struct {
Expand Down Expand Up @@ -116,12 +118,12 @@ func NewService(opts NewServiceOpts) (*Service, error) {

relayerAddr := crypto.PubkeyToAddress(*publicKeyECDSA)

bridge, err := contracts.NewBridge(opts.BridgeAddress, opts.EthClient)
srcBridge, err := bridge.NewBridge(opts.BridgeAddress, opts.EthClient)
if err != nil {
return nil, errors.Wrap(err, "contracts.NewBridge")
}

destBridge, err := contracts.NewBridge(opts.DestBridgeAddress, opts.DestEthClient)
destBridge, err := bridge.NewBridge(opts.DestBridgeAddress, opts.DestEthClient)
if err != nil {
return nil, errors.Wrap(err, "contracts.NewBridge")
}
Expand All @@ -131,14 +133,14 @@ func NewService(opts NewServiceOpts) (*Service, error) {
return nil, errors.Wrap(err, "proof.New")
}

destHeaderSyncer, err := contracts.NewIHeaderSync(opts.DestTaikoAddress, opts.DestEthClient)
destHeaderSyncer, err := iheadersync.NewIHeaderSync(opts.DestTaikoAddress, opts.DestEthClient)
if err != nil {
return nil, errors.Wrap(err, "contracts.NewTaikoL2")
}

var taikoL1 *contracts.TaikoL1
var taikoL1 *taikol1.TaikoL1
if opts.SrcTaikoAddress != ZeroAddress {
taikoL1, err = contracts.NewTaikoL1(opts.SrcTaikoAddress, opts.EthClient)
taikoL1, err = taikol1.NewTaikoL1(opts.SrcTaikoAddress, opts.EthClient)
if err != nil {
return nil, errors.Wrap(err, "contracts.NewTaikoL1")
}
Expand Down Expand Up @@ -168,7 +170,7 @@ func NewService(opts NewServiceOpts) (*Service, error) {
ethClient: opts.EthClient,
destRPC: opts.DestRPCClient,

bridge: bridge,
bridge: srcBridge,
destBridge: destBridge,
taikol1: taikoL1,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (svc *Service) setInitialProcessingBlockByMode(
var startingBlock uint64 = 0

if svc.taikol1 != nil {
genesis, _, _, _, err := svc.taikol1.GetStateVariables(nil)
genesis, _, _, _, _, _, _, _, _, _, err := svc.taikol1.GetStateVariables(nil)
if err != nil {
return errors.Wrap(err, "svc.taikoL1.GetStateVariables")
}
Expand Down
4 changes: 2 additions & 2 deletions packages/relayer/indexer/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
)

// subscribe subscribes to latest events
func (svc *Service) subscribe(ctx context.Context, chainID *big.Int) error {
log.Info("subscribing to new events")

sink := make(chan *contracts.BridgeMessageSent)
sink := make(chan *bridge.BridgeMessageSent)

sub := event.ResubscribeErr(svc.subscriptionBackoff, func(ctx context.Context, err error) (event.Subscription, error) {
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions packages/relayer/message/is_profitable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
)

func (p *Processor) isProfitable(
ctx context.Context, message contracts.IBridgeMessage, proof []byte) (bool, uint64, error) {
ctx context.Context, message bridge.IBridgeMessage, proof []byte) (bool, uint64, error) {
processingFee := message.ProcessingFee

if processingFee == nil || processingFee.Cmp(big.NewInt(0)) != 1 {
Expand Down
12 changes: 6 additions & 6 deletions packages/relayer/message/is_profitable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
"github.com/taikoxyz/taiko-mono/packages/relayer/mock"
)

Expand All @@ -15,14 +15,14 @@ func Test_isProfitable(t *testing.T) {

tests := []struct {
name string
message contracts.IBridgeMessage
message bridge.IBridgeMessage
proof []byte
wantProfitable bool
wantErr error
}{
{
"zeroProcessingFee",
contracts.IBridgeMessage{
bridge.IBridgeMessage{
ProcessingFee: big.NewInt(0),
},
nil,
Expand All @@ -31,14 +31,14 @@ func Test_isProfitable(t *testing.T) {
},
{
"nilProcessingFee",
contracts.IBridgeMessage{},
bridge.IBridgeMessage{},
nil,
false,
nil,
},
{
"lowProcessingFee",
contracts.IBridgeMessage{
bridge.IBridgeMessage{
ProcessingFee: new(big.Int).Sub(mock.ProcessMessageTx.Cost(), big.NewInt(1)),
DestChainId: big.NewInt(167001),
},
Expand All @@ -48,7 +48,7 @@ func Test_isProfitable(t *testing.T) {
},
{
"profitableProcessingFee",
contracts.IBridgeMessage{
bridge.IBridgeMessage{
ProcessingFee: new(big.Int).Add(mock.ProcessMessageTx.Cost(), big.NewInt(1)),
DestChainId: big.NewInt(167001),
},
Expand Down
16 changes: 8 additions & 8 deletions packages/relayer/message/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
)

// Process prepares and calls `processMessage` on the bridge.
Expand All @@ -21,7 +21,7 @@ import (
// expects
func (p *Processor) ProcessMessage(
ctx context.Context,
event *contracts.BridgeMessageSent,
event *bridge.BridgeMessageSent,
e *relayer.Event,
) error {
if event.Message.GasLimit == nil || event.Message.GasLimit.Cmp(common.Big0) == 0 {
Expand All @@ -45,7 +45,7 @@ func (p *Processor) ProcessMessage(

hashed := crypto.Keccak256(
event.Raw.Address.Bytes(),
event.Signal[:],
event.MsgHash[:],
)

key := hex.EncodeToString(hashed)
Expand All @@ -56,7 +56,7 @@ func (p *Processor) ProcessMessage(
event.Message.SrcChainId,
event.Message.DestChainId,
event.Raw.TxHash.Hex(),
common.Hash(event.Signal).Hex(),
common.Hash(event.MsgHash).Hex(),
event.Message.Owner.Hex(),
)

Expand All @@ -68,14 +68,14 @@ func (p *Processor) ProcessMessage(
// an issue with the signal generation.
received, err := p.destBridge.IsMessageReceived(&bind.CallOpts{
Context: ctx,
}, event.Signal, event.Message.SrcChainId, encodedSignalProof)
}, event.MsgHash, event.Message.SrcChainId, encodedSignalProof)
if err != nil {
return errors.Wrap(err, "p.destBridge.IsMessageReceived")
}

// message will fail when we try to process it
if !received {
log.Warnf("signal %v not received on dest chain", common.Hash(event.Signal).Hex())
log.Warnf("msgHash %v not received on dest chain", common.Hash(event.MsgHash).Hex())
return errors.New("message not received")
}

Expand All @@ -93,7 +93,7 @@ func (p *Processor) ProcessMessage(

log.Infof("Mined tx %s", hex.EncodeToString(tx.Hash().Bytes()))

messageStatus, err := p.destBridge.GetMessageStatus(&bind.CallOpts{}, event.Signal)
messageStatus, err := p.destBridge.GetMessageStatus(&bind.CallOpts{}, event.MsgHash)
if err != nil {
return errors.Wrap(err, "p.destBridge.GetMessageStatus")
}
Expand All @@ -110,7 +110,7 @@ func (p *Processor) ProcessMessage(

func (p *Processor) sendProcessMessageCall(
ctx context.Context,
event *contracts.BridgeMessageSent,
event *bridge.BridgeMessageSent,
proof []byte,
) (*types.Transaction, error) {
auth, err := bind.NewKeyedTransactorWithChainID(p.ecdsaKey, event.Message.DestChainId)
Expand Down
Loading

0 comments on commit 2d93c95

Please sign in to comment.