Skip to content

Commit

Permalink
[chore] eliminate concept of Primary address
Browse files Browse the repository at this point in the history
This is an artifact of FastPay--not needed in FastX.
  • Loading branch information
sblackshear committed Jan 31, 2022
1 parent e856db7 commit ed738c7
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 51 deletions.
2 changes: 1 addition & 1 deletion fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl ClientServerBenchmark {
} else {
let transfer = Transfer {
sender: *account_addr,
recipient: Address::FastPay(next_recipient),
recipient: next_recipient,
object_ref,
gas_payment: gas_object_ref,
};
Expand Down
2 changes: 1 addition & 1 deletion fastpay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn make_benchmark_transfer_orders(
let transfer = Transfer {
object_ref,
sender: account.address,
recipient: Address::FastPay(next_recipient),
recipient: next_recipient,
gas_payment: gas_object_ref,
};
debug!("Preparing transfer order: {:?}", transfer);
Expand Down
14 changes: 6 additions & 8 deletions fastpay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use fastpay_core::client::ClientState;
use fastx_types::{
base_types::*,
messages::{Address, CertifiedOrder, OrderKind},
messages::{CertifiedOrder, OrderKind},
};

use move_core_types::language_storage::TypeTag;
Expand Down Expand Up @@ -230,13 +230,11 @@ impl AccountsConfig {
pub fn update_for_received_transfer(&mut self, certificate: CertifiedOrder) {
match &certificate.order.kind {
OrderKind::Transfer(transfer) => {
if let Address::FastPay(recipient) = &transfer.recipient {
if let Some(config) = self.accounts.get_mut(recipient) {
config
.certificates
.entry(certificate.order.digest())
.or_insert(certificate);
}
if let Some(config) = self.accounts.get_mut(&transfer.recipient) {
config
.certificates
.entry(certificate.order.digest())
.or_insert(certificate);
}
}
OrderKind::Publish(_) | OrderKind::Call(_) => {
Expand Down
7 changes: 2 additions & 5 deletions fastpay_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl AuthorityState {
fn transfer(
temporary_store: &mut AuthorityTemporaryStore,
mut inputs: Vec<Object>,
recipient: Address,
recipient: FastPayAddress,
mut gas_object: Object,
) -> FastPayResult<ExecutionStatus> {
let gas_used = gas::calculate_object_transfer_cost(&inputs[0]);
Expand All @@ -310,10 +310,7 @@ impl AuthorityState {
temporary_store.write_object(gas_object);

let mut output_object = inputs.pop().unwrap();
output_object.transfer(match recipient {
Address::Primary(_) => FastPayAddress::default(),
Address::FastPay(addr) => addr,
});
output_object.transfer(recipient);
temporary_store.write_object(output_object);
Ok(ExecutionStatus::Success)
}
Expand Down
6 changes: 3 additions & 3 deletions fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ where
let transfer = Transfer {
object_ref,
sender: self.address,
recipient: Address::FastPay(recipient),
recipient,
gas_payment,
};
let order = Order::new_transfer(transfer, &self.secret);
Expand All @@ -1159,7 +1159,7 @@ where
match &certificate.order.kind {
OrderKind::Transfer(transfer) => {
fp_ensure!(
transfer.recipient == Address::FastPay(self.address),
transfer.recipient == self.address,
FastPayError::IncorrectRecipientError.into()
);
let responses = self
Expand Down Expand Up @@ -1227,7 +1227,7 @@ where
let transfer = Transfer {
object_ref,
sender: self.address,
recipient: Address::FastPay(recipient),
recipient,
gas_payment,
};
let order = Order::new_transfer(transfer, &self.secret);
Expand Down
26 changes: 13 additions & 13 deletions fastpay_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn compare_order_info_responses(o1: &OrderInfoResponse, o2: &OrderInfoResponse)
#[tokio::test]
async fn test_handle_transfer_order_bad_signature() {
let (sender, sender_key) = get_key_pair();
let recipient = Address::FastPay(dbg_addr(2));
let recipient = dbg_addr(2);
let object_id = ObjectID::random();
let gas_object_id = ObjectID::random();
let authority_state =
Expand Down Expand Up @@ -98,7 +98,7 @@ async fn test_handle_transfer_order_unknown_sender() {
let (unknown_address, unknown_key) = get_key_pair();
let object_id: ObjectID = ObjectID::random();
let gas_object_id = ObjectID::random();
let recipient = Address::FastPay(dbg_addr(2));
let recipient = dbg_addr(2);
let authority_state =
init_state_with_ids(vec![(sender, object_id), (sender, gas_object_id)]).await;
let object = authority_state.object_state(&object_id).await.unwrap();
Expand Down Expand Up @@ -164,7 +164,7 @@ fn test_handle_transfer_order_bad_sequence_number() {
#[tokio::test]
async fn test_handle_transfer_order_ok() {
let (sender, sender_key) = get_key_pair();
let recipient = Address::FastPay(dbg_addr(2));
let recipient = dbg_addr(2);
let object_id = ObjectID::random();
let gas_object_id = ObjectID::random();
let authority_state =
Expand Down Expand Up @@ -227,7 +227,7 @@ async fn test_handle_transfer_order_ok() {
#[tokio::test]
async fn test_handle_transfer_zero_balance() {
let (sender, sender_key) = get_key_pair();
let recipient = Address::FastPay(dbg_addr(2));
let recipient = dbg_addr(2);
let object_id = ObjectID::random();
let authority_state = init_state_with_ids(vec![(sender, object_id)]).await;
let object = authority_state.object_state(&object_id).await.unwrap();
Expand Down Expand Up @@ -526,7 +526,7 @@ async fn test_handle_move_order_insufficient_budget() {
#[tokio::test]
async fn test_handle_transfer_order_double_spend() {
let (sender, sender_key) = get_key_pair();
let recipient = Address::FastPay(dbg_addr(2));
let recipient = dbg_addr(2);
let object_id = ObjectID::random();
let gas_object_id = ObjectID::random();
let authority_state =
Expand Down Expand Up @@ -569,7 +569,7 @@ async fn test_handle_confirmation_order_unknown_sender() {
let certified_transfer_order = init_certified_transfer_order(
sender,
&sender_key,
Address::FastPay(recipient),
recipient,
object.to_object_reference(),
gas_object.to_object_reference(),
&authority_state,
Expand Down Expand Up @@ -607,7 +607,7 @@ async fn test_handle_confirmation_order_bad_sequence_number() {
let certified_transfer_order = init_certified_transfer_order(
sender,
&sender_key,
Address::FastPay(recipient),
recipient,
object.to_object_reference(),
gas_object.to_object_reference(),
&authority_state,
Expand Down Expand Up @@ -655,7 +655,7 @@ async fn test_handle_confirmation_order_receiver_equal_sender() {
let certified_transfer_order = init_certified_transfer_order(
address,
&key,
Address::FastPay(address),
address,
object.to_object_reference(),
gas_object.to_object_reference(),
&authority_state,
Expand Down Expand Up @@ -700,7 +700,7 @@ async fn test_handle_confirmation_order_gas() {
let certified_transfer_order = init_certified_transfer_order(
sender,
&sender_key,
Address::FastPay(recipient),
recipient,
object.to_object_reference(),
gas_object_ref,
&authority_state,
Expand Down Expand Up @@ -737,7 +737,7 @@ async fn test_handle_confirmation_order_ok() {
let certified_transfer_order = init_certified_transfer_order(
sender,
&sender_key,
Address::FastPay(recipient),
recipient,
object.to_object_reference(),
gas_object.to_object_reference(),
&authority_state,
Expand Down Expand Up @@ -807,7 +807,7 @@ async fn test_handle_confirmation_order_idempotent() {
let certified_transfer_order = init_certified_transfer_order(
sender,
&sender_key,
Address::FastPay(recipient),
recipient,
object.to_object_reference(),
gas_object.to_object_reference(),
&authority_state,
Expand Down Expand Up @@ -1295,7 +1295,7 @@ async fn init_state_with_object_id(address: FastPayAddress, object: ObjectID) ->
fn init_transfer_order(
sender: FastPayAddress,
secret: &KeyPair,
recipient: Address,
recipient: FastPayAddress,
object_ref: ObjectRef,
gas_object_ref: ObjectRef,
) -> Order {
Expand All @@ -1312,7 +1312,7 @@ fn init_transfer_order(
fn init_certified_transfer_order(
sender: FastPayAddress,
secret: &KeyPair,
recipient: Address,
recipient: FastPayAddress,
object_ref: ObjectRef,
gas_object_ref: ObjectRef,
authority_state: &AuthorityState,
Expand Down
4 changes: 2 additions & 2 deletions fastpay_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ fn test_transfer_object_error() {
// Fabricate a fake pending transfer
let transfer = Transfer {
sender: sender.address,
recipient: Address::FastPay(FastPayAddress::random_for_testing_only()),
recipient: FastPayAddress::random_for_testing_only(),
object_ref: (object_id, Default::default(), ObjectDigest::new([0; 32])),
gas_payment: (gas_object, Default::default(), ObjectDigest::new([0; 32])),
};
Expand Down Expand Up @@ -2046,7 +2046,7 @@ async fn test_receive_object_error() -> Result<(), anyhow::Error> {
order: Order {
kind: OrderKind::Transfer(Transfer {
sender: client1.address,
recipient: Address::FastPay(client2.address),
recipient: client2.address,
object_ref: transfer.object_ref,
gas_payment: transfer.gas_payment,
}),
Expand Down
1 change: 0 additions & 1 deletion fastx_types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ impl TryFrom<&[u8]> for PublicKeyBytes {
}
}

pub type PrimaryAddress = PublicKeyBytes;
pub type FastPayAddress = PublicKeyBytes;
pub type AuthorityName = PublicKeyBytes;

Expand Down
8 changes: 1 addition & 7 deletions fastx_types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ use std::{
hash::{Hash, Hasher},
};

#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, Serialize, Deserialize)]
pub enum Address {
Primary(PrimaryAddress),
FastPay(FastPayAddress),
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub struct Transfer {
pub sender: FastPayAddress,
pub recipient: Address,
pub recipient: FastPayAddress,
pub object_ref: ObjectRef,
pub gas_payment: ObjectRef,
}
Expand Down
4 changes: 2 additions & 2 deletions fastx_types/src/unit_tests/messages_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn test_signed_values() {
ObjectDigest::new([0; 32]),
),
sender: a1,
recipient: Address::FastPay(a2),
recipient: a2,
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -64,7 +64,7 @@ fn test_certificates() {
ObjectDigest::new([0; 32]),
),
sender: a1,
recipient: Address::FastPay(a2),
recipient: a2,
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down
16 changes: 8 additions & 8 deletions fastx_types/src/unit_tests/serialize_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn test_order() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand All @@ -113,7 +113,7 @@ fn test_order() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::FastPay(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -142,7 +142,7 @@ fn test_vote() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -174,7 +174,7 @@ fn test_cert() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -214,7 +214,7 @@ fn test_info_response() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -281,7 +281,7 @@ fn test_time_order() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -321,7 +321,7 @@ fn test_time_vote() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0x20)),
recipient: dbg_addr(0x20),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down Expand Up @@ -367,7 +367,7 @@ fn test_time_cert() {
ObjectDigest::new([0; 32]),
),
sender: sender_name,
recipient: Address::Primary(dbg_addr(0)),
recipient: dbg_addr(0),
gas_payment: (
ObjectID::random(),
SequenceNumber::new(),
Expand Down

0 comments on commit ed738c7

Please sign in to comment.