Skip to content

Commit

Permalink
Merge branch 'main' into a7_relayer_watchdog_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodino authored Feb 19, 2024
2 parents a3c7997 + 5a1f671 commit 565cb53
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 684 deletions.
2 changes: 2 additions & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ library TaikoData {
uint24 blobExpiry;
// True if EIP-4844 is enabled for DA
bool blobAllowedForDA;
// True if blob can be reused
bool blobReuseEnabled;
// ---------------------------------------------------------------------
// Group 3: Proof related configs
// ---------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ abstract contract TaikoErrors {
error L1_BLOB_NOT_FOUND();
error L1_BLOB_NOT_REUSEABLE();
error L1_BLOB_NOT_USED();
error L1_BLOB_REUSE_DISALBED();
error L1_BLOCK_MISMATCH();
error L1_CHAIN_DATA_NOT_RELAYED();
error L1_INVALID_BLOCK_ID();
Expand Down
15 changes: 13 additions & 2 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,18 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
/// @notice Gets the details of a block.
/// @param blockId Index of the block.
/// @return blk The block.
function getBlock(uint64 blockId) public view returns (TaikoData.Block memory blk) {
return LibUtils.getBlock(state, getConfig(), blockId);
/// @return ts The transition used to verify this block.
function getBlock(uint64 blockId)
public
view
returns (TaikoData.Block memory blk, TaikoData.TransitionState memory ts)
{
uint64 slot;
(blk, slot) = LibUtils.getBlock(state, getConfig(), blockId);

if (blk.verifiedTransitionId != 0) {
ts = state.transitions[slot][blk.verifiedTransitionId];
}
}

/// @notice Gets the state transition for a specific block.
Expand Down Expand Up @@ -219,6 +229,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
blockMaxTxListBytes: 120_000,
blobExpiry: 24 hours,
blobAllowedForDA: false,
blobReuseEnabled: false,
livenessBond: 250e18, // 250 Taiko token
// ETH deposit related.
ethDepositRingBufferSize: 1024,
Expand Down
5 changes: 4 additions & 1 deletion packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ library LibProposing {
error L1_BLOB_FOR_DA_DISABLED();
error L1_BLOB_NOT_FOUND();
error L1_BLOB_NOT_REUSEABLE();
error L1_BLOB_REUSE_DISALBED();
error L1_INVALID_HOOK();
error L1_INVALID_PARAM();
error L1_INVALID_PROVER();
Expand Down Expand Up @@ -139,6 +140,8 @@ library LibProposing {
if (!config.blobAllowedForDA) revert L1_BLOB_FOR_DA_DISABLED();

if (params.blobHash != 0) {
if (!config.blobReuseEnabled) revert L1_BLOB_REUSE_DISALBED();

// We try to reuse an old blob
if (!isBlobReusable(state, config, params.blobHash)) {
revert L1_BLOB_NOT_REUSEABLE();
Expand All @@ -156,7 +159,7 @@ library LibProposing {
// Depends on the blob data price, it may not make sense to
// cache the blob which costs 20,000 (sstore) + 631 (event)
// extra gas.
if (params.cacheBlobForReuse) {
if (config.blobReuseEnabled && params.cacheBlobForReuse) {
state.reusableBlobs[meta.blobHash] = block.timestamp;
emit BlobCached(meta.blobHash);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ library LibUtils {
)
external
view
returns (TaikoData.Block storage blk)
returns (TaikoData.Block storage blk, uint64 slot)
{
blk = state.blocks[blockId % config.blockRingBufferSize];
slot = blockId % config.blockRingBufferSize;
blk = state.blocks[slot];
if (blk.blockId != blockId) {
revert L1_INVALID_BLOCK_ID();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/tokenvault/ERC721Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contract ERC721Vault is BaseNFTVault, IERC721ReceiverUpgradeable {
ctoken: ctoken.addr,
token: token,
tokenIds: tokenIds,
amounts: new uint256[](0)
amounts: new uint256[](tokenIds.length)
});
}

Expand Down Expand Up @@ -143,7 +143,7 @@ contract ERC721Vault is BaseNFTVault, IERC721ReceiverUpgradeable {
ctoken: ctoken.addr,
token: token,
tokenIds: tokenIds,
amounts: new uint256[](0)
amounts: new uint256[](tokenIds.length)
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/relayer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
.l1l3processor.env
.l2l1processor.env
.l1processor.env
.l1indexer.env
.l2indexer.env
main
relayer
coverage.txt

# Local .terraform directories
Expand Down
3 changes: 2 additions & 1 deletion packages/relayer/cmd/flags/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
filter: only filter the chain, when caught up, exit
subscribe: do not filter the chain, only subscribe to new events
filter-and-subscribe: the default behavior, filter the chain and subscribe when caught up
crawl-past-blocks: crawl past blocks
`,
Value: "filter-and-subscribe",
Category: indexerCategory,
Expand Down Expand Up @@ -85,14 +86,14 @@ var (

var IndexerFlags = MergeFlags(CommonFlags, QueueFlags, []cli.Flag{
SrcBridgeAddress,
DestBridgeAddress,
// optional
SrcTaikoAddress,
BlockBatchSize,
MaxNumGoroutines,
SubscriptionBackoff,
SyncMode,
WatchMode,
DestBridgeAddress,
NumLatestBlocksToIgnoreWhenCrawling,
EventName,
})
2 changes: 1 addition & 1 deletion packages/relayer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
EventStatusRetriable
EventStatusDone
EventStatusFailed
EventStatusNewOnlyOwner
EventStatusNewOnlyOwner // internal used in Relayer only
)

type EventType int
Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/processor/can_process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func canProcessMessage(
return true
}

slog.Info("cant process message", "eventStatus", eventStatus.String())
slog.Info("cant process message due to", "eventStatus", eventStatus.String())

return false
}
5 changes: 5 additions & 0 deletions packages/relayer/processor/process_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ package processor
import (
"context"
"encoding/json"
"log/slog"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/bridge"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
)

func (p *Processor) processSingle(ctx context.Context) error {
slog.Info("processing tx", "estimateGas", common.Hash(*p.targetTxHash).Hex())

bridgeAbi, err := abi.JSON(strings.NewReader(bridge.BridgeABI))
if err != nil {
return err
Expand Down
14 changes: 10 additions & 4 deletions packages/relayer/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log/slog"
"math/big"
"os"
"sync"
"time"

Expand Down Expand Up @@ -362,7 +363,12 @@ func (p *Processor) Start() error {

// if a targetTxHash is set, we only want to process that specific one.
if p.targetTxHash != nil {
return p.processSingle(ctx)
err := p.processSingle(ctx)
if err != nil {
slog.Error(err.Error())
}

os.Exit(0)
}

// otherwise, we can start the queue, and process messages from it
Expand Down Expand Up @@ -411,14 +417,14 @@ func (p *Processor) eventLoop(ctx context.Context) {
err := p.processMessage(ctx, msg)

if err != nil {
slog.Error("err processing message", "err", err.Error())

if errors.Is(err, errUnprocessable) {
if err := p.queue.Ack(ctx, msg); err != nil {
slog.Error("Err acking message", "err", err.Error())
}
} else {
if err := p.queue.Nack(ctx, msg); err != nil {
slog.Error("process message failed", "err", err.Error())

if err = p.queue.Nack(ctx, msg); err != nil {
slog.Error("Err nacking message", "err", err.Error())
}
}
Expand Down
Loading

0 comments on commit 565cb53

Please sign in to comment.