Skip to content
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: add nonce column to actor_states #1105

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions model/actors/common/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type ActorState struct {
Code string `pg:",pk,notnull"`
// Top level of state data as json.
State string `pg:",type:jsonb,notnull"`
// The next Actor nonce that is expected to appear on chain.
Copy link
Member

Choose a reason for hiding this comment

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

Since we're already making changes here, let's add a state_root field too. It will make the table re-org safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, let me think harder about the schema then because I don't wanna overcomplicate things but also make sure it's correct.

Nonce uint64 `pg:",use_zero"`
}

func (as *ActorState) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
Expand Down
14 changes: 14 additions & 0 deletions schemas/v1/13_actorstates_nonce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package v1

func init() {
patches.Register(
13,
`
ALTER TABLE {{ .SchemaName | default "public"}}.actor_states
ADD COLUMN nonce BIGINT,
ADD CONSTRAINT actor_states_uniq_nullable_nonce UNIQUE (height,head,nonce);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should replace height with state_root as it's reorg safe.


COMMENT ON COLUMN {{ .SchemaName | default "public"}}.actor_states.nonce IS 'The nonce of the actor expected to appear on the chain after the actor has been modified or created at each epoch. More precisely, this nonce tracks the number of messages sent by an actor.';
`,
)
}
1 change: 1 addition & 0 deletions tasks/actorstate/raw/actor_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ func (RawActorStateExtractor) Extract(ctx context.Context, a actorstate.ActorInf
Head: a.Actor.Head.String(),
Code: a.Actor.Code.String(),
State: string(state),
Nonce: a.Actor.Nonce,
}, nil
}