-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from raindust/feat/executor
Implement standard transaction executor
- Loading branch information
Showing
61 changed files
with
1,061 additions
and
210 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use rollups_interface::l1::BatchInfo; | ||
use igloo_interface::l1::BatchInfo; | ||
|
||
use super::L1Hash; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use rollups_interface::l1::L1Head; | ||
use igloo_interface::l1::L1Head; | ||
|
||
use super::{L1Hash, L1Height, L1Timestamp}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use rollups_interface::l2::L2Head; | ||
use igloo_interface::l2::L2Head; | ||
|
||
use super::{L2Hash, L2Height, L2Timestamp}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "igloo-executor" | ||
version.workspace = true | ||
authors.workspace = true | ||
repository.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
igloo-interface = { workspace = true } | ||
igloo-storage = { workspace = true } | ||
igloo-validator = { workspace = true } | ||
tempfile = { workspace = true } | ||
|
||
thiserror = { workspace = true } | ||
tokio = { workspace = true } | ||
log = { workspace = true } | ||
crossbeam-channel = { workspace = true } | ||
|
||
solana-ledger = { workspace = true } | ||
solana-accounts-db = { workspace = true } | ||
solana-sdk = { workspace = true } | ||
solana-svm = { workspace = true } | ||
solana-runtime = { workspace = true } | ||
solana-core = { workspace = true } | ||
|
||
[dev-dependencies] | ||
anyhow = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use solana_sdk::transaction::SanitizedTransaction; | ||
|
||
pub struct BlockPayload { | ||
pub transactions: Vec<SanitizedTransaction>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use crate::{ | ||
defs::BlockPayload, | ||
processor::{bank::BankProcessor, Processor}, | ||
Result, | ||
}; | ||
use igloo_interface::l2::{bank::BankOperations, storage::StorageOperations}; | ||
use igloo_storage::{ | ||
blockstore::txs::CommitBatch, config::GlobalConfig, ledger::SlotInfo, RollupStorage, | ||
}; | ||
use igloo_validator::{ | ||
settings::{Settings, Switchs}, | ||
BankValidator, TransactionChecks, | ||
}; | ||
use solana_sdk::clock::Slot; | ||
use std::{borrow::Cow, path::Path}; | ||
|
||
pub mod storage; | ||
|
||
pub struct Engine { | ||
storage: RollupStorage, | ||
finalized: Slot, | ||
validator_settings: Settings, | ||
} | ||
|
||
impl Engine { | ||
pub fn new(ledger_path: &Path) -> Result<Self> { | ||
let mut config = GlobalConfig::new(ledger_path)?; | ||
config.keypairs.set_default_path(ledger_path); | ||
Self::new_with_config(config) | ||
} | ||
|
||
pub fn new_for_test(ledger_path: &Path) -> Result<Self> { | ||
let config = GlobalConfig::new_temp(&ledger_path)?; | ||
Self::new_with_config(config) | ||
} | ||
|
||
pub fn new_with_config(config: GlobalConfig) -> Result<Self> { | ||
let settings = Settings { | ||
max_age: 150, // set default max_age from solana | ||
switchs: Switchs { | ||
tx_sanity_check: true, | ||
txs_conflict_check: true, | ||
}, | ||
}; | ||
Self::new_with_validator_settings(config, settings) | ||
} | ||
|
||
pub fn new_with_validator_settings( | ||
config: GlobalConfig, | ||
validator_settings: Settings, | ||
) -> Result<Self> { | ||
let mut storage = RollupStorage::new(config)?; | ||
storage.init()?; | ||
|
||
let finalized = storage.get_root(); | ||
Ok(Self { | ||
storage, | ||
finalized, | ||
validator_settings, | ||
}) | ||
} | ||
|
||
pub async fn close(self) -> Result<()> { | ||
self.storage.close().await?; | ||
Ok(()) | ||
} | ||
|
||
/// Check the block before processing | ||
pub fn check_block(&self, block: &BlockPayload, settins: Option<Switchs>) -> Result<()> { | ||
let switchs = settins.unwrap_or(self.validator_settings.switchs.clone()); | ||
let validator = BankValidator::new(self.storage.current_bank(), Default::default()); | ||
if switchs.tx_sanity_check { | ||
validator.transactions_sanity_check(&block.transactions)?; | ||
} | ||
if switchs.txs_conflict_check { | ||
validator.transactions_conflict_check(&block.transactions)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub async fn new_block(&mut self, block: BlockPayload) -> Result<SlotInfo> { | ||
self.storage.bump()?; | ||
|
||
let processor = | ||
BankProcessor::new(self.storage.current_bank(), self.validator_settings.clone()); | ||
let results = processor.process(Cow::Borrowed(&block.transactions))?; | ||
self.storage | ||
.commit( | ||
results.into(), | ||
CommitBatch::new(Cow::Borrowed(&block.transactions)), | ||
) | ||
.await?; | ||
|
||
let info = self.storage.get_slot_info(self.storage.current_height())?; | ||
info!("New block: {:?}", info); | ||
Ok(info) | ||
} | ||
|
||
pub fn confirm(&mut self, block: Slot) -> Result<()> { | ||
self.storage.confirm(block)?; | ||
Ok(()) | ||
} | ||
|
||
pub fn reorg(&mut self, reset_to: Slot) -> Result<()> { | ||
self.storage.reorg(reset_to, Some(self.finalized))?; | ||
Ok(()) | ||
} | ||
|
||
pub fn finalize(&mut self, block: Slot) -> Result<()> { | ||
self.storage.set_root(block, None)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use igloo_storage::RollupStorage; | ||
|
||
use super::Engine; | ||
|
||
impl Engine { | ||
pub fn store(&self) -> &RollupStorage { | ||
&self.storage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use thiserror::Error; | ||
|
||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
StorageError(#[from] igloo_storage::Error), | ||
|
||
#[error(transparent)] | ||
ValidatorError(#[from] igloo_validator::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pub mod defs; | ||
pub mod engine; | ||
pub mod error; | ||
pub mod processor; | ||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub use { | ||
engine::Engine, | ||
error::{Error, Result}, | ||
}; | ||
|
||
#[macro_use] | ||
extern crate log; |
Oops, something went wrong.