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

Change how insertion is made to OwnerTeamsList storage for add_new_team extrinsic #19

Open
dharjeezy opened this issue Apr 9, 2023 · 3 comments

Comments

@dharjeezy
Copy link

In the add add_new_team extrinsic we are mutating the storage and assuming the owner of the team to add exists in storage. We need to change this as causes panic in tests.

Reference is in this part of the code https://github.com/totem-tech/totem-parachains/blob/add-back-totem-pallets/pallets/teams/src/lib.rs#L154

OwnerTeamsList::<T>::mutate_or_err(&who, |owner_teams_list| {
                owner_teams_list.push(team_hash)
})?;

We probably need to insert into the storage directly or make sure when we are mutating, we don't return an error when value does not exist and just insert into storage for the add_new_teamextrinsic

@dharjeezy
Copy link
Author

dharjeezy commented May 20, 2023

The error it fails with is

panicked at 'Expected Ok(_). Got Err(
    DispatchErrorWithPostInfo {
        post_info: PostDispatchInfo {
            actual_weight: None,
            pays_fee: Pays::Yes,
        },
        error: Other(
            "Cannot recover the value",
        ),
    },
)'

This also occurs in pallet timekeeping when trying to insert into WorkerTeamsBacklogList and TeamInvitesList in notify_team_worker extrinsic

This also occurs in pallet timekeeping when trying to insert into WorkerTimeRecordsHashList, TeamTimeRecordsHashList in submit_time extrinsic

This also occurs in pallet timekeeping when trying to insert into TeamWorkersList in store_worker_acceptance function

@dharjeezy
Copy link
Author

The better way to insert should be this

OwnerTeamsList::<T>::try_mutate(&who, |teams| -> DispatchResult {
				match teams {
					Some(ref mut team_hashes) => {
						team_hashes.push(team_hash);
						Ok(())
					},
					None => {
						let new_team_hash = vec![team_hash];
						*teams = Some(new_team_hash);
						Ok(())
					}
				}
			})?;

@dharjeezy
Copy link
Author

This also occurs in pallet prefunding when trying to insert into the storage of OwnerPrefundingHashList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant