Commit Graph

73 Commits

Author SHA1 Message Date
pezkuwichain 24fe8b6b6f Fix perpetual dispute-window reset: compare against pending, not just cache
hasDataChanged() only compared fresh data against CachedStakingDetails -
which stays empty until a submission matures and gets finalized. For any
account whose real stake was genuinely stable, every 5-minute scan still
saw "changed from empty cache", resubmitted, and reset submitted_at to the
current block. Confirmed live: Serok's and QaziM's real, correctly-computed
stake (490,000 / 100,000 HEZ) never once reached CachedStakingDetails/
TrustScores despite multiple successful submissions - each new scan arrived
before the previous one's 300-block dispute window elapsed and overwrote it
with a fresh timer, a self-perpetuating loop.

getPendingData() now reads PendingStakingDetails first; hasDataChanged()
compares against that when present, only falling back to the cache once
nothing is pending. Applied to both the AssetHub and legacy RelayChain-clear
comparisons. Also reordered main()'s cycle to finalizeMaturedPending()
before fullScan(), so anything that matured this cycle gets promoted before
a new scan pass runs at all.
2026-07-14 19:04:21 -07:00
pezkuwichain 17c23670ea Call finalize_staking_details() - nothing ever promoted matured pending entries
The staking-score pallet's audit-fix (commit 9afd99ae) added a dispute-window
model: receive_staking_details() only writes to PendingStakingDetails, and a
separate, permissionless finalize_staking_details() call promotes it to
CachedStakingDetails once DisputeWindow blocks have passed. No caller of that
promotion step existed anywhere in this bot (or anywhere else in this repo) -
confirmed live: Serok's and QaziM's real stake was correctly submitted to
Pending after the earlier NotRegisteredNoter/nonce fixes, but sat there
indefinitely with no path to ever reaching CachedStakingDetails/TrustScores.

