Skip to content

Commit

Permalink
default to finalzied head (#881)
Browse files Browse the repository at this point in the history
* default to finalzied head

* update endpoint

* fix
  • Loading branch information
xlc authored Feb 10, 2025
1 parent 968b65d commit 4552a27
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export class Api {
return this.send<Header | null>('chain_getHeader', hash ? [hash] : [], !!hash)
}

async getFinalizedHead() {
return this.send<string>('chain_getFinalizedHead', [])
}

async getBlock(hash?: string) {
return this.send<SignedBlock | null>('chain_getBlock', hash ? [hash] : [], !!hash)
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/genesis-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class GenesisProvider implements ProviderInterface {
case 'chain_getBlock':
return this.getBlock()
case 'chain_getBlockHash':
case 'chain_getFinalizedHead':
return this.blockHash
case 'state_getKeysPaged':
case 'state_getKeysPagedAt': {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const processOptions = async (options: SetupOptions) => {

let blockHash: string
if (options.block == null) {
blockHash = await api.getBlockHash().then((hash) => {
blockHash = await api.getFinalizedHead().then((hash) => {
if (!hash) {
// should not happen, but just in case
throw new Error('Cannot find block hash')
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/connect-horizontal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('connectHorizontal', () => {
},
})
const zeitgeist = await setupContext({
endpoint: ['wss://main.rpc.zeitgeist.pm/ws', 'wss://zeitgeist.api.onfinality.io/public-ws'],
endpoint: ['wss://zeitgeist.api.onfinality.io/public-ws'],
blockNumber: 5084336,
db: !process.env.RUN_TESTS_WITHOUT_DB ? 'e2e-tests-db.sqlite' : undefined,
})
Expand Down

0 comments on commit 4552a27

Please sign in to comment.