-
Notifications
You must be signed in to change notification settings - Fork 45
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: implement vm message extraction #1027
Changes from 3 commits
1f883dc
db929fe
3436263
e29c595
59f8217
6e88926
ac53c8c
b6b937f
9290f14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ const ( | |||||
ParsedMessage = "parsed_message" | ||||||
InternalMessage = "internal_messages" | ||||||
InternalParsedMessage = "internal_parsed_messages" | ||||||
VmMessage = "vm_messages" | ||||||
MultisigTransaction = "multisig_transaction" | ||||||
ChainPower = "chain_power" | ||||||
PowerActorClaim = "power_actor_claim" | ||||||
|
@@ -62,6 +63,7 @@ var AllTableTasks = []string{ | |||||
ParsedMessage, | ||||||
InternalMessage, | ||||||
InternalParsedMessage, | ||||||
VmMessage, | ||||||
MultisigTransaction, | ||||||
ChainPower, | ||||||
PowerActorClaim, | ||||||
|
@@ -100,6 +102,7 @@ var TableLookup = map[string]struct{}{ | |||||
ParsedMessage: {}, | ||||||
InternalMessage: {}, | ||||||
InternalParsedMessage: {}, | ||||||
VmMessage: {}, | ||||||
MultisigTransaction: {}, | ||||||
ChainPower: {}, | ||||||
PowerActorClaim: {}, | ||||||
|
@@ -138,6 +141,7 @@ var TableComment = map[string]string{ | |||||
ParsedMessage: ``, | ||||||
InternalMessage: ``, | ||||||
InternalParsedMessage: ``, | ||||||
VmMessage: ``, | ||||||
MultisigTransaction: ``, | ||||||
ChainPower: ``, | ||||||
PowerActorClaim: ``, | ||||||
|
@@ -178,8 +182,9 @@ var TableFieldComments = map[string]map[string]string{ | |||||
"DealID": "Identifier for the deal.", | ||||||
"EndEpoch": "The epoch at which this deal with end.", | ||||||
"Height": "Epoch at which this deal proposal was added or changed.", | ||||||
"IsString": "Related to FIP: https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0027.md", | ||||||
"IsVerified": "Deal is with a verified provider.", | ||||||
"Label": "An arbitrary client chosen label to apply to the deal.", | ||||||
"Label": "An arbitrary client chosen label to apply to the deal. The value is base64 encoded before persisting.", | ||||||
"PaddedPieceSize": "The piece size in bytes with padding.", | ||||||
"PieceCID": "CID of a sector piece. A Piece is an object that represents a whole or part of a File.", | ||||||
"ProviderCollateral": "The amount of FIL (in attoFIL) the provider has pledged as collateral. The Provider deal collateral is only slashed when a sector is terminated before the deal expires.", | ||||||
|
@@ -197,6 +202,21 @@ var TableFieldComments = map[string]map[string]string{ | |||||
ParsedMessage: {}, | ||||||
InternalMessage: {}, | ||||||
InternalParsedMessage: {}, | ||||||
VmMessage: { | ||||||
"ActorCode": "ActorCode of To (receiver)", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"Cid": "Cid of the message.", | ||||||
"ExitCode": "ExitCode of message execution.", | ||||||
"From": "From sender of message.", | ||||||
"GasUsed": "GasUsed by message.", | ||||||
"Height": "Height message was executed at.", | ||||||
"Method": "Method called on To (receiver)", | ||||||
"Params": "Params contained in message.", | ||||||
"Returns": "Return value of message.", | ||||||
"Source": "On-chain message triggering the message.", | ||||||
"StateRoot": "StateRoot message was applied to.", | ||||||
"To": "To receiver of message.", | ||||||
"Value": "Value attoFIL contained in message.", | ||||||
}, | ||||||
MultisigTransaction: { | ||||||
"To": "Transaction State", | ||||||
}, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||
package messages | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
|
||||||
"go.opencensus.io/tag" | ||||||
|
||||||
"github.com/filecoin-project/lily/metrics" | ||||||
"github.com/filecoin-project/lily/model" | ||||||
) | ||||||
|
||||||
type VMMessage struct { | ||||||
tableName struct{} `pg:"vm_messages"` // nolint: structcheck | ||||||
|
||||||
// Height message was executed at. | ||||||
Height int64 `pg:",pk,notnull,use_zero"` | ||||||
// StateRoot message was applied to. | ||||||
StateRoot string `pg:",pk,notnull"` | ||||||
// Cid of the message. | ||||||
Cid string `pg:",pk,notnull"` | ||||||
// On-chain message triggering the message. | ||||||
Source string `pg:",pk,notnull"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source must remain a primary key as VM message CIDs can conflict at the same height/stateroot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes correct. Are you proposing we drop source as a primary key? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Just remove from the PK to reduce the size of that index. We can use the standalone hash index for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. After some discussion w @frrist, it seems that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably recommend the removal of the hash-based There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on dropping the |
||||||
|
||||||
// From sender of message. | ||||||
From string `pg:",notnull"` | ||||||
// To receiver of message. | ||||||
To string `pg:",notnull"` | ||||||
// Value attoFIL contained in message. | ||||||
Value string `pg:"type:numeric,notnull"` | ||||||
// Method called on To (receiver) | ||||||
Method uint64 `pg:",use_zero"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not null? (I know this is inconsequential given we write our own migrations, but it's good context that doesn't hurt to include and keeps consistency w other fields usage of the same tag.)
Suggested change
|
||||||
// ActorCode of To (receiver) | ||||||
ActorCode string `pg:",notnull"` | ||||||
// ExitCode of message execution. | ||||||
ExitCode int64 `pg:",use_zero"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// GasUsed by message. | ||||||
GasUsed int64 `pg:",use_zero"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Params contained in message. | ||||||
Params string `pg:",type:jsonb"` | ||||||
// Return value of message. | ||||||
Returns string `pg:",type:jsonb"` | ||||||
} | ||||||
|
||||||
func (v *VMMessage) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { | ||||||
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "vm_messages")) | ||||||
stop := metrics.Timer(ctx, metrics.PersistDuration) | ||||||
defer stop() | ||||||
|
||||||
metrics.RecordCount(ctx, metrics.PersistModel, 1) | ||||||
return s.PersistModel(ctx, v) | ||||||
} | ||||||
|
||||||
type VMMessageList []*VMMessage | ||||||
|
||||||
func (vl VMMessageList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { | ||||||
if len(vl) == 0 { | ||||||
return nil | ||||||
} | ||||||
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "vm_messages")) | ||||||
stop := metrics.Timer(ctx, metrics.PersistDuration) | ||||||
defer stop() | ||||||
|
||||||
metrics.RecordCount(ctx, metrics.PersistModel, len(vl)) | ||||||
return s.PersistModel(ctx, vl) | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||
package v1 | ||||||
|
||||||
func init() { | ||||||
patches.Register( | ||||||
8, | ||||||
` | ||||||
CREATE TABLE {{ .SchemaName | default "public"}}.vm_messages ( | ||||||
height bigint NOT NULL, | ||||||
state_root text NOT NULL, | ||||||
cid text NOT NULL, | ||||||
source text, | ||||||
"from" text NOT NULL, | ||||||
"to" text NOT NULL, | ||||||
value numeric NOT NULL, | ||||||
method bigint NOT NULL, | ||||||
actor_code text NOT NULL, | ||||||
exit_code bigint NOT NULL, | ||||||
gas_used bigint NOT NULL, | ||||||
params jsonb, | ||||||
returns jsonb | ||||||
); | ||||||
ALTER TABLE ONLY {{ .SchemaName | default "public"}}.vm_messages ADD CONSTRAINT vm_messages_pkey PRIMARY KEY (height, state_root, cid, source); | ||||||
frrist marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
CREATE INDEX vm_messages_height_idx ON {{ .SchemaName | default "public"}}.vm_messages USING BRIN (height); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think BRIN indexing is dependent on write order, which is use-case specific. BTREE is the better generalized index here.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, will use btree instead. |
||||||
CREATE INDEX vm_messages_cid_idx ON {{ .SchemaName | default "public"}}.vm_messages USING HASH (cid); | ||||||
CREATE INDEX vm_messages_source_idx ON {{ .SchemaName | default "public"}}.vm_messages USING HASH (source); | ||||||
CREATE INDEX vm_messages_from_idx ON {{ .SchemaName | default "public"}}.vm_messages USING HASH ("from"); | ||||||
CREATE INDEX vm_messages_to_idx ON {{ .SchemaName | default "public"}}.vm_messages USING HASH ("to"); | ||||||
CREATE INDEX vm_messages_actor_code_method_idx ON {{ .SchemaName | default "public"}}.vm_messages USING BTREE (actor_code, method); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
|
||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.height IS 'Height message was executed at.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.state_root IS 'CID of the parent state root at which this message was executed.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.cid IS 'CID of the message (note this CID does not appear on chain).'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.source IS 'CID of the on-chain message that caused this message to be sent.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages."from" IS 'Address of the actor that sent the message.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages."to" IS 'Address of the actor that received the message.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.value IS 'Amount of FIL (in attoFIL) transferred by this message.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.method IS 'The method number invoked on the recipient actor. Only unique to the actor the method is being invoked on. A method number of 0 is a plain token transfer - no method execution'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.actor_code IS 'The CID of the actor that received the message.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.exit_code IS 'The exit code that was returned as a result of executing the message.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.gas_used IS 'A measure of the amount of resources (or units of gas) consumed, in order to execute a message.'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious: Do you know what resources this would be other than gas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reusing the description of gas here that we use elsewhere, e.g.: https://github.com/filecoin-project/lily/blob/v0.10.0/schemas/v1/base.go#L391 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspected it was copypasta. Just wondering if there is anything other than gas that it would have been referring to and couldn't think of. |
||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.params IS 'Message parameters parsed and serialized as a JSON object.'; | ||||||
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.returns IS 'Result returned from executing a message parsed and serialized as a JSON object.'; | ||||||
`, | ||||||
) | ||||||
} |
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 want to read the FIP to get the gist.