@@ -144,6 +144,15 @@ class LegacyPayload : public IContractPayload
144144// !
145145class AppCacheContractHandler : public IContractHandler
146146{
147+ public:
148+ void Reset () override
149+ {
150+ ClearCache (Section::POLL);
151+ ClearCache (Section::PROTOCOL);
152+ ClearCache (Section::SCRAPER);
153+ ClearCache (Section::VOTE);
154+ }
155+
147156 bool Validate (const Contract& contract, const CTransaction& tx) const override
148157 {
149158 return true ; // No contextual validation needed yet
@@ -182,6 +191,12 @@ class AppCacheContractHandler : public IContractHandler
182191// !
183192class UnknownContractHandler : public IContractHandler
184193{
194+ public:
195+ void Reset () override
196+ {
197+ // Nothing to do.
198+ }
199+
185200 bool Validate (const Contract& contract, const CTransaction& tx) const override
186201 {
187202 return true ; // No contextual validation needed yet
@@ -225,6 +240,17 @@ class UnknownContractHandler : public IContractHandler
225240class Dispatcher
226241{
227242public:
243+ // !
244+ // ! \brief Reset the cached state of each contract handler to prepare for
245+ // ! historical contract replay.
246+ // !
247+ void ResetHandlers ()
248+ {
249+ GetBeaconRegistry ().Reset ();
250+ GetWhitelist ().Reset ();
251+ m_appcache_handler.Reset ();
252+ }
253+
228254 // !
229255 // ! \brief Validate the provided contract and forward it to the appropriate
230256 // ! contract handler.
@@ -343,6 +369,8 @@ void NN::ReplayContracts(const CBlockIndex* pindex)
343369 return ;
344370 }
345371
372+ g_dispatcher.ResetHandlers ();
373+
346374 CBlock block;
347375
348376 // These are memorized consecutively in order from oldest to newest.
0 commit comments