diff --git a/actors/verifreg/src/emit.rs b/actors/verifreg/src/emit.rs index ac8e11195..f4027934d 100644 --- a/actors/verifreg/src/emit.rs +++ b/actors/verifreg/src/emit.rs @@ -17,8 +17,9 @@ pub fn verifier_balance( rt: &impl Runtime, verifier: ActorID, new_balance: &DataCap, + client: Option, ) -> Result<(), ActorError> { - let event = build_verifier_balance_event(verifier, new_balance)?; + let event = build_verifier_balance_event(verifier, new_balance, client)?; rt.emit_event(&event) } @@ -63,11 +64,13 @@ pub fn claim_removed(rt: &impl Runtime, id: ClaimID, claim: &Claim) -> Result<() pub fn build_verifier_balance_event( verifier: ActorID, balance: &DataCap, + client: Option, ) -> Result { EventBuilder::new() .typ("verifier-balance") .field_indexed("verifier", &verifier) .field("balance", &BigIntSer(balance)) + .field_indexed("client", &client) .build() } diff --git a/actors/verifreg/src/lib.rs b/actors/verifreg/src/lib.rs index 141d0c817..64dbf029a 100644 --- a/actors/verifreg/src/lib.rs +++ b/actors/verifreg/src/lib.rs @@ -130,7 +130,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( @@ -143,7 +143,7 @@ impl Actor { rt.transaction(|st: &mut State, rt| { rt.validate_immediate_caller_is(std::iter::once(&st.root_key))?; 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) })?; Ok(()) } @@ -203,7 +203,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 82391b338..568c93c08 100644 --- a/actors/verifreg/tests/harness/mod.rs +++ b/actors/verifreg/tests/harness/mod.rs @@ -139,12 +139,13 @@ impl Harness { ExitCode::OK, None, ); - + let client: Option = None; rt.expect_emitted_event( EventBuilder::new() .typ("verifier-balance") .field_indexed("verifier", &verifier_resolved.id().unwrap()) .field("balance", &BigIntSer(allowance)) + .field_indexed("client", &client) .build()?, ); @@ -162,12 +163,14 @@ impl Harness { pub fn remove_verifier(&self, rt: &MockRuntime, verifier: &Address) -> Result<(), ActorError> { rt.expect_validate_caller_addr(vec![self.root]); + let client: Option = None; rt.expect_emitted_event( EventBuilder::new() .typ("verifier-balance") .field_indexed("verifier", &verifier.id().unwrap()) .field("balance", &BigIntSer(&DataCap::zero())) + .field_indexed("client", &client) .build()?, ); @@ -233,13 +236,16 @@ 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() { + 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, 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..08eed0929 100644 --- a/integration_tests/src/tests/verifreg_remove_datacap_test.rs +++ b/integration_tests/src/tests/verifreg_remove_datacap_test.rs @@ -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( + verifier1.id().unwrap(), + verifier_datacap, + Some(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 4f24c42c9..2fe7f974e 100644 --- a/integration_tests/src/util/workflows.rs +++ b/integration_tests/src/util/workflows.rs @@ -759,13 +759,18 @@ pub fn submit_invalid_post( ); } -pub fn verifier_balance_event(verifier: ActorID, data_cap: DataCap) -> EmittedEvent { +pub fn verifier_balance_event( + verifier: ActorID, + data_cap: DataCap, + client: Option, +) -> 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(), } @@ -803,7 +808,7 @@ pub fn verifreg_add_verifier(v: &dyn VM, verifier: &Address, data_cap: StoragePo DATACAP_TOKEN_ACTOR_ADDR, *verifier, )]), - events: vec![verifier_balance_event(verifier.id().unwrap(), data_cap)], + events: vec![verifier_balance_event(verifier.id().unwrap(), data_cap, None)], ..Default::default() }]), ..Default::default() @@ -863,7 +868,11 @@ pub fn verifreg_add_client( )]), ..Default::default() }]), - events: vec![verifier_balance_event(verifier.id().unwrap(), updated_verifier_balance)], + events: vec![verifier_balance_event( + verifier.id().unwrap(), + updated_verifier_balance, + Some(client.id().unwrap()), + )], ..Default::default() } .matches(v.take_invocations().last().unwrap());