Skip to content

Commit

Permalink
Small bug in rollback was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Apr 17, 2017
1 parent 33437de commit adaaa53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,36 @@ class StoredState(protected[blockchain] val storage: StateStorageI with OrderMat
}
}

private def deleteAtHeight(height: Int, key: Address): Unit = {
val changes = storage.removeAccountChanges(key, height)
changes.reason.foreach(id => {
storage.getTransaction(id) match {
case Some(t: AssetIssuance) =>
assetsExtension.rollback(t, height)
case Some(t: BurnTransaction) =>
assetsExtension.rollback(t, height)
case Some(t: LeaseTransaction) =>
leaseExtendedState.cancelLease(t)
case Some(t: LeaseCancelTransaction) =>
leaseExtendedState.cancelLeaseCancel(t)
case _ =>
}
storage.removeTransaction(id)
})
val prevHeight = changes.lastRowHeight
storage.putLastStates(key, prevHeight)
}

def rollbackTo(rollbackTo: Int): State = synchronized {
val startHeight = storage.stateHeight

for (h <- startHeight until rollbackTo by -1) {
storage.lastStatesKeys.filter(storage.getLastStates(_).getOrElse(0) == h).foreach { key =>
deleteAtHeight(h, key)
}
storage.setStateHeight(h)

storage.setStateHeight(h - 1)
}

def deleteAtHeight(height: Int, key: Address): Unit = {
val changes = storage.removeAccountChanges(key, height)
changes.reason.foreach(id => {
storage.getTransaction(id) match {
case Some(t: AssetIssuance) =>
assetsExtension.rollback(t, height)
case Some(t: BurnTransaction) =>
assetsExtension.rollback(t, height)
case Some(t: LeaseTransaction) =>
leaseExtendedState.cancelLease(t)
case Some(t: LeaseCancelTransaction) =>
leaseExtendedState.cancelLeaseCancel(t)
case _ =>
}
storage.removeTransaction(id)
})
val prevHeight = changes.lastRowHeight
storage.putLastStates(key, prevHeight)
}

this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ class StoredStateUnitTests extends PropSpec with PropertyChecks with GeneratorDr
val h = state.hash
var lastFinalStateHash: Option[Int] = None
for {i <- 1 to retries} {
log.info(s"Iteration $i of test with rollback")
try {
test
} catch {
Expand Down

0 comments on commit adaaa53

Please sign in to comment.