-
Notifications
You must be signed in to change notification settings - Fork 772
Proposervm API #4029
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?
Proposervm API #4029
Conversation
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. |
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.
The lint job did not like including 2025
in the copyright date, nor did I find any instances of 2025
in the codebase, so I assume it is alright to add this file with a terminal date of 2024
.
|
||
// GetProposerBlockArgs is the parameters supplied to the GetProposerBlockWrapper API | ||
type GetProposerBlockArgs struct { | ||
ProposerID ids.ID `json:"proposerID"` |
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 added this type rather than using the existing api.GetBlockArgs
to eliminate confusion over what exactly this parameter is. It is the "Proposer ID" listed in the subnets explorer, e.g. https://subnets.avax.network/c-chain/block/64357262, not the block hash/ID as seen by the inner VM.
That said, I'm not sure what the best way to actually source the "Proposer ID" in the general case, since it's not exposed by the innerVM. Similarly, an endpoint to map Block hash -> Proposer ID seems like it would break encapsulation.
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.
The word Proposer
sounds like the actual proposer node. But if that's the common usage, I think it's fine. Maybe ProposerBlockID
etc can make it cleaner. I think the actual word for that is OuterBlockID
but sounds even more complicated.
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.
The explorer uses Proposer ID
/Proposer Node ID
to disambiguate, but yes I agree the naming is awkward. Happy to go with whatever the consensus here is.
|
||
return handlers, 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.
what about a unit test that invokes this API?
server := rpc.NewServer() | ||
server.RegisterCodec(json.NewCodec(), "application/json") | ||
server.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8") | ||
err = server.RegisterService(&ProposerAPI{vm}, "proposervm") |
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.
Why don't we have these two also similar to the platformVM?
server.RegisterInterceptFunc(vm.metrics.InterceptRequest)
server.RegisterAfterFunc(vm.metrics.AfterRequest)
Any thoughts about this?
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/formatting" | ||
"github.com/ava-labs/avalanchego/utils/rpc" | ||
) |
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 we add unit tests for this file?
avajson "github.com/ava-labs/avalanchego/utils/json" | ||
) | ||
|
||
type ProposerAPI struct { |
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.
What is the reason for having the proposerVM as a field instead of just adding the functions to the proposerVM VM?
If we wish to isolate the VM object then it makes sense to add two functions or (an) interface(s) with:
- getLastAcceptedHeight
- GetBlock
and then it'll be easier to test.
|
||
var _ Client = (*client)(nil) | ||
|
||
type Client interface { |
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.
who/what is consuming this interface? Usually in Golang, interfaces are declared where they're used, not where they're implemented.
@@ -0,0 +1,70 @@ | |||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. |
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 we add tests to the code in this file?
p.vm.ctx.Lock.Lock() | ||
defer p.vm.ctx.Lock.Unlock() | ||
|
||
block, err := p.vm.GetBlock(r.Context(), args.ProposerID) |
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.
am I reading this wrong and we're actually sending back the entire proposerVM block which also contains the inner VM block? If so, is it possible to only distill the proposerVM bytes?
Why this should be merged
Adds a path
/proposervm
to all ProposerVM chains (C, P, subnet-evm) that exposes the following methods:proposervm.getProposedHeight
proposervm.getProposerBlockWrapper
This API will also be useful for exposing P-Chain epoch views if ACP-181 is adopted.
How this works
Overrides
CreateHandlers
inproposervm.VM
to call the inner VM'sCreateHandlers
method, and register the/proposervm
endpoint.How this was tested
Manual testing on a local network. Meaningful unit tests would likely require refactoring
package platformvm
to expose internal structs that are used to setup a concrete VM. Happy to take suggestions on alternatives.Need to be documented in RELEASES.md?
Yes