-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve block handling in remote store #489
base: master
Are you sure you want to change the base?
Conversation
@@ -15,7 +15,7 @@ GOPATH ?= $(HOME)/go | |||
install-tools: | |||
mkdir -p ${GOPATH}; \ | |||
cd ${GOPATH}; \ | |||
GO111MODULE=on go install github.com/golang/mock/mockgen@v1.6.0; \ | |||
GO111MODULE=on go install go.uber.org/mock/mockgen@v0.3.0; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github.com/golang/mock
is deprecated
@@ -176,11 +224,6 @@ func (s *Store) LedgerByHeight( | |||
ctx context.Context, | |||
blockHeight uint64, | |||
) (snapshot.StorageSnapshot, error) { | |||
err := s.SetBlockHeight(blockHeight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting this here could have confusing results, since it may reset the latest height to an earlier block if ExecuteScript
is called with a past height.
It's already called when committing a block, so I think we can skip it
flow-emulator/storage/store.go
Lines 213 to 216 in 0273f8f
if block.Header.Height >= latestBlockHeight { | |
return s.DataSetter.SetBytes(ctx, s.KeyGenerator.Storage(globalStoreName), s.KeyGenerator.LatestBlock(), mustEncodeUint64(block.Header.Height)) | |
} | |
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sideninja keep me honest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looking at this it doesn't need to be here, not sure what was my thinking at the time.
@peterargue thanks a lot for this, btw do we have archive nodes still ? last time I tried to work on this I was failing at that. Also if someone can fix, or at least explain to me, how flow-archive tags works, it would be great, there are 2 version stream one with v1.x another one is v0.x but I guess newer is v0.x but last time I tried archive node was using v1.x etc |
We are working on merging archive node functionality into access nodes as we speak. So right now the issues you are experiencing are due to that. We should have something available soon. |
store.DataGetter = store | ||
store.DataSetter = store | ||
store.KeyGenerator = &storage.DefaultKeyGenerator{} | ||
|
||
return store, nil | ||
} | ||
|
||
func (s *Store) initializeStartBlock(ctx context.Context) error { | ||
if s.startBlockHeight > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This misses a case where you don't provide the block height but you persisted it in the previous session.
@@ -287,3 +292,224 @@ func Test_SimulatedMainnetTransactionWithChanges(t *testing.T) { | |||
assert.Equal(t, txRes.Events[0].String(), "A.9799f28ff0453528.Ping.PingEmitted: 0x953f6f26d61710cb0e140bfde1022483b9ef410ddd181bac287d9968c84f4778") | |||
assert.Equal(t, txRes.Events[0].Value.String(), `A.9799f28ff0453528.Ping.PingEmitted(sound: "pong pong pong")`) | |||
} | |||
|
|||
func Test_SimulatedMainnetProgressesBlocks(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return snapshot.NewReadFuncStorageSnapshot(func(id flowgo.RegisterID) (flowgo.RegisterValue, error) { | ||
// first try to see if we have local stored ledger | ||
value, err := s.DefaultStore.GetBytesAtVersion( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here needs a check, something like: if blockHeight <= s.CurrentHeight
or we should totally disallow higher block height requests than forked one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point. I think this should just rewrite the height if it's greater than the fork height
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -154,6 +198,10 @@ func (s *Store) BlockByHeight(ctx context.Context, height uint64) (*flowgo.Block | |||
return block, nil | |||
} | |||
|
|||
if latestBlockHeight, err := s.LatestBlockHeight(ctx); err == nil && height > latestBlockHeight { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if err != nil
?
I think we need to fix also register requests part, I messed up there before because of flow-archive versioning problems. ( I can make a PR for it, or contribute to this PR ) |
ok I updated #433 with required changes, which required a PR on flow-archive ( for conflicting go versions ) onflow/flow-archive#143 |
Closes #???
Description
The forked mainnet functionality is helpful to testing full application integration. With the current implementation, there are some key differences between behavior of the real network and emulator, particularly with error messages and block handling.
This PR attempts to close the gap and adds testing to cover various cases to ensure block responses behave as expected.
For contributor use:
master
branchFiles changed
in the GitHub PR explorer