Skip to content

Commit

Permalink
Merge branch 'main' into kunal/token-minor-audit
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Oct 23, 2024
2 parents 10ef624 + 7f3e066 commit e3ed366
Show file tree
Hide file tree
Showing 73 changed files with 1,118 additions and 390 deletions.
7 changes: 7 additions & 0 deletions .changeset/flat-swans-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/utils': minor
'@hyperlane-xyz/cli': minor
'@hyperlane-xyz/sdk': minor
---

Adds new `core check` command to compare local configuration and on chain deployments. Adds memoization to the EvmHookReader to avoid repeating configuration derivation
6 changes: 6 additions & 0 deletions .changeset/quiet-cooks-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/cli': minor
'@hyperlane-xyz/sdk': minor
---

Add `EthJsonRpcBlockParameterTag` enum for validating reorgPeriod
7 changes: 7 additions & 0 deletions .changeset/strange-beers-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/infra': minor
'@hyperlane-xyz/cli': minor
'@hyperlane-xyz/sdk': minor
---

Add support for an arbitrary string in `reorgPeriod`, which is used as a block tag to get the finalized block.
5 changes: 5 additions & 0 deletions .changeset/sweet-humans-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/core': minor
---

Added PRECISION and rateUpdateNonce to ensure compatibility of HypERC4626
5 changes: 5 additions & 0 deletions .changeset/tough-bats-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---

Fix filtering non-evm addresses in appFromAddressesMapHelper
16 changes: 15 additions & 1 deletion .github/actions/yarn-build-with-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@ runs:
steps:
- name: Cache
uses: buildjet/cache@v4
id: cache
with:
path: |
**/node_modules
.yarn
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
fail-on-cache-miss: true

# Typically, the cache will be hit, but if there's a network error when
# restoring the cache, let's run the install step ourselves.
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
yarn install
CHANGES=$(git status -s --ignore-submodules)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
- name: Build
shell: bash
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ jobs:
- name: Unit Tests
run: yarn test:ci

cli-e2e:
runs-on: ubuntu-latest
needs: [yarn-install]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive
fetch-depth: 0

- name: foundry-install
uses: foundry-rs/foundry-toolchain@v1

- name: yarn-build
uses: ./.github/actions/yarn-build-with-cache
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Checkout registry
uses: ./.github/actions/checkout-registry

- name: CLI e2e tests
run: yarn --cwd typescript/cli test:e2e