Adds finalizeMaturedPending(), called once per periodic scan cycle (and once
at startup): scans PendingStakingDetails.entries(), finalizes whichever have
matured, batched into one utility.batchAll like the existing submission path,
routed through the same submitQueue so it can never race with a concurrent
submitStakingDetails call.
2026-07-14 18:06:13 -07:00
pezkuwichain 92022d79c1 Fix noter bot: serialize signAndSend to stop concurrent-nonce tx rejection
fullScan() processes accounts in concurrent batches of 10, and each account's
own data-gathering takes variable time, so multiple accounts' submitStakingDetails
calls landed close enough together to race on nonce assignment - the pool then
rejected most of them as duplicate-priority ("Priority is too low ... already in
the pool"). Observed live: 37 of 50 tracked accounts silently dropped in a single
scan cycle, including real accounts with genuine stake (Serok, QaziM) whose trust
scores stayed stuck at 0 as a result even after the separate NotRegisteredNoter
bond issue was fixed.

Routes every submission (both fullScan's batches and the live event listener)
through a single queue so exactly one signAndSend is ever in flight at a time,
in call order - data-gathering stays concurrent (unaffected), only the actual
chain submission is serialized.
2026-07-14 17:51:08 -07:00
pezkuwichain 1f6a81de25 fix(subquery): AH startBlock 1029487 (tip-50, within 256-block state pruning window) 2026-05-23 05:21:53 -07:00
pezkuwichain 67a246a760 fix(subquery): bump startBlocks past pruning window
Both governance and AH indexers were crashing at pruned blocks (RPC
nodes only retain last ~256 blocks of state). Bumping startBlock to
near-tip allows clean indexing forward from current state.

- governance: 57100 → 1228500 (relay tip - ~200)
- AH: 582592 → 1029200 (AH tip - ~200)

Loss: governance 57100-1228500 (mostly empty, pre-governance-activity);
AH 582592-1029200 (~410k blocks of staking/transfer data — postgres
state will be dropped, accept loss).

Long-term fix: provision Asset Hub archive node so reindexing from
genesis is possible without recurring pruning issues.
2026-05-23 05:08:16 -07:00
pezkuwichain 7ef82c7390 fix: paginate activeStakers cleanup with limit 100 (SubQuery max) 2026-04-11 15:09:39 +03:00
pezkuwichain 7468da0f75 fix: update AH startBlock to 582592 (within current state window) 2026-04-11 15:02:38 +03:00
pezkuwichain ad4c9c9331 fix: update startBlock to current chain height to avoid pruned state crash
Both AH (56400→579775) and Relay (57100→708687) startBlocks were
pointing to blocks whose state has been pruned by the chain nodes.
This caused a crash loop: SubQuery couldn't index those blocks because
api.query calls returned 'State already discarded' errors.

Root cause: AH node has ~200 block state window (default pruning).
Fix: set startBlock to current tip - 50 blocks (safely within window).
Also added --state-pruning=archive to AH collator azad on VPS3 so
this doesn't recur as SubQuery re-syncs.
2026-04-11 14:58:09 +03:00
pezkuwichain 7dac1598dc fix: deploy workflow stash local changes before git pull
git pull was silently failing when VPS had local modifications,
causing deploys to not actually update the code.
2026-03-10 00:53:05 +03:00
pezkuwichain 6b188858db fix: prevent crash loop on pruned state — patch getExtrinsicSuccess and events.toArray
When SubQuery restarts and hits pruned blocks, events are empty (from patch 4).
This caused two downstream crashes:
- getExtrinsicSuccess(undefined) → TypeError on findIndex
- wrapBlock with events.toArray() → TypeError on undefined

Patches 5-6 handle undefined events gracefully.
2026-03-10 00:40:45 +03:00
pezkuwichain 1fd75fa043 fix: TS2554 getByNetworkId options param + prettier formatting 2026-03-10 00:16:05 +03:00
pezkuwichain 23b6227772 fix: stale activeStakers — era detection fallback + cleanup on era change
- handleBlock now checks activeEra every block as fallback when
  StakersElected event is dropped due to pruned state patch
- Clear all existing ActiveStaker entries before saving fresh data
  from current era exposure set (prevents stale nominators)
- Re-save pool stash accounts after cleanup
- Robust exposure parsing (handle Option and non-Option types)
- Better error logging with stack traces for APY computation failures
2026-03-10 00:11:50 +03:00
pezkuwichain 95e6e49d90 Fix auto-pr to not fail when branches are already in sync 2026-03-02 15:08:19 +03:00
pezkuwichain bc2ecb3a0e Replace force-push sync with PR-based auto-merge workflow 2026-03-02 14:22:23 +03:00
pezkuwichain 718fea7cad fix: noter bot flip-flop bug — combine direct+pool before cache comparison
processAccount() was comparing direct staking against cache BEFORE
checking pool data. This caused a flip-flop: when cache=121K and
direct=100K, the bot submitted 100K (missing pool). Next scan it
detected the difference and submitted 121K. Every 5 minutes, forever.

Worse, when direct staking went to 0, the bot submitted 0 which
caused the pallet to delete StakingStartBlock — permanently removing
the user from tracking and zeroing their trust score.

Fix: collect ALL staking data (direct + pool) first, combine into
a single total, then compare against cache. Also adds queryFailed
flag to prevent downgrading stake when pool RPC query fails.
2026-02-28 01:32:55 +03:00
pezkuwichain 45784e1196 fix: handle pruned state in event fetch to prevent crash loops
When SubQuery restarts and the last processed block's state has been
pruned by the RPC node, fetchEventsRange would crash the indexer in a
loop. Now returns empty events for pruned blocks so the indexer can
skip forward gracefully.
2026-02-21 17:30:34 +03:00
pezkuwichain a4a5314f79 Add auto-payout bot for AH staking rewards
- payout-bot/bot.js: Periodically calls payoutStakersByPage for all
  validators in completed eras. Runs every 10 minutes.
- payout-bot/Dockerfile: Node 20 alpine with @pezkuwi/api
- docker-compose.prod.yml: Add payout-bot service with secret mnemonic
2026-02-21 17:03:13 +03:00
pezkuwichain 9259b68a3d Refactor: remove dead relay staking code, add AH reward handlers
- Delete NewEra.ts (all relay staking code was dead)
- Refactor Rewards.ts: remove relay/parachain handlers, add handleAHRewarded/handleAHSlashed for Asset Hub staking rewards
- Add staking::Rewarded and staking::Slashed handlers to pezkuwi-assethub.yaml
- Remove dead cachedStakingRewardEraIndex from Cache.ts
- Clean unused PEZKUWI_RELAY_GENESIS import from PoolRewards.ts
2026-02-21 14:23:58 +03:00
pezkuwichain fc5d101b75 fix: noter bot queries staking data from Asset Hub instead of Relay Chain
Staking pallet moved from RC to AH. Updated noter to query
assetHubApi.query.staking.* for direct staking data.
2026-02-21 14:12:48 +03:00
pezkuwichain 6c5b7ae879 feat: save direct nominators and validators as activeStakers on AH
Previously only pool stash accounts were saved as activeStakers.
Direct nominators/validators on Asset Hub were missing, causing
the wallet dashboard to show INACTIVE for direct stakers.
2026-02-21 02:42:18 +03:00
pezkuwichain 727deaefb6 Fix Prettier formatting 2026-02-21 01:49:53 +03:00
pezkuwichain 57563c7fc0 Remove obsolete docker-compose version attribute 2026-02-21 01:46:24 +03:00
pezkuwichain 3cc7a7b245 Remove relay staking handlers after pallet removal (spec 1_020_006)
Staking pallet (index 9), FastUnstake (15), and VoterBagsList (100)
were removed from the relay chain. The relay indexer now only tracks
transfers and signed extrinsics. Added safety try-catch to staking
queries in case handlers are accidentally re-enabled.
2026-02-21 01:40:34 +03:00
pezkuwichain 8a5681db33 fix: use GITHUB_TOKEN instead of PAT_TOKEN for branch sync 2026-02-19 06:21:26 +03:00
pezkuwichain ae0dac0a11 ci: add sync-branches workflow to keep main and master in sync 2026-02-19 05:55:42 +03:00
pezkuwichain fe95e137b3 fix: use explicit yaml path for codegen and build in deploy 2026-02-19 04:38:59 +03:00
pezkuwichain 37ee9ffd9f fix: add yarn build to deploy workflow
dist/ is gitignored so VPS needs to build TypeScript
handlers locally after git pull.
2026-02-19 04:34:16 +03:00
pezkuwichain dcbd38fb5f fix: set startBlock to current chain height
RPC nodes run in pruned mode (~256 blocks state history).
Setting startBlock to recent blocks ensures all required
state is available. Old blocks have no significant user
transactions to index.
2026-02-19 02:33:47 +03:00
pezkuwichain 0130c5984a fix: also patch @polkadot/api Init.js for pruned state
The _getBlockRegistryViaHash method in @polkadot/api calls
getRuntimeVersion.raw(header.parentHash) which fails for genesis
and other pruned blocks. Add fallback to current runtime version.
2026-02-19 02:28:40 +03:00
pezkuwichain d270504c9a fix: handle pruned RPC state in SubQuery node
Substrate nodes prune historical state by default (~256 blocks).
When SubQuery restarts and tries to fetch runtime version for old
blocks, it crashes with "State already discarded". This patch adds
a fallback to current runtime version when historical state is
unavailable, preventing crash loops on pruned RPC endpoints.

Also removes --pull from deploy workflow to avoid unnecessary
full rebuilds on every push.
2026-02-19 02:22:52 +03:00
pezkuwichain 151389a0cc style: fix prettier formatting across mapping files 2026-02-19 01:51:15 +03:00
pezkuwichain 71f0cce337 feat(governance): add OpenGov v2 indexer for referenda, votes, delegations
Index convictionVoting and referenda pallet data to support PezWallet
governance UI — referendum tracking, casting votes, delegation stats,
and delegator vote propagation.
2026-02-19 01:40:21 +03:00
pezkuwichain f717173d3d fix: use AH totalIssuance for APY, filter tiny-stake validator outliers 2026-02-18 06:13:31 +03:00
pezkuwichain b4e765ee50 fix: use relay total supply constant for AH APY calculation 2026-02-18 06:04:21 +03:00
pezkuwichain a7d11ce6a2 feat: add APY computation to AH SubQuery, clean relay SubQuery from AH pool logic 2026-02-18 06:00:45 +03:00
pezkuwichain 5447579477 feat: save pool stash active stakers with AH genesis from relay SubQuery 2026-02-18 05:55:05 +03:00
pezkuwichain 9c9c2a132f fix: add 'modl' prefix to pool stash derivation to match Substrate PalletId::into_sub_account_truncating 2026-02-18 05:42:45 +03:00
pezkuwichain c22f9b90e0 fix: convert Uint8Array to hex string for AccountId createType 2026-02-18 05:23:45 +03:00
pezkuwichain 358f13db50 fix: save pool stash accounts with relaychain type for wallet compat
The wallet queries activeStakers with the pool's bonded stash address
and stakingType="relaychain" (unwrapped from nomination-pool). Derive
pool stash accounts from bondedPools and save with correct type.
2026-02-18 05:18:44 +03:00
pezkuwichain 81c6c89bfb fix: read validators from overview to capture all active stakers
Validators with only self-stake (no nominator pages) were missing.
Now reads erasStakersOverview for complete validator list.
2026-02-18 04:50:18 +03:00
pezkuwichain 3dc7a19dee fix: add relay block handler to init active stakers from chain state
The event-based StakersElected handler had a bug where paged exposure
data wasn't properly extracted. Add handleRelayBlock that queries
erasStakersPaged directly from live chain state on first block to
ensure all validators and nominators are captured.
2026-02-18 04:44:57 +03:00
pezkuwichain 7b58fa0e4a feat: add AH GraphQL engine + block handler for pool stakers init
- Add handleBlock to query live chain state for existing pool members
- Add second GraphQL engine container for Asset Hub schema (port 3001)
- Register block handler in pezkuwi-assethub.yaml
2026-02-18 04:07:45 +03:00
pezkuwichain 1c79402d5c feat: track nomination pool members as active stakers
Add handlePoolBonded/handlePoolUnbonded handlers to Asset Hub SubQuery.
When a user bonds to a nomination pool, they are saved as an ActiveStaker
with networkId=AssetHub and stakingType=nomination-pool. This fixes the
wallet showing INACTIVE for HEZ stakers.
2026-02-18 03:14:44 +03:00
pezkuwichain 407cba9aef fix: noter bot RPC endpoints point to VPS3 chain nodes 2026-02-17 01:55:05 +03:00
pezkuwichain 64c5f9e5d6 feat: add noter secret setup script 2026-02-17 01:35:02 +03:00
pezkuwichain 174bd41d6e feat: add noter bot service for staking score data submission 2026-02-17 01:32:51 +03:00
pezkuwichain eefae7469d Update genesis hashes and startBlock for mainnet relaunch
- Relay chain: 0xbb4a61ab... -> 0x1aa94987...
- Asset Hub: 0x00d0e1d0... -> 0xe7c15092...
- Reset startBlock to 1 for full re-index from genesis
2026-02-15 22:18:07 +03:00
pezkuwichain 8f051d719a Fix prettier formatting 2026-02-14 04:45:15 +03:00
pezkuwichain 9ca7f8d00f Add TZ=UTC to SubQuery node environments 2026-02-14 04:37:14 +03:00
pezkuwichain a8b7d16b97 Patch api-augment exports map instead of filesystem shim
Node.js checks package.json exports before filesystem, so the
mkdir+echo shim didn't work. Now patches the exports map with
node -e to add ./substrate pointing to pezkuwi augmentation.
2026-02-14 04:33:32 +03:00