From 03c54bde6cc71c6f3ada7f1ea665f98335a26f08 Mon Sep 17 00:00:00 2001 From: rachid Date: Mon, 23 Oct 2023 19:43:33 +0100 Subject: [PATCH] feat: orchestrator signing up to earliest attestation nonce --- e2e/Dockerfile_e2e | 2 +- orchestrator/orchestrator.go | 39 ++++-------------------------------- rpc/app_querier.go | 11 ++++++++++ rpc/app_querier_test.go | 14 +++++++++++++ 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/e2e/Dockerfile_e2e b/e2e/Dockerfile_e2e index 1ff6c61d..2a9d9dcc 100644 --- a/e2e/Dockerfile_e2e +++ b/e2e/Dockerfile_e2e @@ -6,7 +6,7 @@ WORKDIR /orchestrator-relayer RUN make build # final image -FROM ghcr.io/celestiaorg/celestia-app:v1.1.0 +FROM ghcr.io/celestiaorg/celestia-app:v1.2.0 USER root diff --git a/orchestrator/orchestrator.go b/orchestrator/orchestrator.go index f8d9b392..ee82b2c0 100644 --- a/orchestrator/orchestrator.go +++ b/orchestrator/orchestrator.go @@ -203,50 +203,19 @@ func (orch Orchestrator) EnqueueMissingEvents( return err } - lastUnbondingHeight, err := orch.AppQuerier.QueryLastUnbondingHeight(ctx) + earliestAttestationNonce, err := orch.AppQuerier.QueryEarliestAttestationNonce(ctx) if err != nil { return err } - var startingNonce uint64 - if lastUnbondingHeight == 0 { - // chain startup case - startingNonce = 1 - } else { - lastDc, err := orch.AppQuerier.QueryLatestDataCommitment(ctx) - if err != nil { - return err - } - if lastUnbondingHeight >= int64(lastDc.EndBlock) { - // if no data commitment has committed to the last unbonding height, - // then, the orchestrator should start signing at the latest valset - vs, err := orch.AppQuerier.QueryLatestValset(ctx) - if err != nil { - return err - } - startingNonce = vs.Nonce - } else { - // some data commitment has committed to the last unbonding height, - // so, we start signing from the valset that attests to that one - dc, err := orch.AppQuerier.QueryDataCommitmentForHeight(ctx, uint64(lastUnbondingHeight)) - if err != nil { - return err - } - startingValset, err := orch.AppQuerier.QueryLastValsetBeforeNonce(ctx, dc.Nonce) - if err != nil { - return err - } - startingNonce = startingValset.Nonce - } - } - orch.Logger.Info("syncing missing nonces", "latest_nonce", latestNonce, "first_nonce", startingNonce) + orch.Logger.Info("syncing missing nonces", "latest_nonce", latestNonce, "first_nonce", earliestAttestationNonce) // To accommodate the delay that might happen between starting the two go routines above. // Probably, it would be a good idea to further refactor the orchestrator to the relayer style // as it is entirely synchronous. Probably, enqueuing separately old nonces and new ones, is not // the best design. // TODO decide on this later - for i := uint64(0); i < latestNonce-startingNonce+1; i++ { + for i := uint64(0); i < latestNonce-uint64(earliestAttestationNonce)+1; i++ { select { case <-signalChan: return ErrSignalChanNotif @@ -263,7 +232,7 @@ func (orch Orchestrator) EnqueueMissingEvents( } } } - orch.Logger.Info("finished syncing missing nonces", "latest_nonce", latestNonce, "first_nonce", startingNonce) + orch.Logger.Info("finished syncing missing nonces", "latest_nonce", latestNonce, "first_nonce", earliestAttestationNonce) return nil } diff --git a/rpc/app_querier.go b/rpc/app_querier.go index a6397c5d..1a4d873d 100644 --- a/rpc/app_querier.go +++ b/rpc/app_querier.go @@ -181,6 +181,17 @@ func (aq *AppQuerier) QueryLastUnbondingHeight(ctx context.Context) (int64, erro return int64(resp.Height), nil } +// QueryEarliestAttestationNonce query the earliest attestation nonce from state machine. +func (aq *AppQuerier) QueryEarliestAttestationNonce(ctx context.Context) (int64, error) { + queryClient := celestiatypes.NewQueryClient(aq.clientConn) + resp, err := queryClient.EarliestAttestationNonce(ctx, &celestiatypes.QueryEarliestAttestationNonceRequest{}) + if err != nil { + return 0, err + } + + return int64(resp.Nonce), nil +} + // unmarshallAttestation unmarshal a wrapper protobuf `Any` type to an `AttestationRequestI`. func (aq *AppQuerier) unmarshallAttestation(attestation *cdctypes.Any) (celestiatypes.AttestationRequestI, error) { var unmarshalledAttestation celestiatypes.AttestationRequestI diff --git a/rpc/app_querier_test.go b/rpc/app_querier_test.go index a76093ab..0dab597f 100644 --- a/rpc/app_querier_test.go +++ b/rpc/app_querier_test.go @@ -119,3 +119,17 @@ func (s *QuerierTestSuite) TestQueryLastUnbondingHeight() { s.NoError(err) s.Equal(int64(0), unbondingHeight) } + +func (s *QuerierTestSuite) TestQueryEarliestAttestationNonce() { + appQuerier := rpc.NewAppQuerier( + s.Logger, + s.Network.GRPCAddr, + s.EncConf, + ) + require.NoError(s.T(), appQuerier.Start()) + defer appQuerier.Stop() //nolint:errcheck + + earliestNonce, err := appQuerier.QueryEarliestAttestationNonce(context.Background()) + s.NoError(err) + s.Equal(int64(1), earliestNonce) +}