Skip to content

Commit

Permalink
Bugfixes for bulk vote
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Mar 6, 2025
1 parent dde5d1f commit 57df64c
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 37 deletions.
1 change: 1 addition & 0 deletions anchor-30-programs/hpl-crons-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@coral-xyz/anchor": "^0.30.1",
"@helium/cron-sdk": "^0.0.2",
"@helium/helium-sub-daos-sdk": "^0.9.23",
"@helium/organization-sdk": "^0.1.4",
"@helium/proposal-sdk": "^0.1.4",
"@helium/spl-utils": "^0.9.19",
"@helium/state-controller-sdk": "^0.1.4",
Expand Down
59 changes: 34 additions & 25 deletions anchor-30-programs/hpl-crons-runner/src/queue-proxy-jobs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as anchor from "@coral-xyz/anchor";
import { sendInstructionsWithPriorityFee } from "@helium/spl-utils";
import { batchParallelInstructionsWithPriorityFee, sendInstructionsWithPriorityFee } from "@helium/spl-utils";
import {
customSignerKey,
init as initTuktuk,
Expand All @@ -18,6 +18,7 @@ import { HplCrons } from "../../target/types/hpl_crons";
import { nextAvailableTaskIds } from "./queue-hotspot-claims";
import { init as initProposal } from "@helium/proposal-sdk";
import { init as initStateController } from "@helium/state-controller-sdk";
import { organizationKey } from "@helium/organization-sdk";

const PROGRAM_ID = new PublicKey("hcrLPFgFUY6sCUKzqLWxXx5bntDiDCrAZVcrXfx9AHu");

Expand Down Expand Up @@ -57,46 +58,54 @@ export async function run(args: any = process.argv) {
const vsrProgram = await initVsr(provider);
const tuktukProgram = await initTuktuk(provider);
const taskQueueAcc = await tuktukProgram.account.taskQueueV0.fetch(taskQueue);
const nextAvailable = nextAvailableTaskIds(taskQueueAcc.taskBitmap, 2);
// @ts-ignore
const proxyMarkers = await vsrProgram.account.proxyMarkerV0.all();

const instructions: TransactionInstruction[] = [];
for (const marker of proxyMarkers) {
const proposal = await proposalProgram.account.proposalV0.fetch(
marker.account.proposal
);
const proposalConfig = await proposalProgram.account.proposalConfigV0.fetch(
proposal?.proposalConfig
);
const resolution =
await stateControllerProgram.account.resolutionSettingsV0.fetch(
proposalConfig?.stateController
);
const distinctProposals: Set<string> = new Set(proxyMarkers.map((m) => m.account.proposal.toBase58()));
const proposalKeys = Array.from(distinctProposals).map(d => new PublicKey(d));
const proposals = await proposalProgram.account.proposalV0.fetchMultiple(proposalKeys);
const proposalConfigs = await proposalProgram.account.proposalConfigV0.fetchMultiple(proposals.map(p => p!.proposalConfig));
const resolutions = await stateControllerProgram.account.resolutionSettingsV0.fetchMultiple(proposalConfigs.map(pc => pc!.stateController));

const currTs = new Date().valueOf() / 1000;
const endTs =
resolution &&
const endTsByProposal: Record<string, anchor.BN> = proposals.reduce((acc, proposal, i) => {
const resolution = resolutions[i]
acc[proposalKeys[i].toBase58()] = (resolution &&
(proposal?.state.resolved
? proposal?.state.resolved.endTs
: proposal?.state.voting?.startTs.add(
resolution.settings.nodes.find(
(node) => typeof node.offsetFromStartTs !== "undefined"
)?.offsetFromStartTs?.offset ?? new anchor.BN(0)
));
if (endTs!.toNumber() > currTs) {
)))!
return acc;
}, {} as Record<string, anchor.BN>);
const proposalsByPubkey = proposals.reduce((acc, proposal, i) => {
acc[proposalKeys[i].toBase58()] = proposal;
return acc;
}, {} as Record<string, any>);

const nextAvailable = nextAvailableTaskIds(taskQueueAcc.taskBitmap, proxyMarkers.length * 2);
const instructions: TransactionInstruction[] = [];
const org = organizationKey("Helium")[0]
for (const marker of proxyMarkers) {
const currTs = new Date().valueOf() / 1000;
const endTs = endTsByProposal[marker.account.proposal.toBase58()];
const proposal = proposalsByPubkey[marker.account.proposal.toBase58()];
if (endTs!.toNumber() > currTs && proposal?.organization === org) {
const queueAuthority = PublicKey.findProgramAddressSync(
[Buffer.from("queue_authority")],
program.programId
)[0];
const task1 = nextAvailable.pop()!;
const task2 = nextAvailable.pop()!;
instructions.push(
await program.methods
.queueProxyVoteV0({
freeTaskId: nextAvailable[0],
freeTaskId: task1,
})
.accountsStrict({
marker: marker.publicKey,
task: taskKey(taskQueue, nextAvailable[0])[0],
task: taskKey(taskQueue, task1)[0],
taskQueue,
payer: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
Expand All @@ -115,12 +124,12 @@ export async function run(args: any = process.argv) {
.instruction(),
await program.methods
.queueRelinquishExpiredProxyVoteMarkerV0({
freeTaskId: nextAvailable[0],
freeTaskId: task2,
triggerTs: endTs!,
})
.accountsStrict({
marker: marker.publicKey,
task: taskKey(taskQueue, nextAvailable[1])[0],
task: taskKey(taskQueue, task2)[0],
taskQueue,
payer: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
Expand All @@ -136,7 +145,7 @@ export async function run(args: any = process.argv) {
}
}

await sendInstructionsWithPriorityFee(provider, instructions, {
computeUnitLimit: 500000,
await batchParallelInstructionsWithPriorityFee(provider, instructions, {
onProgress: console.log,
});
}
83 changes: 76 additions & 7 deletions anchor-30-programs/hpl-crons-runner/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ __metadata:
languageName: node
linkType: hard

"@helium/anchor-resolvers@npm:^0.10.0-alpha.4, @helium/anchor-resolvers@npm:^0.10.0-alpha.6":
version: 0.10.0-alpha.13
resolution: "@helium/anchor-resolvers@npm:0.10.0-alpha.13"
dependencies:
"@solana/spl-token": ^0.3.8
"@solana/web3.js": ^1.91.1
peerDependencies:
"@coral-xyz/anchor": ^0.30.1
checksum: 3632aa2af404dc91366ac147ca648f6db5cbcd6b15f7e56d2913c025c1eb24ab6f91618198a3cfcddefe3cffc471ab8537cd91faba174a5c9091fcafde14ed36
languageName: node
linkType: hard

"@helium/anchor-resolvers@npm:^0.2.17":
version: 0.2.21
resolution: "@helium/anchor-resolvers@npm:0.2.21"
Expand Down Expand Up @@ -215,8 +227,11 @@ __metadata:
"@coral-xyz/anchor": ^0.30.1
"@helium/cron-sdk": ^0.0.2
"@helium/helium-sub-daos-sdk": ^0.9.23
"@helium/organization-sdk": ^0.1.4
"@helium/proposal-sdk": ^0.1.4
"@helium/spl-utils": ^0.9.19
"@helium/tuktuk-sdk": ^0.0.2
"@helium/state-controller-sdk": ^0.1.4
"@helium/tuktuk-sdk": ^0.0.4
"@helium/voter-stake-registry-sdk": ^0.9.23
"@solana/web3.js": ^1.91.1
"@types/yargs": ^17.0.24
Expand Down Expand Up @@ -256,6 +271,16 @@ __metadata:
languageName: node
linkType: hard

"@helium/modular-governance-idls@npm:^0.1.4":
version: 0.1.4
resolution: "@helium/modular-governance-idls@npm:0.1.4"
dependencies:
"@coral-xyz/anchor": ^0.30.1
"@solana/web3.js": ^1.78.4
checksum: 5b23c2a614af863bd982d68268527ef09ce3046f49e22d41c8985c4210e9f1aec45092d78357fce0fe02fdf762e6ee424aa45bbc3dafa06b019cd1d4d59d1972
languageName: node
linkType: hard

"@helium/nft-proxy-sdk@npm:^0.0.15":
version: 0.0.15
resolution: "@helium/nft-proxy-sdk@npm:0.0.15"
Expand All @@ -268,6 +293,29 @@ __metadata:
languageName: node
linkType: hard

"@helium/organization-sdk@npm:^0.1.4":
version: 0.1.4
resolution: "@helium/organization-sdk@npm:0.1.4"
dependencies:
"@coral-xyz/anchor": ^0.30.1
"@helium/anchor-resolvers": ^0.10.0-alpha.6
"@helium/modular-governance-idls": ^0.1.4
"@helium/proposal-sdk": ^0.1.4
checksum: 9402d65158269188150ce4581eccb0dc6143ee78d7765120db8128a984824358b4c68559a72b3670e3369fdd5675f85095f0ecdec92ecc40f0f885fa0c9462d4
languageName: node
linkType: hard

"@helium/proposal-sdk@npm:^0.1.4":
version: 0.1.4
resolution: "@helium/proposal-sdk@npm:0.1.4"
dependencies:
"@coral-xyz/anchor": ^0.30.1
"@helium/anchor-resolvers": ^0.10.0-alpha.6
"@helium/modular-governance-idls": ^0.1.4
checksum: 725dfa9e110f805b829f10b7e4f92881bb718a0432a8d319d4245cd2ef13ff80c339552049722bbb5207a662afdec7814865ca8067a1c06b116ffc4b3a4b99c7
languageName: node
linkType: hard

"@helium/spl-utils@npm:^0.9.19":
version: 0.9.19
resolution: "@helium/spl-utils@npm:0.9.19"
Expand Down Expand Up @@ -308,6 +356,17 @@ __metadata:
languageName: node
linkType: hard

"@helium/state-controller-sdk@npm:^0.1.4":
version: 0.1.4
resolution: "@helium/state-controller-sdk@npm:0.1.4"
dependencies:
"@coral-xyz/anchor": ^0.30.1
"@helium/anchor-resolvers": ^0.10.0-alpha.6
"@helium/modular-governance-idls": ^0.1.4
checksum: 0bb5b9820b17492595c71dd6469ffff0525d39ed3bae5ead83a9007bbadf09d779a2ff95a9686fe294fd8d4d248eabc993df387415ba68bc7c3dcee756901cdd
languageName: node
linkType: hard

"@helium/treasury-management-sdk@npm:^0.9.23":
version: 0.9.23
resolution: "@helium/treasury-management-sdk@npm:0.9.23"
Expand All @@ -333,15 +392,25 @@ __metadata:
languageName: node
linkType: hard

"@helium/tuktuk-sdk@npm:^0.0.2":
version: 0.0.2
resolution: "@helium/tuktuk-sdk@npm:0.0.2"
"@helium/tuktuk-idls@npm:^0.0.4":
version: 0.0.4
resolution: "@helium/tuktuk-idls@npm:0.0.4"
dependencies:
"@coral-xyz/anchor": ^0.30.1
"@helium/anchor-resolvers": ^0.9.2
"@helium/tuktuk-idls": ^0.0.2
"@solana/web3.js": ^1.95.2
checksum: 8dfeb6f3405947720f7d06ee97ccdcd243ff214d6a0967157d86f47f383b49fce92c9ce0a8b637075ca61634e7d0ff685f43a042fdc5fa2555198c450fb4d02d
languageName: node
linkType: hard

"@helium/tuktuk-sdk@npm:^0.0.4":
version: 0.0.4
resolution: "@helium/tuktuk-sdk@npm:0.0.4"
dependencies:
"@coral-xyz/anchor": ^0.30.1
"@helium/anchor-resolvers": ^0.10.0-alpha.4
"@helium/tuktuk-idls": ^0.0.4
js-sha256: ^0.11.0
checksum: 7bd0f009a24f0b14093fca407ff1db9f522c962016611dd765ae9af5b9abb5c93e78d9e79039fe3a5496683b4da537c01da9e72ef543138eb556536ec4b73190
checksum: dbadbcac8d8cbb9cd404a5b5d8ef24bb4ef1655f60df9f09f17a99aa4f86814aceab0fa000cb49da31413a5e5c301821ac6d969d81b3f7dc85fdd7e82f0fa4cd
languageName: node
linkType: hard

Expand Down
10 changes: 7 additions & 3 deletions packages/helium-admin-cli/src/backfill-proxy-markers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ export async function run(args: any = process.argv) {
const key = marker.account.voter.toBase58();
const proxyChoices = acc[proposal][key];
if (proxyChoices && !arrayEquals(proxyChoices, marker.account.choices)) {
throw new Error(
console.log(
`Proxy marker choice mismatch ${key} ${proxyChoices} ${marker.account.choices}`
);
acc[proposal][key] =
marker.account.choices.length > proxyChoices.length
? marker.account.choices
: proxyChoices;
} else {
acc[proposal][key] = marker.account.choices;
}
Expand All @@ -66,11 +70,11 @@ export async function run(args: any = process.argv) {
new PublicKey(proposal),
hvsrProgram.programId
)[0];
const markerAccount = await hvsrProgram.account.proxyMarkerV0.fetch(
const markerAccount = await hvsrProgram.account.proxyMarkerV0.fetchNullable(
proxyMarker
);
for (const choice of choices) {
if (!markerAccount.choices.includes(choice)) {
if (!markerAccount?.choices.includes(choice)) {
instructions.push(
await hvsrProgram.methods
.tempBackfillProxyMarker({ choice })
Expand Down
6 changes: 4 additions & 2 deletions packages/helium-admin-cli/src/extend-common-lut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ export async function run(args: any = process.argv) {

const accounts = [
// Proposal config
"7Tp4CsSw5b62vdtUFiS9F3MMYdturt5q9ZuZpt9vwgby",
"22SWTDZVj1L81SXfwbEeUmdZBFj23MFmER3Gv8BmxbBS",
// Vote controller
"7Vrme34DXPH8ow4HEAatZKwZF9AR5vq8MZhA3CanMEbr",
// State controller
"3tAi3bF6zHF4FsqFhh4JFQfnjkx9qNBKNsH6cLvK9pT8",
"stcfiqW3fwD9QCd8Bqr1NBLrs7dftZHBQe7RiMMA4aM",
// Task queue
"H39gEszvsi6AT4rYBiJTuZHJSF5hMHy6CKGTd7wzhsg7",
// Task Queue Authority
Expand Down
1 change: 1 addition & 0 deletions packages/helium-vote-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ server.post<{
AND vm.choices IS NOT DISTINCT FROM ARRAY[${choices.join(
","
)}]::integer[]
AND vm.proxy_index >= pa.index
)
LEFT OUTER JOIN delegated_positions dp ON dp.mint = pa.asset
WHERE pa.voter = '${wallet.toBase58()}' AND pa.index > 0 AND vm is NULL
Expand Down

0 comments on commit 57df64c

Please sign in to comment.