Skip to content
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

[EFM] Added a service event to update EpochExtensionViewCount #6272

Merged
merged 19 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions model/flow/kvstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package flow

// SetEpochExtensionViewCount is a service event emitted by the FlowServiceAccount for updating
// the `EpochExtensionViewCount` parameter in the protocol state's key-value store.
// NOTE: A SetEpochExtensionViewCount event `E` is accepted while processing block `B`
// which seals `E` if and only if E.Value > 2*FinalizationSafetyThreshold.
type SetEpochExtensionViewCount struct {
Value uint64
}

// EqualTo returns true if the two events are equivalent.
func (s *SetEpochExtensionViewCount) EqualTo(other *SetEpochExtensionViewCount) bool {
return s.Value == other.Value
}

// ServiceEvent returns the event as a generic ServiceEvent type.
func (s *SetEpochExtensionViewCount) ServiceEvent() ServiceEvent {
return ServiceEvent{
Type: ServiceEventSetEpochExtensionViewCount,
Event: s,
}
}
22 changes: 22 additions & 0 deletions model/flow/service_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
ServiceEventRecover ServiceEventType = "recover"
ServiceEventVersionBeacon ServiceEventType = "version-beacon" // VersionBeacon only controls version of ENs, describing software compatability via semantic versioning
ServiceEventProtocolStateVersionUpgrade ServiceEventType = "protocol-state-version-upgrade" // Protocol State version applies to all nodes and uses an _integer version_ of the _protocol_
ServiceEventSetEpochExtensionViewCount ServiceEventType = "set-epoch-extension-view-count" // Sets value for parameter `EpochExtensionViewCount` in the protocol state's KV store.
)

// ServiceEvent represents a service event, which is a special event that when
Expand Down Expand Up @@ -124,6 +125,8 @@ func (marshaller marshallerImpl) UnmarshalWrapped(b []byte) (ServiceEvent, error
event, err = unmarshalWrapped[VersionBeacon](b, marshaller)
case ServiceEventProtocolStateVersionUpgrade:
event, err = unmarshalWrapped[ProtocolStateVersionUpgrade](b, marshaller)
case ServiceEventSetEpochExtensionViewCount:
event, err = unmarshalWrapped[SetEpochExtensionViewCount](b, marshaller)
default:
return ServiceEvent{}, fmt.Errorf("invalid type: %s", eventType)
}
Expand Down Expand Up @@ -168,6 +171,8 @@ func (marshaller marshallerImpl) UnmarshalWithType(b []byte, eventType ServiceEv
event = new(VersionBeacon)
case ServiceEventProtocolStateVersionUpgrade:
event = new(ProtocolStateVersionUpgrade)
case ServiceEventSetEpochExtensionViewCount:
event = new(SetEpochExtensionViewCount)
default:
return ServiceEvent{}, fmt.Errorf("invalid type: %s", eventType)
}
Expand Down Expand Up @@ -308,6 +313,23 @@ func (se *ServiceEvent) EqualTo(other *ServiceEvent) (bool, error) {
)
}
return version.EqualTo(otherVersion), nil
case ServiceEventSetEpochExtensionViewCount:
typedEvent, ok := se.Event.(*SetEpochExtensionViewCount)
if !ok {
return false, fmt.Errorf(
"internal invalid type for SetEpochExtensionViewCount: %T",
se.Event,
)
}
otherTypedEvent, ok := other.Event.(*SetEpochExtensionViewCount)
if !ok {
return false,
fmt.Errorf(
"internal invalid type for SetEpochExtensionViewCount: %T",
other.Event,
)
}
return typedEvent.EqualTo(otherTypedEvent), nil

default:
return false, fmt.Errorf("unknown serice event type: %s", se.Type)
Expand Down
Loading
Loading