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

Feature/reuse init owner #970

Merged
merged 33 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ef8b539
Save gateway owner for later use in erc20 bandwidth request
neacsu Dec 8, 2021
96a1819
Pass owner in network monitor
neacsu Dec 16, 2021
ab6fbd4
Switch to variable length owner address
neacsu Dec 16, 2021
ec6e084
Add erc20 bridge contract in validator client
neacsu Dec 16, 2021
b7b3ae0
Check bandwidth credential refers to gateway
neacsu Dec 16, 2021
eaad4a7
Check the owner of the gateway from the eth event
neacsu Dec 16, 2021
4ff0f4f
Fix wasm client
neacsu Dec 16, 2021
2ad8af6
Merge remote-tracking branch 'origin/develop' into feature/reuse_init…
neacsu Jan 25, 2022
03cdbe9
Hack to avoid unused warning on coconut path
neacsu Jan 25, 2022
0a7eb09
Hacked, one-time payment
neacsu Feb 1, 2022
e54c612
Remove print
neacsu Feb 1, 2022
b09d81b
Update arg format
neacsu Feb 1, 2022
5860ea9
Fix token check
neacsu Feb 11, 2022
f228709
Fix native template
neacsu Feb 11, 2022
13f348e
Use utokens instead of full token
neacsu Feb 14, 2022
0f38bc6
Fix parse event for new field
neacsu Feb 14, 2022
f7bc9f0
Fix socks5 template
neacsu Feb 14, 2022
b1d7d0a
Add estimation of gas call
neacsu Feb 15, 2022
61ea759
Make fs backup more reliable
neacsu Feb 15, 2022
dd7907d
Fix clippy
neacsu Feb 15, 2022
a181d23
Merge remote-tracking branch 'origin' into feature/reuse_init_owner
neacsu Feb 15, 2022
76e2117
Fix unused import
neacsu Feb 15, 2022
fec6f47
Update waiting time
neacsu Feb 15, 2022
118aded
Remove defaults from run, as it they should be set on init
neacsu Feb 15, 2022
5f2e139
Remove debugging prints
neacsu Feb 15, 2022
a5c96f9
Merge remote-tracking branch 'origin' into feature/reuse_init_owner
neacsu Feb 15, 2022
8358997
Replaced unwrap with error
neacsu Feb 15, 2022
6f07f57
Fix build
neacsu Feb 16, 2022
393fd1e
Make eth contract address dependent of network
neacsu Feb 16, 2022
eb595db
Use tokio for sleep
neacsu Feb 16, 2022
d7e7bce
Add approve before spending token on bandwidth
neacsu Feb 16, 2022
114513d
Put bandwidth claim only at the beginning of the process
neacsu Feb 16, 2022
cad0c76
Merge remote-tracking branch 'origin' into feature/reuse_init_owner
neacsu Feb 17, 2022
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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/develop' into feature/reuse_init…
…_owner
  • Loading branch information
neacsu committed Jan 25, 2022
commit 2ad8af63ed57f575124aa1a501111255a2160eac
4 changes: 4 additions & 0 deletions clients/client-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl<T: NymConfig> Config<T> {
self.client.id = id;
}

pub fn with_testnet_mode(&mut self, testnet_mode: bool) {
self.client.testnet_mode = testnet_mode;
}

