Skip to content

Commit

Permalink
Merge branch 'main' into noah/merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli committed Jun 26, 2024
2 parents 2de63aa + 44cc9bf commit a2a633b
Show file tree
Hide file tree
Showing 126 changed files with 6,475 additions and 1,624 deletions.
6 changes: 6 additions & 0 deletions .changeset/brave-penguins-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/cli': minor
'@hyperlane-xyz/core': minor
---

Add CLI command to support AVS validator status check
7 changes: 7 additions & 0 deletions .changeset/clean-numbers-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/helloworld': minor
'@hyperlane-xyz/infra': minor
'@hyperlane-xyz/cli': minor
---

Upgrade registry to 2.1.1
6 changes: 0 additions & 6 deletions .changeset/mean-impalas-leave.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/olive-geckos-behave.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/sixty-ducks-brush.md

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/monorepo-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'typescript/infra/**'
- 'Dockerfile'
- '.dockerignore'
- '.github/workflows/monorepo-docker.yml'

concurrency:
group: build-push-monorepo-${{ github.ref }}
Expand Down Expand Up @@ -47,7 +48,7 @@ jobs:
id: taggen
run: |
echo "TAG_DATE=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
echo "TAG_SHA=$(echo '${{ github.sha }}' | cut -b 1-7)" >> $GITHUB_OUTPUT
echo "TAG_SHA=$(echo '${{ github.event.pull_request.head.sha || github.sha }}' | cut -b 1-7)" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/rust-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
paths:
- 'rust/**'
- '.github/workflows/rust-docker.yml'
concurrency:
group: build-push-agents-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -40,7 +41,7 @@ jobs:
id: taggen
run: |
echo "TAG_DATE=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
echo "TAG_SHA=$(echo '${{ github.sha }}' | cut -b 1-7)" >> $GITHUB_OUTPUT
echo "TAG_SHA=$(echo '${{ github.event.pull_request.head.sha || github.sha }}' | cut -b 1-7)" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rust-skipped.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ name: rust
on:
push:
branches: [main]
paths-ignore:
- 'rust/**'
- .github/workflows/rust.yml
pull_request:
branches: [main]
paths-ignore:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: rust

on:
push:
branches: [main]
paths:
- 'rust/**'
- .github/workflows/rust.yml
- '!*.md'
pull_request:
branches: [main]
paths:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-skipped.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: test
on:
push:
branches: [main]
paths:
- '*.md'
- '!**/*'
pull_request:
branches:
- '*'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
# Triggers the workflow on pushes to main & cli-2.0 branches
push:
branches: [main, cli-2.0]
paths-ignore:
- '*.md'
# Triggers on pull requests ignoring md files
pull_request:
branches:
Expand Down
44 changes: 26 additions & 18 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pretty_env_logger = "0.5.0"
primitive-types = "=0.12.1"
prometheus = "0.13"
protobuf = "*"
rand = "0.8.5"
regex = "1.5"
reqwest = "0.11"
ripemd = "0.1.3"
Expand Down Expand Up @@ -163,8 +164,8 @@ spl-token = { version = "=3.5.0", features = ["no-entrypoint"] }
spl-token-2022 = { version = "=0.5.0", features = ["no-entrypoint"] }
spl-type-length-value = "=0.1.0"
static_assertions = "1.1"
strum = "0.25.0"
strum_macros = "0.25.2"
strum = "0.26.2"
strum_macros = "0.26.2"
tempfile = "3.3"
tendermint = "0.32.2"
tendermint-rpc = { version = "0.32.0", features = ["http-client", "tokio"] }
Expand Down
3 changes: 2 additions & 1 deletion rust/agents/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ itertools.workspace = true
num-derive.workspace = true
num-traits.workspace = true
prometheus.workspace = true
rand.workspace = true
regex.workspace = true
reqwest = { workspace = true, features = ["json"] }
serde.workspace = true
Expand All @@ -43,7 +44,7 @@ hyperlane-ethereum = { path = "../../chains/hyperlane-ethereum" }

