-
Notifications
You must be signed in to change notification settings - Fork 212
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
feat(cosmos): contextual and declarative VM action field defaults #8703
Conversation
ff87a1c
to
6511df8
Compare
53c04f3
to
405e2d5
Compare
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.
Approved, but please see strong suggestions in comments.
golang/cosmos/vm/action.go
Outdated
if !field.IsZero() { | ||
continue | ||
} |
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.
Cute, but consider an explicit continue
for each case in the switch.
golang/cosmos/vm/action.go
Outdated
|
||
// WithActionContext interprets `default:"..."` tags and adds other fields from | ||
// the SDK context to the action. | ||
func WithActionContext(ctx sdk.Context, action Jsonable) Jsonable { |
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.
Consider renaming to PopulateAction()
. The "with...context" triggers me to think of the various "with" methods for sdk.Context
.
golang/cosmos/x/swingset/abci.go
Outdated
Type string `json:"type" default:"BEGIN_BLOCK"` | ||
BlockHeight int64 `json:"blockHeight"` | ||
BlockTime int64 `json:"blockTime"` |
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.
Here and below, consider embedding a common ActionHeader
structure as in Richard's version. Also, make some reference to the understanding that certain fields will be automagically populated. Having the common header lets you put that reference in just one place.
405e2d5
to
040fda4
Compare
Removing the automerge label, was reviewing |
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.
This is a nice consolidation. I am a little nervous about the init action change, but it's likely fine. Please consider addressing my nits before re-enabling automerge.
var blockTime int64 = 0 | ||
if bootstrap || app.upgradePlan != nil { | ||
blockTime = ctx.BlockTime().Unix() | ||
} |
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 am uncomfortable with providing a blockTime
and blockHeight
for the init action sent during simple restart scenarios since there is so much non determinism in this case.
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 you explain more about "so much non-determinism"? Are we trying to paper over a Cosmos bug, or is there some subtlety that the cosmic-swingset side of things needs to understand?
The AG_COSMOS_INIT
handler is already very careful in its assumptions, and does not look at blockTime/blockHeight unless isBootstrap or upgradePlan. I don't think it's beneficial to override the Golang propagation of these values when we may need them someday in the handler.
If it's really Golang that should change, I would prefer changing the construction of the ctx sdk.Context
passed into app.SwingSetKeeper.BlockingSend
, not in special-casing the ActionHeader population. That to me falls into the "papering over a Cosmos bug" category, and would necessitate a bunch of justifying commentary so that the reader would be left with an (uncomfortable) understanding of the bug.
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.
There is no bug. It's just how we use the init "blocking send", and that a node can be started either after consensus stop, or from per validator action. I was simply concerned about including consensus state in actions happening outside of consensus. But you're right, there isn't really a problem as long as no consensus decision is taken from that data.
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.
Thanks. I will add a comment describing that to the init blocking send call.
golang/cosmos/vm/action.go
Outdated
// Default the Type field to the default tag. | ||
if len(defaultType) != 0 && len(ah.Type) == 0 { | ||
ah.Type = defaultType | ||
} |
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.
Is there a case where defaultType
would not be set?
Should we assert that Type
is never empty?
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 semantics I'm aiming for is "never fail, just set defaults when they're available". It's reasonable to make Type
a mandatory non-empty field in PushAction
and BlockingSend
, though. I'll do that.
golang/cosmos/vm/action.go
Outdated
// Populate the embedded *ActionHeader struct. | ||
if fieldType.Anonymous && fieldType.Type == actionHeaderType { | ||
ahp := field.Addr().Interface().(*ActionHeader) | ||
setActionHeaderDefaults(ctx, defaultTag, ahp) |
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.
It feels weird to use the default
tag an an embedded header like this. I know it might be more verbose, but I think a defaultType
tag would be more appropriate.
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.
Okay, I can do that.
Note that the non-action bridge messages will change format when we switch to JSON-RPC as part of the split brain effort. |
74c27e8
to
33e6c1a
Compare
33e6c1a
to
021fd0f
Compare
feat(cosmos): contextual and declarative VM action field defaults
closes: #8676
Description
Combine Cosmos SDK context and type tags with reflection to reduce the boilerplate needed to create "actions" to be sent to the SwingSet VM.
The pioneering work was done by @gibson042 in #8676, I just tried to make it more thorough and use it throughout
golang/cosmos
.Security Considerations
n/a
Scaling Considerations
n/a
Documentation Considerations
Agoric-Cosmos internals-only, should be documented in comments to give clues, but need not be published elsewhere.
Testing Considerations
Unit tests of
vm.WithActionContext
, otherwise reliant on existing tests for basic functionality.Upgrade Considerations
n/a