Skip to content

Commit

Permalink
Add client to verifier balance event (#1533)
Browse files Browse the repository at this point in the history
* update to Actor events

* changes as per review

* remvoe clippy

* changes as per new FIP update

* Update to latest PR, remove emit:: use from testing

* all itests passing and green CI

* address review feedback, minimise diff

* feat: add term_start to claim events

* fix: claim term_start at current epoch, not at deal_start

* fix: s/deal_term/claim_term

* add client to verifier balance event

* fix: make "client" optional on verifier-balance event

---------

Co-authored-by: Rod Vagg <[email protected]>
  • Loading branch information
aarshkshah1992 and rvagg committed Jun 19, 2024
1 parent 0e0df51 commit fa72bbd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 deletions.
16 changes: 9 additions & 7 deletions actors/verifreg/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ pub fn verifier_balance(
rt: &impl Runtime,
verifier: ActorID,
new_balance: &DataCap,
client: Option<ActorID>,
) -> 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.
Expand Down
11 changes: 8 additions & 3 deletions actors/verifreg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Actor {
.context("failed to add verifier")
})?;

emit::verifier_balance(rt, verifier, &params.allowance)
emit::verifier_balance(rt, verifier, &params.allowance, None)
}

pub fn remove_verifier(
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions actors/verifreg/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,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::<VerifregActor>(
Method::AddVerifiedClient as MethodNum,
IpldBlock::serialize_cbor(&params).unwrap(),
Expand Down
1 change: 1 addition & 0 deletions actors/verifreg/tests/verifreg_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down
8 changes: 6 additions & 2 deletions integration_tests/src/tests/verifreg_remove_datacap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -84,7 +84,11 @@ pub fn remove_datacap_simple_successful_path_test(v: &dyn VM) {
subinvocs: None,
..Default::default()
}]),
events: Some(vec![verifier_balance_event(verifier1.id().unwrap(), verifier_datacap)]),
events: Some(vec![verifier_balance_event_with_client(
verifier1.id().unwrap(),
verifier_datacap,
verified_client.id().unwrap(),
)]),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
20 changes: 19 additions & 1 deletion integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,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
Expand Down Expand Up @@ -869,9 +886,10 @@ pub fn verifreg_add_client(
)]),
..Default::default()
}]),
events: Some(vec![verifier_balance_event(
events: Some(vec![verifier_balance_event_with_client(
verifier.id().unwrap(),
updated_verifier_balance,
client.id().unwrap(),
)]),
..Default::default()
}
Expand Down

0 comments on commit fa72bbd

Please sign in to comment.