Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Get rid of targetHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsidzej committed Aug 28, 2023
1 parent c46d3b3 commit cc30848
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
11 changes: 1 addition & 10 deletions packages/uif/src/BaseIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,13 @@ export abstract class BaseIndexer implements Indexer {
}, this.updateRetryStrategy.timeoutMs())
}

// Partial invalidation scenario:

// 1. ParentIndexer parent is at height 100
// 2. ChildIndexer child is at height 100
// 3. parent invalidates to 90
// 4. child invalidates to 95
// 5. child invalidates to 90

private async executeInvalidate(effect: InvalidateEffect): Promise<void> {
this.logger.info('Invalidating', { to: effect.targetHeight })
try {
const to = await this.invalidate(effect.targetHeight)
this.dispatch({
type: 'InvalidateSucceeded',
targetHeight: effect.targetHeight,
to: to,
to,
})
this.invalidateRetryStrategy.clear()
} catch (e) {
Expand Down
21 changes: 10 additions & 11 deletions packages/uif/src/reducer/indexerReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe(indexerReducer.name, () => {
const [state, effects] = reduceWithIndexerReducer(initState, [
{ type: 'Initialized', safeHeight: 0, childCount: 0 },
{ type: 'ParentUpdated', index: 0, safeHeight: 0 },
{ type: 'InvalidateSucceeded', targetHeight: 0, to: 0 },
{ type: 'InvalidateSucceeded', to: 0 },
])

expect(state).toEqual({
Expand Down Expand Up @@ -175,7 +175,7 @@ describe(indexerReducer.name, () => {
{ type: 'Initialized', safeHeight: 50, childCount: 0 },
{ type: 'ParentUpdated', index: 0, safeHeight: 100 },
{ type: 'ParentUpdated', index: 1, safeHeight: 150 },
{ type: 'InvalidateSucceeded', targetHeight: 50, to: 50 },
{ type: 'InvalidateSucceeded', to: 50 },
])

expect(state).toEqual({
Expand Down Expand Up @@ -283,7 +283,7 @@ describe(indexerReducer.name, () => {
])

const [state2, effects2] = reduceWithIndexerReducer(state1, [
{ type: 'InvalidateSucceeded', targetHeight: 50, to: 50 },
{ type: 'InvalidateSucceeded', to: 50 },
])

expect(state2).toEqual({
Expand Down Expand Up @@ -323,7 +323,7 @@ describe(indexerReducer.name, () => {
])

const [state2, effects2] = reduceWithIndexerReducer(state1, [
{ type: 'InvalidateSucceeded', targetHeight: 50, to: 75 },
{ type: 'InvalidateSucceeded', to: 75 },
])

expect(state2).toEqual({
Expand Down Expand Up @@ -487,7 +487,7 @@ describe(indexerReducer.name, () => {

const [state1, effects1] = reduceWithIndexerReducer(initState, [
{ type: 'ParentUpdated', index: 0, safeHeight: 50 },
{ type: 'InvalidateSucceeded', targetHeight: 50, to: 75 },
{ type: 'InvalidateSucceeded', to: 75 },
{ type: 'ParentUpdated', index: 0, safeHeight: 100 },
])

Expand All @@ -503,7 +503,7 @@ describe(indexerReducer.name, () => {
expect(effects1).toEqual([])

const [state2, effects2] = reduceWithIndexerReducer(state1, [
{ type: 'InvalidateSucceeded', targetHeight: 50, to: 50 },
{ type: 'InvalidateSucceeded', to: 50 },
])

expect(state2).toEqual({
Expand Down Expand Up @@ -789,7 +789,7 @@ describe(indexerReducer.name, () => {
const [state1, effects1] = reduceWithIndexerReducer(initState, [
{ type: 'ParentUpdated', index: 0, safeHeight: 200 },
{ type: 'UpdateFailed' },
{ type: 'InvalidateSucceeded', targetHeight: 100, to: 100 },
{ type: 'InvalidateSucceeded', to: 100 },
])

expect(state1).toEqual({
Expand Down Expand Up @@ -851,7 +851,7 @@ describe(indexerReducer.name, () => {
const [state1, effects1] = reduceWithIndexerReducer(initState, [
{ type: 'ParentUpdated', index: 0, safeHeight: 200 },
{ type: 'UpdateFailed' },
{ type: 'InvalidateSucceeded', targetHeight: 100, to: 100 },
{ type: 'InvalidateSucceeded', to: 100 },
{ type: 'ParentUpdated', index: 0, safeHeight: 50 },
])

Expand All @@ -867,7 +867,7 @@ describe(indexerReducer.name, () => {
])

const [state2, effects2] = reduceWithIndexerReducer(state1, [
{ type: 'InvalidateSucceeded', targetHeight: 50, to: 50 },
{ type: 'InvalidateSucceeded', to: 50 },
{ type: 'RetryUpdate' },
// TODO: we need the 'RetryUpdate' action to arrive to set retryingUpdate to false,
// but actually, because we invalidated further down, we could just start updating straight away I guess
Expand Down Expand Up @@ -964,7 +964,7 @@ describe(indexerReducer.name, () => {
expect(effects1).toEqual([])

const [state2, effects2] = reduceWithIndexerReducer(state1, [
{ type: 'InvalidateSucceeded', targetHeight: 100, to: 100 },
{ type: 'InvalidateSucceeded', to: 100 },
])

expect(state2).toEqual({
Expand Down Expand Up @@ -1309,7 +1309,6 @@ function getAfterInit({
})),
{
type: 'InvalidateSucceeded',
targetHeight: Math.min(safeHeight, ...parentHeights),
to: Math.min(safeHeight, ...parentHeights),
},
])
Expand Down
1 change: 0 additions & 1 deletion packages/uif/src/reducer/types/IndexerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export interface RetryUpdateAction {

export interface InvalidateSucceededAction {
type: 'InvalidateSucceeded'
targetHeight: number
to: number
}

Expand Down

0 comments on commit cc30848

Please sign in to comment.