From 11f7d7edf7bd8a993092582dbeb45af0913c25a0 Mon Sep 17 00:00:00 2001
From: CJentzsch <jentzsch.software@gmail.com>
Date: Mon, 23 Feb 2015 08:15:36 +0100
Subject: [PATCH 1/2] add new mem test for quadratic mem gas costs

---
 test/vmSha3TestFiller.json | 238 +++++++++++++++++++++++++++++++++++--
 1 file changed, 231 insertions(+), 7 deletions(-)

diff --git a/test/vmSha3TestFiller.json b/test/vmSha3TestFiller.json
index 48a395e80..142af79d0 100644
--- a/test/vmSha3TestFiller.json
+++ b/test/vmSha3TestFiller.json
@@ -201,13 +201,13 @@
             "currentNumber" : "0",
             "currentGasLimit" : "1000000",
             "currentDifficulty" : "256",
-            "currentTimestamp" : 1,
+            "currentTimestamp" : "1",
             "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
         },
         "pre" : {
             "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
                 "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
-                "nonce" : 0,
+                "nonce" : "0",
                 "code" : "{ [[ 0 ]] (SHA3 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)}",
                 "storage": {}
             }
@@ -229,13 +229,13 @@
             "currentNumber" : "0",
             "currentGasLimit" : "1000000",
             "currentDifficulty" : "256",
-            "currentTimestamp" : 1,
+            "currentTimestamp" : "1",
             "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
         },
         "pre" : {
             "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
                 "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
-                "nonce" : 0,
+                "nonce" : "0",
                 "code" : "{ [[ 0 ]] (SHA3 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 2)}",
                 "storage": {}
             }
@@ -257,13 +257,13 @@
             "currentNumber" : "0",
             "currentGasLimit" : "1000000",
             "currentDifficulty" : "256",
-            "currentTimestamp" : 1,
+            "currentTimestamp" : "1",
             "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
         },
         "pre" : {
             "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
                 "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
-                "nonce" : 0,
+                "nonce" : "0",
                 "code" : "{ [[ 0 ]] (SHA3 0x1000000 2)}",
                 "storage": {}
             }
@@ -277,5 +277,229 @@
             "gasPrice" : "1",
             "gas" : "0x100000000"
         }
-    }
+    },
+
+    "sha3_memSizeNoQuadraticCost31": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 960 1)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost32": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 992 1)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost32_zeroSize": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 1024 0)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost33": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 1024 1)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost63": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 1984 1)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost64": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 2016 1)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost64_2": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 2016 32)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
+
+    "sha3_memSizeQuadraticCost65": {
+        "env" : {
+            "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+            "currentNumber" : "0",
+            "currentGasLimit" : "1000000",
+            "currentDifficulty" : "256",
+            "currentTimestamp" : "1",
+            "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+        },
+        "pre" : {
+            "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+                "balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+                "nonce" : "0",
+                "code" : "{ [[ 0 ]] (SHA3 2048 1)}",
+                "storage": {}
+            }
+        },
+        "exec" : {
+            "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+            "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+            "value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+            "data" : "",
+            "gasPrice" : "1",
+            "gas" : "0x100000000"
+        }
+    },
 }

From 77026ac6124cb90a5ae4a9b5e2248bd7d72b5f9e Mon Sep 17 00:00:00 2001
From: Gav Wood <i@gavwood.com>
Date: Thu, 26 Feb 2015 14:00:55 +0100
Subject: [PATCH 2/2] Verbosity to test big with watch garbage collection.

---
 libethereum/Client.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp
index d72762f36..11b9557df 100644
--- a/libethereum/Client.cpp
+++ b/libethereum/Client.cpp
@@ -257,7 +257,9 @@ LocalisedLogEntries Client::peekWatch(unsigned _watchId) const
 	Guard l(m_filterLock);
 
 	try {
+		cdebug << "peekWatch" << _watchId;
 		auto& w = m_watches.at(_watchId);
+		cdebug << "lastPoll updated to " << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
 		w.lastPoll = chrono::system_clock::now();
 		return w.changes;
 	} catch (...) {}
@@ -271,7 +273,9 @@ LocalisedLogEntries Client::checkWatch(unsigned _watchId)
 	LocalisedLogEntries ret;
 
 	try {
+		cdebug << "checkWatch" << _watchId;
 		auto& w = m_watches.at(_watchId);
+		cdebug << "lastPoll updated to " << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
 		std::swap(ret, w.changes);
 		w.lastPoll = chrono::system_clock::now();
 	} catch (...) {}