Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/stores/useBaseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ export const useBaseStore = defineStore('baseStore', {
async fetchLatest() {
if (!this.hasRpc) return this.latest;
try {
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
const latest = await this.blockchain.rpc?.getBaseBlockLatest();
// A malformed 200 - an error body, a rate-limit page, a truncated
// response - would otherwise be stored as `latest`. The chain_id
// comparison below would then see undefined against the previous chain,
// wipe earliest/recents and reset the average block time to the 1000ms
// placeholder. Treat it as a failed poll instead.
//
// chain_id is checked as well as height: it is specifically the missing
// chain_id that trips that reset, so a partial payload carrying a height
// but no chain_id would otherwise still cause the state loss this guards.
const header = latest?.block?.header;
if (!header?.height || !header?.chain_id) {
throw new Error('malformed blocks/latest payload');
}
this.latest = latest;
this.connected = true;
} catch (error) {
console.error('Error fetching latest block:', error);
Expand Down
Loading