Skip to content

Commit d2db904

Browse files
authored
fix: Update state store after applying update (#3052)
1 parent c3dc51f commit d2db904

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/core/src/state-management/repository.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ export class Repository {
531531
this.logger.verbose(`Learned of new tip ${cid} for stream ${state$.id}`)
532532
const next = await this.streamUpdater.applyTipFromNetwork(state$.state, cid)
533533
if (next) {
534-
await this._updateStateIfPinned(state$)
535534
state$.next(next)
535+
await this._updateStateIfPinned(state$)
536536
this.logger.verbose(`Stream ${state$.id} successfully updated to tip ${cid}`)
537537
return true
538538
} else {
@@ -720,8 +720,12 @@ export class Repository {
720720
tip: CID,
721721
witnessCAR: CAR | undefined
722722
): Promise<void> {
723+
const streamId = StreamUtils.streamIdFromState(state$.state)
723724
const anchorCommitCID = witnessCAR.roots[0]
724725
if (!anchorCommitCID) throw new Error(`No anchor commit CID as root`)
726+
727+
this.logger.verbose(`Handling anchor commit for ${streamId} with CID ${anchorCommitCID}`)
728+
725729
for (
726730
let remainingRetries = APPLY_ANCHOR_COMMIT_ATTEMPTS - 1;
727731
remainingRetries >= 0;
@@ -730,6 +734,7 @@ export class Repository {
730734
try {
731735
if (witnessCAR) {
732736
await this.dispatcher.importCAR(witnessCAR)
737+
this.logger.verbose(`successfully imported CAR file for ${streamId}`)
733738
}
734739

735740
const applied = await this._handleTip(state$, anchorCommitCID)
@@ -742,6 +747,12 @@ export class Repository {
742747
// If we failed to apply the commit at least once, then it's worth logging when
743748
// we are able to do so successfully on the retry.
744749
this.logger.imp(
750+
`Successfully applied anchor commit ${anchorCommitCID} for stream ${
751+
state$.id
752+
} after ${APPLY_ANCHOR_COMMIT_ATTEMPTS - remainingRetries} attempts`
753+
)
754+
} else {
755+
this.logger.verbose(
745756
`Successfully applied anchor commit ${anchorCommitCID} for stream ${state$.id}`
746757
)
747758
}

0 commit comments

Comments
 (0)