-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(relayer): header sync check before processing messages (#441)
* header sync check before processing messages * rm gas limit + warn logs * get latest synced header after waiting * lint * use header by hash instead of block by hash
- Loading branch information
1 parent
8216cc1
commit e9fda8b
Showing
12 changed files
with
180 additions
and
86 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
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,55 @@ | ||
package message | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts" | ||
) | ||
|
||
func (p *Processor) waitHeaderSynced(ctx context.Context, event *contracts.BridgeMessageSent) error { | ||
ticker := time.NewTicker(time.Duration(p.headerSyncIntervalSeconds) * time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
case <-ticker.C: | ||
// get latest synced header since not every header is synced from L1 => L2, | ||
// and later blocks still have the storage trie proof from previous blocks. | ||
latestSyncedHeader, err := p.destHeaderSyncer.GetLatestSyncedHeader(&bind.CallOpts{}) | ||
if err != nil { | ||
return errors.Wrap(err, "p.destHeaderSyncer.GetLatestSyncedHeader") | ||
} | ||
|
||
header, err := p.srcEthClient.HeaderByHash(ctx, latestSyncedHeader) | ||
if err != nil { | ||
return errors.Wrap(err, "p.destHeaderSyncer.GetLatestSyncedHeader") | ||
} | ||
|
||
// header is caught up and processible | ||
if header.Number.Uint64() >= event.Raw.BlockNumber { | ||
log.Infof( | ||
"signal: %v is processable. occured in block %v, latestSynced is block %v", | ||
common.Hash(event.Signal).Hex(), | ||
event.Raw.BlockNumber, | ||
header.Number.Uint64(), | ||
) | ||
|
||
return nil | ||
} | ||
|
||
log.Infof( | ||
"signal: %v waiting to be processable. occured in block %v, latestSynced is block %v", | ||
common.Hash(event.Signal).Hex(), | ||
event.Raw.BlockNumber, | ||
header.Number.Uint64(), | ||
) | ||
} | ||
} | ||
} |
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,21 @@ | ||
package message | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts" | ||
) | ||
|
||
func Test_waitHeaderSynced(t *testing.T) { | ||
p := newTestProcessor(true) | ||
|
||
err := p.waitHeaderSynced(context.TODO(), &contracts.BridgeMessageSent{ | ||
Raw: types.Log{ | ||
BlockNumber: 1, | ||
}, | ||
}) | ||
assert.Nil(t, err) | ||
} |
Oops, something went wrong.