Skip to content

Commit

Permalink
Revert "Revert lazy transactions bitmap"
Browse files Browse the repository at this point in the history
This reverts commit 5a1e79c.
  • Loading branch information
ChewingGlass committed Sep 29, 2023
1 parent c89dd28 commit 46b3cdf
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 11 deletions.
2 changes: 1 addition & 1 deletion programs/lazy-transactions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ spl-concurrent-merkle-tree = "0.2.0"
bytemuck = "1.13.0"
shared-utils = { workspace = true }
solana-security-txt = { workspace = true }
default-env = { workspace = true }
default-env = { workspace = true }
3 changes: 3 additions & 0 deletions programs/lazy-transactions/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ pub enum ErrorCode {

#[msg("Invalid canopy length")]
CanopyLengthMismatch,

#[msg("Transaction has already been executed")]
TransactionAlreadyExecuted,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::state::*;
use crate::{state::*, util::set_executed};
use anchor_lang::prelude::*;

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct CloseMarkerArgsV0 {
pub index: u64,
pub index: u32,
}

#[derive(Accounts)]
Expand All @@ -13,6 +13,7 @@ pub struct CloseMarkerV0<'info> {
/// CHECK: Just receiving funds
pub refund: UncheckedAccount<'info>,
#[account(
mut,
has_one = authority
)]
pub lazy_transactions: Account<'info, LazyTransactionsV0>,
Expand All @@ -26,6 +27,8 @@ pub struct CloseMarkerV0<'info> {
pub block: Account<'info, Block>,
}

pub fn handler(_ctx: Context<CloseMarkerV0>, _args: CloseMarkerArgsV0) -> Result<()> {
pub fn handler(ctx: Context<CloseMarkerV0>, args: CloseMarkerArgsV0) -> Result<()> {
set_executed(&mut ctx.accounts.lazy_transactions.executed, args.index);

Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::canopy::fill_in_proof_from_canopy;
use crate::error::ErrorCode;
use crate::util::{is_executed, set_executed};
use crate::{merkle_proof::verify, state::*};
use anchor_lang::{prelude::*, solana_program, solana_program::instruction::Instruction};

Expand Down Expand Up @@ -30,7 +31,9 @@ pub struct ExecuteTransactionV0<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
has_one = canopy
mut,
has_one = canopy,
constraint = !is_executed(&lazy_transactions.executed, args.index) @ ErrorCode::TransactionAlreadyExecuted,
)]
pub lazy_transactions: Account<'info, LazyTransactionsV0>,
/// CHECK: Verified by has one
Expand All @@ -42,18 +45,20 @@ pub struct ExecuteTransactionV0<'info> {
)]
/// CHECK: You can throw things behind this signer and it will sign the tx via cpi
pub lazy_signer: AccountInfo<'info>,
/// CHECK: Temporary. We can remove this once executed txns is fully populated
#[account(
init,
payer = payer,
space = 8,
constraint = block.lamports() == 0,
constraint = block.data.borrow().len() == 0,
seeds = ["block".as_bytes(), lazy_transactions.key().as_ref(), &args.index.to_le_bytes()],
bump
)]
pub block: Account<'info, Block>,
pub block: AccountInfo<'info>,
pub system_program: Program<'info, System>,
}

pub fn handler(ctx: Context<ExecuteTransactionV0>, args: ExecuteTransactionArgsV0) -> Result<()> {
set_executed(&mut ctx.accounts.lazy_transactions.executed, args.index);

let largest_acct_idx: usize = (*args
.instructions
.iter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{canopy::check_canopy_bytes, id, state::*};
use crate::{canopy::check_canopy_bytes, id, state::*, util::get_bitmap_len};
use anchor_lang::prelude::*;

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
Expand All @@ -17,7 +17,7 @@ pub struct InitializeLazyTransactionsV0<'info> {
#[account(
init,
payer = payer,
space = 8 + 60 + std::mem::size_of::<LazyTransactionsV0>(),
space = 8 + 60 + std::mem::size_of::<LazyTransactionsV0>() + get_bitmap_len(args.max_depth),
seeds = ["lazy_transactions".as_bytes(), args.name.as_bytes()],
bump,
)]
Expand Down Expand Up @@ -50,6 +50,7 @@ pub fn handler(
canopy: ctx.accounts.canopy.key(),
max_depth: args.max_depth,
bump_seed: ctx.bumps["lazy_transactions"],
executed: vec![0; get_bitmap_len(args.max_depth)],
});