[dev-dependencies]
once_cell.workspace = true
mockall.worksapce = true
mockall.workspace = true
tokio-test.workspace = true
hyperlane-test = { path = "../../hyperlane-test" }
hyperlane-base = { path = "../../hyperlane-base", features = ["test-utils"] }
Expand Down
123 changes: 123 additions & 0 deletions rust/agents/relayer/src/msg/blacklist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use hyperlane_core::HyperlaneMessage;

#[derive(Debug, Clone, Default)]
pub struct AddressBlacklist {
// A list of addresses that are blocked from being relayed.
// Addresses are any length to support different address types.
pub blacklist: Vec<Vec<u8>>,
}

impl AddressBlacklist {
pub fn new(blacklist: Vec<Vec<u8>>) -> Self {
Self { blacklist }
}

/// Returns true if the message is blocked by the blacklist.
/// At the moment, this only checks if the sender, recipient, or body of the
/// message contains any of the blocked addresses.
pub fn find_blacklisted_address(&self, message: &HyperlaneMessage) -> Option<Vec<u8>> {
self.blacklist.iter().find_map(|address| {
if is_subsequence(message.sender.as_bytes(), address)
|| is_subsequence(message.recipient.as_bytes(), address)
|| is_subsequence(&message.body, address)
{
// Return the blocked address that was found.
Some(address.clone())
} else {
None
}
})
}
}

/// Returns true if `needle` is a subsequence of `haystack`.
fn is_subsequence<T: PartialEq>(mut haystack: &[T], needle: &[T]) -> bool {
if needle.is_empty() {
return true;
}

while !haystack.is_empty() {
if needle.len() > haystack.len() {
return false;
}
if haystack.starts_with(needle) {
return true;
}
haystack = &haystack[1..];
}
false
}

#[cfg(test)]
mod test {
use hyperlane_core::H256;

use super::*;

#[test]
fn test_is_subsequence() {
assert!(is_subsequence(b"hello", b"hello"));
assert!(is_subsequence(b"hello", b"he"));
assert!(is_subsequence(b"hello", b"lo"));
assert!(is_subsequence(b"hello", b""));
assert!(is_subsequence(b"hello", b"o"));

assert!(!is_subsequence(b"hello", b"hello world"));
assert!(!is_subsequence(b"hello", b"world"));
assert!(!is_subsequence(b"hello", b"world hello"));
}

#[test]
fn test_is_blocked() {
let blocked = b"blocked";
let blocklist = AddressBlacklist::new(vec![blocked.to_vec()]);

let bytes_with_subsequence = |subsequence: &[u8], index: usize, len: usize| {
let mut bytes = vec![0; len];
bytes[index..index + subsequence.len()].copy_from_slice(subsequence);
bytes
};

let h256_with_subsequence = |subsequence: &[u8], index: usize| {
let bytes = bytes_with_subsequence(subsequence, index, H256::len_bytes());
H256::from_slice(&bytes)
};

// Blocked - sender includes the blocked address
let message = HyperlaneMessage {
sender: h256_with_subsequence(blocked, 0),
..Default::default()
};
assert_eq!(
blocklist.find_blacklisted_address(&message),
Some(blocked.to_vec())
);

// Blocked - recipient includes the blocked address
let message = HyperlaneMessage {
recipient: h256_with_subsequence(blocked, 20),
..Default::default()
};
assert_eq!(
blocklist.find_blacklisted_address(&message),
Some(blocked.to_vec())
);

// Blocked - body includes the blocked address
let message = HyperlaneMessage {
body: bytes_with_subsequence(blocked, 100 - blocked.len(), 100),
..Default::default()
};
assert_eq!(
blocklist.find_blacklisted_address(&message),
Some(blocked.to_vec())
);

// Not blocked - sender, recipient, and body do not include the blocked address
let message = HyperlaneMessage {
body: vec![1; 100],
..Default::default()
};
assert!(blocklist.find_blacklisted_address(&message).is_none());
}
}
Loading

0 comments on commit a2a633b

Please sign in to comment.