-
Notifications
You must be signed in to change notification settings - Fork 180
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
In-Memory Snapshot Implementation #204
In-Memory Snapshot Implementation #204
Conversation
there are cyclical dependencies otherwise
These were effectively already using similar memory-backed implementations, this removes the duplication
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.
Looks good to me
} | ||
|
||
func (u *Epochs) Next() protocol.Epoch { | ||
return NewEpoch(u.err) |
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.
can this recursively go through? (e.g., ..Next().Next().Next()
), if so, does this make sense to prefix the error each time we create a new epoch?
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.
No there's only one layer of querying. From a block reference (ie state.AtBlockID(id)
) we can query only the previous/current/next epochs from that reference. Next
returns an Epoch
object which doesn't have a Next
method.
return nil, err | ||
} | ||
snap.Identities, err = from.Identities(filter.Any) | ||
if err != 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.
I would add some prefix to this error letting them get nested: return nil, fmt.Errorf("could not retrieve identities: %w")
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.
Same suggestion for the rest of the errors (unless you want to preserve their type later on).
) | ||
|
||
// should be able to convert from protocol.Snapshot | ||
func TestFromSnapshot(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.
better to start godoc
with name of the function // TestFromSnapshot ....
state/protocol/inmem/convert_test.go
Outdated
t.Run("staking phase", func(t *testing.T) { | ||
expected := state.AtHeight(1) | ||
actual, err := inmem.FromSnapshot(expected) | ||
require.Nil(t, err) |
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.
you may use require.NoError
here as well.
state/protocol/inmem/encodable.go
Outdated
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
// Snapshot is the encoding format for protocol.Snapshot |
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.
// Snapshot is the encoding format for protocol.Snapshot | |
// EncodableSnapshot is the encoding format for protocol.Snapshot |
state/protocol/inmem/encodable.go
Outdated
Next *EncodableEpoch | ||
} | ||
|
||
// Epoch is the encoding format for protocol.Epoch |
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.
// Epoch is the encoding format for protocol.Epoch | |
// EncodableEpoch is the encoding format for protocol.Epoch |
state/protocol/inmem/encodable.go
Outdated
DKG *EncodableDKG | ||
} | ||
|
||
// DKG is the encoding format for protocol.DKG |
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.
// DKG is the encoding format for protocol.DKG | |
// EncodableDKG is the encoding format for protocol.DKG |
state/protocol/inmem/encodable.go
Outdated
Participants map[flow.Identifier]flow.DKGParticipant | ||
} | ||
|
||
// Cluster is the encoding format for protocol.Cluster |
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.
// Cluster is the encoding format for protocol.Cluster | |
// EncodableCluster is the encoding format for protocol.Cluster |
state/protocol/inmem/snapshot.go
Outdated
enc EncodableSnapshot | ||
} | ||
|
||
func (s *Snapshot) Head() (*flow.Header, error) { |
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 these methods are not required to be pointer receiver. They do not change affect s
and safer to be by value.
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.
Clean implementation 👍 left a few comments basically related to the linting
Thanks @yhassanzadeh13, applied those suggestions |
This PR defines an in-memory implementation of
protocol.Snapshot
and a canonical encoding structure forSnapshot
.Changes
EncodableSnapshot
and sub-structures, which define the structure of encoding a snapshotinmem.Snapshot
, a memory-backed implementation ofprotocol.Snapshot
that usesEncodableSnapshot
as its underlying data structureinmem.FromSnapshot
which converts any implementation ofprotocol.Snapshot
to a memory-backed snapshot + smoke tests