Expose parent hash on the Config::Header trait (parent_hash())
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- rust
- Ambito
- api, backend-api-design
Direzione di ricerca
Inizia individuando il trait Config::Header e la sua implementazione SubstrateHeader, quindi esamina il tipo Hash associato proposto e l’API parent_hash(). Esegui cargo check --workspace --exclude test-runtime e cargo test -p subxt --lib; il completamento con successo significa che la decisione sull’API è accettata, che l’implementazione nel repository funziona e che il doctest esistente di runtime_path continua a essere considerato non correlato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
The Config::Header trait only exposes number(). There's no way to read a
header's parent hash generically over T::Header — it's only available as a
public field on the concrete SubstrateHeader. I'd like to propose adding a
parent_hash() accessor (plus an associated hash type) to the trait.
What I was building / why I hit this
I'm building a Rust, code-first Substrate indexer framework on top of subxt
(kunal171/subdex). To stay reorg-safe,
the indexer validates chain continuity by comparing each incoming block's
parent_hash against the hash it stored for the previous height; on a mismatch it
rolls back and re-syncs the corrected chain.
I wanted the ingestion layer to be generic over subxt::Config (so it works for
any chain): client.blocks() → block.header() → T::Header. But:
fn parent_of<T: subxt::Config>(h: &T::Header) -> ??? {
// not possible — Header only exposes number()
}
The only workaround is to abandon the generic abstraction and hard-code a concrete
config (e.g. PolkadotConfig) so I can touch SubstrateHeader's parent_hash
field directly — which defeats the purpose of Config being generic and is awkward
for any tool that wants to support arbitrary chains.
Current state
pub trait Header: Sized + Encode + Decode + Debug + Sync + Send + DeserializeOwned + Clone {
fn number(&self) -> u64;
}
number() is exposed, but parent_hash (which every Substrate header carries,
right next to the number) is not.
Proposed change
Add an associated hash type + accessor:
pub trait Header: ... {
type Hash: Hash;
fn number(&self) -> u64;
fn parent_hash(&self) -> Self::Hash;
}
implemented for SubstrateHeader<H> as type Hash = H, returning the existing
field (Hash already requires Copy, so it's a by-value return).
This is a breaking trait change (external Header impls would need to add the
associated type + method), but it's small and SubstrateHeader is the only in-repo
implementor. I'm also open to alternatives — e.g. tying the hash type to
Config::Hasher instead of a new associated type — whichever you prefer.
Status
I have a working implementation that passes cargo check --workspace --exclude test-runtime and cargo test -p subxt --lib (30 passed). The only failing doctest
(runtime_path field in subxt/src/lib.rs) fails identically on current master,
so it's pre-existing and unrelated.
Happy to open a PR shortly once there's agreement on the API shape. Would a
contribution along these lines be welcome?
- Lingua principale
- Rust
- Stelle
- 490
- Fork
- 292
- Merge medio
- 8h 33m
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di paritytech/subxt
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
paritytech/subxt#2238 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
paritytech/subxt#2297 ·
-
Support transaction extensions that authorize over the inherited implicationForse già presa @TarikGul l’ha presa 4 giorni fa. Aperta
paritytech/subxt#2295 · 1 assegnatario ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
paritytech/subxt#2291 ·
-
View functions don't work as expectedForse già presa @RaphaelFakhri l’ha presa 5 giorni fa. Aperta
Difficoltà 4/5 1-2 giorni Idoneità per principianti 35/100
paritytech/subxt#2290 ·
Tutte le issue di paritytech/subxt
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Y-ASLant/ElegantClipboard#178 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
linxiv-dev/linXiv#384 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug drawings ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#1595 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
smoltcp-rs/smoltcp#1235 ·
I maintainer di solito rispondono entro 1 giorno
-
scope:core type:security
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno