Skip to content

Commit 0abf0e2

Browse files
authored
[xc-admin] Create multiple proposals if too many instructions (#621)
* Add code * Remove console log
1 parent bbe10ba commit 0abf0e2

File tree

1 file changed

+82
-48
lines changed
  • governance/xc_admin/packages/xc_admin_common/src

1 file changed

+82
-48
lines changed

governance/xc_admin/packages/xc_admin_common/src/propose.ts

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { OPS_KEY } from "./multisig";
2121

2222
export const MAX_EXECUTOR_PAYLOAD_SIZE = PACKET_DATA_SIZE - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
2323
export const SIZE_OF_SIGNED_BATCH = 30;
24+
export const MAX_INSTRUCTIONS_PER_PROPOSAL = 256 - 1;
2425

2526
type SquadInstruction = {
2627
instruction: TransactionInstruction;
@@ -45,72 +46,105 @@ export async function proposeInstructions(
4546
wormholeAddress?: PublicKey
4647
): Promise<PublicKey> {
4748
const msAccount = await squad.getMultisig(vault);
48-
let ixToSend: TransactionInstruction[] = [];
49-
ixToSend.push(
50-
await squad.buildCreateTransaction(
51-
msAccount.publicKey,
52-
msAccount.authorityIndex,
53-
msAccount.transactionIndex + 1
54-
)
55-
);
56-
const newProposalAddress = getTxPDA(
57-
vault,
58-
new BN(msAccount.transactionIndex + 1),
59-
squad.multisigProgramId
60-
)[0];
49+
const newProposals = [];
6150

51+
let ixToSend: TransactionInstruction[] = [];
6252
if (remote) {
6353
if (!wormholeAddress) {
6454
throw new Error("Need wormhole address");
6555
}
66-
6756
const batches = batchIntoExecutorPayload(instructions);
68-
if (255 <= batches.length) {
69-
throw new Error("A proposal can only support 255 instructions");
70-
}
71-
for (const [i, batch] of batches.entries()) {
72-
const squadIx = await wrapAsRemoteInstruction(
73-
squad,
74-
vault,
75-
newProposalAddress,
76-
batch,
77-
i + 1,
78-
wormholeAddress
79-
);
57+
58+
for (let j = 0; j < batches.length; j += MAX_INSTRUCTIONS_PER_PROPOSAL) {
59+
const proposalIndex =
60+
msAccount.transactionIndex + 1 + j / MAX_INSTRUCTIONS_PER_PROPOSAL;
8061
ixToSend.push(
81-
await squad.buildAddInstruction(
62+
await squad.buildCreateTransaction(
63+
msAccount.publicKey,
64+
msAccount.authorityIndex,
65+
proposalIndex
66+
)
67+
);
68+
const newProposalAddress = getTxPDA(
69+
vault,
70+
new BN(proposalIndex),
71+
squad.multisigProgramId
72+
)[0];
73+
newProposals.push(newProposalAddress);
74+
75+
for (const [i, batch] of batches
76+
.slice(j, j + MAX_INSTRUCTIONS_PER_PROPOSAL)
77+
.entries()) {
78+
const squadIx = await wrapAsRemoteInstruction(
79+
squad,
8280
vault,
8381
newProposalAddress,
84-
squadIx.instruction,
82+
batch,
8583
i + 1,
86-
squadIx.authorityIndex,
87-
squadIx.authorityBump,
88-
squadIx.authorityType
89-
)
84+
wormholeAddress
85+
);
86+
ixToSend.push(
87+
await squad.buildAddInstruction(
88+
vault,
89+
newProposalAddress,
90+
squadIx.instruction,
91+
i + 1,
92+
squadIx.authorityIndex,
93+
squadIx.authorityBump,
94+
squadIx.authorityType
95+
)
96+
);
97+
}
98+
ixToSend.push(
99+
await squad.buildActivateTransaction(vault, newProposalAddress)
100+
);
101+
ixToSend.push(
102+
await squad.buildApproveTransaction(vault, newProposalAddress)
90103
);
91104
}
92105
} else {
93-
if (255 <= instructions.length) {
94-
throw new Error("A proposal can only support 255 instructions");
95-
}
96-
for (let i = 0; i < instructions.length; i++) {
106+
for (
107+
let j = 0;
108+
j < instructions.length;
109+
j += MAX_INSTRUCTIONS_PER_PROPOSAL
110+
) {
111+
const proposalIndex =
112+
msAccount.transactionIndex + 1 + j / MAX_INSTRUCTIONS_PER_PROPOSAL;
97113
ixToSend.push(
98-
await squad.buildAddInstruction(
99-
vault,
100-
newProposalAddress,
101-
instructions[i],
102-
i + 1
114+
await squad.buildCreateTransaction(
115+
msAccount.publicKey,
116+
msAccount.authorityIndex,
117+
proposalIndex
103118
)
104119
);
120+
const newProposalAddress = getTxPDA(
121+
vault,
122+
new BN(proposalIndex),
123+
squad.multisigProgramId
124+
)[0];
125+
newProposals.push(newProposalAddress);
126+
127+
for (let [i, instruction] of instructions
128+
.slice(j, j + MAX_INSTRUCTIONS_PER_PROPOSAL)
129+
.entries()) {
130+
ixToSend.push(
131+
await squad.buildAddInstruction(
132+
vault,
133+
newProposalAddress,
134+
instruction,
135+
i + 1
136+
)
137+
);
138+
}
139+
ixToSend.push(
140+
await squad.buildActivateTransaction(vault, newProposalAddress)
141+
);
142+
ixToSend.push(
143+
await squad.buildApproveTransaction(vault, newProposalAddress)
144+
);
105145
}
106146
}
107147

108-
ixToSend.push(
109-
await squad.buildActivateTransaction(vault, newProposalAddress)
110-
);
111-
112-
ixToSend.push(await squad.buildApproveTransaction(vault, newProposalAddress));
113-
114148
const txToSend = batchIntoTransactions(ixToSend);
115149

116150
for (let i = 0; i < txToSend.length; i += SIZE_OF_SIGNED_BATCH) {
@@ -124,7 +158,7 @@ export async function proposeInstructions(
124158
})
125159
);
126160
}
127-
return newProposalAddress;
161+
return newProposals[0];
128162
}
129163

130164
/**

0 commit comments

Comments
 (0)