Skip to content

Commit f4b2e60

Browse files
authored
chore(relayer): fix correct order of dest/src (#21154)
1 parent 70c4c5e commit f4b2e60

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

packages/relayer/pkg/mock/event_repository.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,29 @@ import (
1515
)
1616

1717
type EventRepository struct {
18-
events []*relayer.Event
18+
events []*relayer.Event
19+
ChainDataSyncedEventByBlockNumberOrGreaterFunc func(
20+
ctx context.Context,
21+
srcChainId uint64,
22+
syncedChainId uint64,
23+
blockNumber uint64,
24+
) (*relayer.Event, error)
25+
LatestChainDataSyncedEventFunc func(
26+
ctx context.Context,
27+
srcChainId uint64,
28+
syncedChainId uint64,
29+
) (uint64, error)
30+
CheckpointSyncedEventByBlockNumberOrGreaterFunc func(
31+
ctx context.Context,
32+
chainId uint64,
33+
syncedChainId uint64,
34+
blockNumber uint64,
35+
) (*relayer.Event, error)
36+
LatestCheckpointSyncedEventFunc func(
37+
ctx context.Context,
38+
chainId uint64,
39+
syncedChainId uint64,
40+
) (uint64, error)
1941
}
2042

2143
func NewEventRepository() *EventRepository {
@@ -190,6 +212,10 @@ func (r *EventRepository) ChainDataSyncedEventByBlockNumberOrGreater(
190212
syncedChainId uint64,
191213
blockNumber uint64,
192214
) (*relayer.Event, error) {
215+
if r.ChainDataSyncedEventByBlockNumberOrGreaterFunc != nil {
216+
return r.ChainDataSyncedEventByBlockNumberOrGreaterFunc(ctx, srcChainId, syncedChainId, blockNumber)
217+
}
218+
193219
return &relayer.Event{
194220
ID: rand.Int(), // nolint: gosec
195221
ChainID: MockChainID.Int64(),
@@ -201,6 +227,10 @@ func (r *EventRepository) LatestChainDataSyncedEvent(
201227
srcChainId uint64,
202228
syncedChainId uint64,
203229
) (uint64, error) {
230+
if r.LatestChainDataSyncedEventFunc != nil {
231+
return r.LatestChainDataSyncedEventFunc(ctx, srcChainId, syncedChainId)
232+
}
233+
204234
return 5, nil
205235
}
206236

@@ -210,6 +240,10 @@ func (r *EventRepository) CheckpointSyncedEventByBlockNumberOrGreater(
210240
syncedChainId uint64,
211241
blockNumber uint64,
212242
) (*relayer.Event, error) {
243+
if r.CheckpointSyncedEventByBlockNumberOrGreaterFunc != nil {
244+
return r.CheckpointSyncedEventByBlockNumberOrGreaterFunc(ctx, chainId, syncedChainId, blockNumber)
245+
}
246+
213247
return &relayer.Event{
214248
ID: rand.Int(), // nolint: gosec
215249
ChainID: MockChainID.Int64(),
@@ -221,6 +255,10 @@ func (r *EventRepository) LatestCheckpointSyncedEvent(
221255
chainId uint64,
222256
syncedChainId uint64,
223257
) (uint64, error) {
258+
if r.LatestCheckpointSyncedEventFunc != nil {
259+
return r.LatestCheckpointSyncedEventFunc(ctx, chainId, syncedChainId)
260+
}
261+
224262
return 5, nil
225263
}
226264

packages/relayer/processor/process_message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (p *Processor) generateEncodedSignalProof(ctx context.Context,
337337
// we can grab the latestBlockID, create a singular "hop" of srcChain => destChain,
338338
// and generate a proof.
339339
if len(p.hops) == 0 {
340-
latestBlockID, err := p.latestSyncedBlockID(ctx, p.srcChainId.Uint64(), p.destChainId.Uint64())
340+
latestBlockID, err := p.latestSyncedBlockID(ctx, p.destChainId.Uint64(), p.srcChainId.Uint64())
341341
if err != nil {
342342
return nil, err
343343
}

packages/relayer/processor/process_message_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/taikoxyz/taiko-mono/packages/relayer"
1616
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/bridge"
1717
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/mock"
18+
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/proof"
1819
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
1920
)
2021

@@ -319,3 +320,70 @@ func Test_ProcessMessage_continuesOutsideShastaForkWindow(t *testing.T) {
319320
assert.Nil(t, err)
320321
assert.True(t, shouldRequeue)
321322
}
323+
324+
func TestGenerateEncodedSignalProofUsesDestChainCheckpoint(t *testing.T) {
325+
const (
326+
srcChainID = uint64(1)
327+
destChainID = uint64(2)
328+
)
329+
330+
repo := mock.NewEventRepository()
331+
repo.LatestChainDataSyncedEventFunc = func(
332+
ctx context.Context,
333+
chainID uint64,
334+
syncedChainID uint64,
335+
) (uint64, error) {
336+
if chainID != destChainID || syncedChainID != srcChainID {
337+
return 0, errors.New("unexpected chain IDs")
338+
}
339+
340+
return 1, nil
341+
}
342+
repo.LatestCheckpointSyncedEventFunc = func(
343+
ctx context.Context,
344+
chainID uint64,
345+
syncedChainID uint64,
346+
) (uint64, error) {
347+
if chainID != destChainID || syncedChainID != srcChainID {
348+
return 0, errors.New("unexpected chain IDs")
349+
}
350+
351+
return 10, nil
352+
}
353+
354+
ethClient := &mock.EthClient{}
355+
prover, err := proof.New(ethClient, 0)
356+
assert.Nil(t, err)
357+
358+
p := &Processor{
359+
eventRepo: repo,
360+
srcChainId: big.NewInt(int64(srcChainID)),
361+
destChainId: big.NewInt(int64(destChainID)),
362+
srcEthClient: ethClient,
363+
srcCaller: &mock.Caller{},
364+
prover: prover,
365+
srcSignalService: &mock.SignalService{},
366+
srcSignalServiceAddress: common.HexToAddress("0x0000000000000000000000000000000000000001"),
367+
ethClientTimeout: time.Second,
368+
}
369+
370+
event := &bridge.BridgeMessageSent{
371+
MsgHash: [32]byte{0x01},
372+
Message: bridge.IBridgeMessage{
373+
SrcChainId: srcChainID,
374+
DestChainId: destChainID,
375+
From: common.HexToAddress("0x0000000000000000000000000000000000000002"),
376+
SrcOwner: common.HexToAddress("0x0000000000000000000000000000000000000002"),
377+
DestOwner: common.HexToAddress("0x0000000000000000000000000000000000000002"),
378+
To: common.HexToAddress("0x0000000000000000000000000000000000000002"),
379+
GasLimit: 1,
380+
},
381+
Raw: types.Log{
382+
Address: common.HexToAddress("0x0000000000000000000000000000000000000003"),
383+
BlockNumber: 1,
384+
},
385+
}
386+
387+
_, err = p.generateEncodedSignalProof(context.Background(), event)
388+
assert.Nil(t, err)
389+
}

0 commit comments

Comments
 (0)