Skip to content

Commit

Permalink
Remove unused comments, imports. Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sviatoslav-alekseev committed Apr 27, 2023
1 parent d0f1f07 commit fd641ad
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 540 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ members = [
"sdk",
"sdk/cargo-build-bpf",
"sdk/cargo-test-bpf",
"sdk/cargo-build-sbf",
"sdk/gen-headers",
"send-transaction-service",
"sortition",
Expand Down
18 changes: 6 additions & 12 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ fn get_default_program_keypair(program_location: &Option<String>) -> Keypair {
}

/// Deploy using upgradeable loader
// process_program_deploy
#[allow(clippy::too_many_arguments)]
fn process_program_deploy(
rpc_client: Arc<RpcClient>,
Expand Down Expand Up @@ -859,7 +858,6 @@ fn process_program_deploy(
.get_account_with_commitment(&program_pubkey, config.commitment)?
.value
{
dbg!(&account.owner, wasm_loader_upgradeable::id(), &program_pubkey);
if account.owner != wasm_loader_upgradeable::id() {
return Err(format!(
"Account {} is not an upgradeable program or already in use",
Expand Down Expand Up @@ -922,8 +920,7 @@ fn process_program_deploy(
};

let (program_data, program_len) = if let Some(program_location) = program_location {
// read_and_verify_elf
// TODO(dev): Allow both ELF & WASM
// TODO(Dev): Allow both ELF & WASM
// let program_data = read_and_verify_elf(program_location)?;
let program_data = read_and_verify_wasm(program_location)?;
let program_len = program_data.len();
Expand All @@ -934,7 +931,6 @@ fn process_program_deploy(
.get_account_with_commitment(&buffer_pubkey, config.commitment)?
.value
{
dbg!(&account.owner);
if !wasm_loader_upgradeable::check_id(&account.owner) {
return Err(format!(
"Buffer account {buffer_pubkey} is not owned by the BPF Upgradeable Loader",
Expand Down Expand Up @@ -1913,7 +1909,6 @@ fn do_process_program_write_and_deploy(
)?;
}

// send_deploy_messages
send_deploy_messages(
rpc_client,
config,
Expand Down Expand Up @@ -2075,7 +2070,6 @@ fn do_process_program_upgrade(
Ok(config.output_format.formatted_string(&program_id))
}

// read_and_verify_elf
fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
let mut file = File::open(program_location)
.map_err(|err| format!("Unable to open program file: {}", err))?;
Expand All @@ -2094,13 +2088,13 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
},
register_syscalls(&mut invoke_context, true).unwrap(),
)
.map_err(|err| format!("ELF error: {}", err)).unwrap();
.map_err(|err| format!("ELF error: {}", err))?;

let _ =
VerifiedExecutable::<RequisiteVerifier, BpfError, ThisInstructionMeter>::from_executable(
executable,
)
.map_err(|err| format!("ELF error: {}", err)).unwrap();
.map_err(|err| format!("ELF error: {}", err))?;

Ok(program_data)
}
Expand All @@ -2111,10 +2105,11 @@ fn read_and_verify_wasm(program_location: &str) -> Result<Vec<u8>, Box<dyn std::
let mut program_data = Vec::new();
file.read_to_end(&mut program_data)
.map_err(|err| format!("Unable to read program file: {}", err))?;

// TODO(Dev): move WASM register_syscalls here
// let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
// let mut invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);

// TODO(dev): register syscalls for WASM
let engine = wasmi::Engine::default();
let _module = wasmi::Module::new(&engine, &mut &program_data[..]).expect("Binary should be valid WASM");

Expand Down Expand Up @@ -2289,8 +2284,7 @@ fn send_deploy_messages(
..RpcSendTransactionConfig::default()
},
)
// Error: Deploying program failed: Error processing Instruction 1: invalid account data for instruction
.map_err(|e| format!("Deploying program failed: {}", e)).unwrap();
.map_err(|e| format!("Deploying program failed: {}", e))?;
}
}

Expand Down
1 change: 0 additions & 1 deletion core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ impl ClusterInfoVoteListener {
)
}


fn listen_and_confirm_votes(
gossip_vote_txs_receiver: &VerifiedVoteTransactionsReceiver,
vote_tracker: &VoteTracker,
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn builtin_feature_transitions() -> Vec<BuiltinFeatureTransition> {
}

pub(crate) fn get(bpf_jit: bool) -> Builtins {
dbg!(Builtins {
Builtins {
genesis_builtins: genesis_builtins(bpf_jit),
feature_transitions: builtin_feature_transitions(),
})
}
}
43 changes: 4 additions & 39 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use {
domichain_measure::measure::Measure,
domichain_sdk::{
account::{AccountSharedData, ReadableAccount},
// bpf_loader_upgradeable::{self, UpgradeableLoaderState},
wasm_loader_upgradeable::{self, UpgradeableLoaderState},
wasm_loader_upgradeable,
feature_set::{
cap_accounts_data_len, record_instruction_in_transaction_context_push,
tx_wide_compute_cap, FeatureSet,
Expand Down Expand Up @@ -137,7 +136,6 @@ impl TransactionExecutor {
}

/// Compute meter
#[derive(Debug)]
pub struct ComputeMeter {
remaining: u64,
}
Expand Down Expand Up @@ -168,7 +166,7 @@ impl ComputeMeter {
}

/// Based loosely on the unstable std::alloc::Alloc trait
pub trait Alloc: Debug {
pub trait Alloc {
fn alloc(&mut self, layout: Layout) -> Result<u64, AllocErr>;
fn dealloc(&mut self, addr: u64, layout: Layout);
}
Expand All @@ -187,7 +185,6 @@ impl fmt::Display for AllocErr {
note = "Please use InstructionContext instead of StackFrame"
)]
#[allow(deprecated)]
#[derive(Debug)]
pub struct StackFrame<'a> {
pub number_of_program_accounts: usize,
pub keyed_accounts: Vec<KeyedAccount<'a>>,
Expand Down Expand Up @@ -215,15 +212,13 @@ impl<'a> StackFrame<'a> {
}
}

#[derive(Debug)]
struct SyscallContext {
check_aligned: bool,
check_size: bool,
orig_account_lengths: Vec<usize>,
allocator: Rc<RefCell<dyn Alloc>>,
}

#[derive(Debug)]
pub struct InvokeContext<'a> {
pub transaction_context: &'a mut TransactionContext,
#[allow(deprecated)]
Expand Down Expand Up @@ -487,8 +482,7 @@ impl<'a> InvokeContext<'a> {
for account_index in program_indices.iter() {
self.transaction_context
.get_account_at_index(*account_index)
.inspect_err(|x| { dbg!(x); })
?
.inspect_err(|x| { dbg!(x); })?
.try_borrow_mut()
.map_err(|_| InstructionError::AccountBorrowOutstanding)?;
}
Expand Down Expand Up @@ -809,7 +803,7 @@ impl<'a> InvokeContext<'a> {
}
let mut program_indices = vec![];
if borrowed_program_account.get_owner() == &wasm_loader_upgradeable::id() {
if let UpgradeableLoaderState::Program {
if let wasm_loader_upgradeable::UpgradeableLoaderState::Program {
programdata_address,
} = borrowed_program_account.get_state()?
{
Expand Down Expand Up @@ -837,7 +831,6 @@ impl<'a> InvokeContext<'a> {
}
program_indices.push(borrowed_program_account.get_index_in_transaction());

// program_indices
Ok((instruction_accounts, program_indices))
}

Expand All @@ -861,12 +854,6 @@ impl<'a> InvokeContext<'a> {
.unwrap_or_else(|| Ok(native_loader::id()))
.inspect_err(|x| { dbg!(x); })?;

// if format!("{program_id}") != "Vote111111111111111111111111111111111111111" {
// dbg!(&program_id);
// dbg!(&program_indices);
// dbg!(&self.transaction_context);
// }

let nesting_level = self
.transaction_context
.get_instruction_context_stack_height();
Expand Down Expand Up @@ -910,7 +897,6 @@ impl<'a> InvokeContext<'a> {
.set_return_data(program_id, Vec::new())
.inspect_err(|x| { dbg!(x); })?;
let pre_remaining_units = self.compute_meter.borrow().get_remaining();
// process_executable_chain
let execution_result = self
.process_executable_chain()
.inspect_err(|x| { dbg!(x); });
Expand Down Expand Up @@ -958,7 +944,6 @@ impl<'a> InvokeContext<'a> {
}

/// Calls the instruction's program entrypoint method
// process_executable_chain
fn process_executable_chain(&mut self) -> Result<(), InstructionError> {
let instruction_context = self.transaction_context
.get_current_instruction_context()
Expand All @@ -977,16 +962,6 @@ impl<'a> InvokeContext<'a> {
}
};

// if format!("{builtin_id}") != "Vote111111111111111111111111111111111111111" {
// dbg!(builtin_id);
// dbg!(&instruction_context);
// dbg!(&self.transaction_context);
// dbg!(
// &instruction_context
// .try_borrow_program_account(self.transaction_context, 0)
// );
// }

for entry in self.builtin_programs {
if entry.program_id == builtin_id {
let program_id =
Expand All @@ -996,14 +971,6 @@ impl<'a> InvokeContext<'a> {
let logger = self.get_log_collector();
stable_log::program_invoke(&logger, &program_id, self.get_stack_height());

// if format!("{}", &entry.program_id) != "Vote111111111111111111111111111111111111111" {
// // dbg!(&instruction_context);
// // dbg!(&self.transaction_context);
// dbg!(&self.builtin_programs);
// dbg!(&entry, &first_instruction_account);
// // dbg!(std::thread::current().id());
// // dbg!(std::time::SystemTime::now());
// }
return (entry.process_instruction)(first_instruction_account, self)
.inspect_err(|x| { dbg!(x, &entry, &first_instruction_account); })
.map(|()| {
Expand Down Expand Up @@ -1215,7 +1182,6 @@ pub fn with_mock_invoke_context<R, F: FnMut(&mut InvokeContext) -> R>(
}];
let preparation =
prepare_mock_invoke_context(transaction_accounts, instruction_accounts, &program_indices);
dbg!(&preparation.transaction_accounts);
let mut transaction_context = TransactionContext::new(
preparation.transaction_accounts,
ComputeBudget::default().max_invoke_depth.saturating_add(1),
Expand Down Expand Up @@ -1246,7 +1212,6 @@ pub fn mock_process_instruction(
preparation
.transaction_accounts
.push((*loader_id, processor_account));
dbg!(&preparation.transaction_accounts);
let mut transaction_context = TransactionContext::new(
preparation.transaction_accounts,
ComputeBudget::default().max_invoke_depth.saturating_add(1),
Expand Down
1 change: 0 additions & 1 deletion program-runtime/src/log_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{cell::RefCell, rc::Rc};

const LOG_MESSAGES_BYTES_LIMIT: usize = 10 * 1000;

#[derive(Debug)]
pub struct LogCollector {
messages: Vec<String>,
bytes_written: usize,
Expand Down
Loading

0 comments on commit fd641ad

Please sign in to comment.