Skip to content

Commit

Permalink
Merge branch 'tiago/hotfix-trigger-nut-vp' (#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Aug 30, 2023
2 parents 5bcbcf8 + bfc99e7 commit 8e34ca5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/1854-hotfix-trigger-nut-vp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Trigger the NUT VP when NUTs are moved between accounts during wasm
transaction execution ([\#1854](https://github.com/anoma/namada/pull/1854))
12 changes: 10 additions & 2 deletions core/src/ledger/storage/write_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,15 @@ impl WriteLog {
// get changed keys grouped by the address
for key in changed_keys.iter() {
// for token keys, trigger Multitoken VP and the owner's VP
if let Some([_, owner]) = is_any_token_balance_key(key) {
//
// TODO: this should not be a special case, as it is error prone.
// any internal addresses corresponding to tokens which have
// native vp equivalents should be automatically added as verifiers
if let Some([token, owner]) = is_any_token_balance_key(key) {
if matches!(&token, Address::Internal(InternalAddress::Nut(_)))
{
verifiers.insert(token.clone());
}
verifiers
.insert(Address::Internal(InternalAddress::Multitoken));
verifiers.insert(owner.clone());
Expand All @@ -545,7 +553,7 @@ impl WriteLog {
verifiers
.insert(Address::Internal(InternalAddress::Multitoken));
} else {
for addr in &key.find_addresses() {
for addr in key.iter_addresses() {
if verifiers_from_tx.contains(addr)
|| initialized_accounts.contains(addr)
{
Expand Down
19 changes: 11 additions & 8 deletions core/src/types/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,17 @@ impl Key {

/// Returns the addresses from the key segments
pub fn find_addresses(&self) -> Vec<Address> {
let mut addresses = Vec::new();
for s in &self.segments {
match s {
DbKeySeg::AddressSeg(addr) => addresses.push(addr.clone()),
_ => continue,
}
}
addresses
self.iter_addresses().cloned().collect()
}

/// Iterates over all addresses in the key segments
pub fn iter_addresses<'k, 'this: 'k>(
&'this self,
) -> impl Iterator<Item = &'_ Address> + 'k {
self.segments.iter().filter_map(|s| match s {
DbKeySeg::AddressSeg(addr) => Some(addr),
_ => None,
})
}

/// Return the segment at the index parameter
Expand Down

0 comments on commit 8e34ca5

Please sign in to comment.