flow-go icon indicating copy to clipboard operation
flow-go copied to clipboard

[Dynamic Protocol State | M1] Updating data in the KV store

Open durkmurder opened this issue 1 year ago • 0 comments

Context

KV store was designed to be backward compatible and support multiple versions, to reflect this in the code base we need an version agnostic way to mutate data. The proposed solution is to use an interface which allows updating values in the KV store, that interface has to support all values starting from current version and ending with the latest supported version. The concrete implementation of the interface will depend on the current version which is active based on view. This approach allows us to use single interface across all supported versions as well as expand them, details on the approach can be found in the design doc.

For fields that are deprecated(not supported anymore) as result of the update or fields that were added(in new version but weren't present in previous one) but not yet activated we have agreed to use sentinel errors to inform caller that value is not available.

Specifically we want next behavior:

CurrentVersion = 1
VersionUpgrade = (2 at view 1000)

for any v: v <= 1000 | mutator := Version1Mutator{}
for any v: v > 1000 | mutator := Version2Mutator{}

type KVStoreMutator interface {
	MutateVersion1
	MutateVersion2
}

Version1Mutator implements MutateVersion1 and returns errors for MutateVersion2
Version2Mutator implements both MutateVersion1 and MutateVersion2. 

Definition of Done

  • Implement a generic, version agnostic interface to update values in the KV store.
  • Implement a factory to correctly instantiate correct instances based on current version.
  • Define sentinel errors to represent unsupported values.
  • Add tests.
  • Add a comprehensive godoc that describes how to maintain interface across different versions.

durkmurder avatar Jan 29 '24 21:01 durkmurder