|  | 
| 1 | 1 | use dlp::args::{CallHandlerArgs, CommitDiffArgs, CommitStateArgs}; | 
|  | 2 | +use solana_account::ReadableAccount; | 
| 2 | 3 | use solana_pubkey::Pubkey; | 
| 3 |  | -use solana_sdk::instruction::{AccountMeta, Instruction}; | 
|  | 4 | +use solana_rpc_client::rpc_client::RpcClient; | 
|  | 5 | +use solana_sdk::{ | 
|  | 6 | +    commitment_config::CommitmentConfig, | 
|  | 7 | +    instruction::{AccountMeta, Instruction}, | 
|  | 8 | +}; | 
| 4 | 9 | 
 | 
| 5 | 10 | #[cfg(test)] | 
| 6 | 11 | use crate::tasks::TaskStrategy; | 
| 7 |  | -use crate::tasks::{ | 
| 8 |  | -    buffer_task::{BufferTask, BufferTaskType}, | 
| 9 |  | -    visitor::Visitor, | 
| 10 |  | -    BaseActionTask, BaseTask, BaseTaskError, BaseTaskResult, CommitTask, | 
| 11 |  | -    FinalizeTask, PreparationState, TaskType, UndelegateTask, | 
|  | 12 | +use crate::{ | 
|  | 13 | +    config::ChainConfig, | 
|  | 14 | +    diff::compute_diff, | 
|  | 15 | +    tasks::{ | 
|  | 16 | +        buffer_task::{BufferTask, BufferTaskType}, | 
|  | 17 | +        visitor::Visitor, | 
|  | 18 | +        BaseActionTask, BaseTask, BaseTaskError, BaseTaskResult, CommitTask, | 
|  | 19 | +        FinalizeTask, PreparationState, TaskType, UndelegateTask, | 
|  | 20 | +    }, | 
|  | 21 | +    ComputeBudgetConfig, | 
| 12 | 22 | }; | 
| 13 | 23 | 
 | 
| 14 | 24 | /// Task that will be executed on Base layer via arguments | 
| @@ -59,44 +69,64 @@ impl BaseTask for ArgsTask { | 
| 59 | 69 |                     args, | 
| 60 | 70 |                 ) | 
| 61 | 71 |             } | 
| 62 |  | -            // algo: | 
| 63 |  | -            // - delegated_account, prev | 
| 64 |  | -            // - changed delegated_account | 
| 65 |  | -            // - diff = prev - delegated_account | 
| 66 |  | -            // - commit | 
| 67 |  | -            // - prev = delegated_account | 
| 68 |  | -            // - update cache with prev | 
| 69 |  | -            // | 
| 70 |  | -            // relevant files/modules/crates: | 
| 71 |  | -            // - | 
| 72 |  | -            // - https://docs.rs/scc/latest/scc/#hashcache | 
| 73 |  | -            // | 
| 74 |  | -            // diff: | 
| 75 |  | -            // - [offset1][offset2]data | 
| 76 |  | -            // | 
| 77 |  | -            // 100 | 
| 78 |  | -            // | 
| 79 |  | -            // 11..15 | 
| 80 |  | -            // | 
| 81 |  | -            // 31...40 | 
| 82 |  | -            // | 
| 83 |  | -            // - complete: [2] [5][11] [10][31] [11..15 31 ..40] | 
| 84 |  | -            // | 
| 85 |  | -            // - [3][8][11..15 31 ..40] | 
| 86 |  | -            // | 
| 87 | 72 |             ArgsTaskType::CommitDiff(value) => { | 
|  | 73 | +                let chain_config = | 
|  | 74 | +                    ChainConfig::local(ComputeBudgetConfig::new(1_000_000)); | 
|  | 75 | + | 
|  | 76 | +                log::info!( | 
|  | 77 | +                    "Fetch account from the main chain: {}", | 
|  | 78 | +                    value.committed_account.pubkey | 
|  | 79 | +                ); | 
|  | 80 | +                let rpc_client = RpcClient::new_with_commitment( | 
|  | 81 | +                    chain_config.rpc_uri.to_string(), | 
|  | 82 | +                    CommitmentConfig { | 
|  | 83 | +                        commitment: chain_config.commitment, | 
|  | 84 | +                    }, | 
|  | 85 | +                ); | 
|  | 86 | + | 
|  | 87 | +                let account = match rpc_client | 
|  | 88 | +                    .get_account(&value.committed_account.pubkey) | 
|  | 89 | +                { | 
|  | 90 | +                    Ok(account) => { | 
|  | 91 | +                        log::info!("Account Found: {:?}", account); | 
|  | 92 | +                        account | 
|  | 93 | +                    } | 
|  | 94 | +                    Err(e) => { | 
|  | 95 | +                        log::error!("error while receiving account: {}", e); | 
|  | 96 | +                        let args = CommitStateArgs { | 
|  | 97 | +                            nonce: value.commit_id, | 
|  | 98 | +                            lamports: value.committed_account.account.lamports, | 
|  | 99 | +                            data: value.committed_account.account.data.clone(), | 
|  | 100 | +                            allow_undelegation: value.allow_undelegation, | 
|  | 101 | +                        }; | 
|  | 102 | +                        return dlp::instruction_builder::commit_state( | 
|  | 103 | +                            *validator, | 
|  | 104 | +                            value.committed_account.pubkey, | 
|  | 105 | +                            value.committed_account.account.owner, | 
|  | 106 | +                            args, | 
|  | 107 | +                        ); | 
|  | 108 | +                    } | 
|  | 109 | +                }; | 
|  | 110 | + | 
| 88 | 111 |                 let args = CommitDiffArgs { | 
| 89 | 112 |                     nonce: value.commit_id, | 
| 90 | 113 |                     lamports: value.committed_account.account.lamports, | 
| 91 |  | -                    diff: vec![], // compute diff for this field | 
|  | 114 | +                    diff: compute_diff( | 
|  | 115 | +                        //&vec![0; value.committed_account.account.data().len()], | 
|  | 116 | +                        account.data(), | 
|  | 117 | +                        value.committed_account.account.data(), | 
|  | 118 | +                    ), | 
| 92 | 119 |                     allow_undelegation: value.allow_undelegation, | 
| 93 | 120 |                 }; | 
| 94 |  | -                dlp::instruction_builder::commit_diff( | 
|  | 121 | +                log::info!("commit_diff: create instruction"); | 
|  | 122 | +                let ix = dlp::instruction_builder::commit_diff( | 
| 95 | 123 |                     *validator, | 
| 96 | 124 |                     value.committed_account.pubkey, | 
| 97 | 125 |                     value.committed_account.account.owner, | 
| 98 | 126 |                     args, | 
| 99 |  | -                ) | 
|  | 127 | +                ); | 
|  | 128 | +                log::info!("commit_diff: created instruction"); | 
|  | 129 | +                ix | 
| 100 | 130 |             } | 
| 101 | 131 |             ArgsTaskType::Finalize(value) => { | 
| 102 | 132 |                 dlp::instruction_builder::finalize( | 
|  | 
0 commit comments