Conversation
also add some key computation
|
The bot added |
| next_wakeup: Tick, | ||
| our_assignment: Option<OurAssignment>, | ||
| // `n_validators` bits. | ||
| assignments: BitVec<BitOrderLsb0, u8>, |
There was a problem hiding this comment.
We could discuss this feature further, and even if we keep it caching the assignments remains fine, but in my design no-shows giving approval votes can unassign some no show replacements.
There was a problem hiding this comment.
That's still maintained in the logic PR that follows, because we always compute a mask over this bit-vec based on the tranches we take.
There was a problem hiding this comment.
polkadot/node/core/approval-voting/src/aux_schema/mod.rs
Lines 83 to 93 in b854306
| session: SessionIndex, | ||
| // Assignments are based on blocks, so we need to track assignments separately | ||
| // based on the block we are looking at. | ||
| block_assignments: BTreeMap<Hash, ApprovalEntry>, |
There was a problem hiding this comment.
I suppose the Hash here is the hash of the relay chain block where inclusion happens? It's ambiguous form this comment.
There was a problem hiding this comment.
Yes, that's right. In our code-base Hash is block hash and CandidateHash is candidate hash.
There was a problem hiding this comment.
Would it be worthwhile to define a BlockHash newtype adjacent to CandidateHash? It won't change anything re: type safety, but it might make it even harder to confuse what each hash represents.
There was a problem hiding this comment.
"worthwhile" is always a question of opportunity cost :) . I wouldn't object to such a change, but I don't think it's in the scope of this PR.
There was a problem hiding this comment.
Agree, that would be its own thing. I'll extract an issue.
| // A bitfield where the i'th bit corresponds to the i'th candidate in `candidates`. | ||
| // The i'th bit is `true` iff the candidate has been approved in the context of this | ||
| // block. The block can be considered approved if the bitfield has all bits set to `true`. | ||
| approved_bitfield: BitVec<BitOrderLsb0, u8>, |
There was a problem hiding this comment.
Actually either all bits for which self.candidates.binary_search_by(|probe| probe.0.cmp(&i)).is_ok() holds or else all bits but we set any missing cores initially.
I should double check when these bits get set later.
There was a problem hiding this comment.
This bitfield is by candidates, not by cores. So if there were candidates included from cores [1, 3, 7], then the bit-field would have 3 bits corresponding to each of those, respectively. I think all bits is correct with that in mind, but I might misunderstand the purpose of the binary search snippet you posted if it's not for checking existence of the core in the included candidates set.
It does mean that every time we want to mark a candidate as approved, we have an extra search of the candidate set for each block entry a candidate appears in, but that's contiguous memory and would be dwarfed by the cost of writing that metadata to disk.
There was a problem hiding this comment.
I only meant that approved_bitfield could be initialized to zero for bits representing existent candidates and one for bits representing non-existent candidates. I just assumed candidates would always be indexed by core in this stage. Appears you're indexing by some other candidate index, which yes makes BitVec's length is equivalent to presetting non-existent candidates to one. I see..
There was a problem hiding this comment.
From the outside of this struct, we do lookup by core, but we have to do an internal look-up via the candidates vec first, which is cheap.
| #### `OverseerSignal::BlockFinalized` | ||
|
|
||
| On receiving an `OverseerSignal::BlockFinalized(h)`, we fetch the block number `b` of that block from the ChainApi subsystem. We update our `StoredBlockRange` to begin at `b+1`. Additionally, we remove all block entries and candidates referenced by them up to and including `b`. Lastly, we prune out all descendents of `h` transitively: when we remove a `BlockEntry` with number `b` that is not equal to `h`, we recursively delete all the `BlockEntry`s referenced as children. We remove the `block_assignments` entry for the block hash and if `block_assignments` is now empty, remove the `CandidateEntry`. | ||
| On receiving an `OverseerSignal::BlockFinalized(h)`, we fetch the block number `b` of that block from the ChainApi subsystem. We update our `StoredBlockRange` to begin at `b+1`. Additionally, we remove all block entries and candidates referenced by them up to and including `b`. Lastly, we prune out all descendents of `h` transitively: when we remove a `BlockEntry` with number `b` that is not equal to `h`, we recursively delete all the `BlockEntry`s referenced as children. We remove the `block_assignments` entry for the block hash and if `block_assignments` is now empty, remove the `CandidateEntry`. We also update each of the `BlockNumber -> Vec<Hash>` keys in the database to reflect the blocks at that height, clearing if empty. |
There was a problem hiding this comment.
We keep an checks running however I guess. We should also keep the erasure coded pieces and the outgoing messages sent by blocks for another 24 hours or whatever our XCMP window is.
There was a problem hiding this comment.
We keep around the data but don't do any checks after finality anymore.
coriolinus
left a comment
There was a problem hiding this comment.
Some nits, but nothing essential. Looks like a reasonable implementation of a data store backed by AuxStore for the types described in the guide.
| polkadot-overseer = { path = "../../overseer" } | ||
| polkadot-primitives = { path = "../../../primitives" } | ||
| polkadot-node-primitives = { path = "../../primitives" } | ||
| bitvec = "0.17.4" |
There was a problem hiding this comment.
nit: bitvec should go among the external dependencies, not among the polkadot dependencies.
| sp-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
| sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
|
|
||
| [dev-dependencies] No newline at end of file |
There was a problem hiding this comment.
nit: text files should have trailing newlines.
Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
This change-set became large on its own. This is implementing the described database and operations from the Approval Voting subsystem, against the
AuxStoretrait.Main points to review:
fn clearfn canonicalizeActiveLeavesUpdatelogic is fulfilled byfn add_block_entryRelated to #1975