Skip to main content

Message filtering

配置要中继的消息以及要忽略的消息

默认情况下,中继器将尝试将从其源链发送到任何配置的目标链的消息传递到目标链。

中继器可能希望进一步筛选它们尝试传递的消息。例如,构建跨链应用程序的人可能希望运行一个仅传递发送到该应用程序的消息的中继器。同样,一些中继器可能希望仅将消息中继到一部分可用的链。

中继器可以通过设置 --whitelist--blacklist 环境变量来可选地筛选它们传递的消息。另请参阅配置参考configuration reference's 的白名单部分。

这些配置是字符串化的 JSON 对象,格式如下:

// 一个匹配规则列表。如果列表中的任何一个匹配,则消息会匹配。
// 元素匹配消息。
type MatchingList = Array<ListElement>;

// 如果提供的任何值匹配,则匹配消息。
interface ListElement {
originDomain?: NumericFilter
senderAddress?: HashFilter
destinationDomain?: NumericFilter
recipientAddress?: HashFilter
}

type NumericFilter = Wildcard | U32 | Array<U32>;
type HashFilter = Wildcard | H256 | Array<H256>;

// 32-bit unsigned integer
type U32 = number | string;
// 256-bit hash (can also be less) encoded as hex
type H256 = string;
// Matches anything
type Wildcard = "*";

白名单和黑名单都有 "任意 "语义。换句话说,中继器将传送符合_any_个白名单过滤器的信息,并忽略符合_any_个黑名单过滤器的信息。

例如,将以下配置用作白名单将确保中继器转发发送到以太坊的任何消息,从地址 0xca7f632e91B592178D83A70B404f398c0a51581F 发送到 Celo 或 Avalanche 的任何消息,以及发送到 Arbitrum 或 Optimism 上地址 0xca7f632e91B592178D83A70B404f398c0a51581F 的任何消息。

[
{
senderAddress: "*",
destinationDomain: ["1"],
recipientAddress: "*"
},
{
senderAddress: "0xca7f632e91B592178D83A70B404f398c0a51581F",
destinationDomain: ["42220", "43114"],
recipientAddress: "*"
},
{
senderAddress: "*",
destinationDomain: ["42161", "420"],
recipientAddress: "0xca7f632e91B592178D83A70B404f398c0a51581F"
}
]

一个有效的配置可能如下所示:

--whitelist='[{"senderAddress":"*","destinationDomain":["1"],"recipientAddress":"*"},{"senderAddress":"0xca7f632e91B592178D83A70B404f398c0a51581F","destinationDomain":["42220","43114"],"recipientAddress":"*"},{"senderAddress":"*","destinationDomain":["42161","420"],"recipientAddress":"0xca7f632e91B592178D83A70B404f398c0a51581F"}]'

黑名单会覆盖白名单,即如果消息同时匹配白名单和黑名单,则该消息不会被传递。