A guide to Solana Geyser Plugins
Tags: solana, geyser, devtool, database
Published: 2023-05-03 10:29:32

## What even is Geyser ?
Geyser consists of something called the "Solana Geyser Plugin Interface". This interface enables developers to build Plugins into validators. The Plugin interface will then listen to events on the Solana Blockchain and notify the Plugin of those events.
These events can be: 
- account updates, meaning every time an account is updated on the chain, it will notify your Plugin.
- new transactions
- new slots

This enables amazing use cases, such as streaming all account changes for your specific program to a database. This means you could perform initially high load RPC requests such as getProgramAccounts directly from your favourite database, which is pretty cool and makes the process up to 10 times faster

## Examples
There are several already developed Geyser Plugins which you can run, here is a quick overview:
- [AccountsDB Postgres](https://github.com/solana-labs/solana-accountsdb-plugin-postgres): Stores your accounts and transactions in a Postgres database.
- [AccountsDB Kafka](https://github.com/Blockdaemon/solana-accountsdb-plugin-kafka): Streams account changes to Kafka.
- [AccountsDB Plugin Bigtable](https://github.com/lijunwangs/solana-accountsdb-plugin-bigtable): Streams tx + accounts to Google Bigtable.
- [Yellowstone gRPC](https://github.com/rpcpool/yellowstone-grpc): gRPC interface for Solana.
- [Waverider](https://github.com/nautilus-project/waverider): Streams account data from specific programs (PDA's) to a Supabase instance, which can then be queried via Supabase realtime.

## Requirements
To run a Geyser Plugin, you will need to run a validator or an RPC node, which is essentially a non voting validator that can index data from the chain.
The hardware requirements will vary on the cluster you want to run your validator on. I strongly recommend you take a look at the recommended specifications to run a non voting validator.
In this post, we are going to use the Solana Local Validator, which you can run with pretty much every hardware.

## How to run a Plugin ?
It's pretty straightforward, you just have to start a Solana validator with the Geyser Plugin you want to run attached. Here is an example:
`solana-test-validator --geyser-plugin-config <path to your plugin config>`
Let's take a look at an example plugin scaffold, [here](https://github.com/mwrites/solana-geyser-plugin-scaffold.git).
Create a file where you want your plugin to live, and open a terminal in it. Then clone the Plugin.
`git clone https://github.com/mwrites/solana-geyser-plugin-scaffold.git .`
We are now ready to go, but there is something important to take notice of:
⚠️ You need to build the Plugin with the same Rust version as you've build your Solana CLI. Also, your Solana CLI version should match the `solana-geyser-plugin-interface` in the plugin's Cargo.toml file.
The Interface version of this plugin is: 11.1.1. To install the corresponding Solana CLI version, run:
`sh -c "$(curl -sSfL https://release.solana.com/v1.11.1/install)"`

Now  run `cargo build`.

There's one more thing to do, in your config/config.json file, make sure to set your file extension for "libpath" to `.so` if you are on Linux or Windows or `.dylib` if you are on mac.

Your plugin should now run and log every single account change happening on the ledger, including it's Public Key and the current slot. You can also get way more information such as the account's data Buffer. Pretty cool right ?

## Build your own plugin
Now while this is pretty cool, you might think of a lot of use cases this plugin framework enables. While I recommend that you work up from this Plugin Scaffold, I can still give you a little insight on how the plugin interface works.
After defining an entrypoint to your program, for which you can find an example [here](https://github.com/mwrites/solana-geyser-plugin-scaffold/blob/main/src/entrypoint.rs).
Now the validator will call a couple functions whenever certain events are triggered. Some examples are:
```rust
// 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<()> {
```
```rust
// This gets called when startup has ended
fn notify_end_of_startup(&mut self) -> solana_geyser_plugin_interface::geyser_plugin_interface::Result<()> {
```
```rust
// 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<()> {
```
```rust
// 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<()> {
```
```rust
// 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
} 
```

## Conclusion
As you've probably noticed, this Geyser thing is pretty cool. Go build something with it !
Feel free to tag me on [Twitter](https://twitter.com/valentinmadrid_) if you need any help.

-- 
Speaking of Geyser ! I have built this validator extension called [Waverider](https://github.com/nautilus-project/waverider). It essentially allows you to stream your program's account changes to a Supabase Database, making gPa's 10 times faster and you're even able to listen to realtime account changes, which is essential to a lot of dApps. Again, feel free to contact me if you have any questions on this.