-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Remove &mut constraint from BlockImport API #6521
Conversation
|
Can you point me to the original code you show in the description for why this is needed? |
|
@andresilva I just update the description: here is the code. |
|
So I'm not entirely sure why the API required a &mut reference in the first place, maybe someone else can explain. |
|
@seunlanlege #3058 |
@andresilva Yes and no:
|
|
https://github.com/paritytech/substrate/blob/master/client/finality-grandpa/src/import.rs#L59 And also from polkadot using test client: https://github.com/paritytech/polkadot/blob/master/node/service/src/grandpa_support.rs#L249 I think you need to look into the |
I just can't use any of them, I tried. I already spent hours and hours trying everything and I just can't use those traits. If anyone has a solution I would be very happy too and will probably close this PR. Also you're not explaining why this has been converted an an &mut. I would really like to know that to understand the big picture. Right now it looks like it's the right thing to do because all the other impl for PolkadotClient look very alike (without the `for<'r> &'r Client: syntax). As you can see here. |
Parent branch: origin/master Forked at: 606c56d
|
Before modifying a trait to take
The reason is that, for any non-idempotent method, |
I did consider it. As I said, I spent hours on this and I am really open to a solution but I can't find one. What you say makes sense but what I understand of the issue is that Arc does not impl DerefMut and therefore there is no way I could possibly call those method on it (since they require a mutable reference). If you want to give it a shot: I need to change the trait PolkadotClient here so it impl BlockImport and I can call
I think I understand your point... if it wasn't wrapped in an Arc everything would be fine. |
You would pass a
Maybe re-define the |
|
|
|
Overall this is what's happening: As you can see on the first example in main it is able to call |
|
Thanks to everybody for having tried to help me find a solution to this issue. Big update: I won't re-open this ticket at all because importing a block was not what I needed to do for my task. 🙃 Mistakes were made! |

Use case
I'm trying to make an integration test in cumulus where I run multiple full nodes and I need to register a block. For that I would like to use the
importmethod of the traitClientBlockImportExtwhich depends onBlockImport. If I can't, I want to be able to use at least the methodimport_blockfromBlockImport.In polkadot I have extended the trait PolkadotClient to impl BlockImport. But no matter what I put there, I couldn't get it working.
The error
(The particular error come from this code)
This problem occurs because the API of block import requires that
selfis given as mutable reference (&mut self) and you can't access it if it's wrapped in anArc(that's because Arc does not implementDerefMutbut onlyDeref). Unfortunately, the client is, afaik, always wrapped in an Arc except in our tests.Solution proposed
The mutable reference requirement is actually not needed. I could remove it without breaking anything. So, to solve this problem I replaced all the mutable reference to self in all methods of the traits BlockImport and ClientBlockImportExt. Everything works just fine but I had to do a lot of changes everywhere.
I also changed some tests so they use an
Arc<Client>instead of a simple Client. Often they were going to be wrapped in an Arc anyway.Companion PR: paritytech/polkadot#1319