diff --git a/actors/verifreg/src/lib.rs b/actors/verifreg/src/lib.rs index 5989482f5..c874b38f6 100644 --- a/actors/verifreg/src/lib.rs +++ b/actors/verifreg/src/lib.rs @@ -52,8 +52,8 @@ pub enum Method { AddVerifier = 2, RemoveVerifier = 3, AddVerifiedClient = 4, - UseBytes = 5, // Deprecated - RestoreBytes = 6, // Deprecated + // UseBytes = 5, // Deprecated + // RestoreBytes = 6, // Deprecated RemoveVerifiedClientDataCap = 7, RemoveExpiredAllocations = 8, ClaimAllocations = 9, @@ -229,97 +229,6 @@ impl Actor { Ok(()) } - /// Called by StorageMarketActor during PublishStorageDeals. - /// Do not allow partially verified deals (DealSize must be greater than equal to allowed cap). - /// Delete VerifiedClient if remaining DataCap is smaller than minimum VerifiedDealSize. - pub fn use_bytes(rt: &mut RT, params: UseBytesParams) -> Result<(), ActorError> - where - BS: Blockstore, - RT: Runtime, - { - rt.validate_immediate_caller_is(std::iter::once(&*STORAGE_MARKET_ACTOR_ADDR))?; - - let client = resolve_to_actor_id(rt, ¶ms.address).map_err(|e| { - e.downcast_default( - ExitCode::USR_ILLEGAL_STATE, - format!("failed to resolve addr {} to ID", params.address), - ) - })?; - - let client = Address::new_id(client); - - if params.deal_size < rt.policy().minimum_verified_allocation_size { - return Err(actor_error!( - illegal_argument, - "use bytes {} is below minimum {}", - params.deal_size, - rt.policy().minimum_verified_allocation_size - )); - } - - // Deduct from client's token allowance. - let remaining = destroy(rt, &client, ¶ms.deal_size).context(format!( - "failed to deduct {} from allowance for {}", - ¶ms.deal_size, &client - ))?; - - // Destroy any remaining balance below minimum verified deal size. - if remaining.is_positive() && remaining < rt.policy().minimum_verified_allocation_size { - destroy(rt, &client, &remaining).context(format!( - "failed to destroy remaining {} from allowance for {}", - &remaining, &client - ))?; - } - Ok(()) - } - - /// Called by HandleInitTimeoutDeals from StorageMarketActor when a VerifiedDeal fails to init. - /// Restore allowable cap for the client, creating new entry if the client has been deleted. - pub fn restore_bytes(rt: &mut RT, params: RestoreBytesParams) -> Result<(), ActorError> - where - BS: Blockstore, - RT: Runtime, - { - rt.validate_immediate_caller_is(std::iter::once(&*STORAGE_MARKET_ACTOR_ADDR))?; - if params.deal_size < rt.policy().minimum_verified_allocation_size { - return Err(actor_error!( - illegal_argument, - "Below minimum VerifiedDealSize requested in RestoreBytes: {}", - params.deal_size - )); - } - - let client = resolve_to_actor_id(rt, ¶ms.address).map_err(|e| { - e.downcast_default( - ExitCode::USR_ILLEGAL_STATE, - format!("failed to resolve addr {} to ID", params.address), - ) - })?; - - let client = Address::new_id(client); - - let st: State = rt.state()?; - // Disallow root as a client. - if client == st.root_key { - return Err(actor_error!(illegal_argument, "cannot restore allowance for root")); - } - - // Disallow existing verifiers as clients. - if st.get_verifier_cap(rt.store(), &client)?.is_some() { - return Err(actor_error!( - illegal_argument, - "cannot restore allowance for verifier {}", - client - )); - } - - let operators = vec![*STORAGE_MARKET_ACTOR_ADDR]; - mint(rt, &client, ¶ms.deal_size, operators).context(format!( - "failed to restore {} to allowance for {}", - ¶ms.deal_size, &client - )) - } - /// Removes DataCap allocated to a verified client. pub fn remove_verified_client_data_cap( rt: &mut RT, @@ -1067,14 +976,6 @@ impl ActorCode for Actor { Self::add_verified_client(rt, cbor::deserialize_params(params)?)?; Ok(RawBytes::default()) } - Some(Method::UseBytes) => { - Self::use_bytes(rt, cbor::deserialize_params(params)?)?; - Ok(RawBytes::default()) - } - Some(Method::RestoreBytes) => { - Self::restore_bytes(rt, cbor::deserialize_params(params)?)?; - Ok(RawBytes::default()) - } Some(Method::RemoveVerifiedClientDataCap) => { let res = Self::remove_verified_client_data_cap(rt, cbor::deserialize_params(params)?)?; diff --git a/actors/verifreg/src/types.rs b/actors/verifreg/src/types.rs index 5355e91dd..b79d1b3f8 100644 --- a/actors/verifreg/src/types.rs +++ b/actors/verifreg/src/types.rs @@ -36,18 +36,6 @@ pub type AddVerifierClientParams = VerifierParams; /// We can introduce policy changes and replace this in the future. pub type DataCap = StoragePower; -#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)] -pub struct BytesParams { - /// Address of verified client. - pub address: Address, - /// Number of bytes to use. - #[serde(with = "bigint_ser")] - pub deal_size: StoragePower, -} - -pub type UseBytesParams = BytesParams; -pub type RestoreBytesParams = BytesParams; - pub const SIGNATURE_DOMAIN_SEPARATION_REMOVE_DATA_CAP: &[u8] = b"fil_removedatacap:"; impl Cbor for RemoveDataCapParams {} diff --git a/actors/verifreg/tests/harness/mod.rs b/actors/verifreg/tests/harness/mod.rs index 539360833..3f1109f0f 100644 --- a/actors/verifreg/tests/harness/mod.rs +++ b/actors/verifreg/tests/harness/mod.rs @@ -21,7 +21,7 @@ use fil_actor_verifreg::{ AllocationID, AllocationRequest, AllocationRequests, AllocationsResponse, ClaimAllocationsParams, ClaimAllocationsReturn, ClaimID, DataCap, GetClaimsParams, GetClaimsReturn, Method, RemoveExpiredAllocationsParams, RemoveExpiredAllocationsReturn, - RestoreBytesParams, SectorAllocationClaim, State, + SectorAllocationClaim, State, }; use fil_actors_runtime::cbor::serialize; use fil_actors_runtime::runtime::policy_constants::{ @@ -200,41 +200,6 @@ impl Harness { Ok(()) } - pub fn restore_bytes( - &self, - rt: &mut MockRuntime, - client: &Address, - amount: &DataCap, - ) -> Result<(), ActorError> { - rt.expect_validate_caller_addr(vec![*STORAGE_MARKET_ACTOR_ADDR]); - rt.set_caller(*MARKET_ACTOR_CODE_ID, *STORAGE_MARKET_ACTOR_ADDR); - let client_resolved = rt.get_id_address(client).unwrap_or(*client); - - // Expect tokens to be minted. - let mint_params = ext::datacap::MintParams { - to: client_resolved, - amount: TokenAmount::from_whole(amount.to_i64().unwrap()), - operators: vec![*STORAGE_MARKET_ACTOR_ADDR], - }; - rt.expect_send( - *DATACAP_TOKEN_ACTOR_ADDR, - ext::datacap::Method::Mint as MethodNum, - RawBytes::serialize(&mint_params).unwrap(), - TokenAmount::zero(), - RawBytes::default(), - ExitCode::OK, - ); - - let params = RestoreBytesParams { address: *client, deal_size: amount.clone() }; - let ret = rt.call::( - Method::RestoreBytes as MethodNum, - &RawBytes::serialize(params).unwrap(), - )?; - assert_eq!(RawBytes::default(), ret); - rt.verify(); - Ok(()) - } - pub fn check_state(&self, rt: &MockRuntime) { let (_, acc) = check_state_invariants(&rt.get_state(), rt.store()); acc.assert_empty(); diff --git a/actors/verifreg/tests/verifreg_actor_test.rs b/actors/verifreg/tests/verifreg_actor_test.rs index f13afc695..bb37c5976 100644 --- a/actors/verifreg/tests/verifreg_actor_test.rs +++ b/actors/verifreg/tests/verifreg_actor_test.rs @@ -552,7 +552,7 @@ mod datacap { use fvm_shared::error::ExitCode; use fvm_shared::{ActorID, MethodNum}; - use fil_actor_verifreg::{Actor as VerifregActor, Method, RestoreBytesParams, State}; + use fil_actor_verifreg::{Actor as VerifregActor, Method, State}; use fil_actors_runtime::cbor::serialize; use fil_actors_runtime::runtime::policy_constants::{ MAXIMUM_VERIFIED_ALLOCATION_EXPIRATION, MAXIMUM_VERIFIED_ALLOCATION_TERM, @@ -560,12 +560,8 @@ mod datacap { }; use fil_actors_runtime::runtime::Runtime; use fil_actors_runtime::test_utils::*; - use fil_actors_runtime::{ - DATACAP_TOKEN_ACTOR_ADDR, EPOCHS_IN_YEAR, STORAGE_MARKET_ACTOR_ADDR, - STORAGE_POWER_ACTOR_ADDR, - }; + use fil_actors_runtime::{DATACAP_TOKEN_ACTOR_ADDR, EPOCHS_IN_YEAR, STORAGE_MARKET_ACTOR_ADDR}; use harness::*; - use util::*; use crate::*; @@ -790,76 +786,4 @@ mod datacap { } h.check_state(&rt); } - - #[test] - fn restore() { - let (h, mut rt) = new_harness(); - let deal_size = &rt.policy.minimum_verified_allocation_size.clone(); - h.restore_bytes(&mut rt, &CLIENT, deal_size).unwrap(); - h.check_state(&rt); - } - - #[test] - fn restore_resolves_client_address() { - let (h, mut rt) = new_harness(); - let client_pubkey = Address::new_secp256k1(&[3u8; 65]).unwrap(); - rt.id_addresses.insert(client_pubkey, *CLIENT); - - // Restore to pubkey address. - let deal_size = rt.policy.minimum_verified_allocation_size.clone(); - h.restore_bytes(&mut rt, &client_pubkey, &deal_size).unwrap(); - h.check_state(&rt) - } - - #[test] - fn restore_requires_market_actor_caller() { - let (h, mut rt) = new_harness(); - rt.expect_validate_caller_addr(vec![*STORAGE_MARKET_ACTOR_ADDR]); - rt.set_caller(*POWER_ACTOR_CODE_ID, *STORAGE_POWER_ACTOR_ADDR); - let params = RestoreBytesParams { - address: *CLIENT, - deal_size: rt.policy.minimum_verified_allocation_size.clone(), - }; - expect_abort( - ExitCode::USR_FORBIDDEN, - rt.call::( - Method::RestoreBytes as MethodNum, - &RawBytes::serialize(params).unwrap(), - ), - ); - h.check_state(&rt) - } - - #[test] - fn restore_requires_minimum_deal_size() { - let (h, mut rt) = new_harness(); - - let deal_size = rt.policy.minimum_verified_allocation_size.clone() - 1; - expect_abort(ExitCode::USR_ILLEGAL_ARGUMENT, h.restore_bytes(&mut rt, &CLIENT, &deal_size)); - h.check_state(&rt) - } - - #[test] - fn restore_rejects_root() { - let (h, mut rt) = new_harness(); - let deal_size = rt.policy.minimum_verified_allocation_size.clone(); - expect_abort( - ExitCode::USR_ILLEGAL_ARGUMENT, - h.restore_bytes(&mut rt, &ROOT_ADDR, &deal_size), - ); - h.check_state(&rt) - } - - #[test] - fn restore_rejects_verifier() { - let (h, mut rt) = new_harness(); - let allowance = verifier_allowance(&rt); - h.add_verifier(&mut rt, &VERIFIER, &allowance).unwrap(); - let deal_size = rt.policy.minimum_verified_allocation_size.clone(); - expect_abort( - ExitCode::USR_ILLEGAL_ARGUMENT, - h.restore_bytes(&mut rt, &VERIFIER, &deal_size), - ); - h.check_state(&rt) - } }