消息过滤
配置要中继的消息和要忽略的消息
默认情况下,Relayer 将尝试将从其源链发送的消息传递到任何已配置的目标链。
Relayer 可能希望进一步过滤它们尝试传递的消息。例如,构建跨链应用程序的人可能希望运行一个只传递发送到该应用程序的消息的 Relayer。同样,一些 Relayer 可能希望仅将消息中继到可用链的子集。
Relayer 可以通过设置 --whitelist
或 --blacklist
环境变量来可选地过滤它们传递的消息。另请参阅 配置参考 的白名单部分。
这些配置是字符串化的 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 位无符号整数
type U32 = number | string;
// 256 位哈希(也可以更少)以十六进制编码
type H256 = string;
// 匹配任何内容
type Wildcard = "*";
白名单和黑名单都具有"任意"语义。换句话说,Relayer 将传递与任何白名单过滤器匹配的消息,并忽略与任何黑名单过滤器匹配的消息。
例如,以下配置用作白名单将确保 Relayer 将中继发送到以太坊的任何消息,从地址 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"}]'
黑名单优先于白名单,即如果一条消息同时匹配白名单和黑名单,则该消息将不会被传递。