From 1afb8be4dc53346ce9b50b92f25482f37702d5ac Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:06:10 +0100 Subject: [PATCH] test(e2e): test finalize snapshot in e2e tests --- abci/example/kvstore/kvstore.go | 17 +++++++++++++++++ test/e2e/networks/rotate.toml | 4 ++-- test/e2e/pkg/mockcoreserver/methods.go | 2 +- test/e2e/runner/setup.go | 6 +++++- types/quorum_sign_data.go | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/abci/example/kvstore/kvstore.go b/abci/example/kvstore/kvstore.go index bf952d5ab4..66b01ab1e4 100644 --- a/abci/example/kvstore/kvstore.go +++ b/abci/example/kvstore/kvstore.go @@ -579,6 +579,23 @@ func (app *Application) ApplySnapshotChunk(_ context.Context, req *abci.RequestA app.logger.Debug("ApplySnapshotChunk", "resp", resp) return resp, nil } + +func (app *Application) FinalizeSnapshot(ctx context.Context, req *abci.RequestFinalizeSnapshot) (*abci.ResponseFinalizeSnapshot, error) { + app.mu.Lock() + defer app.mu.Unlock() + + // we only verify the snapshot + if app.LastCommittedState.GetHeight() != req.LightBlock.SignedHeader.Header.Height { + return &abci.ResponseFinalizeSnapshot{}, fmt.Errorf("snapshot height mismatch") + } + + if !app.LastCommittedState.GetAppHash().Equal(req.LightBlock.SignedHeader.Header.AppHash) { + return &abci.ResponseFinalizeSnapshot{}, fmt.Errorf("snapshot apphash mismatch") + } + + app.logger.Info("FinalizeSnapshot finished successfully", "req", req) + return &abci.ResponseFinalizeSnapshot{}, nil +} func (app *Application) appVersionForHeight(height int64) uint64 { if app.appVersion == 0 { return uint64(height) diff --git a/test/e2e/networks/rotate.toml b/test/e2e/networks/rotate.toml index 2e725ec190..30f6943097 100644 --- a/test/e2e/networks/rotate.toml +++ b/test/e2e/networks/rotate.toml @@ -152,7 +152,7 @@ start_at = 1005 # Becomes part of the validator set at 1030 to ensure ther seeds = ["seed01"] snapshot_interval = 5 block_sync = "v0" -#state_sync = "p2p" +state_sync = "p2p" #persistent_peers = ["validator01", "validator02", "validator03", "validator04", "validator05", "validator07", "validator08"] perturb = ["pause", "disconnect", "restart"] privval_protocol = "dashcore" @@ -192,7 +192,7 @@ privval_protocol = "dashcore" start_at = 1030 mode = "full" block_sync = "v0" -#state_sync = "rpc" +state_sync = "p2p" persistent_peers = [ "validator01", "validator02", diff --git a/test/e2e/pkg/mockcoreserver/methods.go b/test/e2e/pkg/mockcoreserver/methods.go index 5894dfa867..b38f17982b 100644 --- a/test/e2e/pkg/mockcoreserver/methods.go +++ b/test/e2e/pkg/mockcoreserver/methods.go @@ -64,8 +64,8 @@ func WithQuorumVerifyMethod(cs CoreServer, times int) MethodFunc { &cmd.LLMQType, &cmd.RequestID, &cmd.MessageHash, - &cmd.QuorumHash, &cmd.Signature, + &cmd.QuorumHash, ) if err != nil { return nil, err diff --git a/test/e2e/runner/setup.go b/test/e2e/runner/setup.go index b15302408a..77665e932e 100644 --- a/test/e2e/runner/setup.go +++ b/test/e2e/runner/setup.go @@ -455,6 +455,10 @@ func MakeAppConfig(node *e2e.Node) ([]byte, error) { } // UpdateConfigStateSync updates the state sync config for a node. +// Arguments: +// - node: the node to update +// - height: the height to trust +// - hash: the hash of the block at `height` to trust func UpdateConfigStateSync(node *e2e.Node, height int64, hash []byte) error { cfgPath := filepath.Join(node.Testnet.Dir, node.Name, "config", "config.toml") @@ -464,7 +468,7 @@ func UpdateConfigStateSync(node *e2e.Node, height int64, hash []byte) error { if err != nil { return err } - bz = regexp.MustCompile(`(?m)^trust-height =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-height = %v`, height-1))) + bz = regexp.MustCompile(`(?m)^trust-height =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-height = %v`, height))) bz = regexp.MustCompile(`(?m)^trust-hash =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust-hash = "%X"`, hash))) //nolint: gosec // G306: Expect WriteFile permissions to be 0600 or less diff --git a/types/quorum_sign_data.go b/types/quorum_sign_data.go index 1bd51c6224..ee73d4b46b 100644 --- a/types/quorum_sign_data.go +++ b/types/quorum_sign_data.go @@ -161,7 +161,7 @@ func (i *SignItem) Validate() error { if len(i.MsgHash) != crypto.DefaultHashSize { return fmt.Errorf("invalid hash size %d: %X", len(i.MsgHash), i.MsgHash) } - if len(i.QuorumHash) != crypto.DefaultHashSize { + if len(i.QuorumHash) != crypto.QuorumHashSize { return fmt.Errorf("invalid quorum hash size %d: %X", len(i.QuorumHash), i.QuorumHash) } // Msg is optional