@@ -133,35 +133,39 @@ async function generateVaaInstructionGroups(
133
133
134
134
// Second write and verify instructions
135
135
const writeSecondPartAndVerifyInstructions : InstructionWithEphemeralSigners [ ] =
136
- [
137
- {
138
- instruction : await wormhole . methods
139
- . writeEncodedVaa ( {
140
- index : VAA_SPLIT_INDEX ,
141
- data : vaa . subarray ( VAA_SPLIT_INDEX ) ,
142
- } )
143
- . accounts ( {
144
- draftVaa : encodedVaaKeypair . publicKey ,
145
- } )
146
- . instruction ( ) ,
147
- signers : [ ] ,
148
- computeUnits : WRITE_ENCODED_VAA_COMPUTE_BUDGET ,
149
- } ,
150
- {
151
- instruction : await wormhole . methods
152
- . verifyEncodedVaaV1 ( )
153
- . accounts ( {
154
- guardianSet : getGuardianSetPda (
155
- getGuardianSetIndex ( vaa ) ,
156
- wormhole . programId ,
157
- ) ,
158
- draftVaa : encodedVaaKeypair . publicKey ,
159
- } )
160
- . instruction ( ) ,
161
- signers : [ ] ,
162
- computeUnits : VERIFY_ENCODED_VAA_COMPUTE_BUDGET ,
163
- } ,
164
- ] ;
136
+ [ ] ;
137
+
138
+ // The second write instruction is only needed if there are more bytes past the split index in the VAA
139
+ if ( vaa . length > VAA_SPLIT_INDEX ) {
140
+ writeSecondPartAndVerifyInstructions . push ( {
141
+ instruction : await wormhole . methods
142
+ . writeEncodedVaa ( {
143
+ index : VAA_SPLIT_INDEX ,
144
+ data : vaa . subarray ( VAA_SPLIT_INDEX ) ,
145
+ } )
146
+ . accounts ( {
147
+ draftVaa : encodedVaaKeypair . publicKey ,
148
+ } )
149
+ . instruction ( ) ,
150
+ signers : [ ] ,
151
+ computeUnits : WRITE_ENCODED_VAA_COMPUTE_BUDGET ,
152
+ } ) ;
153
+ }
154
+
155
+ writeSecondPartAndVerifyInstructions . push ( {
156
+ instruction : await wormhole . methods
157
+ . verifyEncodedVaaV1 ( )
158
+ . accounts ( {
159
+ guardianSet : getGuardianSetPda (
160
+ getGuardianSetIndex ( vaa ) ,
161
+ wormhole . programId ,
162
+ ) ,
163
+ draftVaa : encodedVaaKeypair . publicKey ,
164
+ } )
165
+ . instruction ( ) ,
166
+ signers : [ ] ,
167
+ computeUnits : VERIFY_ENCODED_VAA_COMPUTE_BUDGET ,
168
+ } ) ;
165
169
166
170
// Close instructions
167
171
const closeInstructions : InstructionWithEphemeralSigners [ ] = [
0 commit comments