-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: stop calling public kernels #9971
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,13 @@ export class SequencerClient { | |
contractDataSource: ContractDataSource, | ||
l2BlockSource: L2BlockSource, | ||
l1ToL2MessageSource: L1ToL2MessageSource, | ||
simulationProvider: SimulationProvider, | ||
_simulationProvider: SimulationProvider, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Do we have plans to remove this? Or will it be used in another PR? |
||
telemetryClient: TelemetryClient, | ||
) { | ||
const publisher = new L1Publisher(config, telemetryClient); | ||
const globalsBuilder = new GlobalVariableBuilder(config); | ||
|
||
const publicProcessorFactory = new PublicProcessorFactory(contractDataSource, simulationProvider, telemetryClient); | ||
const publicProcessorFactory = new PublicProcessorFactory(contractDataSource, telemetryClient); | ||
|
||
const rollup = publisher.getRollupContract(); | ||
const [l1GenesisTime, slotDuration] = await Promise.all([ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ export class AvmPersistableStateManager { | |
/** Interface to perform merkle tree operations */ | ||
public merkleTrees: MerkleTreeWriteOperations; | ||
|
||
/** Make sure a forked state is never merged twice. */ | ||
private alreadyMergedIntoParent = false; | ||
|
||
constructor( | ||
/** Reference to node storage */ | ||
private readonly worldStateDB: WorldStateDB, | ||
|
@@ -79,16 +82,46 @@ export class AvmPersistableStateManager { | |
/** | ||
* Create a new state manager forked from this one | ||
*/ | ||
public fork(incrementSideEffectCounter: boolean = false) { | ||
public fork() { | ||
return new AvmPersistableStateManager( | ||
this.worldStateDB, | ||
this.trace.fork(incrementSideEffectCounter), | ||
this.trace.fork(), | ||
this.publicStorage.fork(), | ||
this.nullifiers.fork(), | ||
this.doMerkleOperations, | ||
); | ||
} | ||
|
||
/** | ||
* Accept forked world state modifications & traced side effects / hints | ||
*/ | ||
public merge(forkedState: AvmPersistableStateManager) { | ||
this._merge(forkedState, /*reverted=*/ false); | ||
} | ||
|
||
/** | ||
* Reject forked world state modifications & traced side effects, keep traced hints | ||
*/ | ||
public reject(forkedState: AvmPersistableStateManager) { | ||
this._merge(forkedState, /*reverted=*/ true); | ||
} | ||
|
||
/** | ||
* Commit cached storage writes to the DB. | ||
* Keeps public storage up to date from tx to tx within a block. | ||
*/ | ||
public async commitStorageWritesToDB() { | ||
await this.publicStorage.commitToDB(); | ||
} | ||
|
||
private _merge(forkedState: AvmPersistableStateManager, reverted: boolean) { | ||
// sanity check to avoid merging the same forked trace twice | ||
assert(!this.alreadyMergedIntoParent, 'Cannot merge forked state that has already been merged into its parent!'); | ||
Comment on lines
+118
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm so, this.merge merges forkedState INTO this, IIUC? Why does it matter if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where alreadyMergedIntoParent is set to true (for the journal itself, I see it for the trace). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parent doesn't keep track of its forks. And it could have children formed and merged multiple times. We just don't want to let a specific fork get merged multiple times. And good catch, I must've missed that in journal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right. I was confused. It should check forkedState.alreadyMerged! Good catch. |
||
this.publicStorage.acceptAndMerge(forkedState.publicStorage); | ||
this.nullifiers.acceptAndMerge(forkedState.nullifiers); | ||
this.trace.merge(forkedState.trace, reverted); | ||
} | ||
|
||
/** | ||
* Write to public storage, journal/trace the write. | ||
* | ||
|
@@ -427,21 +460,6 @@ export class AvmPersistableStateManager { | |
} | ||
} | ||
|
||
/** | ||
* Accept nested world state modifications | ||
*/ | ||
public mergeForkedState(forkedState: AvmPersistableStateManager) { | ||
this.publicStorage.acceptAndMerge(forkedState.publicStorage); | ||
this.nullifiers.acceptAndMerge(forkedState.nullifiers); | ||
this.trace.mergeSuccessfulForkedTrace(forkedState.trace); | ||
} | ||
|
||
public rejectForkedState(forkedState: AvmPersistableStateManager) { | ||
this.publicStorage.acceptAndMerge(forkedState.publicStorage); | ||
this.nullifiers.acceptAndMerge(forkedState.nullifiers); | ||
this.trace.mergeRevertedForkedTrace(forkedState.trace); | ||
} | ||
|
||
/** | ||
* Get a contract's bytecode from the contracts DB, also trace the contract class and instance | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be marked as "to be deleted"?