Overview page background
What is the Solana Geyser Plugin?

What is the Solana Geyser Plugin?

Published on 2023-01-263 min read

Solana’s Geyser Plugin helps reduce dependence on validator nodes. This article will explain what the Solana Geyser Plugin is, how it works, and how to setup a PostgeSQL server to use with a Geyser Plugin interface.

What is the Solana Geyser Plugin?

Solana developed a mechanism called the Solana Geyser Plugin to route RPC requests to another memory location and reduce dependence on validator nodes. The Remote Procedure Call (RPC) allows users to connect, read, and write information to Solana nodes on a network. RPC service providers can get inundated with requests when the Solana network experiences high traffic. This unusual traffic can cause Solana validators to fall behind the node leader.

How does the Solana Geyser Plugin help with external data sources?

The Solana Geyser Plugin enables developers to access some forms of data without requesting them on-chain. Using Kafka, postgreSQL, and other possible data stores, developers do not need to use RPC resources for actions like getting accounts, blocks, and slots. To interface with the Solana Geyser Plugin, developers need to use crates.

What are crates in the Solana Geyser Plugin?

The Solana Geyser Plugin is made up of crates, which is a compilation unit on Rust, that typically converts to a library or binary when compiled. Crates are synonymous with packages in other programming languages. But in Rust, a package is a combination of one or more crates. Crates are made up of compilation units.

What are compilation units?

Compilation units are pieces of a program’s source code that can be compiled independently or separately. Since Rust is a general-purpose programming language, it supports functional, imperative, object-oriented, and concurrent programming. Rust uses statements that change a program’s state as each one of the statements is executed in turn. This approach allows programs written with Rust to be composed of compilation units. 

What are interfaces in the Solana Geyser Plugin?

A plugin interface is defined by the crate that is used. For example the Solana Geyser Plugin interface is specified by its GeyserPlugin trait. By allowing the flow of communication, the GeyserPlugin can transmit account and transaction details. 

Common Solana Geyser Plugin Use Cases

Some of the most practical use cases for a Solana Geyser Plugin interface include receiving notifications of account updates, slot changes, and notifying transactions.

1. Account Updates

The following method is used for notifying on an account update:

 fn update_account(         &amp;mut self,         account: ReplicaAccountInfoVersions,         slot: u64,         is_startup: bool,     ) -> Result<()>

The ReplicaAccountInfoVersions structure contains the metadata and data of the account being streamed. 

When is_startup is true, it indicates the account is loaded from snapshots when the validator node starts up. When is_startup is false, the account is updated when processing a transaction.

Call this function after all accounts have been alerted as validator restores Account details from snapshots. 

fn notify_end_of_startup(&amp;mut self) -> Result<()>

External data persistence is maintained by ensuring that processes run asynchronously. This makes transaction processing work fast and in parallel when update_account is called. 

2. Slot Changes

The following method is used for notifying slot status changes:

fn update_slot_status(         &amp;mut self,         slot: u64,         parent: Option,         status: SlotStatus,     ) -> Result<()>

In case of an error while preserving data, the plugin can decide to abort the validator. Data remains consistent, and once the validator restarts, all account data is re-transmitted.

3. Notifying Transactions

The following method is used for notifying transactions:

  fn notify_transaction(         &amp;mut self,         transaction: ReplicaTransactionInfoVersions,         slot: u64,     ) -> Result<()>

How to Set up a PostgreSQL Database for Solana’s Geyser Plugin

The PostgreSQL plugin is used in storing account data in a PostgreSQL database. To properly configure your files, use the configuration guidelines on Solana’s official documentation page, and follow these steps to setup the database: installing a PostgreSQL server, create the database instance, and create the schema objects.

1. Install PostgreSQL Server

Follow the instructions to install a PostgreSQL server on your machine. For proper performance on your validator node, it is highly recommended that you run the database server on a node that is different from the validator. 

2. Create the Database Instance

Next, start the server, create the database, create a user, and verify that everything is working.

Start the server:

sudo systemctl start postgresql@14-main

In the official example, the following line creates a database named 'solana':

sudo -u postgres createdb solana -p 5433

Create the database user:

sudo -u postgres createuser -p 5433 solana

The previous line of code will create a user named 'solana”.

Verify that the database is working as intended:

psql -U solana -p 5433 -h -w -d solana

3. Create the Schema Objects

Use the create_schema.sql script from GitHub to create the objects for storing accounts and slots.

Run the script below:

psql -U solana -p 5433 -h -w -d solana -f create_schema.sql

Now, start the validator with this plugin that has been loaded into it. 

Start Using the Solana Geyser Plugin to Access Data Faster

Apart from immutability, data should be readily available and accessible on blockchains. Solana’s Geyser Plugin makes this accessibility possible and faster on Solana, while helping validator nodes manage their resources and uptime.

Overview cards background graphic
Section background image

Build blockchain magic

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.

Get your API key