Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tx-tomcat committed May 30, 2024
2 parents 6dfcfd3 + d44f1c0 commit 67d6d0d
Show file tree
Hide file tree
Showing 97 changed files with 3,623 additions and 1,595 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/narwhal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ env:
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
# Some integration tests can produce too much INFO logs that are infeasible to be printed on failure.
RUST_LOG: error
# RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ env:
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
# Some integration tests can produce too much INFO logs that are infeasible to be printed on failure.
RUST_LOG: error
# RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Sui is written in [Rust](https://www.rust-lang.org) and supports smart contracts

Sui has a native token called SUI, with a fixed supply. The SUI token is used to pay for gas, and is also used as [delegated stake on authorities](https://learn.bybit.com/blockchain/delegated-proof-of-stake-dpos/) within an epoch. The voting power of authorities within this epoch is a function of this delegated stake. Authorities are periodically reconfigured according to the stake delegated to them. In any epoch, the set of authorities is [Byzantine fault tolerant](https://pmg.csail.mit.edu/papers/osdi99.pdf). At the end of the epoch, fees collected through all transactions processed are distributed to authorities according to their contribution to the operation of the system. Authorities can in turn share some of the fees as rewards to users that delegated stakes to them.

Sui is backed by a number of state-of-the-art [peer-reviewed works](https://github.com/MystenLabs/sui/blob/main/docs/content/concepts/research-papers.mdx) and years of open source development.
Sui is supported by several cutting-edge [peer-reviewed studies](https://github.com/MystenLabs/sui/blob/main/docs/content/concepts/research-papers.mdx) and extensive years of open-source development.

## More About Sui

Expand Down
16 changes: 12 additions & 4 deletions consensus/core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
block::BlockAPI as _,
context::Context,
dag_state::DagState,
error::ConsensusError,
network::{NetworkClient, NetworkService},
Round,
};
Expand Down Expand Up @@ -170,10 +171,17 @@ impl<C: NetworkClient, S: NetworkService> Subscriber<C, S> {
.handle_send_block(peer, block.clone())
.await;
if let Err(e) = result {
info!(
"Failed to process block from peer {}: {}. Block: {:?}",
peer, e, block,
);
match e {
ConsensusError::BlockRejected { block_ref, reason } => {
debug!(
"Failed to process block from peer {} for block {:?}: {}",
peer, block_ref, reason
);
}
_ => {
info!("Invalid block received from peer {}: {}", peer, e,);
}
}
}
// Reset retries when a block is received.
retries = 0;
Expand Down
101 changes: 93 additions & 8 deletions crates/sui-bridge-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ use shared_crypto::intent::IntentMessage;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use sui_bridge::abi::EthBridgeCommittee;
use sui_bridge::abi::{eth_sui_bridge, EthSuiBridge};
use sui_bridge::crypto::BridgeAuthorityPublicKeyBytes;
use sui_bridge::error::BridgeResult;
use sui_bridge::sui_client::SuiBridgeClient;
use sui_bridge::types::BridgeAction;
use sui_bridge::types::{
AssetPriceUpdateAction, BlocklistCommitteeAction, BlocklistType, EmergencyAction,
EmergencyActionType, EvmContractUpgradeAction, LimitUpdateAction,
AddTokensOnEvmAction, AddTokensOnSuiAction, AssetPriceUpdateAction, BlocklistCommitteeAction,
BlocklistType, EmergencyAction, EmergencyActionType, EvmContractUpgradeAction,
LimitUpdateAction,
};
use sui_bridge::utils::{get_eth_signer_client, EthSigner};
use sui_config::Config;
Expand Down Expand Up @@ -90,6 +92,18 @@ pub enum BridgeCommand {
#[clap(long = "eth-rpc-url")]
eth_rpc_url: String,
},
/// Print current registration info
#[clap(name = "print-bridge-registration-info")]
PrintBridgeRegistrationInfo {
#[clap(long = "sui-rpc-url")]
sui_rpc_url: String,
},
/// Print current committee info
#[clap(name = "print-bridge-committee-info")]
PrintBridgeCommitteeInfo {
#[clap(long = "sui-rpc-url")]
sui_rpc_url: String,
},
/// Client to facilitate and execute Bridge actions
#[clap(name = "client")]
Client {
Expand Down Expand Up @@ -117,7 +131,7 @@ pub enum GovernanceClientCommands {
nonce: u64,
#[clap(name = "blocklist-type", long)]
blocklist_type: BlocklistType,
#[clap(name = "pubkey-hex", long)]
#[clap(name = "pubkey-hex", use_value_delimiter = true, long)]
pubkeys_hex: Vec<BridgeAuthorityPublicKeyBytes>,
},
#[clap(name = "update-limit")]
Expand All @@ -138,6 +152,30 @@ pub enum GovernanceClientCommands {
#[clap(name = "new-usd-price", long)]
new_usd_price: u64,
},
#[clap(name = "add-tokens-on-sui")]
AddTokensOnSui {
#[clap(name = "nonce", long)]
nonce: u64,
#[clap(name = "token-ids", use_value_delimiter = true, long)]
token_ids: Vec<u8>,
#[clap(name = "token-type-names", use_value_delimiter = true, long)]
token_type_names: Vec<TypeTag>,
#[clap(name = "token-prices", use_value_delimiter = true, long)]
token_prices: Vec<u64>,
},
#[clap(name = "add-tokens-on-evm")]
AddTokensOnEvm {
#[clap(name = "nonce", long)]
nonce: u64,
#[clap(name = "token-ids", use_value_delimiter = true, long)]
token_ids: Vec<u8>,
#[clap(name = "token-type-names", use_value_delimiter = true, long)]
token_addresses: Vec<EthAddress>,
#[clap(name = "token-prices", use_value_delimiter = true, long)]
token_prices: Vec<u64>,
#[clap(name = "token-sui-decimals", use_value_delimiter = true, long)]
token_sui_decimals: Vec<u8>,
},
#[clap(name = "upgrade-evm-contract")]
UpgradeEVMContract {
#[clap(name = "nonce", long)]
Expand All @@ -151,7 +189,7 @@ pub enum GovernanceClientCommands {
#[clap(name = "function-selector", long)]
function_selector: String,
/// Params to be passed to the function, e.g. `420,false,hello`
#[clap(name = "params", long)]
#[clap(name = "params", use_value_delimiter = true, long)]
params: Vec<String>,
},
}
Expand Down Expand Up @@ -199,6 +237,43 @@ pub fn make_action(chain_id: BridgeChainId, cmd: &GovernanceClientCommands) -> B
token_id: *token_id,
new_usd_price: *new_usd_price,
}),
GovernanceClientCommands::AddTokensOnSui {
nonce,
token_ids,
token_type_names,
token_prices,
} => {
assert_eq!(token_ids.len(), token_type_names.len());
assert_eq!(token_ids.len(), token_prices.len());
BridgeAction::AddTokensOnSuiAction(AddTokensOnSuiAction {
nonce: *nonce,
chain_id,
native: false, // only foreign tokens are supported now
token_ids: token_ids.clone(),
token_type_names: token_type_names.clone(),
token_prices: token_prices.clone(),
})
}
GovernanceClientCommands::AddTokensOnEvm {
nonce,
token_ids,
token_addresses,
token_prices,
token_sui_decimals,
} => {
assert_eq!(token_ids.len(), token_addresses.len());
assert_eq!(token_ids.len(), token_prices.len());
assert_eq!(token_ids.len(), token_sui_decimals.len());
BridgeAction::AddTokensOnEvmAction(AddTokensOnEvmAction {
nonce: *nonce,
native: true, // only eth native tokens are supported now
chain_id,
token_ids: token_ids.clone(),
token_addresses: token_addresses.clone(),
token_prices: token_prices.clone(),
token_sui_decimals: token_sui_decimals.clone(),
})
}
GovernanceClientCommands::UpgradeEVMContract {
nonce,
proxy_address,
Expand Down Expand Up @@ -268,10 +343,10 @@ pub fn select_contract_address(
config.eth_bridge_committee_proxy_address
}
GovernanceClientCommands::UpdateLimit { .. } => config.eth_bridge_limiter_proxy_address,
GovernanceClientCommands::UpdateAssetPrice { .. } => {
config.eth_bridge_limiter_proxy_address
}
GovernanceClientCommands::UpdateAssetPrice { .. } => config.eth_bridge_config_proxy_address,
GovernanceClientCommands::UpgradeEVMContract { proxy_address, .. } => *proxy_address,
GovernanceClientCommands::AddTokensOnSui { .. } => unreachable!(),
GovernanceClientCommands::AddTokensOnEvm { .. } => config.eth_bridge_config_proxy_address,
}
}

Expand Down Expand Up @@ -307,6 +382,8 @@ pub struct LoadedBridgeCliConfig {
pub eth_bridge_proxy_address: EthAddress,
/// Proxy address for BridgeCommittee deployed on Eth
pub eth_bridge_committee_proxy_address: EthAddress,
/// Proxy address for BridgeConfig deployed on Eth
pub eth_bridge_config_proxy_address: EthAddress,
/// Proxy address for BridgeLimiter deployed on Eth
pub eth_bridge_limiter_proxy_address: EthAddress,
/// Key pair for Sui operations
Expand Down Expand Up @@ -359,6 +436,10 @@ impl LoadedBridgeCliConfig {
let sui_bridge = EthSuiBridge::new(cli_config.eth_bridge_proxy_address, provider.clone());
let eth_bridge_committee_proxy_address: EthAddress = sui_bridge.committee().call().await?;
let eth_bridge_limiter_proxy_address: EthAddress = sui_bridge.limiter().call().await?;
let eth_committee =
EthBridgeCommittee::new(eth_bridge_committee_proxy_address, provider.clone());
let eth_bridge_committee_proxy_address: EthAddress = sui_bridge.committee().call().await?;
let eth_bridge_config_proxy_address: EthAddress = eth_committee.config().call().await?;

let eth_address = eth_signer.address();
let eth_chain_id = provider.get_chainid().await?;
Expand All @@ -373,6 +454,7 @@ impl LoadedBridgeCliConfig {
eth_bridge_proxy_address: cli_config.eth_bridge_proxy_address,
eth_bridge_committee_proxy_address,
eth_bridge_limiter_proxy_address,
eth_bridge_config_proxy_address,
sui_key,
eth_signer,
})
Expand Down Expand Up @@ -401,7 +483,10 @@ impl LoadedBridgeCliConfig {
let gas = gases
.into_iter()
.find(|coin| coin.balance >= 5_000_000_000)
.ok_or(anyhow!("Did not find gas object with enough balance"))?;
.ok_or(anyhow!(
"Did not find gas object with enough balance for {}",
sui_client_address
))?;
println!("Using Gas object: {}", gas.coin_object_id);
Ok((self.sui_key.copy(), sui_client_address, gas.object_ref()))
}
Expand Down
Loading

0 comments on commit 67d6d0d

Please sign in to comment.