Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pink: instance id = hash(group id + ink address) #595

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/phactory/src/contracts/pink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ impl Pink {
Self { instance, group }
}

pub fn address_to_id(address: &AccountId) -> ContractId {
let inner: &[u8; 32] = address.as_ref();
inner.into()
pub fn address_to_id(address: &AccountId, group: &ContractGroupId) -> ContractId {
let mut buffer: Vec<u8> = group.encode();
address.encode_to(&mut buffer);
sp_core::blake2_256(&buffer).into()
}
}

Expand All @@ -76,7 +77,7 @@ impl contracts::NativeContract for Pink {
type QResp = Result<Response, QueryError>;

fn id(&self) -> ContractId {
Pink::address_to_id(&self.instance.address)
Pink::address_to_id(&self.instance.address, &self.group)
}

fn group_id(&self) -> Option<phala_mq::ContractGroupId> {
Expand Down
2 changes: 1 addition & 1 deletion crates/phactory/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ pub fn apply_pink_side_effects(
}

for (address, event) in effects.pink_events {
let id = Pink::address_to_id(&address);
let id = Pink::address_to_id(&address, &group_id);
let contract = match contracts.get_mut(&id) {
Some(contract) => contract,
None => {
Expand Down