agent-configs:
runs-on: ubuntu-latest
needs: [yarn-install]
Expand Down Expand Up @@ -218,7 +242,7 @@ jobs:
run: |
if [[ -n "$(git diff ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event.pull_request.base.sha }} -- ./rust)" ]]; then
echo "rust_changes=true" >> $GITHUB_OUTPUT
echo "$(git diff ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event.pull_request.base.sha }} -- ./rust)"
echo "$(git diff ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event.pull_request.base.sha }} -- ./rust)"
else
echo "rust_changes=false" >> $GITHUB_OUTPUT
fi
Expand Down
2 changes: 1 addition & 1 deletion .registryrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8583d0841615313c8c880e765eba760378e061cd
dee58183e51f4eb43e84dbac0e595a4b389dbe80
10 changes: 5 additions & 5 deletions rust/main/agents/relayer/src/msg/gas_payment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl GasPaymentEnforcer {
for (policy, whitelist) in &self.policies {
if !whitelist.msg_matches(message, true) {
trace!(
msg=%message,
hyp_message=%message,
?policy,
?whitelist,
"Message did not match whitelist for policy"
Expand All @@ -114,13 +114,13 @@ impl GasPaymentEnforcer {
}

trace!(
msg=%message,
hyp_message=%message,
?policy,
?whitelist,
"Message matched whitelist for policy"
);
debug!(
msg=%message,
hyp_message=%message,
?policy,
?current_payment,
?current_expenditure,
Expand Down Expand Up @@ -149,7 +149,7 @@ impl GasPaymentEnforcer {
}

error!(
msg=%message,
hyp_message=%message,
policies=?self.policies,
"No gas payment policy matched for message; consider adding a default policy to the end of the policies array which uses a wildcard whitelist."
);
Expand All @@ -159,7 +159,7 @@ impl GasPaymentEnforcer {
pub fn record_tx_outcome(&self, message: &HyperlaneMessage, outcome: TxOutcome) -> Result<()> {
// This log is required in E2E, hence the use of a `const`
debug!(
msg=%message,
hyp_message=%message,
?outcome,
"{}",
GAS_EXPENDITURE_LOG_MESSAGE,
Expand Down
4 changes: 2 additions & 2 deletions rust/main/agents/relayer/src/msg/metadata/multisig/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ impl<T: MultisigIsmMetadataBuilder> MetadataBuilder for T {
.await
.context(CTX)?
{
debug!(?message, ?metadata.checkpoint, "Found checkpoint with quorum");
debug!(hyp_message=?message, ?metadata.checkpoint, "Found checkpoint with quorum");
Ok(Some(self.format_metadata(metadata)?))
} else {
info!(
?message, ?validators, threshold, ism=%multisig_ism.address(),
hyp_message=?message, ?validators, threshold, ism=%multisig_ism.address(),
"Could not fetch metadata: Unable to reach quorum"
);
Ok(None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl MultisigIsmMetadataBuilder for MerkleRootMultisigMetadataBuilder {
.await
.context(CTX)?,
debug!(
?message,
hyp_message=?message,
"No merkle leaf found for message id, must have not been enqueued in the tree"
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl MultisigIsmMetadataBuilder for MessageIdMultisigMetadataBuilder {
.await
.context(CTX)?,
debug!(
?message,
hyp_message=?message,
"No merkle leaf found for message id, must have not been enqueued in the tree"
)
);
Expand Down
2 changes: 1 addition & 1 deletion rust/main/agents/relayer/src/msg/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl DirectionalNonceIterator {
if let Some(message) = self.indexed_message_with_nonce()? {
Self::update_max_nonce_gauge(&message, metrics);
if !self.is_message_processed()? {
debug!(?message, iterator=?self, "Found processable message");
debug!(hyp_message=?message, iterator=?self, "Found processable message");
return Ok(MessageStatus::Processable(message));
} else {
return Ok(MessageStatus::Processed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ const DOMAINS: &[RawDomain] = &[
is_test_net: false,
is_deprecated: false,
},
RawDomain {
name: "stride",
token: "STRD",
domain: 745,
chain_id: 745,
is_test_net: false,
is_deprecated: false,
},
RawDomain {
name: "cosmostest99990",
token: "OSMO",
Expand Down
12 changes: 7 additions & 5 deletions rust/main/agents/validator/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use hyperlane_base::{
CheckpointSyncerConf, Settings, SignerConf,
},
};
use hyperlane_core::{cfg_unwrap_all, config::*, HyperlaneDomain, HyperlaneDomainProtocol};
use hyperlane_core::{
cfg_unwrap_all, config::*, HyperlaneDomain, HyperlaneDomainProtocol, ReorgPeriod,
};
use serde::Deserialize;
use serde_json::Value;

Expand All @@ -36,8 +38,8 @@ pub struct ValidatorSettings {
pub validator: SignerConf,
/// The checkpoint syncer configuration
pub checkpoint_syncer: CheckpointSyncerConf,
/// The reorg_period in blocks
pub reorg_period: u64,
/// The reorg configuration
pub reorg_period: ReorgPeriod,
/// How frequently to check for new checkpoints
pub interval: Duration,
}
Expand Down Expand Up @@ -122,8 +124,8 @@ impl FromRawConf<RawValidatorSettings> for ValidatorSettings {
.get_key(origin_chain_name)
.get_opt_key("blocks")
.get_opt_key("reorgPeriod")
.parse_u64()
.unwrap_or(1);
.parse_value("Invalid reorgPeriod")
.unwrap_or(ReorgPeriod::from_blocks(1));

cfg_unwrap_all!(cwp, err: [base, origin_chain, validator, checkpoint_syncer]);

Expand Down
26 changes: 13 additions & 13 deletions rust/main/agents/validator/src/submit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::num::NonZeroU64;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::vec;
Expand All @@ -14,13 +13,13 @@ use hyperlane_core::{
accumulator::incremental::IncrementalMerkle, Checkpoint, CheckpointWithMessageId,
HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneSignerExt,
};
use hyperlane_core::{ChainResult, MerkleTreeHook, ReorgEvent};
use hyperlane_core::{ChainResult, MerkleTreeHook, ReorgEvent, ReorgPeriod};
use hyperlane_ethereum::SingletonSignerHandle;

#[derive(Clone)]
pub(crate) struct ValidatorSubmitter {
interval: Duration,
reorg_period: Option<NonZeroU64>,
reorg_period: ReorgPeriod,
signer: SingletonSignerHandle,
merkle_tree_hook: Arc<dyn MerkleTreeHook>,
checkpoint_syncer: Arc<dyn CheckpointSyncer>,
Expand All @@ -31,15 +30,15 @@ pub(crate) struct ValidatorSubmitter {
impl ValidatorSubmitter {
pub(crate) fn new(
interval: Duration,
reorg_period: u64,
reorg_period: ReorgPeriod,
merkle_tree_hook: Arc<dyn MerkleTreeHook>,
signer: SingletonSignerHandle,
checkpoint_syncer: Arc<dyn CheckpointSyncer>,
db: Arc<dyn HyperlaneDb>,
metrics: ValidatorSubmitterMetrics,
) -> Self {
Self {
reorg_period: NonZeroU64::new(reorg_period),
reorg_period,
interval,
merkle_tree_hook,
signer,
Expand Down Expand Up @@ -94,7 +93,8 @@ impl ValidatorSubmitter {
// Lag by reorg period because this is our correctness checkpoint.
let latest_checkpoint = call_and_retry_indefinitely(|| {
let merkle_tree_hook = self.merkle_tree_hook.clone();
Box::pin(async move { merkle_tree_hook.latest_checkpoint(self.reorg_period).await })
let reorg_period = self.reorg_period.clone();
Box::pin(async move { merkle_tree_hook.latest_checkpoint(&reorg_period).await })
})
.await;

Expand Down Expand Up @@ -211,7 +211,7 @@ impl ValidatorSubmitter {
correctness_checkpoint.root,
checkpoint.index,
chrono::Utc::now().timestamp() as u64,
self.reorg_period.map(|x| x.get()).unwrap_or(0),
self.reorg_period.clone(),
);
error!(
?checkpoint,
Expand Down Expand Up @@ -486,9 +486,9 @@ mod test {

#[async_trait]
impl MerkleTreeHook for MerkleTreeHook {
async fn tree(&self, lag: Option<NonZeroU64>) -> ChainResult<IncrementalMerkle>;
async fn count(&self, lag: Option<NonZeroU64>) -> ChainResult<u32>;
async fn latest_checkpoint(&self, lag: Option<NonZeroU64>) -> ChainResult<Checkpoint>;
async fn tree(&self, reorg_period: &ReorgPeriod) -> ChainResult<IncrementalMerkle>;
async fn count(&self, reorg_period: &ReorgPeriod) -> ChainResult<u32>;
async fn latest_checkpoint(&self, reorg_period: &ReorgPeriod) -> ChainResult<Checkpoint>;
}
}

Expand Down Expand Up @@ -532,7 +532,7 @@ mod test {
expected_local_merkle_tree: &IncrementalMerkle,
mock_onchain_merkle_tree: &IncrementalMerkle,
unix_timestamp: u64,
expected_reorg_period: u64,
expected_reorg_period: ReorgPeriod,
) {
assert_eq!(
reorg_event.canonical_merkle_root,
Expand Down Expand Up @@ -617,15 +617,15 @@ mod test {
&expected_local_merkle_tree,
&mock_onchain_merkle_tree_clone,
unix_timestamp,
expected_reorg_period,
ReorgPeriod::from_blocks(expected_reorg_period),
);
Ok(())
});

// instantiate the validator submitter
let validator_submitter = ValidatorSubmitter::new(
Duration::from_secs(1),
expected_reorg_period,
ReorgPeriod::from_blocks(expected_reorg_period),
Arc::new(mock_merkle_tree_hook),
dummy_singleton_handle(),
Arc::new(mock_checkpoint_syncer),
Expand Down
17 changes: 7 additions & 10 deletions rust/main/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{num::NonZeroU64, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};

use crate::server as validator_server;
use async_trait::async_trait;
Expand All @@ -19,8 +19,8 @@ use hyperlane_base::{

use hyperlane_core::{
Announcement, ChainResult, HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneSigner,
HyperlaneSignerExt, Mailbox, MerkleTreeHook, MerkleTreeInsertion, TxOutcome, ValidatorAnnounce,
H256, U256,
HyperlaneSignerExt, Mailbox, MerkleTreeHook, MerkleTreeInsertion, ReorgPeriod, TxOutcome,
ValidatorAnnounce, H256, U256,
};
use hyperlane_ethereum::{SingletonSigner, SingletonSignerHandle};

Expand All @@ -44,7 +44,7 @@ pub struct Validator {
signer: SingletonSignerHandle,
// temporary holder until `run` is called
signer_instance: Option<Box<SingletonSigner>>,
reorg_period: u64,
reorg_period: ReorgPeriod,
interval: Duration,
checkpoint_syncer: Arc<dyn CheckpointSyncer>,
core_metrics: Arc<CoreMetrics>,
Expand Down Expand Up @@ -184,12 +184,10 @@ impl BaseAgent for Validator {
// announce the validator after spawning the signer task
self.announce().await.expect("Failed to announce validator");

let reorg_period = NonZeroU64::new(self.reorg_period);

// Ensure that the merkle tree hook has count > 0 before we begin indexing
// messages or submitting checkpoints.
loop {
match self.merkle_tree_hook.count(reorg_period).await {
match self.merkle_tree_hook.count(&self.reorg_period).await {
Ok(0) => {
info!("Waiting for first message in merkle tree hook");
sleep(self.interval).await;
Expand Down Expand Up @@ -241,18 +239,17 @@ impl Validator {
async fn run_checkpoint_submitters(&self) -> Vec<Instrumented<JoinHandle<()>>> {
let submitter = ValidatorSubmitter::new(
self.interval,
self.reorg_period,
self.reorg_period.clone(),
self.merkle_tree_hook.clone(),
self.signer.clone(),
self.checkpoint_syncer.clone(),
Arc::new(self.db.clone()) as Arc<dyn HyperlaneDb>,
ValidatorSubmitterMetrics::new(&self.core.metrics, &self.origin_chain),
);

let reorg_period = NonZeroU64::new(self.reorg_period);
let tip_tree = self
.merkle_tree_hook
.tree(reorg_period)
.tree(&self.reorg_period)
.await
.expect("failed to get merkle tree");
// This function is only called after we have already checked that the
Expand Down
Loading

0 comments on commit e3ed366

Please sign in to comment.