Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Expose parent hash on the Config::Header trait (parent_hash())

Aperta
#2,242 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di paritytech/subxt

Tutte le issue di paritytech/subxt

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.