Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

feat: orchestrator signing up to earliest attestation nonce #555

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/Dockerfile_e2e
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 4 additions & 35 deletions orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions rpc/app_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions rpc/app_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading