Skip to content

Commit 91de4b3

Browse files
committed
Merge branch 'master' of github.com:input-output-hk/scrypto
2 parents 1a75a1f + 43c5bb9 commit 91de4b3

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/main/scala/scorex/crypto/authds/avltree/batch/AuthenticatedTreeOps.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package scorex.crypto.authds.avltree.batch
22

33
import scorex.crypto.authds.{Balance, _}
4-
import scorex.crypto.encode.Base16
54
import scorex.crypto.hash.Digest
6-
import scorex.utils.{ByteArray, ScryptoLogging}
5+
import scorex.utils.ByteArray
76

87
import scala.collection.mutable.ArrayBuffer
98
import scala.util.{Failure, Success, Try}
@@ -13,7 +12,7 @@ import scala.util.{Failure, Success, Try}
1312
* Code common to the prover and verifier of https://eprint.iacr.org/2016/994
1413
* (see Appendix B, "Our Algorithms")
1514
*/
16-
trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with ScryptoLogging {
15+
trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with ToStringHelper {
1716

1817
type ChangeHappened = Boolean
1918
type HeightIncreased = Boolean
@@ -39,17 +38,17 @@ trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with Scrypto
3938
protected def onNodeVisit(n: Node[D], operation: Operation, isRotate: Boolean = false): Unit = {
4039
n match {
4140
case p: ProverNodes[D] if collectChangedNodes && !n.visited && !p.isNew =>
42-
if (isRotate) {
43-
// during rotate operation node may stay in the tree in a different position
44-
changedNodesBufferToCheck += p
45-
} else if (operation.isInstanceOf[Insert] || operation.isInstanceOf[Remove]
46-
|| operation.isInstanceOf[InsertOrUpdate]) {
47-
// during non-rotate insert and remove operations nodes on the path should not be presented in a new tree
48-
changedNodesBuffer += p
49-
} else if (!operation.isInstanceOf[Lookup]) {
50-
// during other non-lookup operations we don't know, whether node will stay in thee tree or not
51-
changedNodesBufferToCheck += p
52-
}
41+
if (isRotate) {
42+
// during rotate operation node may stay in the tree in a different position
43+
changedNodesBufferToCheck += p
44+
} else if (operation.isInstanceOf[Insert] || operation.isInstanceOf[Remove]
45+
|| operation.isInstanceOf[InsertOrUpdate]) {
46+
// during non-rotate insert and remove operations nodes on the path should not be presented in a new tree
47+
changedNodesBuffer += p
48+
} else if (!operation.isInstanceOf[Lookup]) {
49+
// during other non-lookup operations we don't know, whether node will stay in thee tree or not
50+
changedNodesBufferToCheck += p
51+
}
5352
case _ =>
5453
}
5554
n.visited = true
@@ -382,7 +381,7 @@ trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with Scrypto
382381
if (rightChild.balance < 0) {
383382
// double left rotate
384383
// I know rightChild.left is not a leaf, because rightChild has a higher subtree on the left
385-
onNodeVisit(rightChild.left, operation)
384+
onNodeVisit(rightChild.left, operation, isRotate = true)
386385
(doubleLeftRotate(newRoot, newLeft, rightChild), true)
387386
} else {
388387
// single left rotate
@@ -409,7 +408,7 @@ trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with Scrypto
409408
if (leftChild.balance > 0) {
410409
// double right rotate
411410
// I know leftChild.right is not a leaf, because leftChild has a higher subtree on the right
412-
onNodeVisit(leftChild.right, operation)
411+
onNodeVisit(leftChild.right, operation, isRotate = true)
413412
(doubleRightRotate(r, leftChild, newRight), true)
414413
} else {
415414
// single right rotate

src/test/scala/scorex/crypto/authds/avltree/batch/BatchTestingHelpers.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ trait BatchTestingHelpers extends ToStringHelper with Matchers {
3333
*/
3434
def checkTree(prover: BatchAVLProver[D, HF], oldTop: ProverNodes[D], removedNodes: Seq[ProverNodes[D]]): Unit = {
3535
// check that there are no nodes in removedNodes, that are still in the tree
36-
removedNodes.foreach(r => prover.contains(r) shouldBe false)
36+
removedNodes.foreach{r =>
37+
if(prover.contains(r)) {
38+
throw new Error(s"Node $r is marked to remove while still in the tree")
39+
}
40+
}
3741

3842
var removed = 0
3943

src/test/scala/scorex/crypto/authds/avltree/batch/BatchingPlayground.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ object BatchingPlayground extends App with BatchTestingHelpers with Matchers {
3838
//removedNodesBenchmark
3939
removedNodesBenchmark()
4040

41-
def removedNodesBenchmark(startTreeSize: Int = 1000000,
42-
toRemoveSize: Int = 3000,
43-
toInsertSize: Int = 3000): Unit = {
41+
def removedNodesBenchmark(startTreeSize: Int = 10000,
42+
toRemoveSize: Int = 2000,
43+
toInsertSize: Int = 2000): Unit = {
4444
val iterations = 50
4545
var toRemoveTotal: Long = 0
4646
var proofGenerationTotal: Long = 0
@@ -73,7 +73,7 @@ object BatchingPlayground extends App with BatchTestingHelpers with Matchers {
7373
}
7474

7575
nonModifyingProof shouldEqual proofBytes
76-
// checkTree(prover, oldTop, removedNodes)
76+
checkTree(prover, oldTop, removedNodes)
7777
toRemoveTotal += removedNodesTime
7878
proofGenerationTotal += proofGenerationTime
7979
performOperationTotal += performOperationsTime

0 commit comments

Comments
 (0)