allow using `BlockId` as key in tables (#3467)
`BlockId` is a type that bundles a block root with its slot number. The type can be useful as key in tables that deal with non-finalized blocks (not uniquely identified by slot) and also support pruning (drop data about older blocks by slot). Instead of creating a custom type for those use cases, this patch suggests implementing `hash` for `BlockId` to re-use the existing type.
This commit is contained in:
parent
7d7bfa1299
commit
8955edf158
|
@ -55,6 +55,9 @@ type
|
|||
## Slot time for this BlockSlot which may differ from blck.slot when time
|
||||
## has advanced without blocks
|
||||
|
||||
func hash*(bid: BlockId): Hash =
|
||||
hash(bid.root)
|
||||
|
||||
template root*(blck: BlockRef): Eth2Digest = blck.bid.root
|
||||
template slot*(blck: BlockRef): Slot = blck.bid.slot
|
||||
|
||||
|
|
Loading…
Reference in New Issue