diff --git a/actors/verifreg/src/emit.rs b/actors/verifreg/src/emit.rs index 9715832b4..6fc082fed 100644 --- a/actors/verifreg/src/emit.rs +++ b/actors/verifreg/src/emit.rs @@ -16,14 +16,16 @@ pub fn verifier_balance( rt: &impl Runtime, verifier: ActorID, new_balance: &DataCap, + client: Option, ) -> Result<(), ActorError> { - rt.emit_event( - &EventBuilder::new() - .typ("verifier-balance") - .field_indexed("verifier", &verifier) - .field("balance", &BigIntSer(new_balance)) - .build()?, - ) + let mut event: EventBuilder = EventBuilder::new() + .typ("verifier-balance") + .field_indexed("verifier", &verifier) + .field("balance", &BigIntSer(new_balance)); + if let Some(client) = client { + event = event.field_indexed("client", &client); + } + rt.emit_event(&event.build()?) } /// Indicates a new allocation has been made. diff --git a/actors/verifreg/src/lib.rs b/actors/verifreg/src/lib.rs index 88df433c2..a17a19273 100644 --- a/actors/verifreg/src/lib.rs +++ b/actors/verifreg/src/lib.rs @@ -131,7 +131,7 @@ impl Actor { .context("failed to add verifier") })?; - emit::verifier_balance(rt, verifier, ¶ms.allowance) + emit::verifier_balance(rt, verifier, ¶ms.allowance, None) } pub fn remove_verifier( @@ -146,7 +146,7 @@ impl Actor { st.remove_verifier(rt.store(), &verifier_addr).context("failed to remove verifier") })?; - emit::verifier_balance(rt, verifier, &DataCap::zero()) + emit::verifier_balance(rt, verifier, &DataCap::zero(), None) } pub fn add_verified_client( @@ -204,7 +204,12 @@ impl Actor { st.put_verifier(rt.store(), &verifier_addr, &new_verifier_cap) .context("failed to update verifier allowance")?; - emit::verifier_balance(rt, verifier_addr.id().unwrap(), &new_verifier_cap) + emit::verifier_balance( + rt, + verifier_addr.id().unwrap(), + &new_verifier_cap, + Some(client.id().unwrap()), + ) })?; // Credit client token allowance. diff --git a/actors/verifreg/tests/harness/mod.rs b/actors/verifreg/tests/harness/mod.rs index 063c847b0..c7c344989 100644 --- a/actors/verifreg/tests/harness/mod.rs +++ b/actors/verifreg/tests/harness/mod.rs @@ -232,13 +232,17 @@ impl Harness { ); let params = AddVerifiedClientParams { address: *client, allowance: allowance.clone() }; - rt.expect_emitted_event( - EventBuilder::new() - .typ("verifier-balance") - .field_indexed("verifier", &verifier.id().unwrap()) - .field("balance", &BigIntSer(&(verifier_balance - allowance))) - .build()?, - ); + if client_resolved.id().is_ok() { + // if the client isn't resolved, we don't expect an event because the call should abort + rt.expect_emitted_event( + EventBuilder::new() + .typ("verifier-balance") + .field_indexed("verifier", &verifier.id().unwrap()) + .field("balance", &BigIntSer(&(verifier_balance - allowance))) + .field_indexed("client", &client_resolved.id().unwrap()) + .build()?, + ); + } let ret = rt.call::( Method::AddVerifiedClient as MethodNum, IpldBlock::serialize_cbor(¶ms).unwrap(), diff --git a/actors/verifreg/tests/verifreg_actor_test.rs b/actors/verifreg/tests/verifreg_actor_test.rs index 328bbad58..51d053525 100644 --- a/actors/verifreg/tests/verifreg_actor_test.rs +++ b/actors/verifreg/tests/verifreg_actor_test.rs @@ -449,6 +449,7 @@ mod clients { .typ("verifier-balance") .field_indexed("verifier", &VERIFIER.id().unwrap()) .field("balance", &BigIntSer(&(allowance_verifier - allowance_client))) + .field_indexed("client", &CLIENT.id().unwrap()) .build() .unwrap(), ); diff --git a/integration_tests/src/tests/verifreg_remove_datacap_test.rs b/integration_tests/src/tests/verifreg_remove_datacap_test.rs index 599d8d4d6..e61219e53 100644 --- a/integration_tests/src/tests/verifreg_remove_datacap_test.rs +++ b/integration_tests/src/tests/verifreg_remove_datacap_test.rs @@ -32,7 +32,7 @@ use vm_api::VM; use crate::expects::Expect; use crate::util::{ - assert_invariants, create_accounts, verifier_balance_event, verifreg_add_verifier, + assert_invariants, create_accounts, verifier_balance_event_with_client, verifreg_add_verifier, }; use crate::{TEST_VERIFREG_ROOT_ADDR, TEST_VERIFREG_ROOT_ID}; @@ -84,7 +84,11 @@ pub fn remove_datacap_simple_successful_path_test(v: &dyn VM) { subinvocs: None, ..Default::default() }]), - events: vec![verifier_balance_event(verifier1.id().unwrap(), verifier_datacap)], + events: vec![verifier_balance_event_with_client( + verifier1.id().unwrap(), + verifier_datacap, + verified_client.id().unwrap(), + )], ..Default::default() } .matches(v.take_invocations().last().unwrap()); diff --git a/integration_tests/src/util/workflows.rs b/integration_tests/src/util/workflows.rs index 4831c6c43..3bb3912de 100644 --- a/integration_tests/src/util/workflows.rs +++ b/integration_tests/src/util/workflows.rs @@ -771,6 +771,23 @@ pub fn verifier_balance_event(verifier: ActorID, data_cap: DataCap) -> EmittedEv } } +pub fn verifier_balance_event_with_client( + verifier: ActorID, + data_cap: DataCap, + client: ActorID, +) -> EmittedEvent { + EmittedEvent { + emitter: VERIFIED_REGISTRY_ACTOR_ID, + event: EventBuilder::new() + .typ("verifier-balance") + .field_indexed("verifier", &verifier) + .field("balance", &BigIntSer(&data_cap)) + .field_indexed("client", &client) + .build() + .unwrap(), + } +} + pub fn verifreg_add_verifier(v: &dyn VM, verifier: &Address, data_cap: StoragePower) { let add_verifier_params = VerifierParams { address: *verifier, allowance: data_cap.clone() }; // root address is msig, send proposal from root key @@ -863,7 +880,11 @@ pub fn verifreg_add_client( )]), ..Default::default() }]), - events: vec![verifier_balance_event(verifier.id().unwrap(), updated_verifier_balance)], + events: vec![verifier_balance_event_with_client( + verifier.id().unwrap(), + updated_verifier_balance, + client.id().unwrap(), + )], ..Default::default() } .matches(v.take_invocations().last().unwrap());