Skip to content

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Vm sdk #3909

wants to merge 5 commits into from

Conversation

aaronbuchwald
Copy link
Collaborator

Why this should be merged

How this works

How this was tested

Need to be documented in RELEASES.md?

Copy link
Contributor

@StephenButtolph StephenButtolph left a 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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor

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

Comment on lines +32 to +42
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
Copy link
Contributor

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].
Copy link
Contributor

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

Suggested change
// NewFIFO creates a new First-In-First-Out cache of size [limit].
// NewFIFO creates a new First-In-First-Out cache of size limit.

Comment on lines +54 to +55
// remove is used as the callback in [BoundedBuffer]. It is assumed that the
// [WriteLock] is held when this is accessed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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) {
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
}

Comment on lines +86 to +93
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,
}
}
Copy link
Contributor

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.

Suggested change
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
Copy link
Contributor

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:

Suggested change
// 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mappedSub := Map(func(eventID string) ids.ID { return ids.FromStringOrPanic(eventID) }, sub)
mappedSub := Map(ids.FromStringOrPanic, sub)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants