Skip to content

feat(zhtlc): estimate activation percentage based on block height#230

Merged
takenagain merged 3 commits intobugfix/zhltc-activation-fixesfrom
feat/zhtlc-activation-progress
Sep 30, 2025
Merged

feat(zhtlc): estimate activation percentage based on block height#230
takenagain merged 3 commits intobugfix/zhltc-activation-fixesfrom
feat/zhtlc-activation-progress

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

@takenagain takenagain commented Sep 29, 2025

Summary by CodeRabbit

  • New Features

    • Rich, phase-based progress for ZHTLC activation with clearer step counts and percentage estimates.
    • Dedicated messages for missing Zcash parameters and other terminal states.
    • Actionable error messages and signals when user action is required (e.g., hardware wallet prompts).
  • Improvements

    • More consistent, real-time activation updates driven by a unified progress estimator.
    • Faster, more reliable completion detection and streamlined status handling.
    • Improved guidance for hardware wallet flows (e.g., Trezor).
  • Bug Fixes

    • Reduced spurious failures during activation monitoring and improved error handling.

@takenagain takenagain self-assigned this Sep 29, 2025
@takenagain takenagain added the enhancement New feature or request label Sep 29, 2025
Copilot AI review requested due to automatic review settings September 29, 2025 15:54
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 29, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly follows conventional commit style by indicating a new feature for ZHTLC and clearly communicates the primary change of estimating activation progress based on block height, which aligns with the pull request’s core objective of introducing a progress estimator driven by blockchain height. It is concise, specific to the scope, and directly reflects the main functionality added without extraneous information.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@takenagain
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 29, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the ZHTLC activation strategy to use a new progress estimation system based on block height tracking rather than hardcoded progress percentages. The changes introduce a dedicated progress estimator that can calculate activation percentage based on the current scanned block versus the latest known block height.

Key changes:

  • Introduces a new progress estimation system with block height-based percentage calculations
  • Replaces hardcoded progress updates with a configurable estimator class
  • Adds structured progress reporting with better error handling and user action signals

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
zhtlc_activation_strategy.dart Refactored to use the new progress estimator instead of inline progress calculations
zhtlc_activation_progress_estimator.dart New class that estimates activation progress based on block heights and task phases
zhtlc_activation_progress.dart New convenience wrapper for creating standardized ZHTLC progress snapshots

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 29, 2025

Visit the preview URL for this PR (updated for commit 04c4ca5):

https://kdf-sdk--pr230-feat-zhtlc-activatio-ndlutfl8.web.app

