发布于 2026-01-06 0 阅读
0

Solana Geyser插件使用指南

Solana Geyser插件使用指南

间歇泉到底是什么?

Geyser 由名为“Solana Geyser 插件接口”的组件构成。该接口允许开发者将插件构建到验证器中。插件接口随后会监听 Solana 区块链上的事件,并将这些事件通知插件。
这些事件可以是:

  • 账户更新,意味着每次链上的账户更新时,都会通知您的插件。
  • 新交易
  • 新老虎机

这催生了许多令人惊叹的应用场景,例如将特定项目的所有账户变更流式传输到数据库。这意味着您可以直接从您常用的数据库执行初始负载较高的 RPC 请求,例如 getProgramAccounts,这非常棒,并且可以将处理速度提升高达 10 倍。

示例

目前已有多个成熟的 Geyser 插件可供使用,以下是简要概述:

要求

要运行 Geyser 插件,您需要运行一个验证器或 RPC 节点,后者本质上是一个非投票验证器,可以索引链上的数据。
硬件要求会因您运行验证器的集群而异。我强烈建议您查看运行非投票验证器的推荐配置。
在本文中,我们将使用 Solana 本地验证器,它几乎可以在任何硬件上运行。

如何运行插件?

非常简单,只需启动一个 Solana 验证器,并附加要运行的 Geyser 插件即可。例如:
solana-test-validator --geyser-plugin-config <path to your plugin config>
我们来看一个示例插件脚手架,链接在
创建一个文件,将插件存放在该文件中,并在该文件中打开终端。然后克隆插件。
git clone https://github.com/mwrites/solana-geyser-plugin-scaffold.git .
现在一切就绪,但有一点需要注意:
⚠️ 您需要使用与构建 Solana CLI 相同的 Rust 版本来构建插件。此外,您的 Solana CLI 版本也应solana-geyser-plugin-interface与插件 Cargo.toml 文件中的版本匹配。
此插件的接口版本为:11.1.1。要安装相应的 Solana CLI 版本,请运行:
sh -c "$(curl -sSfL https://release.solana.com/v1.11.1/install)"

现在运行cargo build

还有一件事要做,在你的 config/config.json 文件中,确保将“libpath”的文件扩展名设置为 .htm(.so如果你使用的是 Linux 或 Windows 系统)或 .htm(.dylib如果你使用的是 macOS 系统)。

您的插件现在应该可以运行,并记录账本上发生的每一个账户变更,包括其公钥和当前槽位。您还可以获取更多信息,例如账户的数据缓冲区。是不是很棒?

构建您自己的插件

虽然这很棒,但您可能会想到这个插件框架可以实现的很多用例。我建议您从这个插件脚手架开始构建,但我仍然可以为您简要介绍一下插件接口的工作原理。在定义程序入口点之后(您可以在这里
找到示例),验证器会在特定事件触发时调用一些函数 例如:

// This gets called while the validator is still starting up
fn on_load(&mut self, config_file: &str) -> solana_geyser_plugin_interface::geyser_plugin_interface::Result<()> {
Enter fullscreen mode Exit fullscreen mode
// This gets called when startup has ended
fn notify_end_of_startup(&mut self) -> solana_geyser_plugin_interface::geyser_plugin_interface::Result<()> {
Enter fullscreen mode Exit fullscreen mode
// This gets called every time account data gets changed
fn update_account(&mut self, account: ReplicaAccountInfoVersions, slot: u64, is_startup: bool) -> solana_geyser_plugin_interface::geyser_plugin_interface::Result<()> {
Enter fullscreen mode Exit fullscreen mode
// This gets called each time there is a new transaction
fn notify_transaction(&mut self, transaction: ReplicaTransactionInfoVersions, slot: u64) -> solana_geyser_plugin_interface::geyser_plugin_interface::Result<()> {
Enter fullscreen mode Exit fullscreen mode
// These two are basically the configuration deciding if the interface should notify account changes and transaction notifications
fn account_data_notifications_enabled(&self) -> bool {
       true
}
fn transaction_notifications_enabled(&self) -> bool {
       true
} 
Enter fullscreen mode Exit fullscreen mode

结论

你可能已经注意到了,这个间歇泉模型挺酷的。用它做点什么吧!如果需要任何帮助,
欢迎在推特上@我。

说到
Geyser!我开发了一个名为Waverider 的验证器扩展。它本质上允许你将程序账户的变更数据流式传输到 Supabase 数据库,使 gPa 的运行速度提升 10 倍,甚至还能实时监听账户变更,这对很多去中心化应用 (dApp) 来说至关重要。如有任何疑问,欢迎随时联系我。

文章来源:https://dev.to/valentinmadrid/a-guide-to-solana-geyser-plugins-452k