Ok(())
Expand Down
4 changes: 4 additions & 0 deletions programs/lazy-transactions/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
pub mod close_canopy_v0;
pub mod close_marker_v0;
pub mod execute_transaction_v0;
pub mod initialize_lazy_transactions_v0;
pub mod reinitialize_executed_transactions_v0;
pub mod set_canopy_v0;
pub mod update_lazy_transactions_v0;

pub use close_canopy_v0::*;
pub use close_marker_v0::*;
pub use execute_transaction_v0::*;
pub use initialize_lazy_transactions_v0::*;
pub use reinitialize_executed_transactions_v0::*;
pub use set_canopy_v0::*;
pub use update_lazy_transactions_v0::*;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct UpdateLazyTransactionsV0<'info> {
mut,
owner = id(),
constraint = canopy.key() == lazy_transactions.canopy || canopy.data.borrow()[0] == 0,
constraint = check_canopy_bytes(&canopy.data.borrow()[1..]).is_ok(),
)]
pub canopy: AccountInfo<'info>,
}
Expand Down
29 changes: 29 additions & 0 deletions programs/lazy-transactions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anchor_lang::prelude::*;
#[cfg(not(feature = "no-entrypoint"))]
use {default_env::default_env, solana_security_txt::security_txt};

declare_id!("1atrmQs3eq1N2FEYWu6tyTXbCjP4uQwExpjtnhXtS8h");

Expand All @@ -7,10 +9,27 @@ pub mod error;
pub mod instructions;
pub mod merkle_proof;
pub mod state;
pub mod util;

pub use instructions::*;
pub use state::*;

#[cfg(not(feature = "no-entrypoint"))]
security_txt! {
name: "Lazy Transactions",
project_url: "http://helium.com",
contacts: "email:hello@helium.foundation",
policy: "https://github.com/helium/helium-program-library/tree/master/SECURITY.md",


// Optional Fields
preferred_languages: "en",
source_code: "https://github.com/helium/helium-program-library/tree/master/programs/lazy-transactions",
source_revision: default_env!("GITHUB_SHA", ""),
source_release: default_env!("GITHUB_REF_NAME", ""),
auditors: "Sec3"
}

#[program]
pub mod lazy_transactions {
use super::*;
Expand All @@ -33,6 +52,10 @@ pub mod lazy_transactions {
close_marker_v0::handler(ctx, args)
}

pub fn close_canopy_v0(ctx: Context<CloseCanopyV0>) -> Result<()> {
close_canopy_v0::handler(ctx)
}

pub fn update_lazy_transactions_v0(
ctx: Context<UpdateLazyTransactionsV0>,
args: UpdateLazyTransactionsArgsV0,
Expand All @@ -43,4 +66,10 @@ pub mod lazy_transactions {
pub fn set_canopy_v0(ctx: Context<SetCanopyV0>, args: SetCanopyArgsV0) -> Result<()> {
set_canopy_v0::handler(ctx, args)
}

pub fn reinitialize_executed_transactions_v0(
ctx: Context<ReinitializeExecutedTransactionsV0>,
) -> Result<()> {
reinitialize_executed_transactions_v0::handler(ctx)
}
}
2 changes: 2 additions & 0 deletions programs/lazy-transactions/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct LazyTransactionsV0 {
pub authority: Pubkey,
pub canopy: Pubkey,
pub bump_seed: u8,
// Bitmap of executed transactions
pub executed: Vec<u8>,
}

#[account]
Expand Down

0 comments on commit 46b3cdf

Please sign in to comment.