Revert tps_demo marker
This commit is contained in:
parent
6d275d571c
commit
d698b3da3a
|
@ -415,7 +415,6 @@ fn request_airdrop(
|
||||||
let req = DroneRequest::GetAirdrop {
|
let req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: tokens,
|
airdrop_request_amount: tokens,
|
||||||
client_public_key: id.pubkey(),
|
client_public_key: id.pubkey(),
|
||||||
tps_demo: true,
|
|
||||||
};
|
};
|
||||||
let tx = serialize(&req).expect("serialize drone request");
|
let tx = serialize(&req).expect("serialize drone request");
|
||||||
stream.write_all(&tx).unwrap();
|
stream.write_all(&tx).unwrap();
|
||||||
|
|
|
@ -321,7 +321,6 @@ fn request_airdrop(
|
||||||
let req = DroneRequest::GetAirdrop {
|
let req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: tokens,
|
airdrop_request_amount: tokens,
|
||||||
client_public_key: id.pubkey(),
|
client_public_key: id.pubkey(),
|
||||||
tps_demo: false,
|
|
||||||
};
|
};
|
||||||
let tx = serialize(&req).expect("serialize drone request");
|
let tx = serialize(&req).expect("serialize drone request");
|
||||||
stream.write_all(&tx).unwrap();
|
stream.write_all(&tx).unwrap();
|
||||||
|
|
14
src/drone.rs
14
src/drone.rs
|
@ -13,14 +13,13 @@ use thin_client::ThinClient;
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
|
|
||||||
pub const TIME_SLICE: u64 = 60;
|
pub const TIME_SLICE: u64 = 60;
|
||||||
pub const REQUEST_CAP: u64 = 150_000;
|
pub const REQUEST_CAP: u64 = 1_000_000;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum DroneRequest {
|
pub enum DroneRequest {
|
||||||
GetAirdrop {
|
GetAirdrop {
|
||||||
airdrop_request_amount: u64,
|
airdrop_request_amount: u64,
|
||||||
client_public_key: PublicKey,
|
client_public_key: PublicKey,
|
||||||
tps_demo: bool,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +32,6 @@ pub struct Drone {
|
||||||
pub time_slice: Duration,
|
pub time_slice: Duration,
|
||||||
request_cap: u64,
|
request_cap: u64,
|
||||||
pub request_current: u64,
|
pub request_current: u64,
|
||||||
pub tps_request_current: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drone {
|
impl Drone {
|
||||||
|
@ -62,7 +60,6 @@ impl Drone {
|
||||||
time_slice,
|
time_slice,
|
||||||
request_cap,
|
request_cap,
|
||||||
request_current: 0,
|
request_current: 0,
|
||||||
tps_request_current: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +69,6 @@ impl Drone {
|
||||||
|
|
||||||
pub fn clear_request_count(&mut self) {
|
pub fn clear_request_count(&mut self) {
|
||||||
self.request_current = 0;
|
self.request_current = 0;
|
||||||
self.tps_request_current = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_ip_to_cache(&mut self, ip: IpAddr) {
|
pub fn add_ip_to_cache(&mut self, ip: IpAddr) {
|
||||||
|
@ -108,13 +104,11 @@ impl Drone {
|
||||||
transactions_socket,
|
transactions_socket,
|
||||||
);
|
);
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
let tps_check: bool;
|
|
||||||
|
|
||||||
match req {
|
match req {
|
||||||
DroneRequest::GetAirdrop {
|
DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount,
|
airdrop_request_amount,
|
||||||
client_public_key,
|
client_public_key,
|
||||||
tps_demo,
|
|
||||||
} => {
|
} => {
|
||||||
request_amount = airdrop_request_amount.clone();
|
request_amount = airdrop_request_amount.clone();
|
||||||
tx = Transaction::new(
|
tx = Transaction::new(
|
||||||
|
@ -123,15 +117,11 @@ impl Drone {
|
||||||
airdrop_request_amount as i64,
|
airdrop_request_amount as i64,
|
||||||
last_id,
|
last_id,
|
||||||
);
|
);
|
||||||
tps_check = tps_demo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.check_request_limit(request_amount) {
|
if self.check_request_limit(request_amount) {
|
||||||
self.request_current += request_amount;
|
self.request_current += request_amount;
|
||||||
client.transfer_signed(tx)
|
client.transfer_signed(tx)
|
||||||
} else if tps_check && !self.tps_request_current {
|
|
||||||
self.tps_request_current = true;
|
|
||||||
client.transfer_signed(tx)
|
|
||||||
} else {
|
} else {
|
||||||
Err(Error::new(ErrorKind::Other, "token limit reached"))
|
Err(Error::new(ErrorKind::Other, "token limit reached"))
|
||||||
}
|
}
|
||||||
|
@ -284,7 +274,6 @@ mod tests {
|
||||||
let bob_req = DroneRequest::GetAirdrop {
|
let bob_req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: 50,
|
airdrop_request_amount: 50,
|
||||||
client_public_key: bob_pubkey,
|
client_public_key: bob_pubkey,
|
||||||
tps_demo: false,
|
|
||||||
};
|
};
|
||||||
let bob_result = drone.send_airdrop(bob_req).expect("send airdrop test");
|
let bob_result = drone.send_airdrop(bob_req).expect("send airdrop test");
|
||||||
assert!(bob_result > 0);
|
assert!(bob_result > 0);
|
||||||
|
@ -292,7 +281,6 @@ mod tests {
|
||||||
let carlos_req = DroneRequest::GetAirdrop {
|
let carlos_req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: 5_000_000,
|
airdrop_request_amount: 5_000_000,
|
||||||
client_public_key: carlos_pubkey,
|
client_public_key: carlos_pubkey,
|
||||||
tps_demo: true,
|
|
||||||
};
|
};
|
||||||
let carlos_result = drone.send_airdrop(carlos_req).expect("send airdrop test");
|
let carlos_result = drone.send_airdrop(carlos_req).expect("send airdrop test");
|
||||||
assert!(carlos_result > 0);
|
assert!(carlos_result > 0);
|
||||||
|
|
Loading…
Reference in New Issue