Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ampd deployment k8s #16

Draft
wants to merge 10 commits into
base: solana
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ valuable = { version = "0.1.0", features = ["derive"] }
valuable-serde = { version = "0.1.0", features = ["std"] }
voting-verifier = { workspace = true }
gmp-gateway = { git = "https://github.com/eigerco/solana-axelar.git" }
axelar-message-primitives = { git = "https://github.com/eigerco/solana-axelar.git" }
lru = "0.12.3"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/solana_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ mod test {
let expiration = 100u64;
let (_, rx) = watch::channel(expiration - 1);
let source_chain = ChainName::from_str("solana").unwrap();
let poll_started_source_chain = ChainName::from_str("other_chain").unwrap(); // A different, unexpected source chain.
let poll_started_source_chain = ChainName::from_str("otherchain").unwrap(); // A different, unexpected source chain.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some validations are taking place now in the axelar codebase.


// Prepare the message verifier and the vote broadcaster
let mut broadcast_client = MockBroadcasterClient::new();
Expand Down
35 changes: 15 additions & 20 deletions ampd/src/handlers/solana_verify_worker_set.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::borrow::Cow;
use std::convert::TryInto;

use axelar_message_primitives::command::TransferOperatorshipCommand;
use cosmrs::cosmwasm::MsgExecuteContract;
use error_stack::ResultExt;
use serde::Deserialize;
Expand Down Expand Up @@ -194,10 +196,17 @@ where

let gw_event = parse_gateway_event(&sol_tx).map_err(|_| Error::DeserializeEvent)?;

let pub_key = match gw_event {
GatewayEvent::OperatorshipTransferred {
info_account_address,
} => info_account_address,
let operators = match gw_event {
GatewayEvent::OperatorshipTransferred(Cow::Owned(TransferOperatorshipCommand {
operators,
weights,
quorum,
..
})) => axelar_message_primitives::command::Operators::new(
operators,
weights.into_iter().map(axelar_message_primitives::command::U256::from).collect(),
axelar_message_primitives::command::U256::from(quorum),
Copy link
Member Author

@eloylp eloylp Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am mapping the threshold with the quorum, but unsure if we are talking about the same thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, they are the same thing 👍

),
_ => {
error!(
tx_signature = sol_tx_signature.to_string(),
Expand All @@ -208,21 +217,7 @@ where
}
};

let account_data = match self.rpc_client.get_account_data(&pub_key).await {
Copy link
Member Author

@eloylp eloylp Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems (if this is correct) we already have all needed information coming from the initial Solana tx for verifying the workerset. So we can remove the extra RPC call to fetch the account data.

Ok(data) => data,
Err(err) => {
error!(
tx_signature = sol_tx_signature.to_string(),
pub_key = pub_key.to_string(),
poll_id = poll_id.to_string(),
err = format!("Error fetching account data: {}", err),
);
return self.broadcast_vote(poll_id, Vote::FailedOnChain).await;
}
};

let vote =
verify_worker_set(&source_gateway_address, &sol_tx, &worker_set, &account_data).await;
let vote = verify_worker_set(&source_gateway_address, &sol_tx, &worker_set, &operators).await;
self.broadcast_vote(poll_id, vote).await
}
}
Expand Down Expand Up @@ -299,7 +294,7 @@ mod tests {
let handler = Handler::new(
worker.clone(),
voting_verifier.clone(),
ChainName::from_str("not_matching_chain").unwrap(),
ChainName::from_str("notmatchingchain").unwrap(),
rpc_client,
broadcast_client,
rx,
Expand Down
32 changes: 17 additions & 15 deletions ampd/src/solana/msg_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use axelar_wasm_std::voting::Vote;
use gmp_gateway::events::GatewayEvent;
use gmp_gateway::events::{CallContract, GatewayEvent};
use solana_transaction_status::{
option_serializer::OptionSerializer, EncodedConfirmedTransactionWithStatusMeta,
};
use std::sync::Arc;
use std::{borrow::Cow, sync::Arc};
use tracing::error;

use crate::handlers::solana_verify_msg::Message;

impl PartialEq<&Message> for GatewayEvent {
impl PartialEq<&Message> for GatewayEvent<'_> {
fn eq(&self, msg: &&Message) -> bool {
match self {
GatewayEvent::CallContract {
GatewayEvent::CallContract(Cow::Owned(CallContract {
sender,
destination_chain,
destination_address,
payload: _,
payload_hash,
} => {
})) => {
let event_dest_addr = String::from_utf8(destination_address.to_owned());
let event_dest_chain = String::from_utf8(destination_chain.to_owned());

Expand All @@ -31,6 +31,10 @@ impl PartialEq<&Message> for GatewayEvent {
_ => false,
}
}

fn ne(&self, other: &&Message) -> bool {
!self.eq(other)
}
}

pub fn verify_message(
Expand Down Expand Up @@ -137,7 +141,6 @@ fn find_first_log_message_match(
mod tests {
use base64::{engine::general_purpose, Engine};
use borsh::BorshSerialize;
use gmp_gateway::types::PubkeyWrapper;

use std::str::FromStr;

Expand Down Expand Up @@ -172,7 +175,6 @@ mod tests {
let payload_hash: [u8; 32] = [0; 32];
let source_gateway_address: String = "sol_gateway_addr".to_string();
let source_pubkey = Pubkey::from([0; 32]);
let source_address = PubkeyWrapper::from(source_pubkey);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more PubkeyWrapper anymore only Pubkey


// Code below helps on generating the program log line for adding in the
// tests/solana_tx.json file and use it as test fixture. See the "logMessages" field
Expand All @@ -199,27 +201,27 @@ mod tests {
event_index: 0,
destination_address: destination_address.clone(),
destination_chain: ChainName::from_str(&destination_chain).unwrap(),
source_address: source_address.to_string(),
source_address: source_pubkey.to_string(),
payload_hash,
};

(source_gateway_address, tx_id, tx, message)
}

fn get_tx_log_message(
sender: PubkeyWrapper,
sender: Pubkey,
destination_chain: Vec<u8>,
destination_address: Vec<u8>,
payload: Vec<u8>,
payload_hash: [u8; 32],
) -> String {
let event = gmp_gateway::events::GatewayEvent::CallContract {
let event = gmp_gateway::events::GatewayEvent::CallContract(Cow::Owned(CallContract {
sender,
destination_chain,
destination_address,
payload,
payload_hash,
};
}));

let mut event_data = Vec::new();
event.serialize(&mut event_data).unwrap();
Expand Down Expand Up @@ -253,7 +255,7 @@ mod tests {
#[test]
fn should_not_verify_msg_if_destination_chain_does_not_match() {
let (gateway_address, _, tx, mut msg) = get_matching_msg_and_tx_block();
msg.destination_chain = ChainName::from_str("bad_chain").unwrap();
msg.destination_chain = ChainName::from_str("badchain").unwrap();
assert_eq!(
Vote::FailedOnChain,
verify_message(&gateway_address, Arc::new(tx), &msg)
Expand All @@ -263,7 +265,7 @@ mod tests {
#[test]
fn should_not_verify_msg_if_source_address_does_not_match() {
let (source_gateway_address, _, tx, mut msg) = get_matching_msg_and_tx_block();
msg.source_address = PubkeyWrapper::from(Pubkey::from([13; 32])).to_string();
msg.source_address = Pubkey::from([13; 32]).to_string();
assert_eq!(
Vote::FailedOnChain,
verify_message(&source_gateway_address, Arc::new(tx), &msg)
Expand Down Expand Up @@ -318,7 +320,7 @@ mod tests {

fn not_matching_tx_log_message(msg: &Message) -> String {
get_tx_log_message(
PubkeyWrapper::from(Pubkey::from_str(&msg.source_address).unwrap()),
Pubkey::from_str(&msg.source_address).unwrap(),
"abr".as_bytes().to_vec(),
msg.destination_address.clone().into_bytes(),
Vec::new(),
Expand All @@ -328,7 +330,7 @@ mod tests {

fn matching_tx_log_message(msg: &Message) -> String {
get_tx_log_message(
PubkeyWrapper::from(Pubkey::from_str(&msg.source_address).unwrap()),
Pubkey::from_str(&msg.source_address).unwrap(),
msg.destination_chain.to_string().into_bytes(),
msg.destination_address.clone().into_bytes(),
Vec::new(),
Expand Down
Loading