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:
Etan Kissling 2022-03-07 14:56:58 +01:00 committed by GitHub
parent 7d7bfa1299
commit 8955edf158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -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