-
Notifications
You must be signed in to change notification settings - Fork 254
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
Issue querying storage with tuple key #446
Comments
Hey, thanks for raising an issue! Would it be possible for you to provide some steps for us to be able to reproduce this issue ourselves? |
Okay so here is simple substrate pallet with a storage map that takes a tuple for key. I also wrote unit tests that ensure insert and retrieval works as expected. wzli/substrate-node-template@aa9e5f6 on the subxt side, using v0.17, here's the code use sp_keyring::AccountKeyring;
use subxt::{ClientBuilder, DefaultConfig, DefaultExtra, PairSigner};
#[subxt::subxt(runtime_metadata_path = "metadata.scale")]
pub mod runtime {}
#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let signer = PairSigner::<DefaultConfig, DefaultExtra<DefaultConfig>, _>::new(
AccountKeyring::Alice.pair(),
);
let api = ClientBuilder::new()
.set_url("ws://localhost:9944")
.build()
.await?
.to_runtime_api::<runtime::RuntimeApi<DefaultConfig, DefaultExtra<DefaultConfig>>>();
let test_val = 500;
let tx_result = api
.tx()
.template_module()
.insert(test_val)
.sign_and_submit_then_watch(&signer)
.await?
.wait_for_finalized_success()
.await;
let inserted_event = tx_result?
.find_first_event::<runtime::template_module::events::SomethingInserted>()?
.unwrap();
let runtime::template_module::events::SomethingInserted((acc_id, nonce), _) = inserted_event;
let val = api
.storage()
.template_module()
.tuple_map(acc_id, nonce, None)
.await?;
println!("sent {test_val:?} got {val:?}");
let mut map = api.storage().template_module().tuple_map_iter(None).await?;
while let Some(x) = map.next().await? {
println!("{x:?}");
}
Ok(())
} Think you guys can pick up from here. In the example code, the print saids "sent 500 got None", even though iterating the map proves insert was successful. |
Thanks @wzli, that's very handy! I'll try to get to this in the next few days. |
Ok, so I've dug into this a little. I haven't fully wrapped my head around it, but the issue seems to stem from the fact that the generated code for that pub struct TupleMap(
pub ::subxt::sp_core::crypto::AccountId32,
pub ::core::primitive::u32,
);
impl ::subxt::StorageEntry for TupleMap {
const PALLET: &'static str = "TemplateModule";
const STORAGE: &'static str = "TupleMap";
type Value = ::core::primitive::u32;
fn key(&self) -> ::subxt::StorageEntryKey {
::subxt::StorageEntryKey::Map(vec![::subxt::StorageMapKey::new(
&self.0,
::subxt::StorageHasher::Twox64Concat,
)])
}
} But the pub struct TupleMap(
pub ::subxt::sp_core::crypto::AccountId32,
pub ::core::primitive::u32,
);
impl ::subxt::StorageEntry for TupleMap {
const PALLET: &'static str = "TemplateModule";
const STORAGE: &'static str = "TupleMap";
type Value = ::core::primitive::u32;
fn key(&self) -> ::subxt::StorageEntryKey {
::subxt::StorageEntryKey::Map(vec![::subxt::StorageMapKey::new(
&(&self.0, self.1),
::subxt::StorageHasher::Twox64Concat,
)])
}
} When I point your example code at my generated code with said change applied, we get back I'll need to wrap my head around the storage generation code to work out what's going on here, and why this is the case. It does appear to be a bug in |
The bug is because it is incorrectly assuming that a tuple key belongs to a What it should do is check how many hashers there are, if there is 1 then it is a regular This is the kind of thing that will need a test, as demonstrated by this bug... |
I'm on subxt release 0.17, generated metadata on the same version, my runtime is based on node-template 4.0.0
The storage is defined as:
In the substrate unit tests, inserting and retrieving from the same tuple key there is no problems, but in subxt the same query returns None, even though the insert is successful when I check by iterating all storage entries.
Anything else I can provide to help debug?
The text was updated successfully, but these errors were encountered: