From f32bdec22064011908ce2c81c49093c8cd929f7d Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Thu, 22 Dec 2022 14:32:26 +0900 Subject: [PATCH 1/6] feat: add nonce column to actor_states --- model/actors/common/actors.go | 2 ++ schemas/v1/13_actorstates_nonce.go | 13 +++++++++++++ tasks/actorstate/raw/actor_state.go | 1 + 3 files changed, 16 insertions(+) create mode 100644 schemas/v1/13_actorstates_nonce.go diff --git a/model/actors/common/actors.go b/model/actors/common/actors.go index fd836c8bb..ba5d2b58c 100644 --- a/model/actors/common/actors.go +++ b/model/actors/common/actors.go @@ -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. + Nonce uint64 `pg:",use_zero"` } func (as *ActorState) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { diff --git a/schemas/v1/13_actorstates_nonce.go b/schemas/v1/13_actorstates_nonce.go new file mode 100644 index 000000000..0bdd3f333 --- /dev/null +++ b/schemas/v1/13_actorstates_nonce.go @@ -0,0 +1,13 @@ +package v1 + +func init() { + patches.Register( + 7, + ` +ALTER TABLE {{ .SchemaName | default "public"}}.actor_states +ADD COLUMN nonce BIGINT; + +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.'; +`, + ) +} diff --git a/tasks/actorstate/raw/actor_state.go b/tasks/actorstate/raw/actor_state.go index c599f8759..21a9509f3 100644 --- a/tasks/actorstate/raw/actor_state.go +++ b/tasks/actorstate/raw/actor_state.go @@ -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 } From 464728e84b1cea3252339761dc0e90b0ae38c831 Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Thu, 22 Dec 2022 14:35:11 +0900 Subject: [PATCH 2/6] fix: patch number --- schemas/v1/13_actorstates_nonce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/v1/13_actorstates_nonce.go b/schemas/v1/13_actorstates_nonce.go index 0bdd3f333..b053032b0 100644 --- a/schemas/v1/13_actorstates_nonce.go +++ b/schemas/v1/13_actorstates_nonce.go @@ -2,7 +2,7 @@ package v1 func init() { patches.Register( - 7, + 13, ` ALTER TABLE {{ .SchemaName | default "public"}}.actor_states ADD COLUMN nonce BIGINT; From d9fa6d6570d4232af0d5a06e55483ffc28dd585b Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Tue, 3 Jan 2023 12:46:15 +0900 Subject: [PATCH 3/6] chore: add uniq_nullable on nonce --- schemas/v1/13_actorstates_nonce.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/schemas/v1/13_actorstates_nonce.go b/schemas/v1/13_actorstates_nonce.go index b053032b0..4f3013c84 100644 --- a/schemas/v1/13_actorstates_nonce.go +++ b/schemas/v1/13_actorstates_nonce.go @@ -5,7 +5,8 @@ func init() { 13, ` ALTER TABLE {{ .SchemaName | default "public"}}.actor_states -ADD COLUMN nonce BIGINT; + ADD COLUMN nonce BIGINT + ADD CONSTRAINT uniq_nullable_nonce UNIQUE (head,nonce); 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.'; `, From 549ee0281a348037928057e130ea2dd163ea8e72 Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Tue, 3 Jan 2023 12:49:25 +0900 Subject: [PATCH 4/6] forgot a comma --- schemas/v1/13_actorstates_nonce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/v1/13_actorstates_nonce.go b/schemas/v1/13_actorstates_nonce.go index 4f3013c84..883a93e36 100644 --- a/schemas/v1/13_actorstates_nonce.go +++ b/schemas/v1/13_actorstates_nonce.go @@ -5,7 +5,7 @@ func init() { 13, ` ALTER TABLE {{ .SchemaName | default "public"}}.actor_states - ADD COLUMN nonce BIGINT + ADD COLUMN nonce BIGINT, ADD CONSTRAINT uniq_nullable_nonce UNIQUE (head,nonce); 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.'; From f29e1f5de097b4063d4eb596ae3fd4ffcaacd288 Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Tue, 3 Jan 2023 13:04:37 +0900 Subject: [PATCH 5/6] timescaledb requires ts to be included in index --- schemas/v1/13_actorstates_nonce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/v1/13_actorstates_nonce.go b/schemas/v1/13_actorstates_nonce.go index 883a93e36..6fe4c1ca9 100644 --- a/schemas/v1/13_actorstates_nonce.go +++ b/schemas/v1/13_actorstates_nonce.go @@ -6,7 +6,7 @@ func init() { ` ALTER TABLE {{ .SchemaName | default "public"}}.actor_states ADD COLUMN nonce BIGINT, - ADD CONSTRAINT uniq_nullable_nonce UNIQUE (head,nonce); + ADD CONSTRAINT uniq_nullable_nonce UNIQUE (height,head,nonce); 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.'; `, From abe4b0262d8a0e6d7e1f117ce958b7c10ad7ba2a Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Tue, 3 Jan 2023 13:13:23 +0900 Subject: [PATCH 6/6] chore: rename constraint --- schemas/v1/13_actorstates_nonce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/v1/13_actorstates_nonce.go b/schemas/v1/13_actorstates_nonce.go index 6fe4c1ca9..caa7de885 100644 --- a/schemas/v1/13_actorstates_nonce.go +++ b/schemas/v1/13_actorstates_nonce.go @@ -6,7 +6,7 @@ func init() { ` ALTER TABLE {{ .SchemaName | default "public"}}.actor_states ADD COLUMN nonce BIGINT, - ADD CONSTRAINT uniq_nullable_nonce UNIQUE (height,head,nonce); + ADD CONSTRAINT actor_states_uniq_nullable_nonce UNIQUE (height,head,nonce); 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.'; `,