Skip to content

Commit

Permalink
FIX: using readOnly rocksdb in olavm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Softcloud88 committed Feb 2, 2024
1 parent 41f962f commit 77ed71a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
25 changes: 25 additions & 0 deletions core/src/storage/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ impl RocksDB {
}
}

pub fn new_read_only<P: AsRef<Path>>(database: Database, path: P, tune_options: bool) -> Self {
let options = Self::rocksdb_options(tune_options);
let db = match database {
Database::MerkleTree => {
let cfs = MerkleTreeColumnFamily::all().iter().map(|cf| {
ColumnFamilyDescriptor::new(cf.to_string(), Self::rocksdb_options(tune_options))
});
DB::open_cf_descriptors_read_only(&options, path, cfs, false)
.expect("failed to init rocksdb")
}
Database::Sequencer => {
let cfs = SequencerColumnFamily::all().iter().map(|cf| {
ColumnFamilyDescriptor::new(cf.to_string(), Self::rocksdb_options(tune_options))
});
DB::open_cf_descriptors_read_only(&options, path, cfs, false)
.expect("failed to init rocksdb")
}
};

Self {
db,
_registry_entry: RegistryEntry::new(),
}
}

fn rocksdb_options(tune_options: bool) -> Options {
let mut options = Options::default();
options.create_missing_column_families(true);
Expand Down
2 changes: 1 addition & 1 deletion mini-ola/src/subcommands/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Invoke {
tx_hash: [0; 4].map(|n| GoldilocksField::from_canonical_u64(n)),
};

let mut vm = OlaVM::new(
let mut vm = OlaVM::new_local(
tree_db_path_buf.as_path(),
state_db_path_buf.as_path(),
tx_init_info,
Expand Down
26 changes: 24 additions & 2 deletions zk-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct OlaVM {
}

impl OlaVM {
pub fn new(tree_db_path: &Path, state_db_path: &Path, ctx_info: TxCtxInfo) -> Self {
pub fn new_local(tree_db_path: &Path, state_db_path: &Path, ctx_info: TxCtxInfo) -> Self {
// let acc_db = RocksDB::new(Database::MerkleTree, tree_db_path, false);
// let account_tree = AccountTree::new(acc_db);
let state_db = RocksDB::new(Database::Sequencer, state_db_path, false);
Expand All @@ -72,10 +72,32 @@ impl OlaVM {
}
}

pub fn new(tree_db_path: &Path, state_db_path: &Path, ctx_info: TxCtxInfo) -> Self {
// let acc_db = RocksDB::new(Database::MerkleTree, tree_db_path, false);
// let account_tree = AccountTree::new(acc_db);
let state_db = RocksDB::new_read_only(Database::Sequencer, state_db_path, false);

let ola_state = NodeState::new(
Contracts {
contracts: HashMap::new(),
},
StateStorage { db: state_db },
ZkHasher::default(),
);

OlaVM {
ola_state,
// account_tree,
process_ctx: Vec::new(),
ctx_info,
is_call: false,
}
}

pub fn new_call(tree_db_path: &Path, state_db_path: &Path, ctx_info: TxCtxInfo) -> Self {
// let acc_db = RocksDB::new(Database::MerkleTree, tree_db_path, false);
// let account_tree = AccountTree::new(acc_db);
let state_db = RocksDB::new(Database::Sequencer, state_db_path, false);
let state_db = RocksDB::new_read_only(Database::Sequencer, state_db_path, false);
let ola_state = NodeState::new(
Contracts {
contracts: HashMap::new(),
Expand Down

0 comments on commit 77ed71a

Please sign in to comment.