-
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 all 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 |
---|---|---|
@@ -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"` | ||
|
||
// 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:",notnull,use_zero"` | ||
// ActorCode of To (receiver). | ||
ActorCode string `pg:",notnull"` | ||
// ExitCode of message execution. | ||
ExitCode int64 `pg:",notnull,use_zero"` | ||
// GasUsed by message. | ||
GasUsed int64 `pg:",notnull,use_zero"` | ||
// 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,44 @@ | ||
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 BTREE (height); | ||
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); | ||
|
||
|
||
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 think we need
source
to be included in the primary key.cid
should have enough uniqueness within a height/stateroot.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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
cid
the CID of the intermediate (internal) message? In other words, onesource
has manycid
s? If so, then the index should go on the column with the higher cardinality (betweencid
andsource
) which I expect to be the intermediate message CIDs and I understand that to be thecid
column.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.
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 comment
The 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
source
if we ever need to condition on that column. It should reduce the size of the PK index without any performance cost.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. After some discussion w @frrist, it seems that the
cid
is not unique and sosource
is required in the PK afterall. 😢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 would probably recommend the removal of the hash-based
source
index. I think both indices are redundant and if the PK index isn't getting a trim, let's drop the other.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.
+1 on dropping the
source
hash index esp if it's part of the PK.