(expires Tue, 07 Oct 2025 00:07:16 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 9c1b6e6c010cf0b965c455ba7a69c4aedafa8a1d

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 29, 2025

Visit the preview URL for this PR (updated for commit 04c4ca5):

https://komodo-playground--pr230-feat-zhtlc-activatio-rgbyec5v.web.app

(expires Tue, 07 Oct 2025 00:07:45 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 2bfedd77fdea45b25ba7c784416e81f177aa5c47

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (5)
packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_progress_estimator.dart (1)

181-206: OK + error detail precedence (minor).

If status.status == 'Ok' but details embeds {"error":...}, we emit a terminal failure. That’s safer, but please confirm the daemon never embeds "error" in a success payload (e.g., warning). If it can, gate on a stronger signal (e.g., error.level == 'fatal') or prefer the phase (completed) over the presence of error.

Also applies to: 208-225

packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_progress.dart (2)

52-53: Deduplicate the error code constant.

Avoid hardcoding 'ZHTLC_ACTIVATION_ERROR' in multiple files. Expose a single constant and reuse it.

 class ZhtlcActivationProgress extends ActivationProgress {
+  static const errorCode = 'ZHTLC_ACTIVATION_ERROR';
@@
-        errorCode: 'ZHTLC_ACTIVATION_ERROR',
+        errorCode: ZhtlcActivationProgress.errorCode,

Optionally import and use this in the estimator to replace its private _kZhtlcErrorCode.


56-58: Use UTC timestamps for diagnostics.

DateTime.now().toIso8601String() is local time and ambiguous. Prefer UTC for logs/telemetry.

-          'timestamp': DateTime.now().toIso8601String(),
+          'timestamp': DateTime.now().toUtc().toIso8601String(),
packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_strategy.dart (2)

63-67: Avoid lossy as casts when copying typed config (minor).

If these fields are already strongly typed in userConfig, the as int?/String? casts add risk (throw on unexpected num/String). Pass them directly.

-          .copyWith(
-            scanBlocksPerIteration: userConfig.scanBlocksPerIteration as int?,
-            scanIntervalMs: userConfig.scanIntervalMs as int?,
-            zcashParamsPath: userConfig.zcashParamsPath as String?,
-            privKeyPolicy: privKeyPolicy,
-          );
+          .copyWith(
+            scanBlocksPerIteration: userConfig.scanBlocksPerIteration,
+            scanIntervalMs: userConfig.scanIntervalMs,
+            zcashParamsPath: userConfig.zcashParamsPath,
+            privKeyPolicy: privKeyPolicy,
+          );

93-95: Make polling interval configurable (optional).

500ms is fine for UX but can be heavy on mobile networks. Consider sourcing from config or backing off after N steady states.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6e924c and 0c1f9c2.

📒 Files selected for processing (3)
  • packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_progress.dart (1 hunks)
  • packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_progress_estimator.dart (1 hunks)
  • packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_strategy.dart (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build_and_preview_playground_preview
  • GitHub Check: build_and_preview_sdk_example_preview
  • GitHub Check: Flutter tests (all packages)
🔇 Additional comments (1)
packages/komodo_defi_sdk/lib/src/activation/protocol_strategies/zhtlc_activation_progress_estimator.dart (1)

259-283: Confirm completed heuristic keys appear only in final ZHTLC status
Couldn’t find any example fixtures for enableZhtlcStatus; manually verify that wallet_balance, current_block, and ticker only occur in the terminal “completed” payload (zhtlc_activation_progress_estimator.dart L259–283).

@takenagain takenagain merged commit 1af4278 into bugfix/zhltc-activation-fixes Sep 30, 2025
2 of 3 checks passed
@takenagain takenagain deleted the feat/zhtlc-activation-progress branch September 30, 2025 00:01
CharlVS added a commit that referenced this pull request Oct 2, 2025
* Enhance ZHTLC activation with improved config parsing and RPC methods

Co-authored-by: charl <charl@vanstaden.info>

* feat(zhtlc): integrate ZHTLC types and task RPCs per KDF API

* dragon_logs: remove tracked ignored files and add .gitignore files

* Integrate and verify ZHTLC in komodo_defi_sdk (#196)

* Refactor ZHTLC activation strategy with stream-based task handling

Co-authored-by: charl <charl@vanstaden.info>

* Refactor activation steps to use strongly-typed ActivationStep enum

Co-authored-by: charl <charl@vanstaden.info>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>

* chore: run code generators

* chore(git): delete previously tracked igored files

* Fix ERC20 and ZHTLC activation params serialization and method calls (#212)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>

* fix: misc fixes

* docs(activation): add activation params refactoring plan

Clean base/subclass separation, canonical serialization + encoder strategy, user configuration + persistence, BLoC timeout, SDK integration via AssetId extension and resolveActivationParams, and migration steps. No backwards compatibility required.

* docs(sdk): activation refactoring v2

* feat(activation,zhtlc,sdk,rpc)!: extract ZHTLC fields to ZhtlcActivationParams; add ActivationConfigService; unify priv_key_policy serialization; normalize toRpcParams; formatting fixes

* Checkpoint before follow-up message

Co-authored-by: charl <charl@vanstaden.info>

* Fix: Remove unused import statement

Co-authored-by: charl <charl@vanstaden.info>

* feat: Add support for electrum_servers in Zhtlc activation

Co-authored-by: charl <charl@vanstaden.info>

* feat: initialize Firebase hosting for SDK example and playground

- Add Firebase hosting configuration for packages/komodo_defi_sdk/example
  - Configure to use kdf-sdk hosting site on komodo-defi-sdk project
  - Set up hosting target mapping
- Add Firebase hosting configuration for playground
  - Configure to use default hosting site on komodo-playground project
- Update GitHub Actions workflows to use target parameter for SDK example
- Update .gitignore to allow Firebase config files in example and playground

* fix: update z-coin activation strategy and example UI

- Update zhtlc_activation_strategy for improved activation handling
- Add activation config service enhancements
- Update logged_in_view_widget with improved UI for instance management
- Export additional SDK functionality in public API

* docs(firebase): reorganize Firebase deployment scripts and documentation

- Move Firebase scripts to .github/scripts/firebase/ directory
- Rename scripts for clarity:
  - setup-firebase-secrets.sh → setup-github-secrets.sh
  - verify-firebase-secrets.sh → verify-github-secrets.sh
- Move documentation to docs/firebase/ directory
- Rename documentation file to firebase-deployment-setup.md
- Update script paths in documentation
- Add README for scripts directory

* fix: remove global singleton registration of ActivationConfigService

- Remove global GetIt.I registration to prevent conflicts between multiple SDK instances
- Pass ActivationConfigService through constructor chain instead of global resolution
- Update ZhtlcActivationStrategy to accept service via constructor
- Update ActivationStrategyFactory and ActivationManager to propagate the service
- Prevent memory leaks and use-after-dispose issues when SDK instances are disposed

This ensures each SDK instance maintains its own isolated ActivationConfigService,
fixing issues where only the first SDK's service would be globally registered.

* fix(activation): register ActivationConfigService during bootstrap

- Ensure service is available before ActivationManager to fix ZHTLC/Z-coin activation flow\n- Remove duplicate registration from KomodoDefiSdk.init\n- Example: use instance sdk instead of context.read for ZHTLC prompt

* docs(tech-debt): add Activation & ZHTLC tech-debt report and refine sections

* feat(komodo_defi_sdk): add HiveActivationConfigRepository and integrate in activation flow; update bootstrap, activation service, and example widget

* fix: resolve external logging callback flaws and memory leak

- Fix native callback memory leak by disposing _kdfOperations in KomodoDefiFramework
- Remove debug-only conditional logging in bootstrap.dart
- Fix potential double subscription in komodo_defi_sdk.dart
- Add comprehensive error handling to log stream listeners
- Replace empty catch blocks with proper error handling
- Add safe logging helpers to prevent callback exceptions from crashing
- Ensure log streams continue operating even after callback errors

* refactor(withdrawals): inject LegacyWithdrawalManager and use for Tendermint flows

- add _legacyManager constructor param and field
- delegate Tendermint preview/withdraw to injected manager
- minor formatting and watch() simplifications

* fix(kdf-ops): use conditional imports for platform-specific imports

i.e. dart:ffi

* fix(activation-params): include other RPC server keys

* fix(activation-config-repository): register adapter type

* feat(zhtlc): add desktop zcash params downloader (#228)

* feat(sdk): add zhltc params file downloader

* feat(sdk-example): integrate zcash downloader for desktop

* chore: remove groth from default params download list

* test(komodo-defi-sdk): fix failing zcash unit tests

* refactor: clean up imports, tests, and dialog date conversion

* feat(zhtlc): add mobile config params downloader

* feat(zhtlc): web lightwallet server URLs workaround

* fix(zhtlc): align orderbook RPC with KDF schema, and add id pagination support (#229)

* feat(zhtlc-tx): add from_id pagination support from RPC docs

* fix(orderbook-v2): use v2 fields and types

* fix(source-address-field): use consistent text theme to fix visibility

* fix(order-address): change address data to optional for shielded ops

* fix(json-utils): convert int to string in traverse as it's lossless

* test(sdk): fix missing type in zcash mock classes

* fix(address-select-input): use consistent text theme to fix visibility

* feat(zhtlc): estimate activation percentage based on block height (#230)

* feat(zhtlc): estimate activation percentage based on block height

* refactor(review): remove unnecessary casts, states, and configurable polling

* fix(config-transform): only replace lightwalletservers if wss is not empty

* Fix ZHTLC activation issues and improve resilience

Co-authored-by: charl <charl@vanstaden.info>

---------

Co-authored-by: Charl (Nitride) <77973576+CharlVS@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: charl <charl@vanstaden.info>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants