Conversation
| if maybe_insertion_position.is_none() { | ||
| return; | ||
| } | ||
| let insertion_position = maybe_insertion_position.expect("early return right above. q.e.d."); |
There was a problem hiding this comment.
refactor as a let x = match { None => return, Some(x) => x }
| /// the operation is performed as if there are no blocks greater `max_block_number` | ||
| /// ignoring all blocks with numbers greater | ||
| /// TODO [snd] possibly implement this on blockchain::Backend and just redirect here | ||
| pub fn best_containing(&self, target_hash: Block::Hash, maybe_max_number: Option<<<Block as BlockT>::Header as HeaderT>::Number>) -> error::Result<Option<Block::Hash>> { |
There was a problem hiding this comment.
I think there's a NumberFor<Block> type definition in the runtime_primitives that might be useful.
| } | ||
|
|
||
| // for each chain. longest chain first. shortest last | ||
| for leaf_hash in self.backend.blockchain().leaves()? { |
There was a problem hiding this comment.
this loop could be pre-empted by checking if the block with number target_header.number() in the "canonical" chain is target_header. Could return the "best block" in that case, or its ancestor with max_number. Although the import lock probably has to be held for safety with that approach, to ensure that a block import doesn't race against this thread and trigger a reorganization.
There was a problem hiding this comment.
i believe i tried this before by checking whether the hash of the block at target_header.number() matches target_hash:
substrate/core/client/src/client.rs
Line 593 in c051949
however self.backend.blockchain().hash(*target_header.number()) returned None
for those numbers that were not uniquely mappable to a hash i.e. there were forks and multiple hashes for that number. i'll investigate again. maybe there's a better method.
There was a problem hiding this comment.
The current blockchain backend doesn't handle forks at all, so I've been rewriting it to do so in a local branch.
There was a problem hiding this comment.
this loop could be pre-empted by checking if the block with number target_header.number() in the "canonical" chain is target_header
how do i get the header/hash that's in the canonical chain at position number?
i assumed i could do this through ...blockchain().header(BlockId::Number(number)) / ...blockchain().hash(number).
both do not seem to return the header/hash in the canonical chain but rather the header/hash that was last imported at that position.
i've added a test exposing that problem here 57e758b. note that it only tests the in-memory backend.
is this indeed a bug that should be fixed? is there another method to retrieve a block given a number in the canonical chain? should i leave out the pre-emption for now?
There was a problem hiding this comment.
both do not seem to return the header/hash in the canonical chain but rather the header/hash that was last imported at that position.
This is exactly what #760 is meant to fix; the underlying blockchain DB literally could not accommodate forks before.
There was a problem hiding this comment.
perfect! this should work out then
There was a problem hiding this comment.
pre-emption is in. the tests should pass once #760 is merged and this is rebased on it
|
when i comment in this code here https://github.com/paritytech/substrate/pull/740/files#diff-5a5b3c7041f582d3b3c912d4bf55aea8R609 which adds block C3 which is here in the block tree https://github.com/paritytech/substrate/pull/740/files#diff-5a5b3c7041f582d3b3c912d4bf55aea8R529 i get relevant part: any ideas as to why? |
|
it's not trivial to it requires removing the reverted block hash, then adding the parent again if the parent has no other children. checking the latter is expensive. we could make it faster by keeping a child counter for each block. that requires additional storage for each block however. |
|
Correct reversion should definitely prune out forks that branch off of blocks we've discarded. That's also an issue with the current implementation. @arkpar might have some ideas; I'm pretty ambivalent as long as not reverting the leaves list can't break stuff too badly. |
ok. i'll tackle this last i found a simpler and faster approach to storing the leaves in the kev-value-db. this shouldn't take much longer |
| use substrate_primitives; | ||
| use substrate_primitives::Blake2Hasher; | ||
| use codec::{Codec, Encode}; | ||
| pub use codec::{Codec, Encode, Decode}; |
There was a problem hiding this comment.
i'm not convinced we should re-export these. client already has a parity_codec dependency, perhaps it can import from there?
| // from: Keyring::Alice.to_raw_public().into(), | ||
| // to: Keyring::Ferdie.to_raw_public().into(), | ||
| // amount: 1, | ||
| // nonce: 0, |
There was a problem hiding this comment.
nonce: 1 should fix it AFAICT
There was a problem hiding this comment.
thanks. that fixed the Error(ApplyExtinsicFailed(Stale) issue
snd
left a comment
There was a problem hiding this comment.
looks great! thanks for fixing the backends to make the tests pass and finishing up the leaf list db read/write. i'd say we merge it and do further work on this in other PRs
| Ok(BlockchainDb { | ||
| db, | ||
| leaves: RwLock::new(leaves), | ||
| meta: RwLock::new(meta) |
There was a problem hiding this comment.
we tend to prefer to keep the last , on multiline lists
| db: Arc<KeyValueDB>, | ||
| meta: RwLock<Meta<<Block::Header as HeaderT>::Number, Block::Hash>>, | ||
| meta: RwLock<Meta<NumberFor<Block>, Block::Hash>>, | ||
| leaves: RwLock<LeafSet<Block::Hash, NumberFor<Block>>> |
There was a problem hiding this comment.
we tend to prefer to keep the last , on multiline lists
| let route = ::blockchain::tree_route( | ||
| self, | ||
| BlockId::Hash(best_hash), | ||
| BlockId::Hash(*header.parent_hash()) |
There was a problem hiding this comment.
we tend to prefer to keep the last , on multiline lists
| } | ||
|
|
||
| fn genesis_storage() -> StorageMap { | ||
| let mut storage = genesis_config().genesis_map(); |
gavofyork
left a comment
There was a problem hiding this comment.
Minor style nits. Code quality good and test coverage seems reasonable.
* rough draft of parachains roadmap * flesh out first 2 phases * Fix typo Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Fix typos and add clarifications Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * remove extra space Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * add XCMP work items Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* add log in parse_addr_from_script * refactor for deposit input_addr * refactor for deposit handle
#603
This pull request implements the operation for finding the best chain containing a specific block (potentially number-limited to a given block). This is usually the best chain.
This also adds a number of cross-backend tests in the
test-clientcrate used to ensure that behavior is consistent across them.