Skip to content

Commit

Permalink
Applied initial snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
esuwu committed Dec 17, 2023
1 parent d24add1 commit f4bde2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 7 additions & 9 deletions pkg/state/appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ func (a *txAppender) commitTxApplication(
applicationStatus = applicationRes.status
)

balanceChanges := a.diffStor.allChanges()
//balanceChanges := a.diffStor.allChanges()

Check failure on line 355 in pkg/state/appender.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 355 in pkg/state/appender.go

View workflow job for this annotation

GitHub Actions / ubuntu

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 355 in pkg/state/appender.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 355 in pkg/state/appender.go

View workflow job for this annotation

GitHub Actions / ubuntu

commentFormatting: put a space between `//` and comment text (gocritic)
balanceChanges := applicationRes.changes.diff.balancesChanges()
a.diffStor.reset()
snapshot, err := a.txHandler.performTx(tx, pi, params.validatingUtx, invocationRes, applicationStatus, balanceChanges)
if err != nil {
Expand Down Expand Up @@ -671,7 +672,6 @@ func (a *txAppender) appendBlock(params *appendBlockParams) error {
}

// create the initial snapshot

initialSnapshot, err := a.txHandler.tp.createInitialBlockSnapshot(minerAndRewardDiff.balancesChanges())
if err != nil {
return errors.Wrap(err, "failed to create initial snapshot")
Expand All @@ -693,9 +693,13 @@ func (a *txAppender) appendBlock(params *appendBlockParams) error {
return err
}
// TODO validate before reset

a.diffStor.reset()

err = initialSnapshot.ApplyInitialSnapshot(a.txHandler.sa)
if err != nil {
return errors.Wrap(err, "failed to apply an initial snapshot")
}

defer hasher.Release()

// get initial snapshot hash for block
Expand All @@ -712,12 +716,6 @@ func (a *txAppender) appendBlock(params *appendBlockParams) error {
)
}

// TODO snapshot is apply in hasher
//err = initialSnapshot.ApplyInitialSnapshot(a.txHandler.sa)
//if err != nil {
// return errors.Wrap(err, "failed to apply an initial snapshot")
//}

blockV5Activated, err := a.stor.features.newestIsActivated(int16(settings.BlockV5))
if err != nil {
return err
Expand Down
14 changes: 8 additions & 6 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,10 @@ func (s *stateManager) addGenesisBlock() error {
return err
}

if err := s.appender.applyAllDiffs(); err != nil {
return err
}
// TODO validate it instead
//if err := s.appender.applyAllDiffs(); err != nil {

Check failure on line 607 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 607 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / ubuntu

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 607 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 607 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / ubuntu

commentFormatting: put a space between `//` and comment text (gocritic)
// return err
//}
if err := s.stor.prepareHashes(); err != nil {
return err
}
Expand Down Expand Up @@ -1555,9 +1556,10 @@ func (s *stateManager) addBlocks() (*proto.Block, error) {

// Apply all the balance diffs accumulated from this blocks batch.
// This also validates diffs for negative balances.
if err := s.appender.applyAllDiffs(); err != nil {
return nil, err
}
// TODO validate it instead
//if err := s.appender.applyAllDiffs(); err != nil {

Check failure on line 1560 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 1560 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / ubuntu

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 1560 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 1560 in pkg/state/state.go

View workflow job for this annotation

GitHub Actions / ubuntu

commentFormatting: put a space between `//` and comment text (gocritic)
// return nil, err
//}

// Retrieve and store legacy state hashes for each of new blocks.
if shErr := s.stor.handleLegacyStateHashes(height, ids); shErr != nil {
Expand Down

0 comments on commit f4bde2e

Please sign in to comment.