-
Notifications
You must be signed in to change notification settings - Fork 748
Vm sdk #3909
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
base: master
Are you sure you want to change the base?
Vm sdk #3909
Conversation
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.
Didn't finish the review - but need to go get dinner + workout
|
||
_, exists := f.m[key] | ||
if !exists { | ||
f.buffer.Push(key) // Push removes the oldest [K] if we are at the [limit] |
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.
f.buffer.Push(key) // Push removes the oldest [K] if we are at the [limit] | |
f.buffer.Push(key) // Push calls remove with the oldest key if we are at the limit |
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.
With the recent cache refactor, I think this should be it its own fifo
package like how we have lru
GetID() ids.ID | ||
GetParent() ids.ID | ||
GetTimestamp() int64 | ||
GetBytes() []byte | ||
GetHeight() uint64 | ||
// GetContext returns the P-Chain context of the block. | ||
// May return nil if there is no P-Chain context, which | ||
// should only occur prior to ProposerVM activation. | ||
// This will be verified from the snow package, so that the | ||
// inner chain can simply use its embedded context. | ||
GetContext() *block.Context |
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 don't think it is typically recommended to prefix Get
for getters in golang
m map[K]V | ||
} | ||
|
||
// NewFIFO creates a new First-In-First-Out cache of size [limit]. |
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.
godoc links don't work for function arguments
// NewFIFO creates a new First-In-First-Out cache of size [limit]. | |
// NewFIFO creates a new First-In-First-Out cache of size limit. |
// remove is used as the callback in [BoundedBuffer]. It is assumed that the | ||
// [WriteLock] is held when this is accessed. |
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.
// remove is used as the callback in [BoundedBuffer]. It is assumed that the | |
// [WriteLock] is held when this is accessed. | |
// remove is used as the callback in the bounded buffer. It is assumed that the | |
// write lock is held when this is called. |
return c, nil | ||
} | ||
|
||
func GetConfig[T any](c Config, key string, defaultConfig T) (T, 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.
When first reading this, I thought defaultConfig
would be returned unless overridden.
But in reality, it is a config storing the default values and each individual value are used unless overridden. Perhaps we should rename the var, or perhaps we should just document this function.
return c, nil | ||
} | ||
|
||
func GetConfig[T any](c Config, key string, defaultConfig T) (T, 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.
func GetConfig[T any](c Config, key string, defaultConfig T) (T, error) { | |
func FillConfig[T any](c Configs, configName string, defaultConfig T) (T, error) { |
I still don't love the name, but it feels a bit more correct than GetConfig
.
We could even change the function to:
func FillConfig[T any](cs Config, name string, c *T) error {
val, ok := cs[name]
if !ok {
return nil
}
return json.Unmarshal(val, c)
}
func Map[Input any, Output any](mapF func(Input) Output, sub Subscription[Output]) Subscription[Input] { | ||
return SubscriptionFunc[Input]{ | ||
NotifyF: func(ctx context.Context, t Input) error { | ||
return sub.Notify(ctx, mapF(t)) | ||
}, | ||
Closer: sub.Close, | ||
} | ||
} |
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.
Generic types are typically a single character in golang. I think it makes the code read more easily here.
func Map[Input any, Output any](mapF func(Input) Output, sub Subscription[Output]) Subscription[Input] { | |
return SubscriptionFunc[Input]{ | |
NotifyF: func(ctx context.Context, t Input) error { | |
return sub.Notify(ctx, mapF(t)) | |
}, | |
Closer: sub.Close, | |
} | |
} | |
func Map[I, O any](f func(I) O, sub Subscription[O]) Subscription[I] { | |
return SubscriptionFunc[I]{ | |
NotifyF: func(ctx context.Context, v I) error { | |
return sub.Notify(ctx, f(v)) | |
}, | |
Closer: sub.Close, | |
} | |
} |
} | ||
} | ||
|
||
// Map transforms a subscription from an output sub to an input typed sub |
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 waffled a lot on this description. It really isn't the format I'm used to for a Map function... Typically I would think Map
would take in a Stream[I]
and f(I) O
and return a Stream[O]
. But instead this takes in an EventHandler[O]
and f(I) O
and returns an EventHandler[I]
...
Perhaps:
// Map transforms a subscription from an output sub to an input typed sub | |
// Map returns a new subscription which transforms an event with f and notifies | |
// the original subscription of the result. | |
// | |
// The original subscription will be closed if the returned subscription is closed. |
r := require.New(t) | ||
sub, subCh := newTestSubscription() | ||
|
||
mappedSub := Map(func(eventID string) ids.ID { return ids.FromStringOrPanic(eventID) }, sub) |
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.
mappedSub := Map(func(eventID string) ids.ID { return ids.FromStringOrPanic(eventID) }, sub) | |
mappedSub := Map(ids.FromStringOrPanic, sub) |
Why this should be merged
How this works
How this was tested
Need to be documented in RELEASES.md?