-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Scrape Sealevel dispatched messages (#4776)
### Description Scraper is able to index dispatch messages: 1. Blocks are stored into database 2. Transactions are stored into database (need population of all fields) 3. Dispatched messages are stored into database ### Drive-by changes Initial indexing of delivered messages (so that Scraper does not crush) ### Related issues - Contributes into #4272 ### Backward compatibility Yes (Solana-like chains should not be enabled for Scraper) ### Testing Manual run of Scraper E2E Tests --------- Co-authored-by: Danil Nemirovsky <4614623+ameten@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
916 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use base64::{engine::general_purpose::STANDARD as Base64, Engine}; | ||
use solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig}; | ||
use solana_client::{ | ||
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig}, | ||
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType}, | ||
}; | ||
use solana_sdk::{account::Account, commitment_config::CommitmentConfig, pubkey::Pubkey}; | ||
|
||
use hyperlane_core::{ChainCommunicationError, ChainResult}; | ||
|
||
use crate::rpc::SealevelRpcClient; | ||
|
||
pub async fn search_accounts_by_discriminator( | ||
client: &SealevelRpcClient, | ||
program_id: &Pubkey, | ||
discriminator: &[u8; 8], | ||
nonce_bytes: &[u8], | ||
offset: usize, | ||
length: usize, | ||
) -> ChainResult<Vec<(Pubkey, Account)>> { | ||
let target_message_account_bytes = &[discriminator, nonce_bytes].concat(); | ||
let target_message_account_bytes = Base64.encode(target_message_account_bytes); | ||
|
||
// First, find all accounts with the matching account data. | ||
// To keep responses small in case there is ever more than 1 | ||
// match, we don't request the full account data, and just request | ||
// the field which was used to generate account id | ||
#[allow(deprecated)] | ||
let memcmp = RpcFilterType::Memcmp(Memcmp { | ||
// Ignore the first byte, which is the `initialized` bool flag. | ||
offset: 1, | ||
bytes: MemcmpEncodedBytes::Base64(target_message_account_bytes), | ||
encoding: None, | ||
}); | ||
let config = RpcProgramAccountsConfig { | ||
filters: Some(vec![memcmp]), | ||
account_config: RpcAccountInfoConfig { | ||
encoding: Some(UiAccountEncoding::Base64), | ||
data_slice: Some(UiDataSliceConfig { offset, length }), | ||
commitment: Some(CommitmentConfig::finalized()), | ||
min_context_slot: None, | ||
}, | ||
with_context: Some(false), | ||
}; | ||
let accounts = client | ||
.get_program_accounts_with_config(program_id, config) | ||
.await?; | ||
Ok(accounts) | ||
} | ||
|
||
pub fn search_and_validate_account<F>( | ||
accounts: Vec<(Pubkey, Account)>, | ||
message_account: F, | ||
) -> ChainResult<Pubkey> | ||
where | ||
F: Fn(&Account) -> ChainResult<Pubkey>, | ||
{ | ||
for (pubkey, account) in accounts { | ||
let expected_pubkey = message_account(&account)?; | ||
if expected_pubkey == pubkey { | ||
return Ok(pubkey); | ||
} | ||
} | ||
|
||
Err(ChainCommunicationError::from_other_str( | ||
"Could not find valid storage PDA pubkey", | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.