From f7c223573fc27f394a17cd1355a47027dbabc96a Mon Sep 17 00:00:00 2001 From: chengzhinei Date: Tue, 22 Feb 2022 10:32:57 +0800 Subject: [PATCH] Merge PR: watchdb mv deleteAccount (#1575) * replay add fast-query * DeleteAccount * ut Co-authored-by: xiangjianmeng <805442788@qq.com> --- cmd/exchaind/replay.go | 1 + x/evm/watcher/watcher.go | 7 ++++--- x/evm/watcher/watcher_test.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/exchaind/replay.go b/cmd/exchaind/replay.go index 37fbd0c41a..1292772ad1 100644 --- a/cmd/exchaind/replay.go +++ b/cmd/exchaind/replay.go @@ -97,6 +97,7 @@ func replayCmd(ctx *server.Context) *cobra.Command { cmd.Flags().Int(types.FlagRedisExpire, 300, "delta expiration time. unit is second") cmd.Flags().Int(types.FlagRedisDB, 0, "delta db num") cmd.Flags().Int(types.FlagDeltaVersion, types.DeltaVersion, "Specify delta version") + cmd.Flags().Bool(types.FlagFastQuery, false, "enable watch db or not") cmd.Flags().String(server.FlagPruning, storetypes.PruningOptionNothing, "Pruning strategy (default|nothing|everything|custom)") cmd.Flags().Uint64(server.FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node") diff --git a/x/evm/watcher/watcher.go b/x/evm/watcher/watcher.go index a8ab6f7ef9..b62197c052 100644 --- a/x/evm/watcher/watcher.go +++ b/x/evm/watcher/watcher.go @@ -200,9 +200,10 @@ func (w *Watcher) DeleteAccount(addr sdk.AccAddress) { if !w.Enabled() { return } - w.store.Delete(GetMsgAccountKey(addr.Bytes())) - key := append(prefixRpcDb, GetMsgAccountKey(addr.Bytes())...) - w.delayEraseKey = append(w.delayEraseKey, key) + key1 := GetMsgAccountKey(addr.Bytes()) + key2 := append(prefixRpcDb, key1...) + w.delayEraseKey = append(w.delayEraseKey, key1) + w.delayEraseKey = append(w.delayEraseKey, key2) } func (w *Watcher) AddDirtyAccount(addr *sdk.AccAddress) { diff --git a/x/evm/watcher/watcher_test.go b/x/evm/watcher/watcher_test.go index e9ff46b3a4..8879696a3c 100644 --- a/x/evm/watcher/watcher_test.go +++ b/x/evm/watcher/watcher_test.go @@ -122,8 +122,7 @@ func testWatchData(t *testing.T, w *WatcherTestSt) { wd, err := wdFunc() require.Nil(t, err) require.NotEmpty(t, wd) - err = delDirtyAccount(wd, w) - require.Nil(t, err) + w.app.EvmKeeper.Watcher.ExecuteDelayEraseKey() store := watcher.InstanceOfWatchStore() pWd := getDBKV(store) @@ -134,6 +133,7 @@ func testWatchData(t *testing.T, w *WatcherTestSt) { wData, err := w.app.EvmKeeper.Watcher.UnmarshalWatchData(wd) require.Nil(t, err) w.app.EvmKeeper.Watcher.UseWatchData(wData) + w.app.EvmKeeper.Watcher.ExecuteDelayEraseKey() time.Sleep(time.Second * 1) cWd := getDBKV(store)