pub fn with_gateway_endpoint<S: Into<String>>(&mut self, id: S, owner: S, listener: S) {
self.client.gateway_endpoint = GatewayEndpoint {
gateway_id: id.into(),
Expand Down
22 changes: 11 additions & 11 deletions clients/native/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ impl NymClient {
)
.expect("Could not create bandwidth controller");

let mut gateway_client = GatewayClient::new(
gateway_address,
self.key_manager.identity_keypair(),
gateway_identity,
gateway_owner,
Some(self.key_manager.gateway_shared_key()),
mixnet_message_sender,
ack_sender,
self.config.get_base().get_gateway_response_timeout(),
Some(bandwidth_controller),
);
let mut gateway_client = GatewayClient::new(
gateway_address,
self.key_manager.identity_keypair(),
gateway_identity,
gateway_owner,
Some(self.key_manager.gateway_shared_key()),
mixnet_message_sender,
ack_sender,
self.config.get_base().get_gateway_response_timeout(),
Some(bandwidth_controller),
);

if self.config.get_base().get_testnet_mode() {
gateway_client.set_testnet_mode(true)
Expand Down
20 changes: 7 additions & 13 deletions clients/native/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,14 @@ pub async fn execute(matches: ArgMatches<'static>) {

let chosen_gateway_id = matches.value_of("gateway");

let registration_fut = async {
let gate_details = gateway_details(
config.get_base().get_validator_api_endpoints(),
chosen_gateway_id,
)
.await;
let shared_keys =
register_with_gateway(&gate_details, key_manager.identity_keypair()).await;
(shared_keys, gate_details)
};
let gateway_details = gateway_details(
config.get_base().get_validator_api_endpoints(),
chosen_gateway_id,
)
.await;
let shared_keys =
register_with_gateway(&gateway_details, key_manager.identity_keypair()).await;

// TODO: is there perhaps a way to make it work without having to spawn entire runtime?
let rt = tokio::runtime::Runtime::new().unwrap();
let (shared_keys, gateway_details) = rt.block_on(registration_fut);
config.get_base_mut().with_gateway_endpoint(
gateway_details.identity_key.to_base58_string(),
gateway_details.owner.clone(),
Expand Down
22 changes: 11 additions & 11 deletions clients/socks5/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ impl NymClient {
)
.expect("Could not create bandwidth controller");

let mut gateway_client = GatewayClient::new(
gateway_address,
self.key_manager.identity_keypair(),
gateway_identity,
gateway_owner,
Some(self.key_manager.gateway_shared_key()),
mixnet_message_sender,
ack_sender,
self.config.get_base().get_gateway_response_timeout(),
Some(bandwidth_controller),
);
let mut gateway_client = GatewayClient::new(
gateway_address,
self.key_manager.identity_keypair(),
gateway_identity,
gateway_owner,
Some(self.key_manager.gateway_shared_key()),
mixnet_message_sender,
ack_sender,
self.config.get_base().get_gateway_response_timeout(),
Some(bandwidth_controller),
);

if self.config.get_base().get_testnet_mode() {
gateway_client.set_testnet_mode(true)
Expand Down
20 changes: 7 additions & 13 deletions clients/socks5/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,14 @@ pub async fn execute(matches: ArgMatches<'static>) {

let chosen_gateway_id = matches.value_of("gateway");

let registration_fut = async {
let gate_details = gateway_details(
config.get_base().get_validator_api_endpoints(),
chosen_gateway_id,
)
.await;
let shared_keys =
register_with_gateway(&gate_details, key_manager.identity_keypair()).await;
(shared_keys, gate_details)
};
let gateway_details = gateway_details(
config.get_base().get_validator_api_endpoints(),
chosen_gateway_id,
)
.await;
let shared_keys =
register_with_gateway(&gateway_details, key_manager.identity_keypair()).await;

// TODO: is there perhaps a way to make it work without having to spawn entire runtime?
let rt = tokio::runtime::Runtime::new().unwrap();
let (shared_keys, gateway_details) = rt.block_on(registration_fut);
config.get_base_mut().with_gateway_endpoint(
gateway_details.identity_key.to_base58_string(),
gateway_details.owner.clone(),
Expand Down
3 changes: 1 addition & 2 deletions common/client-libs/gateway-client/src/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ impl BandwidthController {
&self.eth_private_key,
)
.await?;
// 0 means a transaction failure, 1 means success
if Some(U64::from(0)) == recipt.status {
if Some(U64::from(0u64)) == recipt.status {
Err(GatewayClientError::BurnTokenError(
web3::Error::InvalidResponse(format!(
"Transaction status is 0 (failure): {:?}",
Expand Down
25 changes: 15 additions & 10 deletions common/client-libs/validator-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,18 @@ impl Client<QueryNymdClient> {
Some(config.vesting_contract_address.clone().unwrap_or_else(|| {
cosmrs::AccountId::from_str(network_defaults::DEFAULT_VESTING_CONTRACT_ADDRESS)
.unwrap()
}),
config
.erc20_bridge_contract_address
.clone()
.unwrap_or_else(|| {
cosmrs::AccountId::from_str(network_defaults::COSMOS_CONTRACT_ADDRESS).unwrap()
}),
})),
Some(
config
.erc20_bridge_contract_address
.clone()
.unwrap_or_else(|| {
cosmrs::AccountId::from_str(
network_defaults::DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
)
.unwrap()
}),
),
)?;

Ok(Client {
Expand All @@ -185,9 +190,9 @@ impl Client<QueryNymdClient> {
pub fn change_nymd(&mut self, new_endpoint: Url) -> Result<(), ValidatorClientError> {
self.nymd = NymdClient::connect(
new_endpoint.as_ref(),
self.mixnet_contract_address.clone().unwrap(),
self.vesting_contract_address.clone().unwrap(),
self.erc20_bridge_contract_address.clone().unwrap(),
self.mixnet_contract_address.clone(),
self.vesting_contract_address.clone(),
self.erc20_bridge_contract_address.clone(),
)?;
Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions common/client-libs/validator-client/src/nymd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ pub struct NymdClient<C> {
impl NymdClient<QueryNymdClient> {
pub fn connect<U>(
endpoint: U,
mixnet_contract_address: AccountId,
vesting_contract_address: AccountId,
erc20_bridge_contract_address: AccountId,
mixnet_contract_address: Option<AccountId>,
vesting_contract_address: Option<AccountId>,
erc20_bridge_contract_address: Option<AccountId>,
) -> Result<NymdClient<QueryNymdClient>, NymdError>
where
U: TryInto<HttpClientUrl, Error = TendermintRpcError>,
{
Ok(NymdClient {
client: QueryNymdClient::new(endpoint)?,
mixnet_contract_address: Some(mixnet_contract_address),
vesting_contract_address: Some(vesting_contract_address),
erc20_bridge_contract_address: Some(erc20_bridge_contract_address),
mixnet_contract_address,
vesting_contract_address,
erc20_bridge_contract_address,
client_address: None,
custom_gas_limits: Default::default(),
simulated_gas_multiplier: DEFAULT_SIMULATED_GAS_MULTIPLIER,
Expand Down
9 changes: 2 additions & 7 deletions common/network-defaults/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub const ETH_CONTRACT_ADDRESS: [u8; 20] =
hex_literal::hex!("9fEE3e28c17dbB87310A51F13C4fbf4331A6f102");
// Name of the event triggered by the eth contract. If the event name is changed,
// this would also need to be changed; It is currently tested against the json abi
pub const ETH_EVENT_NAME: &str = "Burned";
pub const ETH_BURN_FUNCTION_NAME: &str = "burnTokenForAccessCode";
pub const ETH_EVENT_NAME: &str = "BBCredentialPurchased";
neacsu marked this conversation as resolved.
Show resolved Hide resolved
pub const ETH_BURN_FUNCTION_NAME: &str = "generateBasicBandwidthCredential";

// Ethereum constants used for token bridge
/// How much bandwidth (in bytes) one token can buy
Expand All @@ -124,11 +124,6 @@ pub const TOKENS_TO_BURN: u64 = 10;
pub const BANDWIDTH_VALUE: u64 = TOKENS_TO_BURN * BYTES_PER_TOKEN;

pub const ETH_MIN_BLOCK_DEPTH: usize = 7;
pub const COSMOS_CONTRACT_ADDRESS: &str = "punk1jld76tqw4wnpfenmay2xkv86nr3j0w426eka82";
// Name of the event triggered by the eth contract. If the event name is changed,
// this would also need to be changed; It is currently tested against the json abi
pub const ETH_EVENT_NAME: &str = "BBCredentialPurchased";
pub const ETH_BURN_FUNCTION_NAME: &str = "generateBasicBandwidthCredential";

/// Defaults Cosmos Hub/ATOM path
pub const COSMOS_DERIVATION_PATH: &str = "m/44'/118'/0'/0/0";
Expand Down
1 change: 1 addition & 0 deletions explorer-api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) fn new_nymd_client() -> validator_client::Client<QueryNymdClient> {
api_url,
Some(mixnet_contract.parse().unwrap()),
None,
None,
);

validator_client::Client::new_query(client_config).expect("Failed to connect to nymd!")
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.