mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-17 13:39:39 +00:00
wip
This commit is contained in:
parent
f96f4d9117
commit
7f075fcdd3
@ -12,6 +12,8 @@ use mempool::MemPool;
|
|||||||
use sequencer_store::SequecerChainStore;
|
use sequencer_store::SequecerChainStore;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::sequencer_store::block_store::block_to_transactions_map;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod sequencer_store;
|
pub mod sequencer_store;
|
||||||
|
|
||||||
@ -53,19 +55,39 @@ impl SequencerCore {
|
|||||||
initial_commitments.push(comm);
|
initial_commitments.push(comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
let store = SequecerChainStore::new_with_genesis(
|
||||||
store: SequecerChainStore::new_with_genesis(
|
&config.home,
|
||||||
&config.home,
|
config.genesis_id,
|
||||||
config.genesis_id,
|
config.is_genesis_random,
|
||||||
config.is_genesis_random,
|
&config.initial_accounts,
|
||||||
&config.initial_accounts,
|
&initial_commitments,
|
||||||
&initial_commitments,
|
nssa::PrivateKey::try_new(config.signing_key).unwrap(),
|
||||||
nssa::PrivateKey::try_new(config.signing_key).unwrap(),
|
);
|
||||||
),
|
|
||||||
|
let mut block_id = config.genesis_id;
|
||||||
|
|
||||||
|
let mut this = Self {
|
||||||
|
store,
|
||||||
mempool: MemPool::default(),
|
mempool: MemPool::default(),
|
||||||
chain_height: config.genesis_id,
|
chain_height: config.genesis_id,
|
||||||
sequencer_config: config,
|
sequencer_config: config,
|
||||||
|
};
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let Ok(block) = this.store.block_store.get_block_at_id(block_id) else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
for encoded_transaction in block.body.transactions {
|
||||||
|
let transaction = NSSATransaction::try_from(&encoded_transaction).unwrap();
|
||||||
|
let transaction = this.transaction_pre_check(transaction).unwrap();
|
||||||
|
this.execute_check_transaction_on_state(transaction).unwrap();
|
||||||
|
this.store.block_store.tx_hash_to_block_map.insert(encoded_transaction.hash(), block_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
block_id +=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transaction_pre_check(
|
pub fn transaction_pre_check(
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use storage::RocksDBIO;
|
|||||||
pub struct SequecerBlockStore {
|
pub struct SequecerBlockStore {
|
||||||
dbio: RocksDBIO,
|
dbio: RocksDBIO,
|
||||||
// TODO: Consider adding the hashmap to the database for faster recovery.
|
// TODO: Consider adding the hashmap to the database for faster recovery.
|
||||||
tx_hash_to_block_map: HashMap<HashType, u64>,
|
pub tx_hash_to_block_map: HashMap<HashType, u64>,
|
||||||
pub genesis_id: u64,
|
pub genesis_id: u64,
|
||||||
pub signing_key: nssa::PrivateKey,
|
pub signing_key: nssa::PrivateKey,
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ impl SequecerBlockStore {
|
|||||||
HashMap::new()
|
HashMap::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
let dbio = RocksDBIO::new(location, genesis_block)?;
|
let dbio = RocksDBIO::open_or_create(location, genesis_block)?;
|
||||||
|
|
||||||
let genesis_id = dbio.get_meta_first_block_in_db()?;
|
let genesis_id = dbio.get_meta_first_block_in_db()?;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ impl SequecerBlockStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_to_transactions_map(block: &Block) -> HashMap<HashType, u64> {
|
pub(crate) fn block_to_transactions_map(block: &Block) -> HashMap<HashType, u64> {
|
||||||
block
|
block
|
||||||
.body
|
.body
|
||||||
.transactions
|
.transactions
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use block_store::SequecerBlockStore;
|
use block_store::SequecerBlockStore;
|
||||||
use common::block::HashableBlockData;
|
use common::{block::HashableBlockData, transaction::{self, NSSATransaction}};
|
||||||
use nssa::{self, Address};
|
use nssa::{self, Address};
|
||||||
use rand::{RngCore, rngs::OsRng};
|
use rand::{RngCore, rngs::OsRng};
|
||||||
|
|
||||||
use crate::config::AccountInitialData;
|
use crate::{config::AccountInitialData, sequencer_store::block_store::block_to_transactions_map};
|
||||||
|
|
||||||
pub mod block_store;
|
pub mod block_store;
|
||||||
|
|
||||||
@ -39,21 +39,11 @@ impl SequecerChainStore {
|
|||||||
this
|
this
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut data = [0; 32];
|
|
||||||
let mut prev_block_hash = [0; 32];
|
|
||||||
|
|
||||||
if is_genesis_random {
|
|
||||||
OsRng.fill_bytes(&mut data);
|
|
||||||
OsRng.fill_bytes(&mut prev_block_hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
let curr_time = chrono::Utc::now().timestamp_millis() as u64;
|
|
||||||
|
|
||||||
let hashable_data = HashableBlockData {
|
let hashable_data = HashableBlockData {
|
||||||
block_id: genesis_id,
|
block_id: genesis_id,
|
||||||
transactions: vec![],
|
transactions: vec![],
|
||||||
prev_block_hash,
|
prev_block_hash: [0; 32],
|
||||||
timestamp: curr_time,
|
timestamp: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let genesis_block = hashable_data.into_block(&signing_key);
|
let genesis_block = hashable_data.into_block(&signing_key);
|
||||||
@ -67,6 +57,7 @@ impl SequecerChainStore {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
Self { state, block_store }
|
Self { state, block_store }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ path = "../sequencer_rpc"
|
|||||||
|
|
||||||
[dependencies.sequencer_core]
|
[dependencies.sequencer_core]
|
||||||
path = "../sequencer_core"
|
path = "../sequencer_core"
|
||||||
|
features = ["testnet"]
|
||||||
|
|
||||||
[dependencies.common]
|
[dependencies.common]
|
||||||
path = "../common"
|
path = "../common"
|
||||||
|
|||||||
@ -44,7 +44,7 @@ pub struct RocksDBIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RocksDBIO {
|
impl RocksDBIO {
|
||||||
pub fn new(path: &Path, start_block: Option<Block>) -> DbResult<Self> {
|
pub fn open_or_create(path: &Path, start_block: Option<Block>) -> DbResult<Self> {
|
||||||
let mut cf_opts = Options::default();
|
let mut cf_opts = Options::default();
|
||||||
cf_opts.set_max_write_buffer_number(16);
|
cf_opts.set_max_write_buffer_number(16);
|
||||||
//ToDo: Add more column families for different data
|
//ToDo: Add more column families for different data
|
||||||
@ -74,7 +74,6 @@ impl RocksDBIO {
|
|||||||
let block_id = block.header.block_id;
|
let block_id = block.header.block_id;
|
||||||
dbio.put_meta_first_block_in_db(block)?;
|
dbio.put_meta_first_block_in_db(block)?;
|
||||||
dbio.put_meta_is_first_block_set()?;
|
dbio.put_meta_is_first_block_set()?;
|
||||||
|
|
||||||
dbio.put_meta_last_block_in_db(block_id)?;
|
dbio.put_meta_last_block_in_db(block_id)?;
|
||||||
|
|
||||||
Ok(dbio)
|
Ok(dbio)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user