Skip to content

MultiWriterAppStore for EVM state migration (Phase 1)#1064

Merged
enlight merged 3 commits intomasterfrom
multi-writer-appstore
May 15, 2019
Merged

MultiWriterAppStore for EVM state migration (Phase 1)#1064
enlight merged 3 commits intomasterfrom
multi-writer-appstore

Conversation

@pathornteng
Copy link
Copy Markdown
Contributor

@pathornteng pathornteng commented May 2, 2019

This is an alternative implementation for EVM state migration.

Ref: #1035
Issue: #849

  • I added unit tests for any code that added
  • I updated the CHANGELOG.md
  • All IP is original and not copied from another source
  • I assign all copyright to Loom Network for the code in the pull request

@pathornteng pathornteng requested a review from enlight May 4, 2019 16:34
Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/iavlstore.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/evmstore.go
Copy link
Copy Markdown
Contributor

@enlight enlight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update the store loading code as well, if the evm.db is one block ahead need to load the last height matching app.db

Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/evmstore.go
Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go
Comment thread e2e/loom-6-test.toml
Comment thread e2e/loom-6-test.toml Outdated
Comment thread store/multi_writer_app_store_test.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread cmd/loom/loom.go Outdated
Comment thread e2e/loom-6-test.toml Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
Comment thread store/multi_writer_app_store.go
Comment thread store/multi_writer_app_store.go
Comment thread app.go Outdated
@traceCall traceCall requested a review from enlight May 9, 2019 13:50
Comment thread store/evmstore.go Outdated
Comment thread app.go Outdated
Comment thread app.go Outdated
if cachingStore, ok := (a.Store.(*store.CachingStore)); ok {

readOnlyStore := a.Store.GetSnapshot()
if cachingStore, ok := (readOnlyStore.(*store.CachingStore)); ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so we basically lose the cache on all queries.

Comment thread store/evmstore.go
if root == nil {
root = []byte("")
}
s.evmDB.Set(util.PrefixKey(vmPrefix, rootKey), root)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really don't like this, this will write to the evm.db on disk when loading the store, which is counter-intuitive because a load should really only read from disk, not write to it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary. LoomEthDB will read the current root from vmvmroot. We have to reload the root of target version and set it to vmvmroot for LoomEthDB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we'll have to refactor this later.

Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go Outdated
Comment thread store/evmstore.go
if root == nil {
root = []byte("")
}
s.evmDB.Set(util.PrefixKey(vmPrefix, rootKey), root)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we'll have to refactor this later.

Comment thread evm/config.go Outdated
Comment thread store/multi_writer_app_store.go Outdated
@enlight enlight changed the title [WIP] MultiWriterAppStore for EVM state migration MultiWriterAppStore for EVM state migration (Phase 1) May 13, 2019
@enlight
Copy link
Copy Markdown
Contributor

enlight commented May 13, 2019

Going to merge this as is shortly, but there are a couple of issues that will need to be addressed in follow up PRs before this can be shipped:

  • Store snapshots need to provide consistent view of the data in evm.db & app.db (one can't be one block ahead of the other).
  • Caching store needs to be be updated to work with snapshots... or disabled for the multi-writer app store, or replaced with some kind of other cache.

Comment thread store/iavlstore.go
if err != nil {
log.Error("failed to unprefix key", "key", x, "prefix", prefix, "err", err)
k = nil
for i, k := range keys {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think this is probably to change without a feature flag since all the current uses of Range seem to correctly use util.PrefixKey...

Before this change I take it UnprefixKey always stripped off len(prefix)+1 from the key even if it wasn't prefixed by prefix + 0?

Copy link
Copy Markdown
Contributor Author

@pathornteng pathornteng May 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, previously, UnprefixKey does not check if the key is really prefixed with prefix + 0. If we called Range([]byte("vm") it would return both []byte("vmroot") and util.PrefixKey([]byte("vm"), []byte("root")) keys. It was supposed to return only util.PrefixKey([]byte("vm"),[]byte("root")) key

@mattkanwisher
Copy link
Copy Markdown
Contributor

Every block is setting a "vmevmroot" despite not changing, it just adds a lot of extra writes to the db . Negates a lot of performance games we had

@enlight
Copy link
Copy Markdown
Contributor

enlight commented May 13, 2019

If you're talking about EvmStore.Commit - writing the evm root at each height is what allows us to check if the evm.db and the app.db are in sync when the node starts up.

}

func (s *MultiWriterAppStore) GetSnapshot() Snapshot {
// TODO: Need to ensure that the EvmStore and ImmutableTree are from the same height.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, there is a small chance that the mismatched heights can happen as MultiWriterAppStore.SaveVersion is not atomic. We can prevent this by using a mutex but not sure how much it is going to hurt the performance.

pathornteng and others added 3 commits May 15, 2019 12:26
The caching store doesn't work with the multi writer app store
snapshots, so the snapshots bypass the cache, which means the QueryServer
never hits the cache in the caching store, no point writing to the cache
if nothing ever reads from it.

Also simplified the Range implementation of the multi writer app store
and the EVM store, we don't really use Range(nil) anywhere, and there
was a lot of code to support that use case that just added a lot of
additional complexity.
@enlight enlight force-pushed the multi-writer-appstore branch from 971e1a3 to ae0c80a Compare May 15, 2019 05:31
Copy link
Copy Markdown
Contributor

@enlight enlight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@enlight enlight merged commit 70a5800 into master May 15, 2019
@enlight enlight deleted the multi-writer-appstore branch May 15, 2019 08:22
@enlight
Copy link
Copy Markdown
Contributor

enlight commented May 15, 2019

Remaining issues mentioned in
#1064 (comment) and #1064 (comment) will be addressed in follow up PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants