-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sync): Sync latest globals within merkle tree ops (#1612)
## Overview Ci has been failing due to a race condition where world state operations were not being synchronised. The offending value was that the world latestGlobalVariablesHash was not stored with the rest of the merkle trees, and such could not use the same serial queue to sync their update operations. This lead to the trees being out of sync with the globals value on some occasions. (I think) This pr may be slightly contraversial as it stores non merkle tree data within the merkle_trees abstraction. However think the naming of the merkle_trees abstraction is the limiting factor. The file just stores and synchronises the world state, it just so happens that until now this state was all trees. (although this could be me bending reality to suit my current needs) Adds a Committable type which allows us to add rollback functionality to anything
- Loading branch information
Showing
14 changed files
with
211 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
yarn-project/foundation/src/committable/committable.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Committable } from './committable.js'; | ||
|
||
describe('committable', () => { | ||
it('include uncommitted should work as expected', () => { | ||
const committableNumber: Committable<number> = new Committable(0); | ||
|
||
// Check the initial value is 0 | ||
expect(committableNumber.get(true)).toBe(0); | ||
|
||
// Update the value to 1 | ||
committableNumber.set(1); | ||
committableNumber.commit(); | ||
|
||
// Check the value is 1 | ||
expect(committableNumber.get()).toBe(1); | ||
|
||
// Test include uncommitted | ||
committableNumber.set(2); | ||
expect(committableNumber.get(true)).toBe(2); | ||
expect(committableNumber.get(false)).toBe(1); | ||
|
||
committableNumber.commit(); | ||
expect(committableNumber.get()).toBe(2); | ||
|
||
// Test rollback | ||
committableNumber.set(3); | ||
expect(committableNumber.get(true)).toBe(3); | ||
expect(committableNumber.get(false)).toBe(2); | ||
committableNumber.rollback(); | ||
expect(committableNumber.get()).toBe(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* A class that allows for a value to be committed or rolled back. | ||
*/ | ||
export class Committable<T> { | ||
private currentValue: T; | ||
private nextValue: T | undefined = undefined; | ||
|
||
constructor(initialValue: T) { | ||
this.currentValue = initialValue; | ||
} | ||
|
||
/** | ||
* Commits the uncommitted value. | ||
*/ | ||
public commit() { | ||
if (this.nextValue === undefined) { | ||
return; | ||
} | ||
this.currentValue = this.nextValue; | ||
this.nextValue = undefined; | ||
} | ||
|
||
/** | ||
* Rolls back the uncommitted value. | ||
*/ | ||
public rollback() { | ||
this.nextValue === undefined; | ||
} | ||
|
||
/** | ||
* Gets the current value. | ||
* @param includeUncommitted - Whether to include the uncommitted value. | ||
* @returns The current value if includeUncommitted is false, otherwise the uncommitted value. | ||
*/ | ||
public get(includeUncommitted: boolean = false): T { | ||
return includeUncommitted && this.nextValue ? this.nextValue : this.currentValue; | ||
} | ||
|
||
/** | ||
* Sets the next value to be committed to. | ||
* @param value - The new value to be set. | ||
*/ | ||
public set(value: T) { | ||
this.nextValue = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './committable.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.