Skip to content

Commit 0f83bd9

Browse files
committed
🐛 Fixed case where the same time is used more than once in the system-input
1 parent ec8387f commit 0f83bd9

File tree

7 files changed

+58
-52
lines changed

7 files changed

+58
-52
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ members = [
88
"crates/programs/world",
99
"crates/types",
1010
"examples/*",
11-
"examples/system-with-many-components",
1211
]
1312

1413
[workspace.package]

clients/typescript/test/framework.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Framework {
8080
var worldReport: number = 0;
8181
for (let index in log) {
8282
let line = log[index];
83-
if (line.includes(" consumed ")) {
83+
if (line.includes(" consumed ")) {
8484
if (!line.includes("WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n")) {
8585
cpi.push(this.consume(line));
8686
} else {
@@ -93,4 +93,5 @@ export class Framework {
9393
console.log(`Total CPI Consumed: ${total}`);
9494
console.log(`Number of Instructions: ${numberOfInstructions}`);
9595
console.log(`World Report: ${worldReport}`);
96+
}
9697
}

clients/typescript/test/intermediate-level/ecs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ export function ecs(framework: Framework) {
307307
let transactionResponse: any;
308308
do {
309309
transactionResponse =
310-
await framework.provider.connection.getTransaction(signature, {
311-
commitment: "confirmed",
312-
});
310+
await framework.provider.connection.getTransaction(signature, {
311+
commitment: "confirmed",
312+
});
313313
} while (transactionResponse?.meta?.logMessages === undefined);
314314
framework.report(transactionResponse?.meta?.logMessages);
315315
});
@@ -331,9 +331,9 @@ export function ecs(framework: Framework) {
331331
let transactionResponse: any;
332332
do {
333333
transactionResponse =
334-
await framework.provider.connection.getTransaction(signature, {
335-
commitment: "confirmed",
336-
});
334+
await framework.provider.connection.getTransaction(signature, {
335+
commitment: "confirmed",
336+
});
337337
} while (transactionResponse?.meta?.logMessages === undefined);
338338
framework.report(transactionResponse?.meta?.logMessages);
339339
});

crates/bolt-lang/attribute/system-input/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashSet;
2+
13
use proc_macro::TokenStream;
24

35
use quote::quote;
@@ -61,8 +63,9 @@ pub fn system_input(_attr: TokenStream, item: TokenStream) -> TokenStream {
6163
})
6264
.collect();
6365

64-
let bolt_accounts = fields.iter().map(|f| {
65-
let field_type = &f.ty;
66+
let unique_fields = fields.iter().map(|f| f.ty.clone()).collect::<HashSet<_>>();
67+
let bolt_accounts = unique_fields.iter().map(|f| {
68+
let field_type = &f;
6669
quote! {
6770
pub type #field_type = bolt_lang::account::BoltAccount<super::#field_type, { bolt_lang::account::pubkey_p0(crate::ID) }, { bolt_lang::account::pubkey_p1(crate::ID) }>;
6871
}

crates/programs/world/src/lib.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -494,27 +494,29 @@ fn apply_impl<'info>(
494494
data.copy_from_slice(component.try_borrow_data()?.as_ref());
495495
}
496496

497-
bolt_component::cpi::set_owner(
498-
CpiContext::new_with_signer(
499-
program.to_account_info(),
500-
bolt_component::cpi::accounts::SetOwner {
497+
if component.owner != bolt_system.key {
498+
bolt_component::cpi::set_owner(
499+
CpiContext::new_with_signer(
500+
program.to_account_info(),
501+
bolt_component::cpi::accounts::SetOwner {
502+
cpi_auth: cpi_auth.to_account_info(),
503+
component: component.to_account_info(),
504+
},
505+
&[World::cpi_auth_seeds().as_slice()],
506+
),
507+
*bolt_system.key,
508+
)?;
509+
510+
bolt_system::cpi::set_data(CpiContext::new_with_signer(
511+
bolt_system.to_account_info(),
512+
bolt_system::cpi::accounts::SetData {
501513
cpi_auth: cpi_auth.to_account_info(),
514+
buffer: buffer.to_account_info(),
502515
component: component.to_account_info(),
503516
},
504517
&[World::cpi_auth_seeds().as_slice()],
505-
),
506-
*bolt_system.key,
507-
)?;
508-
509-
bolt_system::cpi::set_data(CpiContext::new_with_signer(
510-
bolt_system.to_account_info(),
511-
bolt_system::cpi::accounts::SetData {
512-
cpi_auth: cpi_auth.to_account_info(),
513-
buffer: buffer.to_account_info(),
514-
component: component.to_account_info(),
515-
},
516-
&[World::cpi_auth_seeds().as_slice()],
517-
))?;
518+
))?;
519+
}
518520
}
519521

520522
bolt_system::cpi::bolt_execute(
@@ -529,31 +531,33 @@ fn apply_impl<'info>(
529531
data.copy_from_slice(component.try_borrow_data()?.as_ref());
530532
}
531533

532-
bolt_system::cpi::set_owner(
533-
CpiContext::new_with_signer(
534-
bolt_system.to_account_info(),
535-
bolt_system::cpi::accounts::SetOwner {
534+
if *component.owner != program.key() {
535+
bolt_system::cpi::set_owner(
536+
CpiContext::new_with_signer(
537+
bolt_system.to_account_info(),
538+
bolt_system::cpi::accounts::SetOwner {
539+
cpi_auth: cpi_auth.to_account_info(),
540+
component: component.to_account_info(),
541+
},
542+
&[World::cpi_auth_seeds().as_slice()],
543+
),
544+
program.key(),
545+
)?;
546+
547+
if *component.owner != program.key() {
548+
return Err(WorldError::InvalidComponentOwner.into());
549+
}
550+
551+
bolt_component::cpi::set_data(CpiContext::new_with_signer(
552+
program.to_account_info(),
553+
bolt_component::cpi::accounts::SetData {
536554
cpi_auth: cpi_auth.to_account_info(),
555+
buffer: buffer.to_account_info(),
537556
component: component.to_account_info(),
538557
},
539558
&[World::cpi_auth_seeds().as_slice()],
540-
),
541-
program.key(),
542-
)?;
543-
544-
if *component.owner != program.key() {
545-
return Err(WorldError::InvalidComponentOwner.into());
559+
))?;
546560
}
547-
548-
bolt_component::cpi::set_data(CpiContext::new_with_signer(
549-
program.to_account_info(),
550-
bolt_component::cpi::accounts::SetData {
551-
cpi_auth: cpi_auth.to_account_info(),
552-
buffer: buffer.to_account_info(),
553-
component: component.to_account_info(),
554-
},
555-
&[World::cpi_auth_seeds().as_slice()],
556-
))?;
557561
}
558562

559563
buffer.realloc(0, false)?;

examples/system-with-few-components/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ declare_id!("A3kNNSgmkTNA5V1qtnrbtNeqKrYHNxUMCTkqTDaQzE97");
77
#[system]
88
pub mod system_with_few_components {
99

10-
pub fn execute(ctx: Context<Components>, _args_p: Vec<u8>) -> Result<Components> {
11-
Ok(ctx.accounts)
10+
pub fn execute(_ctx: Context<Components>, _args_p: Vec<u8>) -> Result<()> {
11+
Ok(())
1212
}
1313

1414
#[system_input]
@@ -19,5 +19,4 @@ pub mod system_with_few_components {
1919
pub large4: Large,
2020
pub large5: Large,
2121
}
22-
2322
}

examples/system-with-many-components/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ declare_id!("Hi4sMEb3uXhWCiLyrF7t3Z384an7YZsTj774cabAAPQB");
66
#[system]
77
pub mod system_with_many_components {
88

9-
pub fn execute(ctx: Context<Components>, _args_p: Vec<u8>) -> Result<Components> {
10-
Ok(ctx.accounts)
9+
pub fn execute(_ctx: Context<Components>, _args_p: Vec<u8>) -> Result<()> {
10+
Ok(())
1111
}
1212

1313
#[system_input]

0 commit comments

Comments
 (0)