Skip to content

Commit

Permalink
fix: Avoid Relayer to use GetBlock for Sealevel (#4883)
Browse files Browse the repository at this point in the history
### Description

Avoid Relayer to use GetBlock for Sealevel.

It is a temporary solution until we migrate Sealevel integration to the
latest Solana libraries

### Related issues

- Contributes into
#4271

### Backward compatibility

Yes

### Testing

E2E Ethereum and Sealevel test

---------

Co-authored-by: Danil Nemirovsky <[email protected]>
  • Loading branch information
ameten and ameten authored Nov 21, 2024
1 parent 58425a2 commit 79e9d02
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 76 deletions.
3 changes: 3 additions & 0 deletions rust/main/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl BaseAgent for Relayer {
dbs.iter()
.map(|(d, db)| (d.clone(), Arc::new(db.clone())))
.collect(),
false,
)
.await?
.into_iter()
Expand All @@ -166,6 +167,7 @@ impl BaseAgent for Relayer {
dbs.iter()
.map(|(d, db)| (d.clone(), Arc::new(db.clone())))
.collect(),
false,
)
.await?
.into_iter()
Expand All @@ -180,6 +182,7 @@ impl BaseAgent for Relayer {
dbs.iter()
.map(|(d, db)| (d.clone(), Arc::new(db.clone())))
.collect(),
false,
)
.await?
.into_iter()
Expand Down
3 changes: 3 additions & 0 deletions rust/main/agents/scraper/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl Scraper {
&metrics.clone(),
&contract_sync_metrics.clone(),
store.into(),
true,
)
.await
.unwrap();
Expand Down Expand Up @@ -229,6 +230,7 @@ impl Scraper {
&metrics.clone(),
&contract_sync_metrics.clone(),
Arc::new(store.clone()) as _,
true,
)
.await
.unwrap();
Expand Down Expand Up @@ -261,6 +263,7 @@ impl Scraper {
&metrics.clone(),
&contract_sync_metrics.clone(),
Arc::new(store.clone()),
true,
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions rust/main/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl BaseAgent for Validator {
&metrics,
&contract_sync_metrics,
msg_db.clone().into(),
false,
)
.await?;

Expand Down
46 changes: 25 additions & 21 deletions rust/main/chains/hyperlane-sealevel/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl InterchainGasPaymaster for SealevelInterchainGasPaymaster {}
pub struct SealevelInterchainGasPaymasterIndexer {
rpc_client: SealevelRpcClient,
igp: SealevelInterchainGasPaymaster,
_log_meta_composer: LogMetaComposer,
log_meta_composer: LogMetaComposer,
advanced_log_meta: bool,
}

/// IGP payment data on Sealevel
Expand All @@ -107,6 +108,7 @@ impl SealevelInterchainGasPaymasterIndexer {
pub async fn new(
conf: &ConnectionConf,
igp_account_locator: ContractLocator<'_>,
advanced_log_meta: bool,
) -> ChainResult<Self> {
// Set the `processed` commitment at rpc level
let rpc_client = SealevelRpcClient::new(conf.url.to_string());
Expand All @@ -122,7 +124,8 @@ impl SealevelInterchainGasPaymasterIndexer {
Ok(Self {
rpc_client,
igp,
_log_meta_composer: log_meta_composer,
log_meta_composer,
advanced_log_meta,
})
}

Expand Down Expand Up @@ -168,23 +171,24 @@ impl SealevelInterchainGasPaymasterIndexer {
gas_amount: gas_payment_account.gas_amount.into(),
};

// let log_meta = self
// .interchain_payment_log_meta(
// U256::from(sequence_number),
// &valid_payment_pda_pubkey,
// &gas_payment_account.slot,
// )
// .await?;

let log_meta = LogMeta {
address: self.igp.program_id.to_bytes().into(),
block_number: gas_payment_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: sequence_number.into(),
let log_meta = if self.advanced_log_meta {
self.interchain_payment_log_meta(
U256::from(sequence_number),
&valid_payment_pda_pubkey,
&gas_payment_account.slot,
)
.await?
} else {
LogMeta {
address: self.igp.program_id.to_bytes().into(),
block_number: gas_payment_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: sequence_number.into(),
}
};

Ok(SealevelGasPayment::new(
Expand Down Expand Up @@ -212,15 +216,15 @@ impl SealevelInterchainGasPaymasterIndexer {
Ok(expected_pubkey)
}

async fn _interchain_payment_log_meta(
async fn interchain_payment_log_meta(
&self,
log_index: U256,
payment_pda_pubkey: &Pubkey,
payment_pda_slot: &Slot,
) -> ChainResult<LogMeta> {
let block = self.rpc_client.get_block(*payment_pda_slot).await?;

self._log_meta_composer
self.log_meta_composer
.log_meta(block, log_index, payment_pda_pubkey, payment_pda_slot)
.map_err(Into::<ChainCommunicationError>::into)
}
Expand Down
82 changes: 45 additions & 37 deletions rust/main/chains/hyperlane-sealevel/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,15 @@ pub struct SealevelMailboxIndexer {
program_id: Pubkey,
dispatch_message_log_meta_composer: LogMetaComposer,
delivery_message_log_meta_composer: LogMetaComposer,
advanced_log_meta: bool,
}

impl SealevelMailboxIndexer {
pub fn new(conf: &ConnectionConf, locator: ContractLocator) -> ChainResult<Self> {
pub fn new(
conf: &ConnectionConf,
locator: ContractLocator,
advanced_log_meta: bool,
) -> ChainResult<Self> {
let program_id = Pubkey::from(<[u8; 32]>::from(locator.address));
let mailbox = SealevelMailbox::new(conf, locator, None)?;

Expand All @@ -672,6 +677,7 @@ impl SealevelMailboxIndexer {
mailbox,
dispatch_message_log_meta_composer,
delivery_message_log_meta_composer,
advanced_log_meta,
})
}

Expand Down Expand Up @@ -712,23 +718,24 @@ impl SealevelMailboxIndexer {
let hyperlane_message =
HyperlaneMessage::read_from(&mut &dispatched_message_account.encoded_message[..])?;

// let log_meta = self
// .dispatch_message_log_meta(
// U256::from(nonce),
// &valid_message_storage_pda_pubkey,
// &dispatched_message_account.slot,
// )
// .await?;

let log_meta = LogMeta {
address: self.program_id.to_bytes().into(),
block_number: dispatched_message_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: U256::zero(),
let log_meta = if self.advanced_log_meta {
self.dispatch_message_log_meta(
U256::from(nonce),
&valid_message_storage_pda_pubkey,
&dispatched_message_account.slot,
)
.await?
} else {
LogMeta {
address: self.program_id.to_bytes().into(),
block_number: dispatched_message_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: U256::zero(),
}
};

Ok((hyperlane_message.into(), log_meta))
Expand All @@ -748,7 +755,7 @@ impl SealevelMailboxIndexer {
Ok(expected_pubkey)
}

async fn _dispatch_message_log_meta(
async fn dispatch_message_log_meta(
&self,
log_index: U256,
message_storage_pda_pubkey: &Pubkey,
Expand Down Expand Up @@ -805,23 +812,24 @@ impl SealevelMailboxIndexer {
.into_inner();
let message_id = delivered_message_account.message_id;

// let log_meta = self
// .delivered_message_log_meta(
// U256::from(nonce),
// &valid_message_storage_pda_pubkey,
// &delivered_message_account.slot,
// )
// .await?;

let log_meta = LogMeta {
address: self.program_id.to_bytes().into(),
block_number: delivered_message_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: U256::zero(),
let log_meta = if self.advanced_log_meta {
self.delivered_message_log_meta(
U256::from(nonce),
&valid_message_storage_pda_pubkey,
&delivered_message_account.slot,
)
.await?
} else {
LogMeta {
address: self.program_id.to_bytes().into(),
block_number: delivered_message_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: U256::zero(),
}
};

Ok((message_id.into(), log_meta))
Expand All @@ -839,7 +847,7 @@ impl SealevelMailboxIndexer {
Ok(expected_pubkey)
}

async fn _delivered_message_log_meta(
async fn delivered_message_log_meta(
&self,
log_index: U256,
message_storage_pda_pubkey: &Pubkey,
Expand Down
15 changes: 11 additions & 4 deletions rust/main/hyperlane-base/src/settings/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ impl Settings {
build_contract_fns!(build_validator_announce, build_validator_announces -> dyn ValidatorAnnounce);
build_contract_fns!(build_provider, build_providers -> dyn HyperlaneProvider);

/// Build a contract sync for type `T` using log store `D`
/// Build a contract sync for type `T` using log store `S`
pub async fn sequenced_contract_sync<T, S>(
&self,
domain: &HyperlaneDomain,
metrics: &CoreMetrics,
sync_metrics: &ContractSyncMetrics,
store: Arc<S>,
advanced_log_meta: bool,
) -> eyre::Result<Arc<SequencedDataContractSync<T>>>
where
T: Indexable + Debug,
Expand All @@ -166,7 +167,8 @@ impl Settings {
{
let setup = self.chain_setup(domain)?;
// Currently, all indexers are of the `SequenceIndexer` type
let indexer = SequenceIndexer::<T>::try_from_with_metrics(setup, metrics).await?;
let indexer =
SequenceIndexer::<T>::try_from_with_metrics(setup, metrics, advanced_log_meta).await?;
Ok(Arc::new(ContractSync::new(
domain.clone(),
store.clone() as SequenceAwareLogStore<_>,
Expand All @@ -175,13 +177,14 @@ impl Settings {
)))
}

/// Build a contract sync for type `T` using log store `D`
/// Build a contract sync for type `T` using log store `S`
pub async fn watermark_contract_sync<T, S>(
&self,
domain: &HyperlaneDomain,
metrics: &CoreMetrics,
sync_metrics: &ContractSyncMetrics,
store: Arc<S>,
advanced_log_meta: bool,
) -> eyre::Result<Arc<WatermarkContractSync<T>>>
where
T: Indexable + Debug,
Expand All @@ -190,7 +193,8 @@ impl Settings {
{
let setup = self.chain_setup(domain)?;
// Currently, all indexers are of the `SequenceIndexer` type
let indexer = SequenceIndexer::<T>::try_from_with_metrics(setup, metrics).await?;
let indexer =
SequenceIndexer::<T>::try_from_with_metrics(setup, metrics, advanced_log_meta).await?;
Ok(Arc::new(ContractSync::new(
domain.clone(),
store.clone() as WatermarkLogStore<_>,
Expand All @@ -208,6 +212,7 @@ impl Settings {
metrics: &CoreMetrics,
sync_metrics: &ContractSyncMetrics,
stores: HashMap<HyperlaneDomain, Arc<S>>,
advanced_log_meta: bool,
) -> Result<HashMap<HyperlaneDomain, Arc<dyn ContractSyncer<T>>>>
where
T: Indexable + Debug + Send + Sync + Clone + Eq + Hash + 'static,
Expand All @@ -227,6 +232,7 @@ impl Settings {
metrics,
sync_metrics,
stores.get(domain).unwrap().clone(),
advanced_log_meta,
)
.await
.map(|r| r as Arc<dyn ContractSyncer<T>>)?,
Expand All @@ -236,6 +242,7 @@ impl Settings {
metrics,
sync_metrics,
stores.get(domain).unwrap().clone(),
advanced_log_meta,
)
.await
.map(|r| r as Arc<dyn ContractSyncer<T>>)?,
Expand Down
Loading

0 comments on commit 79e9d02

Please sign in to comment.